Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/data/gui/scripts/GraphicsMenu.lua @ 7922

Last change on this file since 7922 was 7922, checked in by landauf, 13 years ago

implemented new keyboard control of menu buttons with these new features:

  • more intuitive placement of buttons in table (row/column format instead of linear index)
  • no need to overwrite onShow() and onKeyPressed() functions, no need for P.buttonList
  • highlights the selected button in a different layout than mouse hovering
  • remembers the selection while moving through the menu hierarchy, but resets it if the menu is closed
  • allows preselected button (for example "Yes" in decision popup)
  • when opening a menu, the first selected button is not always the upper left, but instead depends on the pressed key (e.g. the 'up' key selects the button at the bottom, while the 'down' key selects the button at the top. once a button is selected, the keys behave as usual)

+ fixed wrong callback function in ingame menu

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