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