[6206] | 1 | -- GraphicsMenu.lua |
---|
| 2 | |
---|
| 3 | BasicGUI = require("BasicGUI") |
---|
| 4 | local P = BasicGUI:new() --inherit everything from the gui package |
---|
| 5 | if _REQUIREDNAME == nil then |
---|
| 6 | GraphicsMenu = P |
---|
| 7 | else |
---|
| 8 | _G[_REQUIREDNAME] = P |
---|
| 9 | end |
---|
| 10 | |
---|
| 11 | P.filename = "GraphicsMenu" |
---|
| 12 | P.layoutString = "GraphicsMenu.layout" |
---|
| 13 | |
---|
| 14 | function P:init() |
---|
[6262] | 15 | block = true |
---|
[6259] | 16 | file = orxonox.PathConfig:getConfigPathString() .. orxonox.getConfig("GraphicsManager", "ogreConfigFile_") |
---|
[6258] | 17 | search_mode = 0 |
---|
| 18 | f = io.open(file, "r") |
---|
| 19 | firstline = f:read("*line") |
---|
| 20 | rendersystem = string.sub(firstline, 15) |
---|
| 21 | for line in f:lines() do |
---|
| 22 | if search_mode == 0 then |
---|
| 23 | if string.find(line, rendersystem) ~= nil then |
---|
| 24 | search_mode = 1 |
---|
| 25 | end |
---|
| 26 | end |
---|
| 27 | if search_mode == 1 then |
---|
| 28 | if string.sub(line, 1, 11) == "Full Screen" then |
---|
| 29 | if string.sub(line, 13) == "Yes" then |
---|
| 30 | fullscreen = true |
---|
| 31 | else |
---|
| 32 | fullscreen = false |
---|
| 33 | end |
---|
[6262] | 34 | end |
---|
| 35 | if string.sub(line, 1, 10) == "Video Mode" then |
---|
| 36 | if string.match(line, "@") == "@" then |
---|
| 37 | resolution = string.sub(line, 12, string.find(line, "@")-2) |
---|
| 38 | else |
---|
| 39 | resolution = string.sub(line, 12) |
---|
| 40 | end |
---|
[6258] | 41 | break |
---|
| 42 | end |
---|
| 43 | end |
---|
| 44 | end |
---|
| 45 | f:close() |
---|
| 46 | local fullscreenwindow = tolua.cast(winMgr:getWindow("orxonox/FullscreenCheckbox"),"CEGUI::Checkbox") |
---|
| 47 | fullscreenwindow:setSelected(fullscreen) |
---|
[6262] | 48 | listboxwindow = winMgr:getWindow("orxonox/ResolutionListbox") |
---|
[6206] | 49 | local resolutionList = {} |
---|
[6262] | 50 | table.insert(resolutionList, "640 x 480") |
---|
| 51 | table.insert(resolutionList, "720 x 480") |
---|
| 52 | table.insert(resolutionList, "720 x 576") |
---|
| 53 | table.insert(resolutionList, "800 x 480") |
---|
| 54 | table.insert(resolutionList, "800 x 600") |
---|
| 55 | table.insert(resolutionList, "1024 x 480") |
---|
| 56 | table.insert(resolutionList, "1024 x 600") |
---|
| 57 | table.insert(resolutionList, "1024 x 768") |
---|
| 58 | table.insert(resolutionList, "1152 x 864") |
---|
| 59 | table.insert(resolutionList, "1280 x 720") |
---|
| 60 | table.insert(resolutionList, "1280 x 768") |
---|
| 61 | table.insert(resolutionList, "1440 x 900") |
---|
[6206] | 62 | for k,v in pairs(resolutionList) do |
---|
| 63 | item = CEGUI.createListboxTextItem(v) |
---|
| 64 | item:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush") |
---|
[6262] | 65 | CEGUI.toListbox(listboxwindow):addItem(item) |
---|
[6206] | 66 | end |
---|
[6262] | 67 | if resolution == "640 x 480" then |
---|
| 68 | listboxwindow:setItemSelectState(0,true) |
---|
| 69 | elseif resolution == "720 x 480" then |
---|
| 70 | listboxwindow:setItemSelectState(1,true) |
---|
| 71 | elseif resolution == "720 x 576" then |
---|
| 72 | listboxwindow:setItemSelectState(2,true) |
---|
| 73 | elseif resolution == "800 x 480" then |
---|
| 74 | listboxwindow:setItemSelectState(3,true) |
---|
| 75 | elseif resolution == "800 x 600" then |
---|
| 76 | listboxwindow:setItemSelectState(4,true) |
---|
| 77 | elseif resolution == "1024 x 480" then |
---|
| 78 | listboxwindow:setItemSelectState(5,true) |
---|
| 79 | elseif resolution == "1024 x 600" then |
---|
| 80 | listboxwindow:setItemSelectState(6,true) |
---|
| 81 | elseif resolution == "1024 x 768" then |
---|
| 82 | listboxwindow:setItemSelectState(7,true) |
---|
| 83 | elseif resolution == "1152 x 864" then |
---|
| 84 | listboxwindow:setItemSelectState(8,true) |
---|
| 85 | elseif resolution == "1280 x 720" then |
---|
| 86 | listboxwindow:setItemSelectState(9,true) |
---|
| 87 | elseif resolution == "1280 x 768" then |
---|
| 88 | listboxwindow:setItemSelectState(10,true) |
---|
| 89 | elseif resolution == "1440 x 900" then |
---|
| 90 | listboxwindow:setItemSelectState(11,true) |
---|
[6206] | 91 | end |
---|
| 92 | scrollbar_active = false |
---|
[6262] | 93 | block = false |
---|
[6206] | 94 | end |
---|
| 95 | |
---|
[6262] | 96 | function P.GraphicsResolutionListbox_changed(e) |
---|
| 97 | if listboxwindow:isItemSelected(0) then |
---|
| 98 | resolution = "640 x 480" |
---|
| 99 | elseif listboxwindow:isItemSelected(1) then |
---|
| 100 | resolution = "720 x 480" |
---|
| 101 | elseif listboxwindow:isItemSelected(2) then |
---|
| 102 | resolution = "720 x 576" |
---|
| 103 | elseif listboxwindow:isItemSelected(3) then |
---|
| 104 | resolution = "800 x 480" |
---|
| 105 | elseif listboxwindow:isItemSelected(4) then |
---|
| 106 | resolution = "800 x 600" |
---|
| 107 | elseif listboxwindow:isItemSelected(5) then |
---|
| 108 | resolution = "1024 x 480" |
---|
| 109 | elseif listboxwindow:isItemSelected(6) then |
---|
| 110 | resolution = "1024 x 600" |
---|
| 111 | elseif listboxwindow:isItemSelected(7) then |
---|
| 112 | resolution = "1024 x 768" |
---|
| 113 | elseif listboxwindow:isItemSelected(8) then |
---|
| 114 | resolution = "1152 x 864" |
---|
| 115 | elseif listboxwindow:isItemSelected(9) then |
---|
| 116 | resolution = "1280 x 720" |
---|
| 117 | elseif listboxwindow:isItemSelected(10) then |
---|
| 118 | resolution = "1280 x 768" |
---|
| 119 | elseif listboxwindow:isItemSelected(11) then |
---|
| 120 | resolution = "1440 x 900" |
---|
| 121 | end |
---|
[6258] | 122 | search_mode = 0 |
---|
| 123 | f = io.open(file, "r") |
---|
| 124 | firstline = f:read("*line") |
---|
| 125 | text = firstline .. "\n" |
---|
| 126 | rendersystem = string.sub(firstline, 15) |
---|
| 127 | for line in f:lines() do |
---|
| 128 | if search_mode == 0 then |
---|
| 129 | if string.find(line, rendersystem) ~= nil then |
---|
| 130 | search_mode = 1 |
---|
| 131 | end |
---|
| 132 | end |
---|
| 133 | if search_mode == 1 then |
---|
[6262] | 134 | if string.sub(line, 1, 10) == "Video Mode" then |
---|
| 135 | if string.match(line, "@") == "@" then |
---|
| 136 | line = "Video Mode=" .. resolution .. string.sub(line, string.find(line, "@")-1) |
---|
[6258] | 137 | else |
---|
[6262] | 138 | line = "Video Mode=" .. resolution |
---|
[6258] | 139 | end |
---|
| 140 | search_mode = 2 |
---|
| 141 | end |
---|
| 142 | end |
---|
| 143 | text = text .. line .. "\n" |
---|
| 144 | end |
---|
| 145 | f:close() |
---|
| 146 | f = io.open(file, "w") |
---|
| 147 | f:write(text) |
---|
| 148 | f:close() |
---|
[6206] | 149 | end |
---|
| 150 | |
---|
[6262] | 151 | function P.GraphicsBrightnessScrollbar_changed(e) |
---|
| 152 | if scrollbar_active == false then |
---|
| 153 | -- brightness |
---|
| 154 | debug("event: brightness") |
---|
| 155 | end |
---|
| 156 | end |
---|
| 157 | |
---|
| 158 | function P.GraphicsBrightnessScrollbar_started(e) |
---|
| 159 | scrollbar_active = true |
---|
| 160 | end |
---|
| 161 | |
---|
| 162 | function P.GraphicsBrightnessScrollbar_ended(e) |
---|
| 163 | -- brightness |
---|
| 164 | debug("event: brightness") |
---|
| 165 | scrollbar_active = false |
---|
| 166 | end |
---|
| 167 | |
---|
| 168 | function P.GraphicsFullscreenCheckbox_clicked(e) |
---|
| 169 | if block == false then |
---|
| 170 | search_mode = 0 |
---|
| 171 | f = io.open(file, "r") |
---|
| 172 | firstline = f:read("*line") |
---|
| 173 | text = firstline .. "\n" |
---|
| 174 | rendersystem = string.sub(firstline, 15) |
---|
| 175 | for line in f:lines() do |
---|
| 176 | if search_mode == 0 then |
---|
| 177 | if string.find(line, rendersystem) ~= nil then |
---|
| 178 | search_mode = 1 |
---|
| 179 | end |
---|
| 180 | end |
---|
| 181 | if search_mode == 1 then |
---|
| 182 | if string.sub(line, 1, 11) == "Full Screen" then |
---|
| 183 | if fullscreen == true then |
---|
| 184 | line = "Full Screen=No" |
---|
| 185 | fullscreen = false |
---|
| 186 | else |
---|
| 187 | line = "Full Screen=Yes" |
---|
| 188 | fullscreen = true |
---|
| 189 | end |
---|
| 190 | search_mode = 2 |
---|
| 191 | end |
---|
| 192 | end |
---|
| 193 | text = text .. line .. "\n" |
---|
| 194 | end |
---|
| 195 | f:close() |
---|
| 196 | f = io.open(file, "w") |
---|
| 197 | f:write(text) |
---|
| 198 | f:close() |
---|
| 199 | end |
---|
| 200 | end |
---|
| 201 | |
---|
[6206] | 202 | function P.GraphicsBackButton_clicked(e) |
---|
| 203 | hideGUI(P.filename) |
---|
| 204 | end |
---|
| 205 | |
---|
| 206 | return P |
---|
| 207 | |
---|