Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gamestate/data/gui/scripts/GraphicsMenu.lua @ 6459

Last change on this file since 6459 was 6459, checked in by rgrieder, 14 years ago

Simplified BasicGUI construction. Just give the name of the GUI as argument. The rest will be deduced.

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