1 | -- SingleplayerMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("SingleplayerMenu") |
---|
4 | P.loadAlong = {"ShipSelectionMenu"} |
---|
5 | P.levelList = {} |
---|
6 | P.activeTabIndexes = {} |
---|
7 | P.scrollbarWidth = 13 |
---|
8 | selectedlevel = {} -- level for ship selection |
---|
9 | |
---|
10 | function P.onLoad() |
---|
11 | P.createLevelList() |
---|
12 | |
---|
13 | -- create tabs with desired tab as argument (nil for all) |
---|
14 | P.createFilterTab("Gametypes", "gametype") |
---|
15 | P.createFilterTab("Missions", "mission") |
---|
16 | P.createFilterTab("Minigames", "minigame") |
---|
17 | P.createFilterTab("Showcases", "showcase") |
---|
18 | P.createFilterTab("Presentations", "presentation") |
---|
19 | P.createFilterTab("Tests", "test") |
---|
20 | P.createFilterTab("Show All", nil) |
---|
21 | |
---|
22 | -- update description and screenshot boxes |
---|
23 | P.SingleplayerSelectionChanged() |
---|
24 | |
---|
25 | --buttons are arranged in a 1x3 matrix |
---|
26 | P:setButton(1, 1, { |
---|
27 | ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"), |
---|
28 | ["callback"] = P.SingleplayerStartButton_clicked |
---|
29 | }) |
---|
30 | |
---|
31 | P:setButton(1, 2, { |
---|
32 | ["button"] = winMgr:getWindow("orxonox/SingleplayerConfigButton"), |
---|
33 | ["callback"] = P.SingleplayerConfigButton_clicked |
---|
34 | }) |
---|
35 | |
---|
36 | P:setButton(1, 3, { |
---|
37 | ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"), |
---|
38 | ["callback"] = P.SingleplayerBackButton_clicked |
---|
39 | }) |
---|
40 | end |
---|
41 | |
---|
42 | function P.createLevelList() |
---|
43 | P.levelList = {} |
---|
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 and level:getXMLFilename() ~= "_temp.oxw") then |
---|
50 | --os.execute("echo " .. level:getXMLFilename() .." >> ~/outputorx") |
---|
51 | local levelXMLFilename = level:getXMLFilename() |
---|
52 | -- create an imageset for each screenshot |
---|
53 | local imageName = level:getScreenshot() |
---|
54 | if imageName ~= "" then |
---|
55 | CEGUI.ImagesetManager:getSingleton():createFromImageFile(levelXMLFilename..imageName, imageName) |
---|
56 | else |
---|
57 | CEGUI.ImagesetManager:getSingleton():createFromImageFile(levelXMLFilename..imageName, "noscreenshot.png") |
---|
58 | end |
---|
59 | table.insert(P.levelList, level) |
---|
60 | end |
---|
61 | index = index + 1 |
---|
62 | end |
---|
63 | end |
---|
64 | |
---|
65 | function P.createFilterTab(name, tag) |
---|
66 | -- create unique tab window name |
---|
67 | local tabName = "orxonox/SingleplayerLevelTab" |
---|
68 | if tag ~= nil then |
---|
69 | tabName = tabName..tag |
---|
70 | end |
---|
71 | -- create new tab window with desired name |
---|
72 | local listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName)) |
---|
73 | listbox:setText(name) |
---|
74 | listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}") |
---|
75 | listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}") |
---|
76 | -- fill listbox with items |
---|
77 | listbox:resetList() |
---|
78 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
79 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
80 | local tabIndexes = {} |
---|
81 | for k,v in pairs(P.levelList) do |
---|
82 | -- only add level if it has desired tag |
---|
83 | if tag == nil or v:hasTag(tag) then |
---|
84 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
85 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
86 | listbox:addItem(item) |
---|
87 | table.insert(tabIndexes, k) |
---|
88 | if v:getXMLFilename() == preselect then |
---|
89 | listbox:setItemSelectState(item, true) |
---|
90 | end |
---|
91 | orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription()) |
---|
92 | end |
---|
93 | end |
---|
94 | table.insert(P.activeTabIndexes, tabIndexes) |
---|
95 | -- listen to selection changes |
---|
96 | orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".SingleplayerSelectionChanged") |
---|
97 | local tabControl = winMgr:getWindow("orxonox/SingleplayerTabControl") |
---|
98 | orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".SingleplayerSelectionChanged") |
---|
99 | if listbox:getItemCount() > 0 then |
---|
100 | tabControl:addChildWindow(tabName) |
---|
101 | end |
---|
102 | end |
---|
103 | |
---|
104 | function P.SingleplayerGetSelectedLevel() |
---|
105 | -- choose the active listbox |
---|
106 | local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/SingleplayerTabControl")) |
---|
107 | local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) |
---|
108 | local choice = listbox:getFirstSelectedItem() |
---|
109 | if choice ~= nil then |
---|
110 | -- get the right tab and the right index |
---|
111 | local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1] |
---|
112 | local index = tabIndexes[listbox:getItemIndex(choice)+1] |
---|
113 | return P.levelList[index] |
---|
114 | else |
---|
115 | return nil |
---|
116 | end |
---|
117 | end |
---|
118 | |
---|
119 | function P.SingleplayerSelectionChanged(e) |
---|
120 | local levelImage = winMgr:getWindow("orxonox/SingleplayerLevelImage") |
---|
121 | local levelDescription = winMgr:getWindow("orxonox/SingleplayerLevelDescription") |
---|
122 | local configButton = winMgr:getWindow("orxonox/SingleplayerConfigButton") |
---|
123 | local level = P.SingleplayerGetSelectedLevel() |
---|
124 | if level ~= nil then |
---|
125 | local levelXMLFilename = level:getXMLFilename() |
---|
126 | local imageName = level:getScreenshot() |
---|
127 | -- set the screenshot and the description for the selected level |
---|
128 | levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image") |
---|
129 | levelDescription:setText(level:getDescription()) |
---|
130 | -- only enable config button for "gametype" levels |
---|
131 | if level:hasTag("gametype") then |
---|
132 | configButton:setProperty("Disabled", "False") |
---|
133 | else |
---|
134 | configButton:setProperty("Disabled", "True") |
---|
135 | end |
---|
136 | else |
---|
137 | -- also take care of "no level selected" |
---|
138 | levelImage:setProperty("Image", nil) |
---|
139 | levelDescription:setText("") |
---|
140 | configButton:setProperty("Disabled", "True") |
---|
141 | end |
---|
142 | end |
---|
143 | |
---|
144 | function P.SingleplayerStartButton_clicked(e) |
---|
145 | selectedlevel = P.SingleplayerGetSelectedLevel() |
---|
146 | if selectedlevel ~= nil then |
---|
147 | if selectedlevel:hasTag("shipselection") then |
---|
148 | local shipSelectionMenu = showMenuSheet("ShipSelectionMenu", true) |
---|
149 | shipSelectionMenu:update() |
---|
150 | else |
---|
151 | orxonox.execute("startGame " .. selectedlevel:getXMLFilename()) |
---|
152 | hideAllMenuSheets() |
---|
153 | end |
---|
154 | end |
---|
155 | end |
---|
156 | |
---|
157 | function P.SingleplayerConfigButton_clicked(e) |
---|
158 | local level = P.SingleplayerGetSelectedLevel() |
---|
159 | if level ~= nil then |
---|
160 | local configMenu = showMenuSheet("SingleplayerConfigMenu") |
---|
161 | configMenu:loadConfig(level) |
---|
162 | end |
---|
163 | end |
---|
164 | |
---|
165 | function P.SingleplayerBackButton_clicked(e) |
---|
166 | hideMenuSheet(P.name) |
---|
167 | end |
---|
168 | |
---|
169 | return P |
---|