Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sound6/data/gui/scripts/MiscConfigMenu.lua @ 8748

Last change on this file since 8748 was 7928, checked in by landauf, 14 years ago

more improvements for keyboard control of menus:

  • added setSelectionNear(r, c) function which tries to select the button closest to the given row/column
  • no initialization required anymore, the button-table grows dynamically if new buttons are inserted
  • Property svn:eol-style set to native
File size: 6.9 KB
Line 
1-- MiscConfigMenu.lua
2
3local P = createMenuSheet("MiscConfigMenu", true, TriBool.True, TriBool.True)
4
5P.commandList = {}
6P.nameList = {}
7P.linesList = {}
8
9P.sampleWindow = nil
10
11P.lineHeight = 0
12P.commandWidth = 0
13P.configWidth = 0
14P.resetWidth = 0
15P.spaceWidth = 0
16
17function P.onLoad()
18
19    P.commandList = {}
20    table.insert(P.commandList, "KeyBinder mouseSensitivity_")
21    table.insert(P.commandList, "KeyBinder mouseSensitivityDerived_")
22    table.insert(P.commandList, "KeyBinder bDeriveMouseInput_")
23    table.insert(P.commandList, "KeyBinder mouseWheelStepSize_")
24    table.insert(P.commandList, "Shell maxHistoryLength_")
25    table.insert(P.commandList, "Core bStartIOConsole_")
26    table.insert(P.commandList, "Game fpsLimit_")
27    table.insert(P.commandList, "Spectator speed_")
28    table.insert(P.commandList, "SpaceShip bInvertYAxis_")
29    table.insert(P.commandList, "LevelManager defaultLevelName_")
30    table.insert(P.commandList, "Gametype initialStartCountdown_")
31    table.insert(P.commandList, "Gametype bAutoStart_")
32    table.insert(P.commandList, "Gametype numberOfBots_")
33    table.insert(P.commandList, "UnderAttack gameTime_")
34    table.insert(P.commandList, "TeamDeathmatch teams_")
35    table.insert(P.commandList, "HumanPlayer nick_")
36    table.insert(P.commandList, "ChatOverlay displayTime_")
37
38    P.nameList = {}
39    table.insert(P.nameList, "Mouse sensitivity")
40    table.insert(P.nameList, "Mouse acceleration")
41    table.insert(P.nameList, "Derive mouse input")
42    table.insert(P.nameList, "Mouse wheel stepsize")
43    table.insert(P.nameList, "Shell: max. History length")
44    table.insert(P.nameList, "Start IOConsole")
45    table.insert(P.nameList, "FPS limit")
46    table.insert(P.nameList, "Spectator speed")
47    table.insert(P.nameList, "Invert Y-axis")
48    table.insert(P.nameList, "Default level")
49    table.insert(P.nameList, "Start countdown")
50    table.insert(P.nameList, "Autostart")
51    table.insert(P.nameList, "Number of Bots")
52    table.insert(P.nameList, "UnderAttack: game time")
53    table.insert(P.nameList, "TeamDeathmatch: Number of teams")
54    table.insert(P.nameList, "Playername")
55    table.insert(P.nameList, "Chat: display time")
56
57    P.linesList = {}
58
59    --Calculate design parameters:
60    P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/SampleWindow")
61    P.sampleWindow:setText("SampleText")
62
63    local size = getMinTextSize(P.sampleWindow)
64    P.lineHeight = size[1]
65
66    P.commandWidth = 0
67    for k,v in pairs(P.commandList) do
68        P.sampleWindow:setText(P.nameList[k])
69        size = getMinTextSize(P.sampleWindow)
70        if size[2] > P.commandWidth then
71            P.commandWidth = size[2]
72        end
73    end
74
75    P.sampleWindow:setText("configure")
76    size = getMinTextSize(P.sampleWindow)
77    P.configWidth = size[2]+20
78
79    P.sampleWindow:setText("reset")
80    size = getMinTextSize(P.sampleWindow)
81    P.resetWidth = size[2]+20
82
83    P.spaceWidth = math.floor(1/8*P.configWidth)
84
85    P.createLines()
86
87    P:setButton(1, 1, {
88            ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigBackButton"),
89            ["callback"]  = P.MiscConfigBackButton_clicked
90    })
91end
92
93function P.createLine(k)
94    local offset = 0
95    local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k)
96    line:setHeight(CEGUI.UDim(0, P.lineHeight))
97    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
98
99    local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command")
100    command:setText(P.nameList[k])
101    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
102    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
103    line:addChildWindow(command)
104    offset = offset + P.commandWidth + P.spaceWidth
105
106    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
107    configvalue:setProperty("ReadOnly", "set:False")
108    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
109    configvalue:setText(value)
110    P.sampleWindow:setText(value)
111    local size = getMinTextSize(P.sampleWindow)
112    local configvalueWidth = 2*size[2]
113    configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, configvalueWidth), CEGUI.UDim(0.9, 0)))
114    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
115    line:addChildWindow(configvalue)
116    offset = offset + configvalueWidth + P.spaceWidth
117
118    local config = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Config")
119    config:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.configWidth), CEGUI.UDim(0.9, 0)))
120    config:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
121    config:setText("configure")
122    orxonox.GUIManager:subscribeEventHelper(config, "Clicked", P.name .. ".MiscConfigConfigure_clicked")
123    line:addChildWindow(config)
124    offset = offset + P.configWidth + P.spaceWidth
125
126    local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
127    reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
128    reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
129    reset:setText("reset")
130    orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigReset_clicked")
131    line:addChildWindow(reset)
132    reset:setEnabled(false)
133    offset = offset + P.resetWidth + P.spaceWidth
134
135    line:setWidth(CEGUI.UDim(0, offset))
136
137    return line
138end
139
140function P.createLines()
141    local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane")
142
143    for k,v in pairs(P.commandList) do
144        local line = P.createLine(k)
145        table.insert(P.linesList, line)
146        window:addChildWindow(line)
147    end
148
149    local pane = tolua.cast(window, "CEGUI::ScrollablePane")
150    pane:setVerticalStepSize(getScrollingStepSize(window))
151end
152
153function P.MiscConfigReset_clicked(e)
154    local we = CEGUI.toWindowEventArgs(e)
155    local name = we.window:getName()
156
157    local match = string.gmatch(name, "%d+")
158    local commandNr = tonumber(match())
159
160    -- TODO: Implement reset.
161end
162
163function P.MiscConfigConfigure_clicked(e)
164    local we = CEGUI.toWindowEventArgs(e)
165    local name = we.window:getName()
166
167    local match = string.gmatch(name, "%d+")
168    local commandNr = tonumber(match())
169
170    local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
171
172    orxonox.CommandExecutor:execute("config " .. P.commandList[commandNr] .. " " .. window:getText())
173    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
174    window:setText(value)
175end
176
177function P.MiscConfigBackButton_clicked(e)
178    hideMenuSheet("MiscConfigMenu")
179end
180
181return P
Note: See TracBrowser for help on using the repository browser.