Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ai/data/gui/scripts/MiscConfigMenu.lua @ 8328

Last change on this file since 8328 was 7403, checked in by dafrick, 14 years ago

Merged notifications branch back to trunk.

  • Property svn:eol-style set to native
File size: 6.7 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
87end
88
89function P.createLine(k)
90    local offset = 0
91    local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k)
92    line:setHeight(CEGUI.UDim(0, P.lineHeight))
93    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
94
95    local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command")
96    command:setText(P.nameList[k])
97    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
98    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
99    line:addChildWindow(command)
100    offset = offset + P.commandWidth + P.spaceWidth
101
102    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
103    configvalue:setProperty("ReadOnly", "set:False")
104    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
105    configvalue:setText(value)
106    P.sampleWindow:setText(value)
107    local size = getMinTextSize(P.sampleWindow)
108    local configvalueWidth = 2*size[2]
109    configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, configvalueWidth), CEGUI.UDim(0.9, 0)))
110    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
111    line:addChildWindow(configvalue)
112    offset = offset + configvalueWidth + P.spaceWidth
113
114    local config = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Config")
115    config:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.configWidth), CEGUI.UDim(0.9, 0)))
116    config:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
117    config:setText("configure")
118    orxonox.GUIManager:subscribeEventHelper(config, "Clicked", P.name .. ".MiscConfigConfigure_clicked")
119    line:addChildWindow(config)
120    offset = offset + P.configWidth + P.spaceWidth
121
122    local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
123    reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
124    reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
125    reset:setText("reset")
126    orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigReset_clicked")
127    line:addChildWindow(reset)
128    reset:setEnabled(false)
129    offset = offset + P.resetWidth + P.spaceWidth
130
131    line:setWidth(CEGUI.UDim(0, offset))
132
133    return line
134end
135
136function P.createLines()
137    local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane")
138
139    for k,v in pairs(P.commandList) do
140        local line = P.createLine(k)
141        table.insert(P.linesList, line)
142        window:addChildWindow(line)
143    end
144
145    local pane = tolua.cast(window, "CEGUI::ScrollablePane")
146    pane:setVerticalStepSize(getScrollingStepSize(window))
147end
148
149function P.MiscConfigReset_clicked(e)
150    local we = CEGUI.toWindowEventArgs(e)
151    local name = we.window:getName()
152
153    local match = string.gmatch(name, "%d+")
154    local commandNr = tonumber(match())
155
156    -- TODO: Implement reset.
157end
158
159function P.MiscConfigConfigure_clicked(e)
160    local we = CEGUI.toWindowEventArgs(e)
161    local name = we.window:getName()
162
163    local match = string.gmatch(name, "%d+")
164    local commandNr = tonumber(match())
165
166    local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
167
168    orxonox.CommandExecutor:execute("config " .. P.commandList[commandNr] .. " " .. window:getText())
169    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
170    window:setText(value)
171end
172
173function P.MiscConfigBackButton_clicked(e)
174    hideMenuSheet("MiscConfigMenu")
175end
176
177return P
Note: See TracBrowser for help on using the repository browser.