[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 |
---|
[8079] | 16 | P:setButton(1, 1, { |
---|
[7689] | 17 | ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"), |
---|
[8079] | 18 | ["callback"] = P.SingleplayerStartButton_clicked |
---|
| 19 | }) |
---|
[7689] | 20 | |
---|
[8079] | 21 | P:setButton(1, 2, { |
---|
[7689] | 22 | ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"), |
---|
[8079] | 23 | ["callback"] = P.SingleplayerBackButton_clicked |
---|
| 24 | }) |
---|
[7648] | 25 | end |
---|
| 26 | |
---|
[8079] | 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 | |
---|
[7648] | 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() |
---|
[6363] | 45 | local index = 0 |
---|
[7648] | 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 |
---|
[6363] | 55 | end |
---|
[7648] | 56 | for k,v in pairs(P.levelList) do |
---|
| 57 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
[6746] | 58 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
[7648] | 59 | listbox:addItem(item) |
---|
| 60 | if v:getXMLFilename() == preselect then |
---|
[6363] | 61 | listbox:setItemSelectState(item, true) |
---|
| 62 | end |
---|
[7648] | 63 | P.itemList[k] = listbox:getListboxItemFromIndex(k-1) |
---|
| 64 | orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription()) |
---|
[6363] | 65 | end |
---|
| 66 | end |
---|
| 67 | |
---|
| 68 | function P.SingleplayerStartButton_clicked(e) |
---|
[7648] | 69 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")) |
---|
| 70 | local choice = listbox:getFirstSelectedItem() |
---|
| 71 | if choice ~= nil then |
---|
| 72 | local index = listbox:getItemIndex(choice) |
---|
| 73 | local level = P.levelList[index+1] |
---|
| 74 | if level ~= nil then |
---|
[7876] | 75 | orxonox.execute("startGame " .. level:getXMLFilename()) |
---|
[7648] | 76 | hideAllMenuSheets() |
---|
| 77 | end |
---|
[6363] | 78 | end |
---|
| 79 | end |
---|
| 80 | |
---|
[7648] | 81 | function P.SingleplayerShowAll_clicked(e) |
---|
| 82 | local checkbox = tolua.cast(winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox"), "CEGUI::Checkbox") |
---|
| 83 | local show = checkbox:isSelected() |
---|
| 84 | if show ~= P.showAll then |
---|
| 85 | P.showAll = show |
---|
| 86 | P.createLevelList() |
---|
| 87 | end |
---|
| 88 | end |
---|
| 89 | |
---|
[6363] | 90 | function P.SingleplayerBackButton_clicked(e) |
---|
[6746] | 91 | hideMenuSheet(P.name) |
---|
[6363] | 92 | end |
---|
| 93 | |
---|
| 94 | return P |
---|
| 95 | |
---|