Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/data/gui/scripts/GraphicsMenu.lua @ 12146

Last change on this file since 12146 was 11800, checked in by landauf, 7 years ago

updated Settings.lua and all sub-menus to cegui 0.8

  • Property svn:eol-style set to native
File size: 17.2 KB
RevLine 
[6363]1-- GraphicsMenu.lua
2
[6746]3local P = createMenuSheet("GraphicsMenu")
[6363]4
[8079]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"}
[8079]7P.fsaaList = {"0", "2", "4", "8", "8 [Quality]"}
8P.particleLodList = {"None", "Low", "Normal", "High"}
[7689]9
[8079]10function P:onLoad()
11    -------------------
12    -- Button matrix --
13    -------------------
[7689]14
[8079]15    P:setButton(1, 1, {
[11800]16            ["button"] = P.window:getChild("GraphicsOkButton"),
[8079]17            ["callback"]  = P.callback_Ok_Clicked
18    })
19
20    P:setButton(1, 2, {
[11800]21            ["button"] = P.window:getChild("GraphicsCancelButton"),
[8079]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, {
[11800]27            ["button"] = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/Apply"),
[8079]28            ["callback"]  = P.callback_Apply_Clicked
29    })
30
31    -----------------
32    -- Combo boxes --
33    -----------------
34
35    -- resolution combobox
[11800]36    local resolutionCombobox = CEGUI.toCombobox(P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/Combobox"))
[9051]37    resolutionCombobox:setReadOnly(true)
[8079]38
39    for k,v in pairs(P.resolutionList) do
40        local item = CEGUI.createListboxTextItem(v)
[11795]41        item:setSelectionBrushImage(menuImageSet .. "/MultiListSelectionBrush")
[8079]42        resolutionCombobox:addItem(item)
[6363]43    end
[8079]44
45    -- themes combobox
[11800]46    local themeCombobox = CEGUI.toCombobox(P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Theme/Combobox"))
[9051]47    themeCombobox:setReadOnly(true)
[8079]48
49    for k,v in pairs(P.schemeList) do
50        local item = CEGUI.createListboxTextItem(v)
[11795]51        item:setSelectionBrushImage(menuImageSet .. "/MultiListSelectionBrush")
[8079]52        themeCombobox:addItem(item)
[6363]53    end
[8079]54
55    -- fsaa combobox
[11800]56    local fsaaCombobox = CEGUI.toCombobox(P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/More/FSAA"))
[9051]57    fsaaCombobox:setReadOnly(true)
[8079]58
59    for k,v in pairs(P.fsaaList) do
60        local item = CEGUI.createListboxTextItem(v)
[11795]61        item:setSelectionBrushImage(menuImageSet .. "/MultiListSelectionBrush")
[8079]62        fsaaCombobox:addItem(item)
[6363]63    end
[7689]64
[8079]65    -- particle lod combobox
[11800]66    local particleLodCombobox = CEGUI.toCombobox(P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/ParticleLodCombobox"))
[9051]67    particleLodCombobox:setReadOnly(true)
[7801]68
[8079]69    for k,v in pairs(P.particleLodList) do
70        local item = CEGUI.createListboxTextItem(v)
[11795]71        item:setSelectionBrushImage(menuImageSet .. "/MultiListSelectionBrush")
[8079]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
[11800]88    local aspectRatioEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/AspectRatio")
[8079]89    local currentAspectRatio = orxonox.CommandExecutor:query("getConfig Camera aspectRatio_")
90    aspectRatioEditbox:setText(currentAspectRatio)
91
92    -- themes combobox
[11800]93    local themeCombobox =  CEGUI.toCombobox(P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Theme/Combobox"))
[8079]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
[11800]102    local vsyncCheckbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/More/VSync")
[8079]103    local hasVSync = orxonox.GraphicsManager:getInstance():hasVSyncEnabled()
104    CEGUI.toCheckbox(vsyncCheckbox):setSelected(hasVSync)
105
106    -- fsaa combobox
[11800]107    local fsaaCombobox = CEGUI.toCombobox(P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/More/FSAA"))
[8079]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
[11800]123    local fovEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/Fov")
[8079]124    local currentFov = orxonox.CommandExecutor:query("getConfig Camera fov_")
125    fovEditbox:setText(currentFov)
126
127    -- fps limit editbox
[11800]128    local fpsEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/FpsLimit")
[8079]129    local currentFpsLimit = orxonox.CommandExecutor:query("getConfig GraphicsSettings fpsLimit")
130    fpsEditbox:setText(currentFpsLimit)
131
132    -- particle lod combobox
[11800]133    local particleLodCombobox = CEGUI.toCombobox(P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/ParticleLodCombobox"))
[8079]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))
[7801]144        end
145    end
146
[8079]147    -- mesh lod checkbox
[11800]148    local meshLodCheckbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/MeshLodCheckbox")
[8079]149    local hasMeshLod = orxonox.CommandExecutor:query("getConfig GraphicsSettings enableMeshLoD")
150    if hasMeshLod == "true" then
151        hasMeshLod = true
152    elseif hasMeshLod == "false" then
153        hasMeshLod = false
154    end
155    CEGUI.toCheckbox(meshLodCheckbox):setSelected(hasMeshLod)
156
157    -- motion blur checkbox
[11800]158    local motionBlurCheckbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/MotionBlurCheckbox")
[8079]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)
[6363]166end
167
[8079]168function P:onWindowResized()
169    -- fullscreen checkbox
[11800]170    local fullscreenCheckbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/Fullscreen")
[8079]171    local isFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
172    CEGUI.toCheckbox(fullscreenCheckbox):setSelected(isFullscreen)
173
174    -- resolution combobox
[11800]175    local resolutionCombobox = CEGUI.toCombobox(P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/Combobox"))
[8079]176
177    local currentWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
178    local currentHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
179
180    if P.forceResolutionEditboxes then
181        currentWidth = P.newWidth
182        currentHeight = P.newHeight
183        P.forceResolutionEditboxes = false
[7801]184    end
[8079]185
186    local currentResolution = currentWidth .. " x " .. currentHeight
187
188    for i = 0, resolutionCombobox:getDropList():getItemCount() - 1 do
189        local item = resolutionCombobox:getListboxItemFromIndex(i)
190        resolutionCombobox:setItemSelectState(item, item:getText() == currentResolution)
191    end
192
193    -- resolution editboxes
194    self.updateResolutionEditboxes()
[7801]195end
196
[8079]197----------------------
198-- Helper functions --
199----------------------
200
201-- updates the text of the resolution checkboxes and checks if they should be enabled (only if the "custom" resolution was selected)
202function P.updateResolutionEditboxes()
203    -- resolution combobox
[11800]204    local resolutionCombobox = CEGUI.toCombobox(P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/Combobox"))
[8079]205
206    local currentWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
207    local currentHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
208
209    -- resolution editboxes
[11800]210    local widthEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/EditboxWidth")
211    local heightEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/EditboxHeight")
[8079]212    widthEditbox:disable()
213    heightEditbox:disable()
214
215    -- selected combobox item
216    local item = resolutionCombobox:getSelectedItem()
217    if item then
218        local itemText = item:getText()
219        if itemText ~= "custom" then
220            currentWidth = string.sub(itemText, 1, string.find(itemText, "x") - 2)
221            currentHeight = string.sub(itemText, string.find(itemText, "x") + 2)
222        else
223            widthEditbox:enable()
224            heightEditbox:enable()
[6363]225        end
226    end
[8079]227
228    widthEditbox:setText(currentWidth)
229    heightEditbox:setText(currentHeight)
[6363]230end
231
[8079]232-- checks if the apply button should be enabled or disabled (only enabled if the current settings are different from the selected values)
233function P.updateApplyButton()
234    -- fullscreen checkbox
[11800]235    local fullscreenCheckbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/Fullscreen")
[8079]236    local isFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
237    local fullscreenChanged = (isFullscreen ~= CEGUI.toCheckbox(fullscreenCheckbox):isSelected())
238
239    -- resolution editboxes
[11800]240    local widthEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/EditboxWidth")
241    local heightEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/EditboxHeight")
[8079]242    local currentWidth = tostring(orxonox.GraphicsManager:getInstance():getWindowWidth())
243    local currentHeight = tostring(orxonox.GraphicsManager:getInstance():getWindowHeight())
244    local widthChanged = (currentWidth ~= widthEditbox:getText())
245    local heightChanged = (currentHeight ~= heightEditbox:getText())
246    local resolutionEditboxesEnabled = not widthEditbox:isDisabled()
247
248    -- apply button
[11800]249    local applyButton = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/Apply")
[8079]250
251    if fullscreenChanged or widthChanged or heightChanged or resolutionEditboxesEnabled then
252        applyButton:enable()
253    else
254        applyButton:disable()
[6363]255    end
256end
257
[8079]258function P.updateRedLabel()
259    -- theme
[11800]260    local themeCombobox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Theme/Combobox")
[8079]261    local currentTheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_")
262    local themeChanged = (currentTheme ~= themeCombobox:getText())
263
264    -- vsync
[11800]265    local vsyncCheckbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/More/VSync")
[8079]266    local hasVSync = orxonox.GraphicsManager:getInstance():hasVSyncEnabled()
267    local vsyncChanged = (hasVSync ~= CEGUI.toCheckbox(vsyncCheckbox):isSelected())
268
269    -- fsaa
[11800]270    local fsaaCombobox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/More/FSAA")
[8079]271    local currentFSAAMode = orxonox.GraphicsManager:getInstance():getFSAAMode()
272    local fsaaChanged = (currentFSAAMode ~= fsaaCombobox:getText())
273
274    local needRestart = themeChanged or vsyncChanged or fsaaChanged
275
[11800]276    local notice = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Notice")
[8079]277    notice:setVisible(not needRestart)
[11800]278    local noticeRed = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/NoticeRed")
[8079]279    noticeRed:setVisible(needRestart)
[6363]280end
281
[8079]282---------------------
283-- Event callbacks --
284---------------------
285
286-- resolution
287
[11800]288function P.callback_FullscreenCheckbox_SelectStateChanged(e)
[8079]289    P.updateApplyButton()
[6363]290end
291
[8079]292function P.callback_ResolutionCombobox_ListSelectionAccepted(e)
293    P.updateResolutionEditboxes()
294end
295
296function P.callback_ResolutionEditboxWidth_TextChanged(e)
297    P.updateApplyButton()
298end
299
300function P.callback_ResolutionEditboxHeight_TextChanged(e)
301    P.updateApplyButton()
302end
303
304-- theme
305
306function P.callback_ThemeCombobox_ListSelectionAccepted(e)
307    P.updateRedLabel()
308end
309
310-- vsync
311
[11800]312function P.callback_VSyncCheckbox_SelectStateChanged(e)
[8079]313    P.updateRedLabel()
314end
315
316-- fsaa
317
318function P.callback_FSAACombobox_ListSelectionAccepted(e)
319    P.updateRedLabel()
320end
321
322-- buttons
323
324function P.callback_Apply_Clicked(e)
325    -- resolution
[11800]326    local fullscreenCheckbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/Fullscreen")
[8079]327    local checkedFullscreen = tostring(CEGUI.toCheckbox(fullscreenCheckbox):isSelected())
328
[11800]329    local widthEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/EditboxWidth")
330    local heightEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/EditboxHeight")
[8079]331
332    P.newWidth = widthEditbox:getText()
333    P.newHeight = heightEditbox:getText()
334    P.forceResolutionEditboxes = true
335
336    -- start revert timer
337    P.oldWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
338    P.oldHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
339    P.oldFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
340
[11800]341    P.revertTimerHandle = orxonox.CommandExecutor:query("delayreal 10 {hideGUI DecisionPopup; GraphicsManager setScreenResolution " .. P.oldWidth .. " " .. P.oldHeight .. " " .. tostring(P.oldFullscreen) .. "; config CoreConfig lastLevelTimestamp_ [expr [getConfig CoreConfig ogreConfigTimestamp_] + 1]}")
[8079]342
343    -- change settings
344    orxonox.CommandExecutor:execute("GraphicsManager setScreenResolution " .. P.newWidth .. " " .. P.newHeight .. " " .. checkedFullscreen)
345
346    P.updateApplyButton()
347
348    -- prompt for confirmation
349    openDecisionPopup("Do you want to keep these settings? (Settings will be reverted in 10 seconds if not accepted)", GraphicsMenu.callback_ApplyDecisionPopup)
350    if checkedFullscreen then
351        showCursor()
[6363]352    end
353end
354
[8079]355function P.callback_ApplyDecisionPopup(pressedOK)
356    orxonox.CommandExecutor:execute("killdelay " .. P.revertTimerHandle)
357
358    if not pressedOK then
359        orxonox.CommandExecutor:execute("GraphicsManager setScreenResolution " .. P.oldWidth .. " " .. P.oldHeight .. " " .. tostring(P.oldFullscreen))
360        P:onShow()
361    end
362
363    -- update timestamp to avoid showing the ogre config dialog again after the user accepted or reverted the resolution
[11800]364    orxonox.CommandExecutor:execute("config CoreConfig lastLevelTimestamp_ [expr [getConfig CoreConfig ogreConfigTimestamp_] + 1]")
[8079]365end
366
367function P.callback_Ok_Clicked(e)
368    -- aspect ratio
[11800]369    local aspectRatioEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Resolution/AspectRatio")
[8079]370    orxonox.CommandExecutor:execute("config Camera aspectRatio_ " .. aspectRatioEditbox:getText())
371
372    -- theme
[11800]373    local themeCombobox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/Theme/Combobox")
[8079]374    orxonox.CommandExecutor:execute("config GUIManager guiScheme_ " .. themeCombobox:getText())
375
376    -- vsync
[11800]377    local vsyncCheckbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/More/VSync")
[8079]378    local hasVSync = orxonox.GraphicsManager:getInstance():hasVSyncEnabled()
379    if hasVSync ~= CEGUI.toCheckbox(vsyncCheckbox):isSelected() then
380        orxonox.CommandExecutor:execute("GraphicsManager setVSync " .. tostring(CEGUI.toCheckbox(vsyncCheckbox):isSelected()))
381    end
382
383    -- fsaa
[11800]384    local fsaaCombobox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Display/More/FSAA")
[8079]385    local currentFSAAMode = orxonox.GraphicsManager:getInstance():getFSAAMode()
386    if currentFSAAMode ~= fsaaCombobox:getText() then
387        orxonox.CommandExecutor:execute("GraphicsManager setFSAA {" .. fsaaCombobox:getText() .. "}") -- enclose argument in { ... } because it can contain [brackets] (conflicts with tcl)
388    end
389
390    -- fov
[11800]391    local fovEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/Fov")
[8079]392    orxonox.CommandExecutor:execute("config Camera fov_ " .. fovEditbox:getText())
393
394    -- fps limit
[11800]395    local fpsEditbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/FpsLimit")
[8079]396    orxonox.CommandExecutor:execute("config GraphicsSettings fpsLimit " .. fpsEditbox:getText())
397
398    -- particle lod
[11800]399    local particleLodCombobox = CEGUI.toCombobox(P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/ParticleLodCombobox"))
[8079]400    local item = particleLodCombobox:getSelectedItem()
401    if item then
402        orxonox.CommandExecutor:execute("config GraphicsSettings particlesDetailLevel " .. particleLodCombobox:getItemIndex(item))
403    end
404
405    -- mesh lod
[11800]406    local meshLodCheckbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/MeshLodCheckbox")
[8079]407    orxonox.CommandExecutor:execute("config GraphicsSettings enableMeshLoD " .. tostring(CEGUI.toCheckbox(meshLodCheckbox):isSelected()))
408
409    -- motion blur
[11800]410    local motionBlurCheckbox = P.window:getChild("GraphicsWindow/GraphicsTabControl/Settings/MotionBlurCheckbox")
[8079]411    orxonox.CommandExecutor:execute("config GraphicsSettings enableMotionBlur " .. tostring(CEGUI.toCheckbox(motionBlurCheckbox):isSelected()))
412
[6746]413    hideMenuSheet(P.name)
[6363]414end
415
[8079]416function P.callback_Cancel_Clicked(e)
417    hideMenuSheet(P.name)
[7689]418end
419
[6363]420return P
421
Note: See TracBrowser for help on using the repository browser.