[Orxonox-commit 3231] r7922 - code/branches/usability/data/gui/scripts
landauf at orxonox.net
landauf at orxonox.net
Sun Feb 20 00:47:57 CET 2011
Author: landauf
Date: 2011-02-20 00:47:57 +0100 (Sun, 20 Feb 2011)
New Revision: 7922
Modified:
code/branches/usability/data/gui/scripts/AudioMenu.lua
code/branches/usability/data/gui/scripts/ControlsMenu.lua
code/branches/usability/data/gui/scripts/CreditsMenu.lua
code/branches/usability/data/gui/scripts/DecisionPopup.lua
code/branches/usability/data/gui/scripts/GUISheet.lua
code/branches/usability/data/gui/scripts/GUITools.lua
code/branches/usability/data/gui/scripts/GraphicsMenu.lua
code/branches/usability/data/gui/scripts/HostMenu.lua
code/branches/usability/data/gui/scripts/InGameMenu.lua
code/branches/usability/data/gui/scripts/MainMenu.lua
code/branches/usability/data/gui/scripts/MultiplayerMenu.lua
code/branches/usability/data/gui/scripts/NotificationLayer.lua
code/branches/usability/data/gui/scripts/SettingsMenu.lua
code/branches/usability/data/gui/scripts/SheetManager.lua
code/branches/usability/data/gui/scripts/SingleplayerMenu.lua
Log:
implemented new keyboard control of menu buttons with these new features:
- more intuitive placement of buttons in table (row/column format instead of linear index)
- no need to overwrite onShow() and onKeyPressed() functions, no need for P.buttonList
- highlights the selected button in a different layout than mouse hovering
- remembers the selection while moving through the menu hierarchy, but resets it if the menu is closed
- allows preselected button (for example "Yes" in decision popup)
- when opening a menu, the first selected button is not always the upper left, but instead depends on the pressed key (e.g. the 'up' key selects the button at the bottom, while the 'down' key selects the button at the top. once a button is selected, the keys behave as usual)
+ fixed wrong callback function in ingame menu
Modified: code/branches/usability/data/gui/scripts/AudioMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/AudioMenu.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/AudioMenu.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -2,13 +2,6 @@
local P = createMenuSheet("AudioMenu")
-P.buttonList = {}
-
-function P.onShow()
- P.oldindex = -2
- P.index = -1
-end
-
function P.onLoad()
soundMgr = orxonox.SoundManager:getInstance()
block = false
@@ -49,11 +42,11 @@
listboxwindow:setItemSelectState(0,true)
end
- local item = {
+ P:initButtons(1, 1)
+ P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/AudioBackButton"),
- ["function"] = P.AudioBackButton_clicked
- }
- P.buttonList[1] = item
+ ["callback"] = P.AudioBackButton_clicked
+ })
end
function P.AudioMasterScrollbar_changed(e)
@@ -184,9 +177,5 @@
hideMenuSheet(P.name)
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 1, 1)
-end
-
return P
Modified: code/branches/usability/data/gui/scripts/ControlsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/ControlsMenu.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/ControlsMenu.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -1,39 +1,30 @@
-- ControlsMenu.lua
local P = createMenuSheet("ControlsMenu")
-P.buttonList = {}
P.loadAlong = { "MouseControlsMenu", "KeyBindMenu" }
function P.onLoad()
- P.multiplayerMode = "startClient"
+ P.multiplayerMode = "startClient"
--buttons are arranged in a 3x1 matrix:
- local item = {
+ P:initButtons(3, 1)
+
+ P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/MouseControlsButton"),
- ["function"] = P.ControlsMouseControlsButton_clicked
- }
- P.buttonList[1] = item
+ ["callback"] = P.ControlsMouseControlsButton_clicked
+ })
- local item = {
+ P:setButton(2, 1, {
["button"] = winMgr:getWindow("orxonox/KeybindingsButton"),
- ["function"] = P.ControlsKeyboardControlsButton_clicked
- }
- P.buttonList[2] = item
+ ["callback"] = P.ControlsKeyboardControlsButton_clicked
+ })
- local item = {
+ P:setButton(3, 1, {
["button"] = winMgr:getWindow("orxonox/ControlsBackButton"),
- ["function"] = P.ControlsBackButton_clicked
- }
- P.buttonList[3] = item
-
+ ["callback"] = P.ControlsBackButton_clicked
+ })
end
-function P.onShow()
- --indices to iterate through buttonlist
- P.oldindex = -2
- P.index = -1
-end
-
function P.ControlsMouseControlsButton_clicked(e)
showMenuSheet("MouseControlsMenu", true)
end
@@ -46,9 +37,5 @@
hideMenuSheet(P.name)
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 3, 1)
-end
-
return P
Modified: code/branches/usability/data/gui/scripts/CreditsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/CreditsMenu.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/CreditsMenu.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -2,22 +2,17 @@
local P = createMenuSheet("CreditsMenu")
-P.buttonList = {}
P.scrollbarWidth = 13
function P.onLoad()
- local item = {
+ P:initButtons(1, 1)
+ P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/CreditsBackButton"),
- ["function"] = P.CreditsBackButton_clicked
- }
- P.buttonList[1] = item
+ ["callback"] = P.CreditsBackButton_clicked
+ })
end
function P.onShow()
- --indices to iterate through buttonlist
- P.oldindex = -2
- P.index = -1
-
local description = winMgr:getWindow("orxonox/CreditsText")
description:setProperty("HorzFormatting", "WordWrapLeftAligned")
description:setProperty("VertFormatting", "TopAligned")
@@ -32,9 +27,5 @@
hideMenuSheet(P.name)
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 1, 1)
-end
-
return P
Modified: code/branches/usability/data/gui/scripts/DecisionPopup.lua
===================================================================
--- code/branches/usability/data/gui/scripts/DecisionPopup.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/DecisionPopup.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -2,29 +2,24 @@
local P = createMenuSheet("DecisionPopup")
-P.buttonList = {}
-
-function P.onShow()
- --indices to iterate through buttonlist
- P.oldindex = -2
- P.index = -1
-end
-
function P.onLoad()
--button are arranged in a 1x2 matrix
- local item = {
+ P:initButtons(1, 2)
+
+ P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/DecisionPopup_button_yes"),
- ["function"] = P.button_yes
- }
- P.buttonList[1] = item
+ ["callback"] = P.button_yes
+ })
- local item = {
+ P:setButton(1, 2, {
["button"] = winMgr:getWindow("orxonox/DecisionPopup_button_no"),
- ["function"] = P.button_no
- }
- P.buttonList[2] = item
+ ["callback"] = P.button_no
+ })
+end
+function P.onShow()
+ P:setSelection(1, 1)
end
function P.setCallback(functionPtr)
@@ -50,9 +45,5 @@
hideMenuSheet("DecisionPopup")
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 1, 2)
-end
-
return P
Modified: code/branches/usability/data/gui/scripts/GUISheet.lua
===================================================================
--- code/branches/usability/data/gui/scripts/GUISheet.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/GUISheet.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -15,18 +15,31 @@
function P:onLoad()
end
+-- Override this function if you need to do work on show
+function P:onShow()
+end
+
+-- Override this function if you need to do work on hide
+function P:onHide()
+end
+
+-- Override this function if you need to do work just after the sheet has been hidden
+function P:onAfterHide()
+end
+
-- show function for the GUI
function P:show()
self.window:show()
self.bVisible = true
+ -- set the selected button's state
+ if self.buttons and self:hasSelection() then
+ self:setButtonStateSelected()
+ end
+
self:onShow()
end
--- Override this function if you need to do work on show
-function P:onShow()
-end
-
-- hide function for the GUI
function P:hide()
self.window:hide()
@@ -35,12 +48,13 @@
self:onHide()
end
--- Override this function if you need to do work on hide
-function P:onHide()
-end
+function P:afterHide()
+ -- reset the selected button
+ if self.buttons then
+ self:resetSelection()
+ end
--- Override this function if you need to do work just after the sheet has been hidden
-function P:afterHide()
+ self:onAfterHide()
end
function P:load()
@@ -63,7 +77,199 @@
return self
end
-function P:onKeyPressed(e)
+-- Handles key pressed while the gui sheed is displayed
+function P:keyPressed()
+ if self.buttons then
+ if code == "208" then -- key down
+ self:moveSelection(1, 0)
+ elseif code == "200" then -- key up
+ self:moveSelection(-1, 0)
+ elseif code == "205" then -- key right
+ self:moveSelection(0, 1)
+ elseif code == "203" then -- key left
+ self:moveSelection(0, -1)
+ elseif code == "28" then -- key enter
+ self:pressSelectedButton()
+ end
+ end
+
+ self.onKeyPressed()
end
+-- Override this function if you want to ract on keystrokes
+function P:onKeyPressed()
+end
+
+
+-------------------------------------------------------------------------------
+-- Keyboard control -----------------------------------------------------------
+-------------------------------------------------------------------------------
+
+-- Initializes the buttons table, used to control the menu with the keyboard
+function P:initButtons(rows, columns)
+ self.rows = rows
+ self.columns = columns
+ self.buttons = {}
+ self.selectedRow = 0
+ self.selectedColumn = 0
+end
+
+-- Defines the button for a given position in the table. The upper-left button is at position (1, 1)
+function P:setButton(row, column, button)
+ assert(self.rows ~= nil and self.columns ~= nil and self.buttons ~= nil, "You have to call initButtons() before using setButton()")
+ assert(row > 0 and column > 0 and row <= self.rows and column <= self.columns, "(" .. row .. "/" .. column .. ") is not in the valid bounds of the table (1/1)-(" .. self.rows .. "/" .. self.columns .. ")")
+
+ self.buttons[(row - 1) * self.columns + (column - 1)] = button
+end
+
+-- Returns the button at a given position in the table. The upper-left button is at position (1, 1)
+function P:getButton(row, column)
+ assert(row > 0 and column > 0 and row <= self.rows and column <= self.columns, "(" .. row .. "/" .. column .. ") is not in the valid bounds of the table (1/1)-(" .. self.rows .. "/" .. self.columns .. ")")
+
+ return self.buttons[(row - 1) * self.columns + (column - 1)]
+end
+
+-- Returns the selected button
+function P:getSelectedButton()
+ assert(self.selectedRow > 0 and self.selectedColumn > 0, "no button selected")
+
+ return self:getButton(self.selectedRow, self.selectedColumn)
+end
+
+-- Presses the selected button if any
+function P:pressSelectedButton()
+ if self:hasSelection() then
+ self:getSelectedButton().callback()
+ end
+end
+
+-- Sets the selection to a given row and column. The upper-left button is at position (1, 1)
+function P:setSelection(row, column)
+ assert(row > 0 and column > 0 and row <= self.rows and column <= self.columns, "(" .. row .. "/" .. column .. ") is not in the valid bounds of the table (1/1)-(" .. self.rows .. "/" .. self.columns .. ")")
+
+ if self:hasSelection() then
+ self:setButtonStateNormal()
+ end
+
+ self.selectedRow = row
+ self.selectedColumn = column
+
+ self:setButtonStateSelected()
+end
+
+-- Moves the selection by a given number of rows and columns (positive values mean increasing row/column, negative values mean decreasing row/column)
+function P:moveSelection(relRow, relColumn)
+ -- if there's no selection yet, prepare it such that the selection enters the table from the desired side
+ if self:hasSelection() == false then
+ -- note: we assume either relRow or relColumn is 0, thus no diagonal movement. therefore the following checks can be separated
+ if relRow > 0 then
+ self.selectedRow = 0
+ self.selectedColumn = 1
+ elseif relRow < 0 then
+ self.selectedRow = self.rows + 1
+ self.selectedColumn = 1
+ end
+
+ if relColumn > 0 then
+ self.selectedRow = 1
+ self.selectedColumn = 0
+ elseif relColumn < 0 then
+ self.selectedRow = 1
+ self.selectedColumn = self.columns + 1
+ end
+ else
+ self:setButtonStateNormal()
+ end
+
+ -- move the selection according to the parameters
+ self.selectedRow = self.selectedRow + relRow
+ self.selectedColumn = self.selectedColumn + relColumn
+
+ -- wrap around on overflow
+ while self.selectedRow > self.rows do
+ self.selectedRow = self.selectedRow - self.rows
+ end
+ while self.selectedColumn > self.columns do
+ self.selectedColumn = self.selectedColumn - self.columns
+ end
+
+ -- wrap around on underflow
+ while self.selectedRow <= 0 do
+ self.selectedRow = self.selectedRow + self.rows
+ end
+ while self.selectedColumn <= 0 do
+ self.selectedColumn = self.selectedColumn + self.columns
+ end
+
+ -- if the button is deactivated, call this function again
+ if self:getSelectedButton() == nil then
+ self:moveSelection(relRow, relColumn)
+ else
+ self:setButtonStateSelected()
+ end
+end
+
+-- Resets the selection
+function P:resetSelection()
+ if self:hasSelection() then
+ self:setButtonStateNormal()
+ end
+
+ self.selectedRow = 0
+ self.selectedColumn = 0
+end
+
+-- Determines if a button is selected
+function P:hasSelection()
+ if self.selectedRow == 0 or self.selectedColumn == 0 then
+ return false
+ else
+ return true
+ end
+end
+
+-- Sets the selected button's state to normal
+function P:setButtonStateNormal()
+ self:setButtonState("Normal")
+end
+
+-- Sets the selected button's state to selected
+function P:setButtonStateSelected()
+ self:setButtonState("Selected")
+end
+
+-- Sets the selected button's state to pushed
+function P:setButtonStatePushed()
+ self:setButtonState("Pushed")
+end
+
+-- Sets the selected button's state
+function P:setButtonState(state)
+ if self:getSelectedButton() then
+ local element = self:getSelectedButton().button
+ local offset = getElementStateOffset(element)
+
+ if offset then
+ element:setProperty("NormalImageRightEdge", string.sub(element:getProperty("NormalImageRightEdge"), 1, offset) .. state)
+ element:setProperty("NormalImageLeftEdge", string.sub(element:getProperty("NormalImageLeftEdge"), 1, offset) .. state)
+ element:setProperty("NormalImageBackground", string.sub(element:getProperty("NormalImageBackground"), 1, offset) .. state)
+ end
+ end
+end
+
+-- Gets the offset of the button's current state
+function getElementStateOffset(element)
+ local property = element:getProperty("NormalImageRightEdge")
+
+ if string.sub(property, string.len(property) - 5, string.len(property)) == "Normal" then
+ return -7
+ elseif string.sub(property, string.len(property) - 7, string.len(property)) == "Selected" then
+ return -9
+ elseif string.sub(property, string.len(property) - 5, string.len(property)) == "Pushed" then
+ return -7
+ else
+ return nil
+ end
+end
+
return P
Modified: code/branches/usability/data/gui/scripts/GUITools.lua
===================================================================
--- code/branches/usability/data/gui/scripts/GUITools.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/GUITools.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -53,284 +53,3 @@
local height = lines * window:getFont():getLineSpacing() + frameHeight
return height
end
-
---function to iterate through a menu sheet by using arrowkeys
-
--- at arguments:
--- list: 2-dimensional table, arguments are items that contain a button and its function
--- !!note: each button can only be in the list once!!
--- code: code of any key on the keyboard
--- P: menusheet
--- n: number of rows of the buttontable
--- m: number of colums of the buttontable
-
-function buttonIteratorHelper(list, code, P, n, m)
-
- --after a key (down,up,left,right) is pressed the index of the current button has to be updated
-
- --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) --modulo operation works as a "wrap around" in the button menu
-
- 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)%(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
-
- --to update the new current button
- 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"]
- local s = child:getProperty("NormalImageRightEdge")
-
- --teste ob der Button nicht schon gehighlightet ist
- if string.sub(s,string.len(s)-8,string.len(s)) == "Highlight" 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
-
- --for every highlighted button check if index is on its position. If not, set imageproperty on "normal"
- 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"]
- local s = child:getProperty("NormalImageRightEdge")
- if string.sub(s,string.len(s)-8,string.len(s)) == "Highlight" 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" and P.index >= 0 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
-
-end
-
---write index and oldindex on the console
---works like buttonIteratorHelper
-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/usability/data/gui/scripts/GraphicsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/GraphicsMenu.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/GraphicsMenu.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -2,15 +2,8 @@
local P = createMenuSheet("GraphicsMenu")
-P.buttonList = {}
P.schemeList = {"TaharezGreen", "Orxonox"}
-function P.onShow()
- --indices to iterate through buttonlist (trivial in this menu sheet)
- P.oldindex = -2
- P.index = -1
-end
-
function P.onLoad()
block = true
file = orxonox.PathConfig:getConfigPathString() .. orxonox.getConfig("GraphicsManager", "ogreConfigFile_")
@@ -92,11 +85,11 @@
scrollbar_active = false
block = false
- local item = {
+ P:initButtons(1, 1)
+ P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/GraphicsBackButton"),
- ["function"] = P.GraphicsBackButton_clicked
- }
- P.buttonList[1] = item
+ ["callback"] = P.GraphicsBackButton_clicked
+ })
local dropbox = winMgr:getWindow("orxonox/ThemeDropBox")
local scheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_")
@@ -232,9 +225,5 @@
hideMenuSheet(P.name)
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 1, 1)
-end
-
return P
Modified: code/branches/usability/data/gui/scripts/HostMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/HostMenu.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/HostMenu.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -4,29 +4,28 @@
P.multiplayerMode = "startServer"
-P.buttonList = {}
P.levelList = {}
P.itemList = {}
P.showAll = false
function P.onLoad()
- P.multiplayerMode = "startServer"
+ P.multiplayerMode = "startServer"
local window = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
local button = tolua.cast(window,"CEGUI::Checkbox")
button:setSelected(false)
P.createLevelList()
- local item = {
+ P:initButtons(1, 2)
+
+ P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/HostMenuStartButton"),
- ["function"] = P.HostMenuStartButton_clicked
- }
- P.buttonList[1] = item
+ ["callback"] = P.HostMenuStartButton_clicked
+ })
- local item = {
+ P:setButton(1, 2, {
["button"] = winMgr:getWindow("orxonox/HostMenuBackButton"),
- ["function"] = P.HostMenuBackButton_clicked
- }
- P.buttonList[2] = item
+ ["callback"] = P.HostMenuBackButton_clicked
+ })
end
function P.onShow()
@@ -43,10 +42,6 @@
button:setSelected(true)
P.createLevelList()
end
-
- P.oldindex = -2
- P.index = -1
-
end
function P.createLevelList()
@@ -96,7 +91,7 @@
hideMenuSheet(P.name)
end
-function P.HostMenuStartButton_clicked(e)
+function P.HostMenuStartButton_clicked(e)
local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/HostMenuListbox"))
local choice = listbox:getFirstSelectedItem()
if choice ~= nil then
@@ -118,8 +113,4 @@
end
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 1, 2)
-end
-
return P
Modified: code/branches/usability/data/gui/scripts/InGameMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/InGameMenu.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/InGameMenu.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -3,42 +3,37 @@
local P = createMenuSheet("InGameMenu")
P.loadAlong = { "DecisionPopup" }
-P.buttonList = {}
-
function P.onLoad()
- P.multiplayerMode = "startClient"
+ P.multiplayerMode = "startClient"
--button are arranged in a 4x1 matrix, the left lower item is nil
- local item = {
+ P:initButtons(4, 1)
+
+ P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/InGameMenu_ReturnButton"),
- ["function"] = P.button_settings_clicked
- }
- P.buttonList[1] = item
+ ["callback"] = P.button_return_clicked
+ })
- local item = {
+ P:setButton(2, 1, {
["button"] = winMgr:getWindow("orxonox/InGameMenu_MainMenuButton"),
- ["function"] = P.button_mainmenu_clicked
- }
- P.buttonList[2] = item
+ ["callback"] = P.button_mainmenu_clicked
+ })
- local item = {
+ P:setButton(3, 1, {
["button"] = winMgr:getWindow("orxonox/InGameMenu_SettingsButton"),
- ["function"] = P.button_settings_clicked
- }
- P.buttonList[3] = item
+ ["callback"] = P.button_settings_clicked
+ })
- local item = {
+ P:setButton(4, 1, {
["button"] = winMgr:getWindow("orxonox/InGameMenu_QuitButton"),
- ["function"] = P.button_quit_clicked
- }
- P.buttonList[4] = item
-
+ ["callback"] = P.button_quit_clicked
+ })
end
function P.onShow()
- --indices to iterate through buttonlist
- P.oldindex = -2
- P.index = -1
+ if P:hasSelection() == false then
+ P:setSelection(1, 1)
+ end
end
-- events for ingamemenu
@@ -63,14 +58,10 @@
if doExit then
hideMenuSheet("InGameMenu")
orxonox.execute("exit")
- else
+ else
P.onShow()
end
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 4, 1)
-end
-
return P
Modified: code/branches/usability/data/gui/scripts/MainMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/MainMenu.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/MainMenu.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -3,53 +3,41 @@
local P = createMenuSheet("MainMenu")
P.loadAlong = { "SingleplayerMenu", "MultiplayerMenu", "SettingsMenu", "CreditsMenu" }
-P.buttonList = {}
-
function P.onLoad()
--buttons are arranged in a 6x1 Matrix (list)
- local item = {
+ P:initButtons(6, 1)
+
+ P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/QuickGameTestButton"),
- ["function"] = P.QuickGameTestButton_clicked
- }
- table.insert(P.buttonList,item)
+ ["callback"] = P.QuickGameTestButton_clicked
+ })
- item = {
+ P:setButton(2, 1, {
["button"] = winMgr:getWindow("orxonox/SingleplayerButton"),
- ["function"] = P.SingleplayerButton_clicked
- }
- table.insert(P.buttonList,item)
+ ["callback"] = P.SingleplayerButton_clicked
+ })
- item = {
+ P:setButton(3, 1, {
["button"] = winMgr:getWindow("orxonox/MultiplayerButton"),
- ["function"] = P.MultiplayerButton_clicked
- }
- table.insert(P.buttonList,item)
+ ["callback"] = P.MultiplayerButton_clicked
+ })
- item = {
+ P:setButton(4, 1, {
["button"] = winMgr:getWindow("orxonox/SettingsButton"),
- ["function"] = P.SettingsButton_clicked
- }
- table.insert(P.buttonList,item)
+ ["callback"] = P.SettingsButton_clicked
+ })
- item = {
+ P:setButton(5, 1, {
["button"] = winMgr:getWindow("orxonox/CreditsButton"),
- ["function"] = P.CreditsButton_clicked
- }
- table.insert(P.buttonList,item)
+ ["callback"] = P.CreditsButton_clicked
+ })
- item = {
+ P:setButton(6, 1, {
["button"] = winMgr:getWindow("orxonox/ExitButton"),
- ["function"] = P.ExitButton_clicked
- }
- table.insert(P.buttonList,item)
+ ["callback"] = P.ExitButton_clicked
+ })
end
-function P.onShow()
- --indices to iterate through buttonlist
- P.oldindex = -2
- P.index = -1
-end
-
-- events for MainMenu
function P.QuickGameTestButton_clicked(e)
hideAllMenuSheets()
@@ -76,9 +64,5 @@
orxonox.execute("exit")
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 6, 1)
-end
-
return P
Modified: code/branches/usability/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/MultiplayerMenu.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/MultiplayerMenu.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -2,8 +2,6 @@
local P = createMenuSheet("MultiplayerMenu")
-P.buttonList = {}
-
--joinMode is 1 for choice "LAN" and 2 for "Internet"
--initial status 1
P.joinMode = 1
@@ -12,32 +10,27 @@
P.multiplayerMode = "startClient"
--button are arranged in a 2x2 matrix, the left lower item is nil
- local item = {
+ P:initButtons(2, 2)
+
+ P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"),
- ["function"] = P.MultiplayerJoinButton_clicked
- }
- P.buttonList[1] = item
+ ["callback"] = P.MultiplayerJoinButton_clicked
+ })
- local item = {
+ P:setButton(1, 2, {
["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"),
- ["function"] = P.MultiplayerHostButton_clicked
- }
- P.buttonList[2] = item
+ ["callback"] = P.MultiplayerHostButton_clicked
+ })
- local item = {
+ P:setButton(2, 2, {
["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"),
- ["function"] = P.MultiplayerBackButton_clicked
- }
- P.buttonList[4] = item
+ ["callback"] = P.MultiplayerBackButton_clicked
+ })
end
function P.onShow()
--P.showServerList()
- --indices to iterate through buttonlist
- P.oldindex = -2
- P.index = -1
-
if P.joinMode == 1 then
local window = winMgr:getWindow("orxonox/MultiplayerLanButton")
local button = tolua.cast(window,"CEGUI::RadioButton")
@@ -157,9 +150,5 @@
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 2, 2)
-end
-
return P
Modified: code/branches/usability/data/gui/scripts/NotificationLayer.lua
===================================================================
--- code/branches/usability/data/gui/scripts/NotificationLayer.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/NotificationLayer.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -45,7 +45,7 @@
P.queueList[queueName] = nil
end
--- Pushes an input notification to the input queue.
+-- Pushes an input notification to the input queue.
function P.pushNotification(queueName, notification)
local queue = P.queueList[queueName]
if queue == nil then
@@ -332,7 +332,7 @@
end
-- Is called after the sheet has been hidden.
-function P.afterHide()
+function P.onAfterHide()
-- If we leave the edit mode we show the sheet again.
if P.editMode then
P.leaveEditMode()
Modified: code/branches/usability/data/gui/scripts/SettingsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/SettingsMenu.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/SettingsMenu.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -3,50 +3,37 @@
local P = createMenuSheet("SettingsMenu")
P.loadAlong = { "ControlsMenu", "AudioMenu", "GraphicsMenu" }
-P.buttonList = {}
-
function P.onLoad()
--"Gameplay" and "Multiplayer Options" are not integrated in the list
--buttons are arranged in a 4x2 matrix. The lower-right element is not in the matrix!
- local item = {
+ P:initButtons(4, 2)
+
+ P:setButton(1, 2, {
["button"] = winMgr:getWindow("orxonox/SettingsMenu/GraphicsButton"),
- ["function"] = P.SettingsGraphicsButton_clicked
- }
- P.buttonList[2] = item
+ ["callback"] = P.SettingsGraphicsButton_clicked
+ })
- local item = {
+ P:setButton(2, 2, {
["button"] = winMgr:getWindow("orxonox/SettingsMenu/AudioButton"),
- ["function"] = P.SettingsAudioButton_clicked
- }
- P.buttonList[4] = item
+ ["callback"] = P.SettingsAudioButton_clicked
+ })
-
- local item = {
+ P:setButton(3, 1, {
["button"] = winMgr:getWindow("orxonox/SettingsMenu/ControlsButton"),
- ["function"] = P.SettingsControlsButton_clicked
- }
- P.buttonList[5] = item
+ ["callback"] = P.SettingsControlsButton_clicked
+ })
- local item = {
+ P:setButton(3, 2, {
["button"] = winMgr:getWindow("orxonox/SettingsMenu/MiscellaneousButton"),
- ["function"] = P.SettingsMiscellaneousButton_clicked
- }
- P.buttonList[6] = item
+ ["callback"] = P.SettingsMiscellaneousButton_clicked
+ })
- local item = {
+ P:setButton(4, 1, {
["button"] = winMgr:getWindow("orxonox/SettingsMenu/SettingsBackButton"),
- ["function"] = P.SettingsBackButton_clicked
- }
- P.buttonList[7] = item
-
+ ["callback"] = P.SettingsBackButton_clicked
+ })
end
-function P.onShow()
- --indices to iterate through buttonlist
- P.oldindex = 3
- P.index = 2
-end
-
function P.SettingsGameplayButton_clicked(e)
showMenuSheet("GameplayMenu", true)
end
@@ -75,9 +62,5 @@
hideMenuSheet(P.name)
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 4, 2)
-end
-
return P
Modified: code/branches/usability/data/gui/scripts/SheetManager.lua
===================================================================
--- code/branches/usability/data/gui/scripts/SheetManager.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/SheetManager.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -125,7 +125,7 @@
activeMenuSheets[i].sheet:hide()
end
end
-
+
menuSheet:show()
menuSheetsRoot:activate()
@@ -178,7 +178,7 @@
if not sheetTuple.bNoInput then
inputMgr:leaveState(sheetTuple.sheet.inputState)
end
-
+
-- CURSOR SHOWING
local i = activeMenuSheets.size
-- Find top most sheet that doesn't have tShowCusor == TriBool.Dontcare
@@ -244,7 +244,7 @@
orxonox.CommandExecutor:execute("openConsole")
end
end
- sheet.sheet:onKeyPressed()
+ sheet.sheet:keyPressed()
end
function setBackgroundImage(imageSet, imageName)
Modified: code/branches/usability/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/SingleplayerMenu.lua 2011-02-19 23:33:20 UTC (rev 7921)
+++ code/branches/usability/data/gui/scripts/SingleplayerMenu.lua 2011-02-19 23:47:57 UTC (rev 7922)
@@ -2,7 +2,6 @@
local P = createMenuSheet("SingleplayerMenu")
-P.buttonList = {}
P.levelList = {}
P.itemList = {}
P.showAll = false
@@ -14,17 +13,17 @@
P.createLevelList()
--buttons are arranged in a 1x2 matrix
- local item = {
+ P:initButtons(1, 2)
+
+ P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
- ["function"] = P.SingleplayerStartButton_clicked
- }
- P.buttonList[1] = item
+ ["callback"] = P.SingleplayerStartButton_clicked
+ })
- local item = {
+ P:setButton(1, 2, {
["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
- ["function"] = P.SingleplayerBackButton_clicked
- }
- P.buttonList[2] = item
+ ["callback"] = P.SingleplayerBackButton_clicked
+ })
end
function P.createLevelList()
@@ -60,12 +59,6 @@
end
end
-function P.onShow()
- --indices to iterate through buttonlist
- P.oldindex = -2
- P.index = -1
-end
-
function P.SingleplayerStartButton_clicked(e)
local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
local choice = listbox:getFirstSelectedItem()
@@ -92,9 +85,5 @@
hideMenuSheet(P.name)
end
-function P.onKeyPressed()
- buttonIteratorHelper(P.buttonList, code, P, 1, 2)
-end
-
return P
More information about the Orxonox-commit
mailing list