[Orxonox-commit 3237] r7928 - code/branches/usability/data/gui/scripts
landauf at orxonox.net
landauf at orxonox.net
Sun Feb 20 12:42:28 CET 2011
Author: landauf
Date: 2011-02-20 12:42:28 +0100 (Sun, 20 Feb 2011)
New Revision: 7928
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/GraphicsMenu.lua
code/branches/usability/data/gui/scripts/HostMenu.lua
code/branches/usability/data/gui/scripts/InGameMenu.lua
code/branches/usability/data/gui/scripts/KeyBindMenu.lua
code/branches/usability/data/gui/scripts/MainMenu.lua
code/branches/usability/data/gui/scripts/MiscConfigMenu.lua
code/branches/usability/data/gui/scripts/MouseControlsMenu.lua
code/branches/usability/data/gui/scripts/MultiplayerMenu.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:
more improvements for keyboard control of menus:
- added setSelectionNear(r, c) function which tries to select the button closest to the given row/column
- no initialization required anymore, the button-table grows dynamically if new buttons are inserted
Modified: code/branches/usability/data/gui/scripts/AudioMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/AudioMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/AudioMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -42,7 +42,6 @@
listboxwindow:setItemSelectState(0,true)
end
- P:initButtons(1, 1)
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/AudioBackButton"),
["callback"] = P.AudioBackButton_clicked
Modified: code/branches/usability/data/gui/scripts/ControlsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/ControlsMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/ControlsMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -7,8 +7,6 @@
P.multiplayerMode = "startClient"
--buttons are arranged in a 3x1 matrix:
- P:initButtons(3, 1)
-
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/MouseControlsButton"),
["callback"] = P.ControlsMouseControlsButton_clicked
Modified: code/branches/usability/data/gui/scripts/CreditsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/CreditsMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/CreditsMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -5,7 +5,6 @@
P.scrollbarWidth = 13
function P.onLoad()
- P:initButtons(1, 1)
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/CreditsBackButton"),
["callback"] = P.CreditsBackButton_clicked
Modified: code/branches/usability/data/gui/scripts/DecisionPopup.lua
===================================================================
--- code/branches/usability/data/gui/scripts/DecisionPopup.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/DecisionPopup.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -5,8 +5,6 @@
function P.onLoad()
--button are arranged in a 1x2 matrix
- P:initButtons(1, 2)
-
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/DecisionPopup_button_yes"),
["callback"] = P.button_yes
Modified: code/branches/usability/data/gui/scripts/GUISheet.lua
===================================================================
--- code/branches/usability/data/gui/scripts/GUISheet.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/GUISheet.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -33,9 +33,7 @@
self.bVisible = true
-- set the selected button's state
- if self.buttons and self:hasSelection() then
- self:setButtonStateSelected()
- end
+ self:setSelectedButtonsStateToSelected()
self:onShow()
end
@@ -106,42 +104,68 @@
-------------------------------------------------------------------------------
-- Initializes the buttons table, used to control the menu with the keyboard
--- ratio: the button's with divided by the button's height (used to calculate distance between buttons - adjust this until you get the desired behavior)
-function P:initButtons(rows, columns, ratio)
+function P:initButtons(rows, columns)
self.rows = rows
self.columns = columns
self.buttons = {}
self.selectedRow = 0
self.selectedColumn = 0
+ self.ratio = 1
+end
- if ratio then
- self.ratio = ratio
- else
- self.ratio = 1
- end
+-- ratio: the button's with divided by the button's height (used to calculate distance between buttons - adjust this until you get the desired behavior)
+function P:setRatio(ratio)
+ self.ratio = ratio
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 .. ")")
+ if not self.buttons then
+ -- init the table
+ self:initButtons(row, column)
+ elseif row > self.rows or column > self.columns then
+ -- rearrange the table
+ local maxRows = math.max(self.rows, row)
+ local maxColumns = math.max(self.columns, column)
+ for r = self.rows, 1, -1 do
+ for c = self.columns, 1, -1 do
+ local b = self:getButton(r, c)
+ if b then
+ self.buttons[(r - 1) * self.columns + (c - 1)] = nil
+ self.buttons[(r - 1) * maxColumns + (c - 1)] = b
+ end
+ end
+ end
+
+ self.rows = maxRows
+ self.columns = maxColumns
+ end
+
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)
- return self.buttons[(row - 1) * self.columns + (column - 1)]
+ if self.buttons then
+ return self.buttons[(row - 1) * self.columns + (column - 1)]
+ else
+ return nil
+ end
end
-- Returns the selected button
function P:getSelectedButton()
- return self:getButton(self.selectedRow, self.selectedColumn)
+ if self:hasSelection() then
+ return self:getButton(self.selectedRow, self.selectedColumn)
+ else
+ return nil
+ end
end
-- Presses the selected button if any
function P:pressSelectedButton()
- if self:hasSelection() then
+ if self:getSelectedButton() then
self.pressedEnter = true
self:getSelectedButton().callback()
self.pressedEnter = false
@@ -150,18 +174,53 @@
-- Sets the selection to a given row and column. The upper-left button is at position (1, 1)
function P:setSelection(row, column)
+ if not self.buttons then
+ return
+ end
+
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:setSelectedButtonsStateToNormal()
self.selectedRow = row
self.selectedColumn = column
- self:setButtonStateSelected()
+ self:setSelectedButtonsStateToSelected()
end
+-- Sets the selection to the button closest to the given row and column. The upper-left button is at position (1, 1)
+function P:setSelectionNear(row, column)
+ if not self.buttons then
+ return
+ end
+
+ 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:getButton(row, column) then
+ self:setSelection(row, column)
+ else
+ local min = 1000000
+ local minRow, minColumn
+
+ for r = 1, self.rows do
+ for c = 1, self.columns do
+ if self:getButton(r, c) then
+ local distance = math.sqrt((row - r)^2 + ((column - c) * self.ratio)^2)
+ if distance < min then
+ min = distance; minRow = r; minColumn = c
+ end
+ end
+ end
+ end
+
+ if minRow and minColumn then
+ self:setSelection(minRow, minColumn)
+ else
+ self:resetSelection()
+ end
+ end
+end
+
-- Moves the selection by a given number of rows (a positive value means down, a negative value means up)
function P:moveSelectionRow(relRow)
self:moveSelection(relRow, "selectedRow", "selectedColumn", "rows", "columns", true)
@@ -174,9 +233,13 @@
-- Generic move function, the values are determined at runtime depending on the arguments
function P:moveSelection(relMove, selectedThis, selectedOther, limitThis, limitOther, isRow)
+ if not self.buttons then
+ return
+ end
+
-- if there's no selection yet, prepare it such that the selection enters the table from the desired side
if self.selectedRow > 0 or self.selectedColumn > 0 then
- self:setButtonStateNormal()
+ self:setSelectedButtonsStateToNormal()
else
if relMove > 0 then
self[selectedThis] = 0
@@ -198,7 +261,7 @@
-- if the button is deactivated, search the button closest to the desired location
if self:getSelectedButton() == nil then
- local min = self.rows + self.columns * self.ratio
+ local min = 1000000
local minV1, minV2
local limit, step
@@ -246,16 +309,12 @@
end
end
- if self:hasSelection() == true then
- self:setButtonStateSelected()
- end
+ self:setSelectedButtonsStateToSelected()
end
-- Resets the selection
function P:resetSelection()
- if self:hasSelection() then
- self:setButtonStateNormal()
- end
+ self:setSelectedButtonsStateToNormal()
self.selectedRow = 0
self.selectedColumn = 0
@@ -285,22 +344,22 @@
end
-- Sets the selected button's state to normal
-function P:setButtonStateNormal()
- self:setButtonState("Normal")
+function P:setSelectedButtonsStateToNormal()
+ self:setSelectedButtonsState("Normal")
end
-- Sets the selected button's state to selected
-function P:setButtonStateSelected()
- self:setButtonState("Selected")
+function P:setSelectedButtonsStateToSelected()
+ self:setSelectedButtonsState("Selected")
end
-- Sets the selected button's state to pushed
-function P:setButtonStatePushed()
- self:setButtonState("Pushed")
+function P:setSelectedButtonsStateToPushed()
+ self:setSelectedButtonsState("Pushed")
end
-- Sets the selected button's state
-function P:setButtonState(state)
+function P:setSelectedButtonsState(state)
if self:getSelectedButton() then
local element = self:getSelectedButton().button
local offset = getElementStateOffset(element)
Modified: code/branches/usability/data/gui/scripts/GraphicsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/GraphicsMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/GraphicsMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -85,7 +85,6 @@
scrollbar_active = false
block = false
- P:initButtons(1, 1)
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/GraphicsBackButton"),
["callback"] = P.GraphicsBackButton_clicked
Modified: code/branches/usability/data/gui/scripts/HostMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/HostMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/HostMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -15,8 +15,6 @@
button:setSelected(false)
P.createLevelList()
- P:initButtons(1, 2)
-
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/HostMenuStartButton"),
["callback"] = P.HostMenuStartButton_clicked
Modified: code/branches/usability/data/gui/scripts/InGameMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/InGameMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/InGameMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -7,8 +7,6 @@
P.multiplayerMode = "startClient"
--button are arranged in a 4x1 matrix, the left lower item is nil
- P:initButtons(4, 1)
-
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/InGameMenu_ReturnButton"),
["callback"] = P.button_return_clicked
Modified: code/branches/usability/data/gui/scripts/KeyBindMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/KeyBindMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/KeyBindMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -100,7 +100,6 @@
local funct = luaState:createLuaFunctor("KeyBindMenu.callback()")
orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
- P:initButtons(1, 1)
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/KeyBindBackButton"),
["callback"] = P.KeyBindBackButton_clicked
Modified: code/branches/usability/data/gui/scripts/MainMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/MainMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/MainMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -5,8 +5,6 @@
function P.onLoad()
--buttons are arranged in a 6x1 Matrix (list)
- P:initButtons(6, 1)
-
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/QuickGameTestButton"),
["callback"] = P.QuickGameTestButton_clicked
Modified: code/branches/usability/data/gui/scripts/MiscConfigMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/MiscConfigMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/MiscConfigMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -84,7 +84,6 @@
P.createLines()
- P:initButtons(1, 1)
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigBackButton"),
["callback"] = P.MiscConfigBackButton_clicked
Modified: code/branches/usability/data/gui/scripts/MouseControlsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/MouseControlsMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/MouseControlsMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -32,7 +32,6 @@
invert_active = false
end
- P:initButtons(1, 1)
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/MouseControlsBackButton"),
["callback"] = P.MouseControlsBackButton_clicked
Modified: code/branches/usability/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/MultiplayerMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/MultiplayerMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -9,9 +9,7 @@
function P.onLoad()
P.multiplayerMode = "startClient"
- --button are arranged in a 2x2 matrix, the lower items are both the back button
- P:initButtons(2, 3)
-
+ --button are arranged in a 3x2 matrix, Join and Host buttons are in the upper left and middle, the back button in the lower right of the table
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"),
["callback"] = P.MultiplayerJoinButton_clicked
Modified: code/branches/usability/data/gui/scripts/SettingsMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/SettingsMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/SettingsMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -5,9 +5,7 @@
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!
- P:initButtons(4, 2)
-
+ --buttons are arranged in a 4x2 matrix.
P:setButton(1, 2, {
["button"] = winMgr:getWindow("orxonox/SettingsMenu/GraphicsButton"),
["callback"] = P.SettingsGraphicsButton_clicked
Modified: code/branches/usability/data/gui/scripts/SheetManager.lua
===================================================================
--- code/branches/usability/data/gui/scripts/SheetManager.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/SheetManager.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -132,8 +132,8 @@
menuSheetsRoot:activate()
-- select first button if the menu was opened with the keyboard
- if previous and previous.pressedEnter and menuSheet.buttons and menuSheet:hasSelection() == false then
- menuSheet:moveSelectionRow(1)
+ if previous and previous.pressedEnter and menuSheet:hasSelection() == false then
+ menuSheet:setSelectionNear(1, 1)
end
return menuSheet
Modified: code/branches/usability/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- code/branches/usability/data/gui/scripts/SingleplayerMenu.lua 2011-02-20 02:31:35 UTC (rev 7927)
+++ code/branches/usability/data/gui/scripts/SingleplayerMenu.lua 2011-02-20 11:42:28 UTC (rev 7928)
@@ -13,8 +13,6 @@
P.createLevelList()
--buttons are arranged in a 1x2 matrix
- P:initButtons(1, 2)
-
P:setButton(1, 1, {
["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
["callback"] = P.SingleplayerStartButton_clicked
More information about the Orxonox-commit
mailing list