Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/png2/data/gui/scripts/MiscConfigMenu.lua @ 7368

Last change on this file since 7368 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

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