- Timestamp:
- Mar 5, 2011, 5:31:27 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability/data/gui/scripts/GraphicsMenu.lua
r7928 r8018 3 3 local P = createMenuSheet("GraphicsMenu") 4 4 5 P.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"} 5 6 P.schemeList = {"TaharezGreen", "Orxonox"} 6 7 function P.onLoad() 8 block = true 9 file = orxonox.PathConfig:getConfigPathString() .. orxonox.getConfig("GraphicsManager", "ogreConfigFile_") 10 search_mode = 0 11 f = io.open(file, "r") 12 firstline = f:read("*line") 13 rendersystem = string.sub(firstline, 15) 14 for line in f:lines() do 15 if search_mode == 0 then 16 if string.find(line, rendersystem) ~= nil then 17 search_mode = 1 18 end 7 P.fsaaList = {"0", "2", "4", "8", "8 [Quality]"} 8 P.particleLodList = {"None", "Low", "Normal", "High"} 9 10 function 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 74 end 75 76 function 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)) 19 147 end 20 if search_mode == 1 then 21 if string.sub(line, 1, 11) == "Full Screen" then 22 if string.sub(line, 13) == "Yes" then 23 fullscreen = true 24 else 25 fullscreen = false 26 end 27 end 28 if string.sub(line, 1, 10) == "Video Mode" then 29 if string.match(line, "@") == "@" then 30 resolution = string.sub(line, 12, string.find(line, "@")-2) 31 else 32 resolution = string.sub(line, 12) 33 end 34 break 35 end 148 end 149 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) 169 end 170 171 function 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) 187 end 188 189 -- resolution editboxes 190 self.updateResolutionEditboxes() 191 end 192 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) 198 function 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() 36 221 end 37 222 end 38 f:close() 39 local fullscreenwindow = tolua.cast(winMgr:getWindow("orxonox/FullscreenCheckbox"),"CEGUI::Checkbox") 40 fullscreenwindow:setSelected(fullscreen) 41 listboxwindow = winMgr:getWindow("orxonox/ResolutionListbox") 42 local resolutionList = {} 43 table.insert(resolutionList, "640 x 480") 44 table.insert(resolutionList, "720 x 480") 45 table.insert(resolutionList, "720 x 576") 46 table.insert(resolutionList, "800 x 480") 47 table.insert(resolutionList, "800 x 600") 48 table.insert(resolutionList, "1024 x 480") 49 table.insert(resolutionList, "1024 x 600") 50 table.insert(resolutionList, "1024 x 768") 51 table.insert(resolutionList, "1152 x 864") 52 table.insert(resolutionList, "1280 x 720") 53 table.insert(resolutionList, "1280 x 768") 54 table.insert(resolutionList, "1440 x 900") 55 for k,v in pairs(resolutionList) do 56 item = CEGUI.createListboxTextItem(v) 57 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 58 CEGUI.toListbox(listboxwindow):addItem(item) 59 end 60 if resolution == "640 x 480" then 61 listboxwindow:setItemSelectState(0,true) 62 elseif resolution == "720 x 480" then 63 listboxwindow:setItemSelectState(1,true) 64 elseif resolution == "720 x 576" then 65 listboxwindow:setItemSelectState(2,true) 66 elseif resolution == "800 x 480" then 67 listboxwindow:setItemSelectState(3,true) 68 elseif resolution == "800 x 600" then 69 listboxwindow:setItemSelectState(4,true) 70 elseif resolution == "1024 x 480" then 71 listboxwindow:setItemSelectState(5,true) 72 elseif resolution == "1024 x 600" then 73 listboxwindow:setItemSelectState(6,true) 74 elseif resolution == "1024 x 768" then 75 listboxwindow:setItemSelectState(7,true) 76 elseif resolution == "1152 x 864" then 77 listboxwindow:setItemSelectState(8,true) 78 elseif resolution == "1280 x 720" then 79 listboxwindow:setItemSelectState(9,true) 80 elseif resolution == "1280 x 768" then 81 listboxwindow:setItemSelectState(10,true) 82 elseif resolution == "1440 x 900" then 83 listboxwindow:setItemSelectState(11,true) 84 end 85 scrollbar_active = false 86 block = false 87 88 P:setButton(1, 1, { 89 ["button"] = winMgr:getWindow("orxonox/GraphicsBackButton"), 90 ["callback"] = P.GraphicsBackButton_clicked 91 }) 92 93 local dropbox = winMgr:getWindow("orxonox/ThemeDropBox") 94 local scheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_") 95 for k,v in pairs(P.schemeList) do 96 local item = CEGUI.createListboxTextItem(P.schemeList[k]) 97 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 98 CEGUI.toListbox(dropbox):addItem(item) 99 if v == scheme then 100 dropbox:setItemSelectState(item, true) 101 end 102 end 103 104 end 105 106 function P.ThemeDropBox_changed(e) 107 local dropbox = winMgr:getWindow("orxonox/ThemeDropBox") 108 local listbox = CEGUI.toListbox(dropbox) 109 local choice = listbox:getFirstSelectedItem() 110 local index = 0 111 if choice ~= nil then 112 index = listbox:getItemIndex(choice) 113 end 114 orxonox.CommandExecutor:execute("config GUIManager guiScheme_ " .. P.schemeList[index+1]) 115 end 116 117 function P.GraphicsResolutionListbox_changed(e) 118 if listboxwindow:isItemSelected(0) then 119 resolution = "640 x 480" 120 elseif listboxwindow:isItemSelected(1) then 121 resolution = "720 x 480" 122 elseif listboxwindow:isItemSelected(2) then 123 resolution = "720 x 576" 124 elseif listboxwindow:isItemSelected(3) then 125 resolution = "800 x 480" 126 elseif listboxwindow:isItemSelected(4) then 127 resolution = "800 x 600" 128 elseif listboxwindow:isItemSelected(5) then 129 resolution = "1024 x 480" 130 elseif listboxwindow:isItemSelected(6) then 131 resolution = "1024 x 600" 132 elseif listboxwindow:isItemSelected(7) then 133 resolution = "1024 x 768" 134 elseif listboxwindow:isItemSelected(8) then 135 resolution = "1152 x 864" 136 elseif listboxwindow:isItemSelected(9) then 137 resolution = "1280 x 720" 138 elseif listboxwindow:isItemSelected(10) then 139 resolution = "1280 x 768" 140 elseif listboxwindow:isItemSelected(11) then 141 resolution = "1440 x 900" 142 end 143 search_mode = 0 144 f = io.open(file, "r") 145 firstline = f:read("*line") 146 text = firstline .. "\n" 147 rendersystem = string.sub(firstline, 15) 148 for line in f:lines() do 149 if search_mode == 0 then 150 if string.find(line, rendersystem) ~= nil then 151 search_mode = 1 152 end 153 end 154 if search_mode == 1 then 155 if string.sub(line, 1, 10) == "Video Mode" then 156 if string.match(line, "@") == "@" then 157 line = "Video Mode=" .. resolution .. string.sub(line, string.find(line, "@")-1) 158 else 159 line = "Video Mode=" .. resolution 160 end 161 search_mode = 2 162 end 163 end 164 text = text .. line .. "\n" 165 end 166 f:close() 167 f = io.open(file, "w") 168 f:write(text) 169 f:close() 170 end 171 172 function P.GraphicsBrightnessScrollbar_changed(e) 173 if scrollbar_active == false then 174 -- brightness 175 logMessage(0, "event: brightness") 176 end 177 end 178 179 function P.GraphicsBrightnessScrollbar_started(e) 180 scrollbar_active = true 181 end 182 183 function P.GraphicsBrightnessScrollbar_ended(e) 184 -- brightness 185 logMessage(0, "event: brightness") 186 scrollbar_active = false 187 end 188 189 function P.GraphicsFullscreenCheckbox_clicked(e) 190 if block == false then 191 search_mode = 0 192 f = io.open(file, "r") 193 firstline = f:read("*line") 194 text = firstline .. "\n" 195 rendersystem = string.sub(firstline, 15) 196 for line in f:lines() do 197 if search_mode == 0 then 198 if string.find(line, rendersystem) ~= nil then 199 search_mode = 1 200 end 201 end 202 if search_mode == 1 then 203 if string.sub(line, 1, 11) == "Full Screen" then 204 if fullscreen == true then 205 line = "Full Screen=No" 206 fullscreen = false 207 else 208 line = "Full Screen=Yes" 209 fullscreen = true 210 end 211 search_mode = 2 212 end 213 end 214 text = text .. line .. "\n" 215 end 216 f:close() 217 f = io.open(file, "w") 218 f:write(text) 219 f:close() 220 end 221 end 222 223 function P.GraphicsBackButton_clicked(e) 223 224 widthEditbox:setText(currentWidth) 225 heightEditbox:setText(currentHeight) 226 end 227 228 -- checks if the apply button should be enabled or disabled (only enabled if the current settings are different from the selected values) 229 function 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() 251 end 252 end 253 254 function 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) 259 end 260 261 --------------------- 262 -- Event callbacks -- 263 --------------------- 264 265 -- resolution 266 267 function P.callback_FullscreenCheckbox_CheckStateChanged(e) 268 P.updateApplyButton() 269 end 270 271 function P.callback_ResolutionCombobox_ListSelectionAccepted(e) 272 P.updateResolutionEditboxes() 273 end 274 275 function P.callback_ResolutionEditboxWidth_TextChanged(e) 276 P.updateApplyButton() 277 end 278 279 function P.callback_ResolutionEditboxHeight_TextChanged(e) 280 P.updateApplyButton() 281 end 282 283 -- theme 284 285 function P.callback_ThemeCombobox_ListSelectionAccepted(e) 286 P.makeLabelRed() 287 end 288 289 -- vsync 290 291 function P.callback_VSyncCheckbox_CheckStateChanged(e) 292 P.makeLabelRed() 293 end 294 295 -- fsaa 296 297 function P.callback_FSAACombobox_ListSelectionAccepted(e) 298 P.makeLabelRed() 299 end 300 301 -- buttons 302 303 function 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() 314 end 315 316 function 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)) 346 end 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 224 356 hideMenuSheet(P.name) 225 357 end 226 358 359 function P.callback_Cancel_Clicked(e) 360 hideMenuSheet(P.name) 361 end 362 227 363 return P 228 364
Note: See TracChangeset
for help on using the changeset viewer.