Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/data/gui/scripts/GraphicsMenu.lua @ 8022

Last change on this file since 8022 was 8022, checked in by landauf, 13 years ago

added RealTimer, a subclass of Timer which is not affected by the game's time factor
added "delayreal" command which works like "delay" but uses RealTimer instead of Timer

in the graphics menu, the resolution confirmation popup now also closes itself after 10 seconds if it is used ingame while the game is paused

  • Property svn:eol-style set to native
File size: 15.4 KB
Line 
1-- GraphicsMenu.lua
2
3local P = createMenuSheet("GraphicsMenu")
4
5P.resolutionList = {"custom", "640 x 480", "720 x 480", "720 x 576", "800 x 600", "1024 x 600", "1024 x 768", "1152 x 864", "1280 x 720", "1280 x 800", "1280 x 960", "1280 x 1024", "1360 x 768", "1440 x 900", "1600 x 900", "1600 x 1200", "1680 x 1050"}
6P.schemeList = {"TaharezGreen", "Orxonox"}
7P.fsaaList = {"0", "2", "4", "8", "8 [Quality]"}
8P.particleLodList = {"None", "Low", "Normal", "High"}
9
10function P:onLoad()
11    -------------------
12    -- Button matrix --
13    -------------------
14
15    P:setButton(1, 1, {
16            ["button"] = winMgr:getWindow("orxonox/GraphicsOkButton"),
17            ["callback"]  = P.callback_Ok_Clicked
18    })
19
20    P:setButton(1, 2, {
21            ["button"] = winMgr:getWindow("orxonox/GraphicsCancelButton"),
22            ["callback"]  = P.callback_Cancel_Clicked
23    })
24
25    -- place apply button at the bottom in the matrix, even though it's in fact at the top, to make the OK button highlighted by default
26    P:setButton(2, 1, {
27            ["button"] = winMgr:getWindow("orxonox/Display/Resolution/Apply"),
28            ["callback"]  = P.callback_Apply_Clicked
29    })
30
31    -----------------
32    -- Combo boxes --
33    -----------------
34
35    -- resolution combobox
36    local resolutionCombobox = winMgr:getWindow("orxonox/Display/Resolution/Combobox")
37    CEGUI.toCombobox(resolutionCombobox):setReadOnly(true)
38
39    for k,v in pairs(P.resolutionList) do
40        local item = CEGUI.createListboxTextItem(v)
41        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
42        resolutionCombobox:addItem(item)
43    end
44
45    -- themes combobox
46    local themeCombobox = winMgr:getWindow("orxonox/Display/Theme/Combobox")
47    CEGUI.toCombobox(themeCombobox):setReadOnly(true)
48
49    for k,v in pairs(P.schemeList) do
50        local item = CEGUI.createListboxTextItem(v)
51        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
52        themeCombobox:addItem(item)
53    end
54
55    -- fsaa combobox
56    local fsaaCombobox = winMgr:getWindow("orxonox/Display/More/FSAA")
57    CEGUI.toCombobox(fsaaCombobox):setReadOnly(true)
58
59    for k,v in pairs(P.fsaaList) do
60        local item = CEGUI.createListboxTextItem(v)
61        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
62        fsaaCombobox:addItem(item)
63    end
64
65    -- particle lod combobox
66    local particleLodCombobox = winMgr:getWindow("orxonox/Settings/ParticleLodCombobox")
67    CEGUI.toCombobox(particleLodCombobox):setReadOnly(true)
68
69    for k,v in pairs(P.particleLodList) do
70        local item = CEGUI.createListboxTextItem(v)
71        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
72        particleLodCombobox:addItem(item)
73    end
74end
75
76function P:onShow()
77    -----------------
78    -- Display tab --
79    -----------------
80
81    -- fullscreen checkbox / resolution combobox / resolution editboxes
82    self:onWindowResized()
83
84    -- apply button
85    self.updateApplyButton()
86
87    -- aspect ratio editbox
88    local aspectRatioEditbox = winMgr:getWindow("orxonox/Display/Resolution/AspectRatio")
89    local currentAspectRatio = orxonox.CommandExecutor:query("getConfig Camera aspectRatio_")
90    aspectRatioEditbox:setText(currentAspectRatio)
91
92    -- themes combobox
93    local themeCombobox = winMgr:getWindow("orxonox/Display/Theme/Combobox")
94    local currentTheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_")
95
96    for i = 0, themeCombobox:getDropList():getItemCount() - 1 do
97        local item = themeCombobox:getListboxItemFromIndex(i)
98        themeCombobox:setItemSelectState(item, (item:getText() == currentTheme))
99    end
100
101    -- vsync checkbox
102    local vsyncCheckbox = winMgr:getWindow("orxonox/Display/More/VSync")
103    local hasVSync = orxonox.GraphicsManager:getInstance():hasVSyncEnabled()
104    CEGUI.toCheckbox(vsyncCheckbox):setSelected(hasVSync)
105
106    -- fsaa combobox
107    local fsaaCombobox = winMgr:getWindow("orxonox/Display/More/FSAA")
108    local currentFSAAMode = orxonox.GraphicsManager:getInstance():getFSAAMode()
109
110    for i = 0, fsaaCombobox:getDropList():getItemCount() - 1 do
111        local item = fsaaCombobox:getListboxItemFromIndex(i)
112        fsaaCombobox:setItemSelectState(item, (item:getText() == currentFSAAMode))
113    end
114
115    -- notice
116    self:updateRedLabel()
117
118    ------------------
119    -- Settings tab --
120    ------------------
121
122    -- fov editbox
123    local fovEditbox = winMgr:getWindow("orxonox/Settings/Fov")
124    local currentFov = orxonox.CommandExecutor:query("getConfig Camera fov_")
125    fovEditbox:setText(currentFov)
126
127    -- fps limit editbox
128    local fpsEditbox = winMgr:getWindow("orxonox/Settings/FpsLimit")
129    local currentFpsLimit = orxonox.CommandExecutor:query("getConfig GraphicsSettings fpsLimit")
130    fpsEditbox:setText(currentFpsLimit)
131
132    -- particle lod combobox
133    local particleLodCombobox = winMgr:getWindow("orxonox/Settings/ParticleLodCombobox")
134    local currentParticleLod = orxonox.CommandExecutor:query("getConfig GraphicsSettings particlesDetailLevel")
135
136    if currentParticleLod == "" then
137        particleLodCombobox:disable()
138    else
139        particleLodCombobox:enable()
140
141        for i = 0, particleLodCombobox:getDropList():getItemCount() - 1 do
142            local item = particleLodCombobox:getListboxItemFromIndex(i)
143            particleLodCombobox:setItemSelectState(item, (tostring(i) == currentParticleLod))
144        end
145    end
146
147    -- model lod checkbox
148    local modelLodCheckbox = winMgr:getWindow("orxonox/Settings/ModelLodCheckbox")
149    local hasModelLod = orxonox.CommandExecutor:query("getConfig GraphicsSettings enableModelLoD")
150    if hasModelLod == "true" then
151        hasModelLod = true
152    elseif hasModelLod == "false" then
153        hasModelLod = false
154    end
155    CEGUI.toCheckbox(modelLodCheckbox):setSelected(hasModelLod)
156
157    -- motion blur checkbox
158    local motionBlurCheckbox = winMgr:getWindow("orxonox/Settings/MotionBlurCheckbox")
159    local hasMotionBlur = orxonox.CommandExecutor:query("getConfig GraphicsSettings enableMotionBlur")
160    if hasMotionBlur == "true" then
161        hasMotionBlur = true
162    elseif hasMotionBlur == "false" then
163        hasMotionBlur = false
164    end
165    CEGUI.toCheckbox(motionBlurCheckbox):setSelected(hasMotionBlur)
166end
167
168function P:onWindowResized()
169    -- fullscreen checkbox
170    local fullscreenCheckbox = winMgr:getWindow("orxonox/Display/Resolution/Fullscreen")
171    local isFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
172    CEGUI.toCheckbox(fullscreenCheckbox):setSelected(isFullscreen)
173
174    -- resolution combobox
175    local resolutionCombobox = winMgr:getWindow("orxonox/Display/Resolution/Combobox")
176
177    local currentWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
178    local currentHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
179    local currentResolution = currentWidth .. " x " .. currentHeight
180
181    for i = 0, resolutionCombobox:getDropList():getItemCount() - 1 do
182        local item = resolutionCombobox:getListboxItemFromIndex(i)
183        resolutionCombobox:setItemSelectState(item, item:getText() == currentResolution)
184    end
185
186    -- resolution editboxes
187    self.updateResolutionEditboxes()
188end
189
190----------------------
191-- Helper functions --
192----------------------
193
194-- updates the text of the resolution checkboxes and checks if they should be enabled (only if the "custom" resolution was selected)
195function P.updateResolutionEditboxes()
196    -- resolution combobox
197    local resolutionCombobox = winMgr:getWindow("orxonox/Display/Resolution/Combobox")
198
199    local currentWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
200    local currentHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
201
202    -- resolution editboxes
203    local widthEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxWidth")
204    local heightEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxHeight")
205    widthEditbox:disable()
206    heightEditbox:disable()
207
208    -- selected combobox item
209    local item = resolutionCombobox:getSelectedItem()
210    if item then
211        local itemText = item:getText()
212        if itemText ~= "custom" then
213            currentWidth = string.sub(itemText, 1, string.find(itemText, "x") - 2)
214            currentHeight = string.sub(itemText, string.find(itemText, "x") + 2)
215        else
216            widthEditbox:enable()
217            heightEditbox:enable()
218        end
219    end
220
221    widthEditbox:setText(currentWidth)
222    heightEditbox:setText(currentHeight)
223end
224
225-- checks if the apply button should be enabled or disabled (only enabled if the current settings are different from the selected values)
226function P.updateApplyButton()
227    -- fullscreen checkbox
228    local fullscreenCheckbox = winMgr:getWindow("orxonox/Display/Resolution/Fullscreen")
229    local isFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
230    local fullscreenChanged = (isFullscreen ~= CEGUI.toCheckbox(fullscreenCheckbox):isSelected())
231
232    -- resolution editboxes
233    local widthEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxWidth")
234    local heightEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxHeight")
235    local currentWidth = tostring(orxonox.GraphicsManager:getInstance():getWindowWidth())
236    local currentHeight = tostring(orxonox.GraphicsManager:getInstance():getWindowHeight())
237    local widthChanged = (currentWidth ~= widthEditbox:getText())
238    local heightChanged = (currentHeight ~= heightEditbox:getText())
239    local resolutionEditboxesEnabled = not widthEditbox:isDisabled()
240
241    -- apply button
242    local applyButton = winMgr:getWindow("orxonox/Display/Resolution/Apply")
243
244    if fullscreenChanged or widthChanged or heightChanged or resolutionEditboxesEnabled then
245        applyButton:enable()
246    else
247        applyButton:disable()
248    end
249end
250
251function P.updateRedLabel()
252    -- theme
253    local themeCombobox = winMgr:getWindow("orxonox/Display/Theme/Combobox")
254    local currentTheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_")
255    local themeChanged = (currentTheme ~= themeCombobox:getText())
256
257    -- vsync
258    local vsyncCheckbox = winMgr:getWindow("orxonox/Display/More/VSync")
259    local hasVSync = orxonox.GraphicsManager:getInstance():hasVSyncEnabled()
260    local vsyncChanged = (hasVSync ~= CEGUI.toCheckbox(vsyncCheckbox):isSelected())
261
262    -- fsaa
263    local fsaaCombobox = winMgr:getWindow("orxonox/Display/More/FSAA")
264    local currentFSAAMode = orxonox.GraphicsManager:getInstance():getFSAAMode()
265    local fsaaChanged = (currentFSAAMode ~= fsaaCombobox:getText())
266
267    local needRestart = themeChanged or vsyncChanged or fsaaChanged
268
269    local notice = winMgr:getWindow("orxonox/Display/Notice")
270    notice:setVisible(not needRestart)
271    local noticeRed = winMgr:getWindow("orxonox/Display/NoticeRed")
272    noticeRed:setVisible(needRestart)
273end
274
275---------------------
276-- Event callbacks --
277---------------------
278
279-- resolution
280
281function P.callback_FullscreenCheckbox_CheckStateChanged(e)
282    P.updateApplyButton()
283end
284
285function P.callback_ResolutionCombobox_ListSelectionAccepted(e)
286    P.updateResolutionEditboxes()
287end
288
289function P.callback_ResolutionEditboxWidth_TextChanged(e)
290    P.updateApplyButton()
291end
292
293function P.callback_ResolutionEditboxHeight_TextChanged(e)
294    P.updateApplyButton()
295end
296
297-- theme
298
299function P.callback_ThemeCombobox_ListSelectionAccepted(e)
300    P.updateRedLabel()
301end
302
303-- vsync
304
305function P.callback_VSyncCheckbox_CheckStateChanged(e)
306    P.updateRedLabel()
307end
308
309-- fsaa
310
311function P.callback_FSAACombobox_ListSelectionAccepted(e)
312    P.updateRedLabel()
313end
314
315-- buttons
316
317function P.callback_Apply_Clicked(e)
318    -- resolution
319    local fullscreenCheckbox = winMgr:getWindow("orxonox/Display/Resolution/Fullscreen")
320    local checkedFullscreen = tostring(CEGUI.toCheckbox(fullscreenCheckbox):isSelected())
321
322    local widthEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxWidth")
323    local heightEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxHeight")
324
325    -- start revert timer
326    P.oldWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
327    P.oldHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
328    P.oldFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
329
330    P.revertTimerHandle = orxonox.CommandExecutor:query("delayreal 10 \"hideGUI DecisionPopup; GraphicsManager setScreenResolution " .. P.oldWidth .. " " .. P.oldHeight .. " " .. tostring(P.oldFullscreen) .. "\"")
331
332    -- change settings
333    orxonox.CommandExecutor:execute("GraphicsManager setScreenResolution " .. widthEditbox:getText() .. " " .. heightEditbox:getText() .. " " .. checkedFullscreen)
334
335    P.updateApplyButton()
336
337    -- prompt for confirmation
338    openDecisionPopup("Do you want to keep these settings? (Settings will be reverted in 10 seconds if not accepted)", GraphicsMenu.callback_ApplyDecisionPopup)
339end
340
341function P.callback_ApplyDecisionPopup(pressedOK)
342    orxonox.CommandExecutor:execute("killdelay " .. P.revertTimerHandle)
343
344    if not pressedOK then
345        orxonox.CommandExecutor:execute("GraphicsManager setScreenResolution " .. P.oldWidth .. " " .. P.oldHeight .. " " .. tostring(P.oldFullscreen))
346        P:onShow()
347    end
348end
349
350function P.callback_Ok_Clicked(e)
351    -- aspect ratio
352    local aspectRatioEditbox = winMgr:getWindow("orxonox/Display/Resolution/AspectRatio")
353    orxonox.CommandExecutor:execute("config Camera aspectRatio_ " .. aspectRatioEditbox:getText())
354
355    -- theme
356    local themeCombobox = winMgr:getWindow("orxonox/Display/Theme/Combobox")
357    orxonox.CommandExecutor:execute("config GUIManager guiScheme_ " .. themeCombobox:getText())
358
359    -- vsync
360    local vsyncCheckbox = winMgr:getWindow("orxonox/Display/More/VSync")
361    local hasVSync = orxonox.GraphicsManager:getInstance():hasVSyncEnabled()
362    if hasVSync ~= CEGUI.toCheckbox(vsyncCheckbox):isSelected() then
363        orxonox.CommandExecutor:execute("GraphicsManager setVSync " .. tostring(CEGUI.toCheckbox(vsyncCheckbox):isSelected()))
364    end
365
366    -- fsaa
367    local fsaaCombobox = winMgr:getWindow("orxonox/Display/More/FSAA")
368    local currentFSAAMode = orxonox.GraphicsManager:getInstance():getFSAAMode()
369    if currentFSAAMode ~= fsaaCombobox:getText() then
370        orxonox.CommandExecutor:execute("GraphicsManager setFSAA {" .. fsaaCombobox:getText() .. "}") -- enclose argument in { ... } because it can contain [brackets] (conflicts with tcl)
371    end
372
373    -- fov
374    local fovEditbox = winMgr:getWindow("orxonox/Settings/Fov")
375    orxonox.CommandExecutor:execute("config Camera fov_ " .. fovEditbox:getText())
376
377    -- fps limit
378    local fpsEditbox = winMgr:getWindow("orxonox/Settings/FpsLimit")
379    orxonox.CommandExecutor:execute("config GraphicsSettings fpsLimit " .. fpsEditbox:getText())
380
381    -- particle lod
382    local particleLodCombobox = winMgr:getWindow("orxonox/Settings/ParticleLodCombobox")
383    local item = particleLodCombobox:getSelectedItem()
384    if item then
385        orxonox.CommandExecutor:execute("config GraphicsSettings particlesDetailLevel " .. particleLodCombobox:getItemIndex(item))
386    end
387
388    -- model lod
389    local modelLodCheckbox = winMgr:getWindow("orxonox/Settings/ModelLodCheckbox")
390    orxonox.CommandExecutor:execute("config GraphicsSettings enableModelLoD " .. tostring(CEGUI.toCheckbox(modelLodCheckbox):isSelected()))
391
392    -- motion blur
393    local motionBlurCheckbox = winMgr:getWindow("orxonox/Settings/MotionBlurCheckbox")
394    orxonox.CommandExecutor:execute("config GraphicsSettings enableMotionBlur " .. tostring(CEGUI.toCheckbox(motionBlurCheckbox):isSelected()))
395
396    hideMenuSheet(P.name)
397end
398
399function P.callback_Cancel_Clicked(e)
400    hideMenuSheet(P.name)
401end
402
403return P
404
Note: See TracBrowser for help on using the repository browser.