1 | -- SingleplayerMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("SingleplayerMenu") |
---|
4 | |
---|
5 | P.levelList = {} |
---|
6 | |
---|
7 | function P.onLoad() |
---|
8 | P.createLevelList() |
---|
9 | |
---|
10 | -- create tabs with desired tab as argument (nil for all) |
---|
11 | P.createFilterTab("Show All", nil) |
---|
12 | P.createFilterTab("Tests", "test") |
---|
13 | P.createFilterTab("Tutorials", "tutorial") |
---|
14 | P.createFilterTab("Showcases", "showcase") |
---|
15 | P.createFilterTab("SP?", "singleplayer") |
---|
16 | P.createFilterTab("Presentations", "presentation") |
---|
17 | |
---|
18 | --buttons are arranged in a 1x2 matrix |
---|
19 | P:setButton(1, 1, { |
---|
20 | ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"), |
---|
21 | ["callback"] = P.SingleplayerStartButton_clicked |
---|
22 | }) |
---|
23 | |
---|
24 | P:setButton(1, 2, { |
---|
25 | ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"), |
---|
26 | ["callback"] = P.SingleplayerBackButton_clicked |
---|
27 | }) |
---|
28 | end |
---|
29 | |
---|
30 | function P.createLevelList() |
---|
31 | P.levelList = {} |
---|
32 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
33 | local index = 0 |
---|
34 | local level = nil |
---|
35 | while index < size do |
---|
36 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
37 | if level ~= nil then |
---|
38 | table.insert(P.levelList, level) |
---|
39 | end |
---|
40 | index = index + 1 |
---|
41 | end |
---|
42 | end |
---|
43 | |
---|
44 | function P.createFilterTab(name, tag) |
---|
45 | -- create unique tab window name |
---|
46 | local tabName = "orxonox/SingleplayerLevelListbox" |
---|
47 | if tag ~= nil then |
---|
48 | tabName = tabName..tag |
---|
49 | end |
---|
50 | -- add new tab window with desired name |
---|
51 | local tabControl = winMgr:getWindow("orxonox/SingleplayerTabControl") |
---|
52 | local newWindow = winMgr:createWindow("MenuWidgets/Listbox", tabName) |
---|
53 | newWindow:setText(name) |
---|
54 | newWindow:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}") |
---|
55 | newWindow:setProperty("UnifiedAreaRect", "{{0.05,0},{0.15,0},{0.95,0},{0.85,0}}") |
---|
56 | tabControl:addChildWindow(tabName) |
---|
57 | -- fill listbox with items |
---|
58 | local listbox = CEGUI.toListbox(newWindow) |
---|
59 | listbox:resetList() |
---|
60 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
61 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
62 | for k,v in pairs(P.levelList) do |
---|
63 | -- only add level if it has desired tag |
---|
64 | if tag == nil or v:hasTag(tag) then |
---|
65 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
66 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
67 | listbox:addItem(item) |
---|
68 | if v:getXMLFilename() == preselect then |
---|
69 | listbox:setItemSelectState(item, true) |
---|
70 | end |
---|
71 | orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription()) |
---|
72 | end |
---|
73 | end |
---|
74 | end |
---|
75 | |
---|
76 | function P.SingleplayerStartButton_clicked(e) |
---|
77 | -- choose the active listbox |
---|
78 | local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/SingleplayerTabControl")) |
---|
79 | local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) |
---|
80 | local choice = listbox:getFirstSelectedItem() |
---|
81 | if choice ~= nil then |
---|
82 | local index = listbox:getItemIndex(choice) |
---|
83 | local level = P.levelList[index+1] |
---|
84 | if level ~= nil then |
---|
85 | orxonox.execute("startGame " .. level:getXMLFilename()) |
---|
86 | hideAllMenuSheets() |
---|
87 | end |
---|
88 | end |
---|
89 | end |
---|
90 | |
---|
91 | function P.SingleplayerBackButton_clicked(e) |
---|
92 | hideMenuSheet(P.name) |
---|
93 | end |
---|
94 | |
---|
95 | return P |
---|
96 | |
---|