| 1 | -- SingleplayerMenu.lua | 
|---|
| 2 |  | 
|---|
| 3 | local P = createMenuSheet("SingleplayerMenu") | 
|---|
| 4 |  | 
|---|
| 5 | P.levelList = {} | 
|---|
| 6 | P.itemList = {} | 
|---|
| 7 | P.showAll = false | 
|---|
| 8 |  | 
|---|
| 9 | function P.onLoad() | 
|---|
| 10 |     local window = winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox") | 
|---|
| 11 |     local button = tolua.cast(window,"CEGUI::Checkbox") | 
|---|
| 12 |     button:setSelected(false) | 
|---|
| 13 |     P.createLevelList() | 
|---|
| 14 |  | 
|---|
| 15 |     --buttons are arranged in a 1x2 matrix | 
|---|
| 16 |     P:setButton(1, 1, { | 
|---|
| 17 |             ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"), | 
|---|
| 18 |             ["callback"]  = P.SingleplayerStartButton_clicked | 
|---|
| 19 |     }) | 
|---|
| 20 |  | 
|---|
| 21 |     P:setButton(1, 2, { | 
|---|
| 22 |             ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"), | 
|---|
| 23 |             ["callback"]  = P.SingleplayerBackButton_clicked | 
|---|
| 24 |     }) | 
|---|
| 25 | end | 
|---|
| 26 |  | 
|---|
| 27 | function P.onShow() | 
|---|
| 28 |     if P.showAll ~= orxonox.GUIManager:inDevMode() then | 
|---|
| 29 |         local window = winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox") | 
|---|
| 30 |         local button = tolua.cast(window,"CEGUI::Checkbox") | 
|---|
| 31 |         P.showAll = not P.showAll | 
|---|
| 32 |         button:setSelected(P.showAll) | 
|---|
| 33 |         P.createLevelList() | 
|---|
| 34 |     end | 
|---|
| 35 | end | 
|---|
| 36 |  | 
|---|
| 37 | function P.createLevelList() | 
|---|
| 38 |     P.levelList = {} | 
|---|
| 39 |     P.itemList = {} | 
|---|
| 40 |     local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")) | 
|---|
| 41 |     listbox:resetList() | 
|---|
| 42 |     orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) | 
|---|
| 43 |     local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() | 
|---|
| 44 |     local size = orxonox.LevelManager:getInstance():getNumberOfLevels() | 
|---|
| 45 |     local index = 0 | 
|---|
| 46 |     local level = nil | 
|---|
| 47 |     while index < size do | 
|---|
| 48 |         level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) | 
|---|
| 49 |         if level ~= nil then | 
|---|
| 50 |             if P.showAll or not level:hasTag("test") then | 
|---|
| 51 |                 table.insert(P.levelList, level) | 
|---|
| 52 |             end | 
|---|
| 53 |         end | 
|---|
| 54 |         index = index + 1 | 
|---|
| 55 |     end | 
|---|
| 56 |  | 
|---|
| 57 |     for k,v in pairs(P.levelList) do | 
|---|
| 58 |         local item = CEGUI.createListboxTextItem(v:getName()) | 
|---|
| 59 |         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") | 
|---|
| 60 |         listbox:addItem(item) | 
|---|
| 61 |         if v:getXMLFilename() == preselect then | 
|---|
| 62 |             listbox:setItemSelectState(item, true) | 
|---|
| 63 |         end | 
|---|
| 64 |         P.itemList[k] = listbox:getListboxItemFromIndex(k-1) | 
|---|
| 65 |         orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription()) | 
|---|
| 66 |     end | 
|---|
| 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.execute("startGame " .. level:getXMLFilename()) | 
|---|
| 77 |             hideAllMenuSheets() | 
|---|
| 78 |         end | 
|---|
| 79 |     end | 
|---|
| 80 | end | 
|---|
| 81 |  | 
|---|
| 82 | function P.SingleplayerShowAll_clicked(e) | 
|---|
| 83 |     local checkbox = tolua.cast(winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox"), "CEGUI::Checkbox") | 
|---|
| 84 |     local show = checkbox:isSelected() | 
|---|
| 85 |     if show ~= P.showAll then | 
|---|
| 86 |         P.showAll = show | 
|---|
| 87 |         P.createLevelList() | 
|---|
| 88 |    end | 
|---|
| 89 | end | 
|---|
| 90 |  | 
|---|
| 91 | function P.SingleplayerBackButton_clicked(e) | 
|---|
| 92 |     hideMenuSheet(P.name) | 
|---|
| 93 | end | 
|---|
| 94 |  | 
|---|
| 95 | return P | 
|---|
| 96 |  | 
|---|