Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

two changes in graphics menu:

  • fsaa and vsync are only updated if they have actually changed
  • red "restart required" label is hidden again if the settings are changed back
  • Property svn:eol-style set to native
File size: 14.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    orxonox.CommandExecutor:execute("GraphicsManager setScreenResolution " .. widthEditbox:getText() .. " " .. heightEditbox:getText() .. " " .. checkedFullscreen)
326
327    P.updateApplyButton()
328end
329
330function P.callback_Ok_Clicked(e)
331    -- aspect ratio
332    local aspectRatioEditbox = winMgr:getWindow("orxonox/Display/Resolution/AspectRatio")
333    orxonox.CommandExecutor:execute("config Camera aspectRatio_ " .. aspectRatioEditbox:getText())
334
335    -- theme
336    local themeCombobox = winMgr:getWindow("orxonox/Display/Theme/Combobox")
337    orxonox.CommandExecutor:execute("config GUIManager guiScheme_ " .. themeCombobox:getText())
338
339    -- vsync
340    local vsyncCheckbox = winMgr:getWindow("orxonox/Display/More/VSync")
341    local hasVSync = orxonox.GraphicsManager:getInstance():hasVSyncEnabled()
342    if hasVSync ~= CEGUI.toCheckbox(vsyncCheckbox):isSelected() then
343        orxonox.CommandExecutor:execute("GraphicsManager setVSync " .. tostring(CEGUI.toCheckbox(vsyncCheckbox):isSelected()))
344    end
345
346    -- fsaa
347    local fsaaCombobox = winMgr:getWindow("orxonox/Display/More/FSAA")
348    local currentFSAAMode = orxonox.GraphicsManager:getInstance():getFSAAMode()
349    if currentFSAAMode ~= fsaaCombobox:getText() then
350        orxonox.CommandExecutor:execute("GraphicsManager setFSAA {" .. fsaaCombobox:getText() .. "}") -- enclose argument in { ... } because it can contain [brackets] (conflicts with tcl)
351    end
352
353    -- fov
354    local fovEditbox = winMgr:getWindow("orxonox/Settings/Fov")
355    orxonox.CommandExecutor:execute("config Camera fov_ " .. fovEditbox:getText())
356
357    -- fps limit
358    local fpsEditbox = winMgr:getWindow("orxonox/Settings/FpsLimit")
359    orxonox.CommandExecutor:execute("config GraphicsSettings fpsLimit " .. fpsEditbox:getText())
360
361    -- particle lod
362    local particleLodCombobox = winMgr:getWindow("orxonox/Settings/ParticleLodCombobox")
363    local item = particleLodCombobox:getSelectedItem()
364    if item then
365        orxonox.CommandExecutor:execute("config GraphicsSettings particlesDetailLevel " .. particleLodCombobox:getItemIndex(item))
366    end
367
368    -- model lod
369    local modelLodCheckbox = winMgr:getWindow("orxonox/Settings/ModelLodCheckbox")
370    orxonox.CommandExecutor:execute("config GraphicsSettings enableModelLoD " .. tostring(CEGUI.toCheckbox(modelLodCheckbox):isSelected()))
371
372    -- motion blur
373    local motionBlurCheckbox = winMgr:getWindow("orxonox/Settings/MotionBlurCheckbox")
374    orxonox.CommandExecutor:execute("config GraphicsSettings enableMotionBlur " .. tostring(CEGUI.toCheckbox(motionBlurCheckbox):isSelected()))
375
376    hideMenuSheet(P.name)
377end
378
379function P.callback_Cancel_Clicked(e)
380    hideMenuSheet(P.name)
381end
382
383return P
384
Note: See TracBrowser for help on using the repository browser.