Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/GraphicsMenu.lua @ 7801

Last change on this file since 7801 was 7801, checked in by dafrick, 13 years ago

Merging presentation2 branch back to trunk.

  • Property svn:eol-style set to native
File size: 7.9 KB
Line 
1-- GraphicsMenu.lua
2
3local P = createMenuSheet("GraphicsMenu")
4
5P.buttonList = {}
6P.schemeList = {"TaharezGreen", "Orxonox"}
7
8function P.onShow()
9    --indices to iterate through buttonlist (trivial in this menu sheet)
10    P.oldindex = -2
11    P.index = -1
12end
13
14function P.onLoad()
15    block = true
16    file = orxonox.PathConfig:getConfigPathString() .. orxonox.getConfig("GraphicsManager", "ogreConfigFile_")
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
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
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)
48    listboxwindow = winMgr:getWindow("orxonox/ResolutionListbox")
49    local resolutionList = {}
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")
62    for k,v in pairs(resolutionList) do
63        item = CEGUI.createListboxTextItem(v)
64        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
65        CEGUI.toListbox(listboxwindow):addItem(item)
66    end
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)
91    end
92    scrollbar_active = false
93    block = false
94
95    local item = {
96            ["button"] = winMgr:getWindow("orxonox/GraphicsBackButton"),
97            ["function"]  = P.GraphicsBackButton_clicked
98    }
99    P.buttonList[1] = item
100
101    local dropbox = winMgr:getWindow("orxonox/ThemeDropBox")
102    local scheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_")
103    for k,v in pairs(P.schemeList) do
104        local item = CEGUI.createListboxTextItem(P.schemeList[k])
105        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
106        CEGUI.toListbox(dropbox):addItem(item)
107        if v == scheme then
108            dropbox:setItemSelectState(item, true)
109        end
110    end
111
112end
113
114function P.ThemeDropBox_changed(e)
115    local dropbox = winMgr:getWindow("orxonox/ThemeDropBox")
116    local listbox = CEGUI.toListbox(dropbox)
117    local choice = listbox:getFirstSelectedItem()
118    local index = 0
119    if choice ~= nil then
120        index = listbox:getItemIndex(choice)
121    end
122    orxonox.CommandExecutor:execute("config GUIManager guiScheme_ " .. P.schemeList[index+1])
123end
124
125function P.GraphicsResolutionListbox_changed(e)
126    if listboxwindow:isItemSelected(0) then
127        resolution = "640 x 480"
128    elseif listboxwindow:isItemSelected(1) then
129        resolution = "720 x 480"
130    elseif listboxwindow:isItemSelected(2) then
131        resolution = "720 x 576"
132    elseif listboxwindow:isItemSelected(3) then
133        resolution = "800 x 480"
134    elseif listboxwindow:isItemSelected(4) then
135        resolution = "800 x 600"
136    elseif listboxwindow:isItemSelected(5) then
137        resolution = "1024 x 480"
138    elseif listboxwindow:isItemSelected(6) then
139        resolution = "1024 x 600"
140    elseif listboxwindow:isItemSelected(7) then
141        resolution = "1024 x 768"
142    elseif listboxwindow:isItemSelected(8) then
143        resolution = "1152 x 864"
144    elseif listboxwindow:isItemSelected(9) then
145        resolution = "1280 x 720"
146    elseif listboxwindow:isItemSelected(10) then
147        resolution = "1280 x 768"
148    elseif listboxwindow:isItemSelected(11) then
149        resolution = "1440 x 900"
150    end
151    search_mode = 0
152    f = io.open(file, "r")
153    firstline = f:read("*line")
154    text = firstline .. "\n"
155    rendersystem = string.sub(firstline, 15)
156    for line in f:lines() do
157        if search_mode == 0 then
158            if string.find(line, rendersystem) ~= nil then
159                search_mode = 1
160            end
161        end
162        if search_mode == 1 then
163            if string.sub(line, 1, 10) == "Video Mode" then
164                if string.match(line, "@") == "@" then
165                    line = "Video Mode=" .. resolution .. string.sub(line, string.find(line, "@")-1)
166                else
167                    line = "Video Mode=" .. resolution
168                end
169                search_mode = 2
170            end
171        end
172        text = text .. line .. "\n"
173    end
174    f:close()
175    f = io.open(file, "w")
176    f:write(text)
177    f:close()
178end
179
180function P.GraphicsBrightnessScrollbar_changed(e)
181    if scrollbar_active == false then
182        -- brightness
183        logMessage(0, "event: brightness")
184    end
185end
186
187function P.GraphicsBrightnessScrollbar_started(e)
188    scrollbar_active = true
189end
190
191function P.GraphicsBrightnessScrollbar_ended(e)
192    -- brightness
193    logMessage(0, "event: brightness")
194    scrollbar_active = false
195end
196
197function P.GraphicsFullscreenCheckbox_clicked(e)
198    if block == false then
199        search_mode = 0
200        f = io.open(file, "r")
201        firstline = f:read("*line")
202        text = firstline .. "\n"
203        rendersystem = string.sub(firstline, 15)
204        for line in f:lines() do
205            if search_mode == 0 then
206                if string.find(line, rendersystem) ~= nil then
207                    search_mode = 1
208                end
209            end
210            if search_mode == 1 then
211                if string.sub(line, 1, 11) == "Full Screen" then
212                    if fullscreen == true then
213                        line = "Full Screen=No"
214                        fullscreen = false
215                    else
216                        line = "Full Screen=Yes"
217                        fullscreen = true
218                    end
219                    search_mode = 2
220                end
221            end
222            text = text .. line .. "\n"
223        end
224        f:close()
225        f = io.open(file, "w")
226        f:write(text)
227        f:close()
228    end
229end
230
231function P.GraphicsBackButton_clicked(e)
232    hideMenuSheet(P.name)
233end
234
235function P.onKeyPressed() 
236    buttonIteratorHelper(P.buttonList, code, P, 1, 1)
237end
238
239return P
240
Note: See TracBrowser for help on using the repository browser.