[Orxonox-commit 2964] r7663 - code/branches/menu/data/gui/scripts
konrad at orxonox.net
konrad at orxonox.net
Wed Nov 24 15:33:26 CET 2010
Author: konrad
Date: 2010-11-24 15:33:26 +0100 (Wed, 24 Nov 2010)
New Revision: 7663
Modified:
code/branches/menu/data/gui/scripts/CreditsMenu.lua
code/branches/menu/data/gui/scripts/GUITools.lua
code/branches/menu/data/gui/scripts/MainMenu.lua
code/branches/menu/data/gui/scripts/MultiplayerMenu.lua
code/branches/menu/data/gui/scripts/SettingsMenu.lua
Log:
key handling in some menu sheets has been added.
Modified: code/branches/menu/data/gui/scripts/CreditsMenu.lua
===================================================================
--- code/branches/menu/data/gui/scripts/CreditsMenu.lua 2010-11-24 14:29:56 UTC (rev 7662)
+++ code/branches/menu/data/gui/scripts/CreditsMenu.lua 2010-11-24 14:33:26 UTC (rev 7663)
@@ -2,9 +2,28 @@
local P = createMenuSheet("CreditsMenu")
+P.buttonList = {}
+
+function P.onLoad()
+ local item = {
+ ["button"] = winMgr:getWindow("orxonox/CreditsBackButton"),
+ ["function"] = P.CreditsBackButton_clicked
+ }
+ P.buttonList[1] = item
+end
+
+function P.onShow()
+ P.oldindex = -2
+ P.index = -1
+end
+
function P.CreditsBackButton_clicked(e)
hideMenuSheet(P.name)
end
+function P.onKeyPressed()
+ buttonIteratorHelper(P.buttonList, code, P, 1, 1)
+end
+
return P
Modified: code/branches/menu/data/gui/scripts/GUITools.lua
===================================================================
--- code/branches/menu/data/gui/scripts/GUITools.lua 2010-11-24 14:29:56 UTC (rev 7662)
+++ code/branches/menu/data/gui/scripts/GUITools.lua 2010-11-24 14:33:26 UTC (rev 7663)
@@ -53,3 +53,279 @@
local height = lines * window:getFont():getLineSpacing() + frameHeight
return height
end
+
+
+-- at arguments:
+-- list: 2-dimensional table, arguments are items that contain a button and its function
+-- code: code of any key on the keyboard
+-- P: menusheet
+-- n: number of rows
+-- m: number of colums
+
+function buttonIteratorHelper(list, code, P, n, m)
+
+ --key down
+ if code == "208" then
+ if P.index < 0 then -- initial status
+ P.index = 0
+ P.oldindex = -1
+ else
+ P.oldindex = P.index
+ P.index = (P.index + m) % (m*n)
+
+ while list[P.index+1] == nil do
+ P.oldindex = P.index
+ P.index = (P.index + m) % (m*n)
+ end
+ end
+
+ --key up
+ elseif code == "200" then
+ if P.index < 0 then
+ P.index = 0
+ P.oldindex = -1
+ elseif(P.index == 0) then
+ P.oldindex = P.index
+ P.index = m*n-m
+
+ while list[P.index+1] == nil do
+ P.oldindex = P.index
+ P.index = (P.index-m)%(m*n)
+ end
+ else
+ P.oldindex = P.index
+ P.index = (P.index -m) % (m*n)
+
+ while list[P.index+1] == nil do
+ cout(0,P.index)
+ P.oldindex = P.index
+ P.index = (P.index-m)%(m*n)
+ end
+ end
+
+ --key right
+ elseif code == "205" then
+ if P.index < 0 then
+ P.index = 0
+ P.oldindex = -1
+ elseif (P.index+1) % m == 0 then -- we are at the right-end of a row
+ P.oldindex = P.index
+ P.index = P.index + 1 -m
+
+ while list[P.index+1] == nil do
+ P.oldindex = P.index
+ P.index = P.index + 1
+ end
+ else
+ P.oldindex = P.index
+ P.index = P.index + 1
+
+ while list[P.index+1] == nil do
+ if (P.index+1) % m == 0 then -- we are at the right-end of a row
+ P.oldindex = P.index
+ P.index = P.index + 1-m
+
+ else
+ P.oldindex = P.index
+ P.index = P.index + 1
+ end
+ end
+ end
+
+ --key left
+ elseif code == "203" then
+ if P.index < 0 then
+ P.index = 0
+ P.oldindex = -1
+ elseif P.index % m == 0 then -- we are at the left-end of a row
+ P.oldindex = P.index
+ P.index = P.index +m-1
+
+ while list[P.index+1] == nil do
+ P.oldindex = P.index
+ P.index = P.index -1
+ end
+ else
+ P.oldindex = P.index
+ P.index = P.index -1
+
+ while list[P.index+1] == nil do
+ if P.index % m == 0 then -- we are at the left-end of a row
+ P.oldindex = P.index
+ P.index = P.index -1 + m
+ else
+ P.oldindex = P.index
+ P.index = P.index -1
+ end
+ end
+ end
+ end
+
+ if (code == "208" or code == "200" or code == "203" or code == "205") and P.oldindex~= P.index then
+
+ local system = CEGUI.System:getSingleton()
+ local window = winMgr:getWindow("orxonox/MainMenuBackground")
+
+ local item = list[P.index+1]
+ local child = item["button"]
+
+ --teste ob der Button nicht schon gehighlightet ist
+ cout(0,child:getProperty("NormalImageRightEdge"))
+ if child:getProperty("NormalImageRightEdge") == "set:TaharezGreenLook image:ButtonRightHighlight" then
+ --nop
+ else
+ child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-7) .. "Highlight")
+ child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-7) .. "Highlight")
+ child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-7) .. "Highlight")
+ if P.oldindex >= 0 then
+ if list[P.oldindex+1] ~= nil then
+ local item = list[P.oldindex+1]
+ local oldChild = item["button"]
+ oldChild:setProperty("NormalImageRightEdge", string.sub(oldChild:getProperty("NormalImageRightEdge"),1,-10) .. "Normal")
+ oldChild:setProperty("NormalImageLeftEdge", string.sub(oldChild:getProperty("NormalImageLeftEdge"),1,-10) .. "Normal")
+ oldChild:setProperty("NormalImageBackground", string.sub(oldChild:getProperty("NormalImageBackground"),1,-10) .. "Normal")
+ end
+ end
+ end
+
+ local i = 1
+ while i < (n*m) do
+ if i == P.index +1 then
+ i = i+1
+ else
+ if list[i] ~= nil then
+ local item = list[i]
+ local child = item["button"]
+ if child:getProperty("NormalImageRightEdge") == "set:TaharezGreenLook image:ButtonRightHighlight" then
+ child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-10) .. "Normal")
+ child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-10) .. "Normal")
+ child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-10) .. "Normal")
+ end
+ end
+ end
+ i=i+1
+ end
+ end
+
+ --enter
+ if code == "28" then
+ local item = list[P.index+1]
+ local child = item["button"]
+ child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-10) .. "Normal")
+ child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-10) .. "Normal")
+ child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-10) .. "Normal")
+
+ local foo = item["function"]
+ foo()
+ end
+
+ cout(0, P.oldindex)
+ cout(0, P.index)
+
+end
+
+function indexTester(list,code,P,n,m)
+ --key down
+ if code == "208" then
+ if P.index < 0 then -- initial status
+ P.index = 0
+ P.oldindex = -1
+ else
+ P.oldindex = P.index
+ P.index = (P.index + m) % (m*n)
+
+ while list[P.index+1] == nil do
+ P.oldindex = P.index
+ P.index = (P.index + m) % (m*n)
+ end
+ end
+
+ --key up
+ elseif code == "200" then
+ if P.index < 0 then
+ P.index = 0
+ P.oldindex = -1
+ elseif(P.index == 0) then
+ P.oldindex = P.index
+ P.index = m*n-m
+
+ while list[P.index+1] == nil do
+ P.oldindex = P.index
+ P.index = (P.index-m)%(m*n)
+ end
+ else
+ P.oldindex = P.index
+ P.index = (P.index -m) % (m*n)
+
+ while list[P.index+1] == nil do
+ P.oldindex = P.index
+ P.index = P.index -m
+ end
+ end
+
+ --key right
+ elseif code == "205" then
+ if P.index < 0 then
+ P.index = 0
+ P.oldindex = -1
+ elseif (P.index+1) % m == 0 then -- we are at the right-end of a row
+ P.oldindex = P.index
+ P.index = P.index + 1 -m
+
+ while list[P.index+1] == nil do
+ P.oldindex = P.index
+ P.index = P.index + 1
+ end
+ else
+ P.oldindex = P.index
+ P.index = P.index + 1
+
+ while list[P.index+1] == nil do
+ if (P.index+1) % m == 0 then -- we are at the right-end of a row
+ P.oldindex = P.index
+ P.index = P.index + 1-m
+
+ else
+ P.oldindex = P.index
+ P.index = P.index + 1
+ end
+ end
+ end
+
+ --key left
+ elseif code == "203" then
+ if P.index < 0 then
+ P.index = 0
+ P.oldindex = -1
+ elseif P.index % m == 0 then -- we are at the left-end of a row
+ P.oldindex = P.index
+ P.index = P.index +m-1
+
+ while list[P.index+1] == nil do
+ P.oldindex = P.index
+ P.index = P.index -1
+ end
+ else
+ P.oldindex = P.index
+ P.index = P.index -1
+
+ while list[P.index+1] == nil do
+ if P.index % m == 0 then -- we are at the left-end of a row
+ P.oldindex = P.index
+ P.index = P.index -1 + m
+ else
+ P.oldindex = P.index
+ P.index = P.index -1
+ end
+ end
+ end
+ end
+
+ cout(0, P.oldindex)
+ cout(0, P.index)
+
+end
+
+
+
+
Modified: code/branches/menu/data/gui/scripts/MainMenu.lua
===================================================================
--- code/branches/menu/data/gui/scripts/MainMenu.lua 2010-11-24 14:29:56 UTC (rev 7662)
+++ code/branches/menu/data/gui/scripts/MainMenu.lua 2010-11-24 14:33:26 UTC (rev 7663)
@@ -3,18 +3,60 @@
local P = createMenuSheet("MainMenu")
P.loadAlong = { "SingleplayerMenu", "MultiplayerMenu", "SettingsMenu", "CreditsMenu" }
-P.index = 0
+P.buttonList = {}
+P.testArray = {}
+
+
+function P.onLoad()
+ local item = {
+ ["button"] = winMgr:getWindow("orxonox/QuickGameTestButton"),
+ ["function"] = P.QuickGameTestButton_clicked
+ }
+ table.insert(P.buttonList,item)
+
+ item = {
+ ["button"] = winMgr:getWindow("orxonox/SingleplayerButton"),
+ ["function"] = P.SingleplayerButton_clicked
+ }
+ table.insert(P.buttonList,item)
+
+ item = {
+ ["button"] = winMgr:getWindow("orxonox/MultiplayerButton"),
+ ["function"] = P.MultiplayerButton_clicked
+ }
+ table.insert(P.buttonList,item)
+
+ item = {
+ ["button"] = winMgr:getWindow("orxonox/SettingsButton"),
+ ["function"] = P.SettingsButton_clicked
+ }
+ table.insert(P.buttonList,item)
+
+ item = {
+ ["button"] = winMgr:getWindow("orxonox/CreditsButton"),
+ ["function"] = P.CreditsButton_clicked
+ }
+ table.insert(P.buttonList,item)
+
+ item = {
+ ["button"] = winMgr:getWindow("orxonox/ExitButton"),
+ ["function"] = P.ExitButton_clicked
+ }
+ table.insert(P.buttonList,item)
+end
+
+function P.onShow()
+ P.oldindex = -2
+ P.index = -1
+end
+
-- events for MainMenu
function P.QuickGameTestButton_clicked(e)
hideAllMenuSheets()
orxonox.execute("startGame")
end
-function P.onShow()
-
-end
-
function P.SingleplayerButton_clicked(e)
showMenuSheet("SingleplayerMenu", true)
end
@@ -35,34 +77,43 @@
orxonox.execute("exit")
end
-function P.onKeyPressed()
- --local we = tolua.cast(e, "CEGUI::KeyEventArgs")
- cout(0, code)
- if code == "15" then
- P.index = P.index + 1
- local window = winMgr:getWindow("orxonox/MainMenuBackground")
- if P.index == window:getChildCount() then
- P.index = 1
- end
- local child = window:getChildAtIdx(P.index-1)
- child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-7) .. "Highlight")
- child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-7) .. "Highlight")
- child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-7) .. "Highlight")
- elseif code == "28" and P.index ~= 0 then
- if P.index == 1 then
- P.QuickGameTestButton_clicked()
- elseif P.index == 2 then
- P.SingleplayerButton_clicked()
- elseif P.index == 3 then
- P.MultiplayerButton_clicked()
- elseif P.index == 4 then
- P.SettingsButton_clicked()
- elseif P.index == 5 then
- P.CreditsButton_clicked()
- elseif P.index == 6 then
- P.ExitButton_clicked()
- end
+
+--[[
+list = {}
+local item =
+{
+ ["button"] = buttonWindow,
+ ["function"] = buttonFunction,
+}
+table.insert(list, item)
+item = list[i]
+
+for i,item in pairs(list) do
+ button = item["button"]
+end
+
+--]]
+--[[
+function createList()
+ list = {}
+
+ local j
+ while j < P.loadAlong
+ local item =
+ {
+ ["button"] = buttonWindow,
+ ["function"] = buttonFunction,
+ }
+ table.insert(list, item)
end
+
+--]]
+
+function P.onKeyPressed()
+ cout(0,code)
+ buttonIteratorHelper(P.buttonList, code, P, 6, 1)
+ --indexTester(P.buttonList,code,P,6,1)
end
return P
+
Modified: code/branches/menu/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/menu/data/gui/scripts/MultiplayerMenu.lua 2010-11-24 14:29:56 UTC (rev 7662)
+++ code/branches/menu/data/gui/scripts/MultiplayerMenu.lua 2010-11-24 14:33:26 UTC (rev 7663)
@@ -2,12 +2,35 @@
local P = createMenuSheet("MultiplayerMenu")
+P.buttonList = {}
+
function P.onLoad()
- P.multiplayerMode = "startClient"
+ P.multiplayerMode = "startClient"
+
+ local item = {
+ ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton2"),
+ ["function"] = P.MultiplayerJoinButton_clicked
+ }
+ P.buttonList[1] = item
+
+ local item = {
+ ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton2"),
+ ["function"] = P.MultiplayerHostButton_clicked
+ }
+ P.buttonList[2] = item
+
+ local item = {
+ ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"),
+ ["function"] = P.MultiplayerBackButton_clicked
+ }
+ P.buttonList[4] = item
+
end
function P.onShow()
P.showServerList()
+ P.oldindex = -2
+ P.index = -1
end
function P.MultiplayerJoinButton_clicked(e)
@@ -108,5 +131,11 @@
end
end
+function P.onKeyPressed()
+ cout(0,code)
+ buttonIteratorHelper(P.buttonList, code, P, 2, 2)
+ --indexTester(P.buttonList,code,P,2,3)
+end
+
return P
Modified: code/branches/menu/data/gui/scripts/SettingsMenu.lua
===================================================================
--- code/branches/menu/data/gui/scripts/SettingsMenu.lua 2010-11-24 14:29:56 UTC (rev 7662)
+++ code/branches/menu/data/gui/scripts/SettingsMenu.lua 2010-11-24 14:33:26 UTC (rev 7663)
@@ -3,6 +3,49 @@
local P = createMenuSheet("SettingsMenu")
P.loadAlong = { "ControlsMenu", "AudioMenu", "GraphicsMenu" }
+P.buttonList = {}
+
+function P.onLoad()
+ --"Gameplay" and "Multiplayer Options" are not integrated in the list
+
+ local item = {
+ ["button"] = winMgr:getWindow("orxonox/SettingsMenu/GraphicsButton"),
+ ["function"] = P.SettingsGraphicsButton_clicked
+ }
+ P.buttonList[2] = item
+
+ local item = {
+ ["button"] = winMgr:getWindow("orxonox/SettingsMenu/AudioButton"),
+ ["function"] = P.SettingsAudioButton_clicked
+ }
+ P.buttonList[4] = item
+
+
+ local item = {
+ ["button"] = winMgr:getWindow("orxonox/SettingsMenu/ControlsButton"),
+ ["function"] = P.SettingsControlsButton_clicked
+ }
+ P.buttonList[5] = item
+
+ local item = {
+ ["button"] = winMgr:getWindow("orxonox/SettingsMenu/MiscellaneousButton"),
+ ["function"] = P.SettingsMiscellaneousButton_clicked
+ }
+ P.buttonList[6] = item
+
+ local item = {
+ ["button"] = winMgr:getWindow("orxonox/SettingsMenu/SettingsBackButton"),
+ ["function"] = P.SettingsBackButton_clicked
+ }
+ P.buttonList[7] = item
+
+end
+
+function P.onShow()
+ P.oldindex = 3
+ P.index = 2
+end
+
function P.SettingsGameplayButton_clicked(e)
showMenuSheet("GameplayMenu", true)
end
@@ -31,5 +74,11 @@
hideMenuSheet(P.name)
end
+function P.onKeyPressed()
+ cout(0,code)
+ buttonIteratorHelper(P.buttonList, code, P, 4, 2)
+ --indexTester(P.buttonList,code,P,4,2)
+end
+
return P
More information about the Orxonox-commit
mailing list