Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8018 was 8018, checked in by landauf, 15 years ago

added new graphics menu

  • Property svn:eol-style set to native
File size: 13.5 KB
RevLine 
[6363]1-- GraphicsMenu.lua
2
[6746]3local P = createMenuSheet("GraphicsMenu")
[6363]4
[8018]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"}
[7801]6P.schemeList = {"TaharezGreen", "Orxonox"}
[8018]7P.fsaaList = {"0", "2", "4", "8", "8 [Quality]"}
8P.particleLodList = {"None", "Low", "Normal", "High"}
[7689]9
[8018]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)
[6363]43    end
[8018]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)
[6746]51        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
[8018]52        themeCombobox:addItem(item)
[6363]53    end
[8018]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)
[6363]63    end
[7689]64
[8018]65    -- particle lod combobox
66    local particleLodCombobox = winMgr:getWindow("orxonox/Settings/ParticleLodCombobox")
67    CEGUI.toCombobox(particleLodCombobox):setReadOnly(true)
[7801]68
[8018]69    for k,v in pairs(P.particleLodList) do
70        local item = CEGUI.createListboxTextItem(v)
[7801]71        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
[8018]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 currentScheme = 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() == currentScheme))
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    local notice = winMgr:getWindow("orxonox/Display/Notice")
117    notice:setVisible(true)
118    local noticeRed = winMgr:getWindow("orxonox/Display/NoticeRed")
119    noticeRed:setVisible(false)
120
121    ------------------
122    -- Settings tab --
123    ------------------
124
125    -- fov editbox
126    local fovEditbox = winMgr:getWindow("orxonox/Settings/Fov")
127    local currentFov = orxonox.CommandExecutor:query("getConfig Camera fov_")
128    fovEditbox:setText(currentFov)
129
130    -- fps limit editbox
131    local fpsEditbox = winMgr:getWindow("orxonox/Settings/FpsLimit")
132    local currentFpsLimit = orxonox.CommandExecutor:query("getConfig GraphicsSettings fpsLimit")
133    fpsEditbox:setText(currentFpsLimit)
134
135    -- particle lod combobox
136    local particleLodCombobox = winMgr:getWindow("orxonox/Settings/ParticleLodCombobox")
137    local currentParticleLod = orxonox.CommandExecutor:query("getConfig GraphicsSettings particlesDetailLevel")
138
139    if currentParticleLod == "" then
140        particleLodCombobox:disable()
141    else
142        particleLodCombobox:enable()
143
144        for i = 0, particleLodCombobox:getDropList():getItemCount() - 1 do
145            local item = particleLodCombobox:getListboxItemFromIndex(i)
146            particleLodCombobox:setItemSelectState(item, (tostring(i) == currentParticleLod))
[7801]147        end
148    end
149
[8018]150    -- model lod checkbox
151    local modelLodCheckbox = winMgr:getWindow("orxonox/Settings/ModelLodCheckbox")
152    local hasModelLod = orxonox.CommandExecutor:query("getConfig GraphicsSettings enableModelLoD")
153    if hasModelLod == "true" then
154        hasModelLod = true
155    elseif hasModelLod == "false" then
156        hasModelLod = false
157    end
158    CEGUI.toCheckbox(modelLodCheckbox):setSelected(hasModelLod)
159
160    -- motion blur checkbox
161    local motionBlurCheckbox = winMgr:getWindow("orxonox/Settings/MotionBlurCheckbox")
162    local hasMotionBlur = orxonox.CommandExecutor:query("getConfig GraphicsSettings enableMotionBlur")
163    if hasMotionBlur == "true" then
164        hasMotionBlur = true
165    elseif hasMotionBlur == "false" then
166        hasMotionBlur = false
167    end
168    CEGUI.toCheckbox(motionBlurCheckbox):setSelected(hasMotionBlur)
[6363]169end
170
[8018]171function P:onWindowResized()
172    -- fullscreen checkbox
173    local fullscreenCheckbox = winMgr:getWindow("orxonox/Display/Resolution/Fullscreen")
174    local isFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
175    CEGUI.toCheckbox(fullscreenCheckbox):setSelected(isFullscreen)
176
177    -- resolution combobox
178    local resolutionCombobox = winMgr:getWindow("orxonox/Display/Resolution/Combobox")
179
180    local currentWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
181    local currentHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
182    local currentResolution = currentWidth .. " x " .. currentHeight
183
184    for i = 0, resolutionCombobox:getDropList():getItemCount() - 1 do
185        local item = resolutionCombobox:getListboxItemFromIndex(i)
186        resolutionCombobox:setItemSelectState(item, item:getText() == currentResolution)
[7801]187    end
[8018]188
189    -- resolution editboxes
190    self.updateResolutionEditboxes()
[7801]191end
192
[8018]193----------------------
194-- Helper functions --
195----------------------
196
197-- updates the text of the resolution checkboxes and checks if they should be enabled (only if the "custom" resolution was selected)
198function P.updateResolutionEditboxes()
199    -- resolution combobox
200    local resolutionCombobox = winMgr:getWindow("orxonox/Display/Resolution/Combobox")
201
202    local currentWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
203    local currentHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
204
205    -- resolution editboxes
206    local widthEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxWidth")
207    local heightEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxHeight")
208    widthEditbox:disable()
209    heightEditbox:disable()
210
211    -- selected combobox item
212    local item = resolutionCombobox:getSelectedItem()
213    if item then
214        local itemText = item:getText()
215        if itemText ~= "custom" then
216            currentWidth = string.sub(itemText, 1, string.find(itemText, "x") - 2)
217            currentHeight = string.sub(itemText, string.find(itemText, "x") + 2)
218        else
219            widthEditbox:enable()
220            heightEditbox:enable()
[6363]221        end
222    end
[8018]223
224    widthEditbox:setText(currentWidth)
225    heightEditbox:setText(currentHeight)
[6363]226end
227
[8018]228-- checks if the apply button should be enabled or disabled (only enabled if the current settings are different from the selected values)
229function P.updateApplyButton()
230    -- fullscreen checkbox
231    local fullscreenCheckbox = winMgr:getWindow("orxonox/Display/Resolution/Fullscreen")
232    local isFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
233    local fullscreenChanged = (isFullscreen ~= CEGUI.toCheckbox(fullscreenCheckbox):isSelected())
234
235    -- resolution editboxes
236    local widthEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxWidth")
237    local heightEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxHeight")
238    local currentWidth = tostring(orxonox.GraphicsManager:getInstance():getWindowWidth())
239    local currentHeight = tostring(orxonox.GraphicsManager:getInstance():getWindowHeight())
240    local widthChanged = (currentWidth ~= widthEditbox:getText())
241    local heightChanged = (currentHeight ~= heightEditbox:getText())
242    local resolutionEditboxesEnabled = not widthEditbox:isDisabled()
243
244    -- apply button
245    local applyButton = winMgr:getWindow("orxonox/Display/Resolution/Apply")
246
247    if fullscreenChanged or widthChanged or heightChanged or resolutionEditboxesEnabled then
248        applyButton:enable()
249    else
250        applyButton:disable()
[6363]251    end
252end
253
[8018]254function P.makeLabelRed()
255    local notice = winMgr:getWindow("orxonox/Display/Notice")
256    notice:setVisible(false)
257    local noticeRed = winMgr:getWindow("orxonox/Display/NoticeRed")
258    noticeRed:setVisible(true)
[6363]259end
260
[8018]261---------------------
262-- Event callbacks --
263---------------------
264
265-- resolution
266
267function P.callback_FullscreenCheckbox_CheckStateChanged(e)
268    P.updateApplyButton()
[6363]269end
270
[8018]271function P.callback_ResolutionCombobox_ListSelectionAccepted(e)
272    P.updateResolutionEditboxes()
273end
274
275function P.callback_ResolutionEditboxWidth_TextChanged(e)
276    P.updateApplyButton()
277end
278
279function P.callback_ResolutionEditboxHeight_TextChanged(e)
280    P.updateApplyButton()
281end
282
283-- theme
284
285function P.callback_ThemeCombobox_ListSelectionAccepted(e)
286    P.makeLabelRed()
287end
288
289-- vsync
290
291function P.callback_VSyncCheckbox_CheckStateChanged(e)
292    P.makeLabelRed()
293end
294
295-- fsaa
296
297function P.callback_FSAACombobox_ListSelectionAccepted(e)
298    P.makeLabelRed()
299end
300
301-- buttons
302
303function P.callback_Apply_Clicked(e)
304    -- resolution
305    local fullscreenCheckbox = winMgr:getWindow("orxonox/Display/Resolution/Fullscreen")
306    local checkedFullscreen = tostring(CEGUI.toCheckbox(fullscreenCheckbox):isSelected())
307
308    local widthEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxWidth")
309    local heightEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxHeight")
310
311    orxonox.CommandExecutor:execute("GraphicsManager setScreenResolution " .. widthEditbox:getText() .. " " .. heightEditbox:getText() .. " " .. checkedFullscreen)
312
313    P.updateApplyButton()
314end
315
316function P.callback_Ok_Clicked(e)
317    -- aspect ratio
318    local aspectRatioEditbox = winMgr:getWindow("orxonox/Display/Resolution/AspectRatio")
319    orxonox.CommandExecutor:execute("config Camera aspectRatio_ " .. aspectRatioEditbox:getText())
320
321    -- theme
322    local themeCombobox = winMgr:getWindow("orxonox/Display/Theme/Combobox")
323    orxonox.CommandExecutor:execute("config GUIManager guiScheme_ " .. themeCombobox:getText())
324
325    -- vsync
326    local vsyncCheckbox = winMgr:getWindow("orxonox/Display/More/VSync")
327    orxonox.CommandExecutor:execute("GraphicsManager setVSync " .. tostring(CEGUI.toCheckbox(vsyncCheckbox):isSelected()))
328
329    -- fsaa
330    local fsaaCombobox = winMgr:getWindow("orxonox/Display/More/FSAA")
331    orxonox.CommandExecutor:execute("GraphicsManager setFSAA {" .. fsaaCombobox:getText() .. "}") -- enclose argument in { ... } because it can contain [brackets] (conflicts with tcl)
332
333    -- fov
334    local fovEditbox = winMgr:getWindow("orxonox/Settings/Fov")
335    orxonox.CommandExecutor:execute("config Camera fov_ " .. fovEditbox:getText())
336
337    -- fps limit
338    local fpsEditbox = winMgr:getWindow("orxonox/Settings/FpsLimit")
339    orxonox.CommandExecutor:execute("config GraphicsSettings fpsLimit " .. fpsEditbox:getText())
340
341    -- particle lod
342    local particleLodCombobox = winMgr:getWindow("orxonox/Settings/ParticleLodCombobox")
343    local item = particleLodCombobox:getSelectedItem()
344    if item then
345        orxonox.CommandExecutor:execute("config GraphicsSettings particlesDetailLevel " .. particleLodCombobox:getItemIndex(item))
[6363]346    end
[8018]347
348    -- model lod
349    local modelLodCheckbox = winMgr:getWindow("orxonox/Settings/ModelLodCheckbox")
350    orxonox.CommandExecutor:execute("config GraphicsSettings enableModelLoD " .. tostring(CEGUI.toCheckbox(modelLodCheckbox):isSelected()))
351
352    -- motion blur
353    local motionBlurCheckbox = winMgr:getWindow("orxonox/Settings/MotionBlurCheckbox")
354    orxonox.CommandExecutor:execute("config GraphicsSettings enableMotionBlur " .. tostring(CEGUI.toCheckbox(motionBlurCheckbox):isSelected()))
355
356    hideMenuSheet(P.name)
[6363]357end
358
[8018]359function P.callback_Cancel_Clicked(e)
[6746]360    hideMenuSheet(P.name)
[6363]361end
362
363return P
364
Note: See TracBrowser for help on using the repository browser.