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