[6363] | 1 | -- SingleplayerMenu.lua |
---|
| 2 | |
---|
[6746] | 3 | local P = createMenuSheet("SingleplayerMenu") |
---|
[6363] | 4 | |
---|
[7648] | 5 | P.levelList = {} |
---|
| 6 | P.itemList = {} |
---|
| 7 | P.showAll = false |
---|
| 8 | |
---|
[6746] | 9 | function P.onLoad() |
---|
[7648] | 10 | local window = winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox") |
---|
| 11 | local button = tolua.cast(window,"CEGUI::Checkbox") |
---|
| 12 | button:setSelected(false) |
---|
| 13 | P.createLevelList() |
---|
[7689] | 14 | |
---|
| 15 | --buttons are arranged in a 1x2 matrix |
---|
[7922] | 16 | P:setButton(1, 1, { |
---|
[7689] | 17 | ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"), |
---|
[7922] | 18 | ["callback"] = P.SingleplayerStartButton_clicked |
---|
| 19 | }) |
---|
[7689] | 20 | |
---|
[7922] | 21 | P:setButton(1, 2, { |
---|
[7689] | 22 | ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"), |
---|
[7922] | 23 | ["callback"] = P.SingleplayerBackButton_clicked |
---|
| 24 | }) |
---|
[7648] | 25 | end |
---|
| 26 | |
---|
| 27 | function P.createLevelList() |
---|
| 28 | P.levelList = {} |
---|
| 29 | P.itemList = {} |
---|
| 30 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")) |
---|
| 31 | listbox:resetList() |
---|
| 32 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
| 33 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
| 34 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
[6363] | 35 | local index = 0 |
---|
[7648] | 36 | local level = nil |
---|
| 37 | while index < size do |
---|
| 38 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
| 39 | if level ~= nil then |
---|
| 40 | if P.showAll or not level:hasTag("test") then |
---|
| 41 | table.insert(P.levelList, level) |
---|
| 42 | end |
---|
| 43 | end |
---|
| 44 | index = index + 1 |
---|
[6363] | 45 | end |
---|
[7648] | 46 | --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename. |
---|
| 47 | --table.sort(levelList) |
---|
| 48 | for k,v in pairs(P.levelList) do |
---|
| 49 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
[6746] | 50 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
[7648] | 51 | listbox:addItem(item) |
---|
| 52 | if v:getXMLFilename() == preselect then |
---|
[6363] | 53 | listbox:setItemSelectState(item, true) |
---|
| 54 | end |
---|
[7648] | 55 | P.itemList[k] = listbox:getListboxItemFromIndex(k-1) |
---|
| 56 | orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription()) |
---|
[6363] | 57 | end |
---|
| 58 | end |
---|
| 59 | |
---|
| 60 | function P.SingleplayerStartButton_clicked(e) |
---|
[7648] | 61 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")) |
---|
| 62 | local choice = listbox:getFirstSelectedItem() |
---|
| 63 | if choice ~= nil then |
---|
| 64 | local index = listbox:getItemIndex(choice) |
---|
| 65 | local level = P.levelList[index+1] |
---|
| 66 | if level ~= nil then |
---|
[7876] | 67 | orxonox.execute("startGame " .. level:getXMLFilename()) |
---|
[7648] | 68 | hideAllMenuSheets() |
---|
| 69 | end |
---|
[6363] | 70 | end |
---|
| 71 | end |
---|
| 72 | |
---|
[7648] | 73 | function P.SingleplayerShowAll_clicked(e) |
---|
| 74 | local checkbox = tolua.cast(winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox"), "CEGUI::Checkbox") |
---|
| 75 | local show = checkbox:isSelected() |
---|
| 76 | if show ~= P.showAll then |
---|
| 77 | P.showAll = show |
---|
| 78 | P.createLevelList() |
---|
| 79 | end |
---|
| 80 | end |
---|
| 81 | |
---|
[6363] | 82 | function P.SingleplayerBackButton_clicked(e) |
---|
[6746] | 83 | hideMenuSheet(P.name) |
---|
[6363] | 84 | end |
---|
| 85 | |
---|
| 86 | return P |
---|
| 87 | |
---|