1 | -- HighscoreMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("HighscoreMenu") |
---|
4 | |
---|
5 | P.scrollbarWidth = 13 |
---|
6 | P.nameList = {} |
---|
7 | P.scoreList = {} |
---|
8 | P.linesList = {} |
---|
9 | |
---|
10 | P.sampleWindow = nil |
---|
11 | |
---|
12 | P.lineHeight = 0 |
---|
13 | P.playerWidth = 0 |
---|
14 | P.editboxWidth = 0 |
---|
15 | P.resetWidth = 0 |
---|
16 | P.spaceWidth = 0 |
---|
17 | |
---|
18 | function P.onLoad() |
---|
19 | P.nameList = {} |
---|
20 | table.insert(P.nameList, "firsttestPlayer") |
---|
21 | table.insert(P.nameList, "secondtestPlayer") |
---|
22 | P.scoreList = {} |
---|
23 | table.insert(P.scoreList, 120) |
---|
24 | table.insert(P.scoreList, 20) |
---|
25 | |
---|
26 | P.linesList = {} |
---|
27 | |
---|
28 | --Calculate design parameters: |
---|
29 | P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/SampleWindow") |
---|
30 | P.sampleWindow:setText("SampleText") |
---|
31 | |
---|
32 | -- create tabs with desired tab as argument (nil for all) |
---|
33 | |
---|
34 | P.createFilterTab("Gametypes", "gametype") |
---|
35 | P.createFilterTab("Missions", "mission") |
---|
36 | --P.createFilterTab("Minigames", "minigame") |
---|
37 | --P.createFilterTab("Showcases", "showcase") |
---|
38 | --P.createFilterTab("Presentations", "presentation") |
---|
39 | --P.createFilterTab("Tests", "test") |
---|
40 | --P.createFilterTab("Show All", nil) |
---|
41 | |
---|
42 | -- update description and screenshot boxes |
---|
43 | --P.SingleplayerSelectionChanged() |
---|
44 | |
---|
45 | local size = getMinTextSize(P.sampleWindow) |
---|
46 | P.lineHeight = size[1] |
---|
47 | |
---|
48 | P.playerWidth = 0 |
---|
49 | for k,v in pairs(P.scoreList) do |
---|
50 | P.sampleWindow:setText(P.nameList[k]) |
---|
51 | size = getMinTextSize(P.sampleWindow) |
---|
52 | if size[2] > P.playerWidth then |
---|
53 | P.playerWidth = size[2] |
---|
54 | end |
---|
55 | end |
---|
56 | |
---|
57 | P.sampleWindow:setText("reset") |
---|
58 | size = getMinTextSize(P.sampleWindow) |
---|
59 | P.resetWidth = size[2]+20 |
---|
60 | |
---|
61 | P.spaceWidth = 10 |
---|
62 | |
---|
63 | local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane") |
---|
64 | size = pane:getViewableArea() |
---|
65 | |
---|
66 | P.editboxWidth = size:getWidth() - P.playerWidth - P.resetWidth - 5*P.spaceWidth |
---|
67 | |
---|
68 | P.createLines() |
---|
69 | |
---|
70 | P:setButton(1, 1, { |
---|
71 | ["button"] = winMgr:getWindow("orxonox/HighscoreBackButton"), |
---|
72 | ["callback"] = P.HighscoreBackButton_clicked |
---|
73 | }) |
---|
74 | end |
---|
75 | |
---|
76 | function P.onShow() |
---|
77 | --local description = winMgr:getWindow("orxonox/HighscoreText") |
---|
78 | |
---|
79 | --height = getStaticTextWindowHeight(description) |
---|
80 | --description:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -P.scrollbarWidth), CEGUI.UDim(0.0, height))) |
---|
81 | end |
---|
82 | function P.createFilterTab(name, tag) |
---|
83 | -- create unique tab window name |
---|
84 | local tabName = "orxonox/HighscoreLevelTab" |
---|
85 | if tag ~= nil then |
---|
86 | tabName = tabName..tag |
---|
87 | end |
---|
88 | |
---|
89 | |
---|
90 | -- create new tab window with desired name |
---|
91 | local default = CEGUI.toListbox(winMgr:createWindow("DefaultWindow", tabName)) |
---|
92 | default:setText(name) |
---|
93 | |
---|
94 | local tabControl = winMgr:getWindow("orxonox/HighscoreTabControl") |
---|
95 | orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".HighscoreSelectionChanged") |
---|
96 | --if listbox:getItemCount() > 0 then |
---|
97 | tabControl:addChildWindow(tabName) |
---|
98 | --end |
---|
99 | |
---|
100 | |
---|
101 | end |
---|
102 | |
---|
103 | function P.HighscoreGetSelectedLevel() |
---|
104 | -- choose the active listbox |
---|
105 | local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/HighscoreTabControl")) |
---|
106 | local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) |
---|
107 | local choice = listbox:getFirstSelectedItem() |
---|
108 | if choice ~= nil then |
---|
109 | -- get the right tab and the right index |
---|
110 | local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1] |
---|
111 | local index = tabIndexes[listbox:getItemIndex(choice)+1] |
---|
112 | return P.levelList[index] |
---|
113 | else |
---|
114 | return nil |
---|
115 | end |
---|
116 | end |
---|
117 | |
---|
118 | function P.HighscoreSelectionChanged(e) |
---|
119 | local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane") |
---|
120 | pane:moveToFront() |
---|
121 | --[[local levelDescription = winMgr:getWindow("orxonox/SingleplayerLevelDescription") |
---|
122 | local configButton = winMgr:getWindow("orxonox/SingleplayerConfigButton") |
---|
123 | local level = P.HighscoreGetSelectedLevel() |
---|
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", "") |
---|
139 | levelDescription:setText("") |
---|
140 | configButton:setProperty("Disabled", "True") |
---|
141 | end --]] |
---|
142 | end |
---|
143 | |
---|
144 | function P.createLine(k,tag) |
---|
145 | |
---|
146 | local tabName = k |
---|
147 | |
---|
148 | if tag ~= nil then |
---|
149 | tabName = tabName..tag |
---|
150 | end |
---|
151 | |
---|
152 | -- content window for the entire line |
---|
153 | local line = winMgr:createWindow("DefaultWindow", "orxonox/HighscoreMenuPane/Score" .. tabName) |
---|
154 | line:setHeight(CEGUI.UDim(0, P.lineHeight)) |
---|
155 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1)))) |
---|
156 | |
---|
157 | local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane") |
---|
158 | local half = (pane:getViewableArea()):getWidth() * 0.5 |
---|
159 | local offset = half * 0.01 |
---|
160 | -- config name |
---|
161 | local player = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/HighscoreMenuPane/Score" .. tabName .. "/Player") |
---|
162 | player:setText(P.nameList[k]) |
---|
163 | player:setSize(CEGUI.UVector2(CEGUI.UDim(0, half-offset), CEGUI.UDim(1, 0))) |
---|
164 | player:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) |
---|
165 | line:addChildWindow(player) |
---|
166 | |
---|
167 | |
---|
168 | -- config value (editable) |
---|
169 | |
---|
170 | local playerValue = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/HighscoreMenuPane/Score" .. tabName .. "/Value") |
---|
171 | --playerValue:setProperty("ReadOnly", "set:False") |
---|
172 | --local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])SS |
---|
173 | playerValue:setText(P.scoreList[k]) |
---|
174 | playerValue:setSize(CEGUI.UVector2(CEGUI.UDim(0, half-offset), CEGUI.UDim(1, 0))) |
---|
175 | playerValue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, half+offset), CEGUI.UDim(0, 0))) |
---|
176 | -- enable the reset button if the value changed |
---|
177 | orxonox.GUIManager:subscribeEventHelper(playerValue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted") |
---|
178 | line:addChildWindow(playerValue) |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | line:setWidth(CEGUI.UDim(0, 2*half)) |
---|
183 | |
---|
184 | return line |
---|
185 | end |
---|
186 | |
---|
187 | function P.createLines() |
---|
188 | local window = winMgr:getWindow("orxonox/HighscoreMenuPane") |
---|
189 | |
---|
190 | for k,v in pairs(P.scoreList) do |
---|
191 | local line = P.createLine(k,nil) |
---|
192 | table.insert(P.linesList, line) |
---|
193 | window:addChildWindow(line) |
---|
194 | end |
---|
195 | |
---|
196 | local pane = tolua.cast(window, "CEGUI::ScrollablePane") |
---|
197 | pane:setVerticalStepSize(getScrollingStepSize(window)) |
---|
198 | end |
---|
199 | |
---|
200 | |
---|
201 | function P.HighscoreBackButton_clicked(e) |
---|
202 | hideMenuSheet(P.name) |
---|
203 | end |
---|
204 | |
---|
205 | return P |
---|
206 | |
---|