Changeset 8964 for code/branches/menue/data/gui/scripts/MiscConfigMenu.lua
- Timestamp:
- Dec 7, 2011, 3:22:46 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/menue/data/gui/scripts/MiscConfigMenu.lua
r8729 r8964 11 11 P.lineHeight = 0 12 12 P.commandWidth = 0 13 P. configWidth = 013 P.editboxWidth = 0 14 14 P.resetWidth = 0 15 15 P.spaceWidth = 0 … … 75 75 end 76 76 77 P.sampleWindow:setText("configure")78 size = getMinTextSize(P.sampleWindow)79 P.configWidth = size[2]+2080 81 77 P.sampleWindow:setText("reset") 82 78 size = getMinTextSize(P.sampleWindow) 83 79 P.resetWidth = size[2]+20 84 80 85 P.spaceWidth = math.floor(1/8*P.configWidth) 81 P.spaceWidth = 10 82 83 local pane = tolua.cast(winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane"), "CEGUI::ScrollablePane") 84 size = pane:getViewableArea() 85 P.editboxWidth = size:getWidth() - P.commandWidth - P.resetWidth - 5*P.spaceWidth 86 86 87 87 P.createLines() 88 88 89 89 P:setButton(1, 1, { 90 ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigBackButton"), 91 ["callback"] = P.MiscConfigBackButton_clicked 90 ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/CancelButton"), 91 ["callback"] = P.MiscConfigCancelButton_clicked 92 }) 93 94 P:setButton(1, 2, { 95 ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/OKButton"), 96 ["callback"] = P.MiscConfigOKButton_clicked 92 97 }) 93 98 end … … 95 100 function P.createLine(k) 96 101 local offset = 0 102 -- content window for the entire line 97 103 local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k) 98 104 line:setHeight(CEGUI.UDim(0, P.lineHeight)) 99 105 line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1)))) 100 106 107 -- config name 101 108 local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command") 102 109 command:setText(P.nameList[k]) … … 106 113 offset = offset + P.commandWidth + P.spaceWidth 107 114 115 -- config value (editable) 108 116 local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") 109 117 configvalue:setProperty("ReadOnly", "set:False") 110 118 local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k]) 111 119 configvalue:setText(value) 112 P.sampleWindow:setText(value) 113 local size = getMinTextSize(P.sampleWindow) 114 local configvalueWidth = 2*size[2] 115 configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, configvalueWidth), CEGUI.UDim(0.9, 0))) 120 configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0))) 116 121 configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) 122 -- enable the reset button if the value changed 123 orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted") 117 124 line:addChildWindow(configvalue) 118 offset = offset + configvalueWidth + P.spaceWidth125 offset = offset + P.editboxWidth + P.spaceWidth 119 126 120 local config = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Config") 121 config:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.configWidth), CEGUI.UDim(0.9, 0))) 122 config:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) 123 config:setText("configure") 124 orxonox.GUIManager:subscribeEventHelper(config, "Clicked", P.name .. ".MiscConfigConfigure_clicked") 125 line:addChildWindow(config) 126 offset = offset + P.configWidth + P.spaceWidth 127 127 -- reset button (only available when value changed) 128 128 local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset") 129 129 reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0))) 130 130 reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) 131 131 reset:setText("reset") 132 orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigReset _clicked")132 orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigResetButton_clicked") 133 133 line:addChildWindow(reset) 134 134 reset:setEnabled(false) … … 153 153 end 154 154 155 function P.MiscConfigReset_clicked(e) 155 function P.MiscConfigOKButton_clicked(e) 156 for k,v in pairs(P.commandList) do 157 -- save the changes 158 local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") 159 orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText()) 160 local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset") 161 resetButton:setEnabled(false) 162 end 163 164 hideMenuSheet("MiscConfigMenu") 165 end 166 167 function P.MiscConfigCancelButton_clicked(e) 168 hideMenuSheet("MiscConfigMenu") 169 end 170 171 function P.MiscConfigEditbox_textAccepted(e) 156 172 local we = CEGUI.toWindowEventArgs(e) 157 173 local name = we.window:getName() … … 160 176 local commandNr = tonumber(match()) 161 177 162 -- TODO: Implement reset. 178 local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset") 179 resetButton:setEnabled(true) 163 180 end 164 181 165 function P.MiscConfig Configure_clicked(e)182 function P.MiscConfigResetButton_clicked(e) 166 183 local we = CEGUI.toWindowEventArgs(e) 167 184 local name = we.window:getName() … … 170 187 local commandNr = tonumber(match()) 171 188 172 local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue") 173 174 orxonox.CommandExecutor:execute("config " .. P.commandList[commandNr] .. " " .. window:getText()) 189 -- reload the old value 190 local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue") 175 191 local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr]) 176 window:setText(value) 177 end 178 179 function P.MiscConfigBackButton_clicked(e) 180 hideMenuSheet("MiscConfigMenu") 192 editbox:setText(value) 193 194 we.window:setEnabled(false) 181 195 end 182 196
Note: See TracChangeset
for help on using the changeset viewer.