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