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 | end |
---|
15 | |
---|
16 | function P.createLevelList() |
---|
17 | P.levelList = {} |
---|
18 | P.itemList = {} |
---|
19 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")) |
---|
20 | listbox:resetList() |
---|
21 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
22 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
23 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
24 | local index = 0 |
---|
25 | local level = nil |
---|
26 | while index < size do |
---|
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 |
---|
34 | end |
---|
35 | --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename. |
---|
36 | --table.sort(levelList) |
---|
37 | for k,v in pairs(P.levelList) do |
---|
38 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
39 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
40 | listbox:addItem(item) |
---|
41 | if v:getXMLFilename() == preselect then |
---|
42 | listbox:setItemSelectState(item, true) |
---|
43 | end |
---|
44 | P.itemList[k] = listbox:getListboxItemFromIndex(k-1) |
---|
45 | orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription()) |
---|
46 | end |
---|
47 | end |
---|
48 | |
---|
49 | function P.SingleplayerStartButton_clicked(e) |
---|
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 |
---|
60 | end |
---|
61 | end |
---|
62 | |
---|
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 |
---|
70 | end |
---|
71 | |
---|
72 | function P.SingleplayerBackButton_clicked(e) |
---|
73 | hideMenuSheet(P.name) |
---|
74 | end |
---|
75 | |
---|
76 | return P |
---|
77 | |
---|