[Orxonox-commit 4293] r8964 - in code/branches/menue/data/gui: layouts scripts
baermatt at orxonox.net
baermatt at orxonox.net
Wed Dec 7 15:22:46 CET 2011
Author: baermatt
Date: 2011-12-07 15:22:46 +0100 (Wed, 07 Dec 2011)
New Revision: 8964
Modified:
code/branches/menue/data/gui/layouts/MiscConfigMenu.layout
code/branches/menue/data/gui/scripts/MiscConfigMenu.lua
code/branches/menue/data/gui/scripts/SingleplayerConfigMenu.lua
code/branches/menue/data/gui/scripts/SingleplayerMenu.lua
Log:
Cleaned up the miscellaneous menu and added possibility to cancel.
Modified: code/branches/menue/data/gui/layouts/MiscConfigMenu.layout
===================================================================
--- code/branches/menue/data/gui/layouts/MiscConfigMenu.layout 2011-12-07 14:08:18 UTC (rev 8963)
+++ code/branches/menue/data/gui/layouts/MiscConfigMenu.layout 2011-12-07 14:22:46 UTC (rev 8964)
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<GUILayout >
- <Window Type="DefaultWindow" Name="orxonox/MiscConfigMenu/Background" >
+ <Window Type="MenuWidgets/StaticImage" Name="orxonox/MiscConfigMenu/Background" >
+ <Property Name="FrameEnabled" Value="False" />
<Property Name="InheritsAlpha" Value="False" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
<Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
+ <Property Name="BackgroundEnabled" Value="False" />
<Window Type="MenuWidgets/StaticText" Name="orxonox/MicsConfigMenu/ConfigWindow" >
<Property Name="Text" Value="Miscellaneous" />
<Property Name="Alpha" Value="0.8" />
@@ -33,11 +35,17 @@
</Window>
</Window>
</Window>
- <Window Type="MenuWidgets/Button" Name="orxonox/MiscConfigMenu/MiscConfigBackButton" >
- <Property Name="Text" Value="Back" />
+ <Window Type="MenuWidgets/Button" Name="orxonox/MiscConfigMenu/CancelButton" >
+ <Property Name="Text" Value="Cancel" />
<Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.6625,0},{0.6,0},{0.7125,0}}" />
- <Event Name="Clicked" Function="MiscConfigMenu.MiscConfigBackButton_clicked"/>
+ <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.725,0},{0.4,0},{0.775,0}}" />
+ <Event Name="Clicked" Function="MiscConfigMenu.MiscConfigCancelButton_clicked"/>
</Window>
+ <Window Type="MenuWidgets/Button" Name="orxonox/MiscConfigMenu/OKButton" >
+ <Property Name="Text" Value="OK" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.6,0},{0.725,0},{0.75,0},{0.775,0}}" />
+ <Event Name="Clicked" Function="MiscConfigMenu.MiscConfigOKButton_clicked"/>
+ </Window>
</Window>
</GUILayout>
Modified: code/branches/menue/data/gui/scripts/MiscConfigMenu.lua
===================================================================
--- code/branches/menue/data/gui/scripts/MiscConfigMenu.lua 2011-12-07 14:08:18 UTC (rev 8963)
+++ code/branches/menue/data/gui/scripts/MiscConfigMenu.lua 2011-12-07 14:22:46 UTC (rev 8964)
@@ -10,7 +10,7 @@
P.lineHeight = 0
P.commandWidth = 0
-P.configWidth = 0
+P.editboxWidth = 0
P.resetWidth = 0
P.spaceWidth = 0
@@ -74,30 +74,37 @@
end
end
- P.sampleWindow:setText("configure")
- size = getMinTextSize(P.sampleWindow)
- P.configWidth = size[2]+20
-
P.sampleWindow:setText("reset")
size = getMinTextSize(P.sampleWindow)
P.resetWidth = size[2]+20
- P.spaceWidth = math.floor(1/8*P.configWidth)
+ P.spaceWidth = 10
+
+ local pane = tolua.cast(winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane"), "CEGUI::ScrollablePane")
+ size = pane:getViewableArea()
+ P.editboxWidth = size:getWidth() - P.commandWidth - P.resetWidth - 5*P.spaceWidth
P.createLines()
P:setButton(1, 1, {
- ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigBackButton"),
- ["callback"] = P.MiscConfigBackButton_clicked
+ ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/CancelButton"),
+ ["callback"] = P.MiscConfigCancelButton_clicked
})
+
+ P:setButton(1, 2, {
+ ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/OKButton"),
+ ["callback"] = P.MiscConfigOKButton_clicked
+ })
end
function P.createLine(k)
local offset = 0
+ -- content window for the entire line
local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k)
line:setHeight(CEGUI.UDim(0, P.lineHeight))
line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
+ -- config name
local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command")
command:setText(P.nameList[k])
command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
@@ -105,31 +112,24 @@
line:addChildWindow(command)
offset = offset + P.commandWidth + P.spaceWidth
+ -- config value (editable)
local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
configvalue:setProperty("ReadOnly", "set:False")
local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
configvalue:setText(value)
- P.sampleWindow:setText(value)
- local size = getMinTextSize(P.sampleWindow)
- local configvalueWidth = 2*size[2]
- configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, configvalueWidth), CEGUI.UDim(0.9, 0)))
+ configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0)))
configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
+ -- enable the reset button if the value changed
+ orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted")
line:addChildWindow(configvalue)
- offset = offset + configvalueWidth + P.spaceWidth
+ offset = offset + P.editboxWidth + P.spaceWidth
- local config = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Config")
- config:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.configWidth), CEGUI.UDim(0.9, 0)))
- config:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
- config:setText("configure")
- orxonox.GUIManager:subscribeEventHelper(config, "Clicked", P.name .. ".MiscConfigConfigure_clicked")
- line:addChildWindow(config)
- offset = offset + P.configWidth + P.spaceWidth
-
+ -- reset button (only available when value changed)
local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
reset:setText("reset")
- orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigReset_clicked")
+ orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigResetButton_clicked")
line:addChildWindow(reset)
reset:setEnabled(false)
offset = offset + P.resetWidth + P.spaceWidth
@@ -152,32 +152,46 @@
pane:setVerticalStepSize(getScrollingStepSize(window))
end
-function P.MiscConfigReset_clicked(e)
+function P.MiscConfigOKButton_clicked(e)
+ for k,v in pairs(P.commandList) do
+ -- save the changes
+ local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
+ orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText())
+ local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
+ resetButton:setEnabled(false)
+ end
+
+ hideMenuSheet("MiscConfigMenu")
+end
+
+function P.MiscConfigCancelButton_clicked(e)
+ hideMenuSheet("MiscConfigMenu")
+end
+
+function P.MiscConfigEditbox_textAccepted(e)
local we = CEGUI.toWindowEventArgs(e)
local name = we.window:getName()
local match = string.gmatch(name, "%d+")
local commandNr = tonumber(match())
- -- TODO: Implement reset.
+ local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset")
+ resetButton:setEnabled(true)
end
-function P.MiscConfigConfigure_clicked(e)
+function P.MiscConfigResetButton_clicked(e)
local we = CEGUI.toWindowEventArgs(e)
local name = we.window:getName()
local match = string.gmatch(name, "%d+")
local commandNr = tonumber(match())
- local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
-
- orxonox.CommandExecutor:execute("config " .. P.commandList[commandNr] .. " " .. window:getText())
+ -- reload the old value
+ local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
- window:setText(value)
+ editbox:setText(value)
+
+ we.window:setEnabled(false)
end
-function P.MiscConfigBackButton_clicked(e)
- hideMenuSheet("MiscConfigMenu")
-end
-
return P
Modified: code/branches/menue/data/gui/scripts/SingleplayerConfigMenu.lua
===================================================================
--- code/branches/menue/data/gui/scripts/SingleplayerConfigMenu.lua 2011-12-07 14:08:18 UTC (rev 8963)
+++ code/branches/menue/data/gui/scripts/SingleplayerConfigMenu.lua 2011-12-07 14:22:46 UTC (rev 8964)
@@ -29,10 +29,6 @@
})
end
-function P.onHide()
-
-end
-
function P.loadConfig(level)
P.commandList = {}
table.insert(P.commandList, "Gametype initialStartCountdown_")
@@ -100,13 +96,16 @@
function P.createLine(k)
local offset = 0
+ -- destroy config line, if it already exists (otherwise would cause an error)
if winMgr:isWindowPresent("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k) then
winMgr:destroyWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k)
end
+ -- content window for the entire line
local line = winMgr:createWindow("DefaultWindow", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k)
line:setHeight(CEGUI.UDim(0, P.lineHeight))
line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
+ -- config name
local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command")
command:setText(P.nameList[k])
command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
@@ -114,16 +113,19 @@
line:addChildWindow(command)
offset = offset + P.commandWidth + P.spaceWidth
+ -- config value (editable)
local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
configvalue:setProperty("ReadOnly", "set:False")
local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
configvalue:setText(value)
configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0)))
configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
+ -- enable the reset button if the value changed
orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".SingleplayerConfigEditbox_textAccepted")
line:addChildWindow(configvalue)
offset = offset + P.editboxWidth + P.spaceWidth
+ -- reset button (only available when value changed)
local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
@@ -153,6 +155,7 @@
function P.SingleplayerConfigOKButton_clicked(e)
for k,v in pairs(P.commandList) do
+ -- save the changes
local editbox = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText())
local resetButton = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
@@ -184,6 +187,7 @@
local match = string.gmatch(name, "%d+")
local commandNr = tonumber(match())
+ -- reload the old value
local editbox = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
editbox:setText(value)
Modified: code/branches/menue/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- code/branches/menue/data/gui/scripts/SingleplayerMenu.lua 2011-12-07 14:08:18 UTC (rev 8963)
+++ code/branches/menue/data/gui/scripts/SingleplayerMenu.lua 2011-12-07 14:22:46 UTC (rev 8964)
@@ -18,7 +18,8 @@
P.createFilterTab("Tests", "test")
P.createFilterTab("Show All", nil)
- SingleplayerSelectionChanged()
+ -- update description and screenshot boxes
+ P.SingleplayerSelectionChanged()
--buttons are arranged in a 1x3 matrix
P:setButton(1, 1, {
@@ -46,6 +47,7 @@
level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
if level ~= nil then
local levelXMLFilename = level:getXMLFilename()
+ -- create an imageset for each screenshot
local imageName = level:getScreenshot()
if imageName ~= "" then
CEGUI.ImagesetManager:getSingleton():createImagesetFromImageFile(levelXMLFilename..imageName, imageName)
@@ -88,9 +90,10 @@
end
end
table.insert(P.activeTabIndexes, tabIndexes)
- listbox:subscribeEvent("ItemSelectionChanged", "SingleplayerSelectionChanged")
+ -- listen to selection changes
+ orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".SingleplayerSelectionChanged")
local tabControl = winMgr:getWindow("orxonox/SingleplayerTabControl")
- tabControl:subscribeEvent("TabSelectionChanged", "SingleplayerSelectionChanged")
+ orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".SingleplayerSelectionChanged")
if listbox:getItemCount() > 0 then
tabControl:addChildWindow(tabName)
end
@@ -102,6 +105,7 @@
local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex()))
local choice = listbox:getFirstSelectedItem()
if choice ~= nil then
+ -- get the right tab and the right index
local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1]
local index = tabIndexes[listbox:getItemIndex(choice)+1]
return P.levelList[index]
@@ -110,7 +114,7 @@
end
end
-function SingleplayerSelectionChanged(e)
+function P.SingleplayerSelectionChanged(e)
local levelImage = winMgr:getWindow("orxonox/SingleplayerLevelImage")
local levelDescription = winMgr:getWindow("orxonox/SingleplayerLevelDescription")
local configButton = winMgr:getWindow("orxonox/SingleplayerConfigButton")
@@ -118,14 +122,17 @@
if level ~= nil then
local levelXMLFilename = level:getXMLFilename()
local imageName = level:getScreenshot()
+ -- set the screenshot and the description for the selected level
levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image")
levelDescription:setText(level:getDescription())
+ -- only enable config button for "gametype" levels
if level:hasTag("gametype") then
configButton:setProperty("Disabled", "False")
else
configButton:setProperty("Disabled", "True")
end
else
+ -- also take care of "no level selected"
levelImage:setProperty("Image", nil)
levelDescription:setText("")
configButton:setProperty("Disabled", "True")
@@ -143,8 +150,8 @@
function P.SingleplayerConfigButton_clicked(e)
local level = P.SingleplayerGetSelectedLevel()
if level ~= nil then
- local X = showMenuSheet("SingleplayerConfigMenu")
- X:loadConfig(level)
+ local configMenu = showMenuSheet("SingleplayerConfigMenu")
+ configMenu:loadConfig(level)
end
end
More information about the Orxonox-commit
mailing list