Changeset 7928 for code/branches/usability
- Timestamp:
- Feb 20, 2011, 12:42:28 PM (14 years ago)
- Location:
- code/branches/usability/data/gui/scripts
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/usability/data/gui/scripts/AudioMenu.lua
r7922 r7928 43 43 end 44 44 45 P:initButtons(1, 1)46 45 P:setButton(1, 1, { 47 46 ["button"] = winMgr:getWindow("orxonox/AudioBackButton"), -
code/branches/usability/data/gui/scripts/ControlsMenu.lua
r7922 r7928 8 8 9 9 --buttons are arranged in a 3x1 matrix: 10 P:initButtons(3, 1)11 12 10 P:setButton(1, 1, { 13 11 ["button"] = winMgr:getWindow("orxonox/MouseControlsButton"), -
code/branches/usability/data/gui/scripts/CreditsMenu.lua
r7922 r7928 6 6 7 7 function P.onLoad() 8 P:initButtons(1, 1)9 8 P:setButton(1, 1, { 10 9 ["button"] = winMgr:getWindow("orxonox/CreditsBackButton"), -
code/branches/usability/data/gui/scripts/DecisionPopup.lua
r7922 r7928 6 6 7 7 --button are arranged in a 1x2 matrix 8 P:initButtons(1, 2)9 10 8 P:setButton(1, 1, { 11 9 ["button"] = winMgr:getWindow("orxonox/DecisionPopup_button_yes"), -
code/branches/usability/data/gui/scripts/GUISheet.lua
r7927 r7928 34 34 35 35 -- set the selected button's state 36 if self.buttons and self:hasSelection() then 37 self:setButtonStateSelected() 38 end 36 self:setSelectedButtonsStateToSelected() 39 37 40 38 self:onShow() … … 107 105 108 106 -- Initializes the buttons table, used to control the menu with the keyboard 109 -- 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) 110 function P:initButtons(rows, columns, ratio) 107 function P:initButtons(rows, columns) 111 108 self.rows = rows 112 109 self.columns = columns … … 114 111 self.selectedRow = 0 115 112 self.selectedColumn = 0 116 117 if ratio then 118 self.ratio = ratio 119 else 120 self.ratio = 1 121 end113 self.ratio = 1 114 end 115 116 -- 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) 117 function P:setRatio(ratio) 118 self.ratio = ratio 122 119 end 123 120 124 121 -- Defines the button for a given position in the table. The upper-left button is at position (1, 1) 125 122 function P:setButton(row, column, button) 126 assert(self.rows ~= nil and self.columns ~= nil and self.buttons ~= nil, "You have to call initButtons() before using setButton()") 127 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 .. ")") 123 if not self.buttons then 124 -- init the table 125 self:initButtons(row, column) 126 elseif row > self.rows or column > self.columns then 127 -- rearrange the table 128 local maxRows = math.max(self.rows, row) 129 local maxColumns = math.max(self.columns, column) 130 131 for r = self.rows, 1, -1 do 132 for c = self.columns, 1, -1 do 133 local b = self:getButton(r, c) 134 if b then 135 self.buttons[(r - 1) * self.columns + (c - 1)] = nil 136 self.buttons[(r - 1) * maxColumns + (c - 1)] = b 137 end 138 end 139 end 140 141 self.rows = maxRows 142 self.columns = maxColumns 143 end 128 144 129 145 self.buttons[(row - 1) * self.columns + (column - 1)] = button … … 132 148 -- Returns the button at a given position in the table. The upper-left button is at position (1, 1) 133 149 function P:getButton(row, column) 134 return self.buttons[(row - 1) * self.columns + (column - 1)] 150 if self.buttons then 151 return self.buttons[(row - 1) * self.columns + (column - 1)] 152 else 153 return nil 154 end 135 155 end 136 156 137 157 -- Returns the selected button 138 158 function P:getSelectedButton() 139 return self:getButton(self.selectedRow, self.selectedColumn) 159 if self:hasSelection() then 160 return self:getButton(self.selectedRow, self.selectedColumn) 161 else 162 return nil 163 end 140 164 end 141 165 142 166 -- Presses the selected button if any 143 167 function P:pressSelectedButton() 144 if self: hasSelection() then168 if self:getSelectedButton() then 145 169 self.pressedEnter = true 146 170 self:getSelectedButton().callback() … … 151 175 -- Sets the selection to a given row and column. The upper-left button is at position (1, 1) 152 176 function P:setSelection(row, column) 177 if not self.buttons then 178 return 179 end 180 153 181 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 .. ")") 154 182 155 if self:hasSelection() then 156 self:setButtonStateNormal() 157 end 183 self:setSelectedButtonsStateToNormal() 158 184 159 185 self.selectedRow = row 160 186 self.selectedColumn = column 161 187 162 self:setButtonStateSelected() 188 self:setSelectedButtonsStateToSelected() 189 end 190 191 -- Sets the selection to the button closest to the given row and column. The upper-left button is at position (1, 1) 192 function P:setSelectionNear(row, column) 193 if not self.buttons then 194 return 195 end 196 197 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 .. ")") 198 199 if self:getButton(row, column) then 200 self:setSelection(row, column) 201 else 202 local min = 1000000 203 local minRow, minColumn 204 205 for r = 1, self.rows do 206 for c = 1, self.columns do 207 if self:getButton(r, c) then 208 local distance = math.sqrt((row - r)^2 + ((column - c) * self.ratio)^2) 209 if distance < min then 210 min = distance; minRow = r; minColumn = c 211 end 212 end 213 end 214 end 215 216 if minRow and minColumn then 217 self:setSelection(minRow, minColumn) 218 else 219 self:resetSelection() 220 end 221 end 163 222 end 164 223 … … 175 234 -- Generic move function, the values are determined at runtime depending on the arguments 176 235 function P:moveSelection(relMove, selectedThis, selectedOther, limitThis, limitOther, isRow) 236 if not self.buttons then 237 return 238 end 239 177 240 -- if there's no selection yet, prepare it such that the selection enters the table from the desired side 178 241 if self.selectedRow > 0 or self.selectedColumn > 0 then 179 self:set ButtonStateNormal()242 self:setSelectedButtonsStateToNormal() 180 243 else 181 244 if relMove > 0 then … … 199 262 -- if the button is deactivated, search the button closest to the desired location 200 263 if self:getSelectedButton() == nil then 201 local min = self.rows + self.columns * self.ratio264 local min = 1000000 202 265 local minV1, minV2 203 266 local limit, step … … 247 310 end 248 311 249 if self:hasSelection() == true then 250 self:setButtonStateSelected() 251 end 312 self:setSelectedButtonsStateToSelected() 252 313 end 253 314 254 315 -- Resets the selection 255 316 function P:resetSelection() 256 if self:hasSelection() then 257 self:setButtonStateNormal() 258 end 317 self:setSelectedButtonsStateToNormal() 259 318 260 319 self.selectedRow = 0 … … 286 345 287 346 -- Sets the selected button's state to normal 288 function P:set ButtonStateNormal()289 self:set ButtonState("Normal")347 function P:setSelectedButtonsStateToNormal() 348 self:setSelectedButtonsState("Normal") 290 349 end 291 350 292 351 -- Sets the selected button's state to selected 293 function P:set ButtonStateSelected()294 self:set ButtonState("Selected")352 function P:setSelectedButtonsStateToSelected() 353 self:setSelectedButtonsState("Selected") 295 354 end 296 355 297 356 -- Sets the selected button's state to pushed 298 function P:set ButtonStatePushed()299 self:set ButtonState("Pushed")357 function P:setSelectedButtonsStateToPushed() 358 self:setSelectedButtonsState("Pushed") 300 359 end 301 360 302 361 -- Sets the selected button's state 303 function P:set ButtonState(state)362 function P:setSelectedButtonsState(state) 304 363 if self:getSelectedButton() then 305 364 local element = self:getSelectedButton().button -
code/branches/usability/data/gui/scripts/GraphicsMenu.lua
r7922 r7928 86 86 block = false 87 87 88 P:initButtons(1, 1)89 88 P:setButton(1, 1, { 90 89 ["button"] = winMgr:getWindow("orxonox/GraphicsBackButton"), -
code/branches/usability/data/gui/scripts/HostMenu.lua
r7922 r7928 15 15 button:setSelected(false) 16 16 P.createLevelList() 17 18 P:initButtons(1, 2)19 17 20 18 P:setButton(1, 1, { -
code/branches/usability/data/gui/scripts/InGameMenu.lua
r7922 r7928 8 8 9 9 --button are arranged in a 4x1 matrix, the left lower item is nil 10 P:initButtons(4, 1)11 12 10 P:setButton(1, 1, { 13 11 ["button"] = winMgr:getWindow("orxonox/InGameMenu_ReturnButton"), -
code/branches/usability/data/gui/scripts/KeyBindMenu.lua
r7924 r7928 101 101 orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct) 102 102 103 P:initButtons(1, 1)104 103 P:setButton(1, 1, { 105 104 ["button"] = winMgr:getWindow("orxonox/KeyBindBackButton"), -
code/branches/usability/data/gui/scripts/MainMenu.lua
r7922 r7928 6 6 function P.onLoad() 7 7 --buttons are arranged in a 6x1 Matrix (list) 8 P:initButtons(6, 1)9 10 8 P:setButton(1, 1, { 11 9 ["button"] = winMgr:getWindow("orxonox/QuickGameTestButton"), -
code/branches/usability/data/gui/scripts/MiscConfigMenu.lua
r7924 r7928 85 85 P.createLines() 86 86 87 P:initButtons(1, 1)88 87 P:setButton(1, 1, { 89 88 ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigBackButton"), -
code/branches/usability/data/gui/scripts/MouseControlsMenu.lua
r7924 r7928 33 33 end 34 34 35 P:initButtons(1, 1)36 35 P:setButton(1, 1, { 37 36 ["button"] = winMgr:getWindow("orxonox/MouseControlsBackButton"), -
code/branches/usability/data/gui/scripts/MultiplayerMenu.lua
r7926 r7928 10 10 P.multiplayerMode = "startClient" 11 11 12 --button are arranged in a 2x2 matrix, the lower items are both the back button 13 P:initButtons(2, 3) 14 12 --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 15 13 P:setButton(1, 1, { 16 14 ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"), -
code/branches/usability/data/gui/scripts/SettingsMenu.lua
r7924 r7928 6 6 function P.onLoad() 7 7 --"Gameplay" and "Multiplayer Options" are not integrated in the list 8 --buttons are arranged in a 4x2 matrix. The lower-right element is not in the matrix! 9 P:initButtons(4, 2) 10 8 --buttons are arranged in a 4x2 matrix. 11 9 P:setButton(1, 2, { 12 10 ["button"] = winMgr:getWindow("orxonox/SettingsMenu/GraphicsButton"), -
code/branches/usability/data/gui/scripts/SheetManager.lua
r7927 r7928 133 133 134 134 -- select first button if the menu was opened with the keyboard 135 if previous and previous.pressedEnter and menuSheet .buttons and menuSheet:hasSelection() == false then136 menuSheet: moveSelectionRow(1)135 if previous and previous.pressedEnter and menuSheet:hasSelection() == false then 136 menuSheet:setSelectionNear(1, 1) 137 137 end 138 138 -
code/branches/usability/data/gui/scripts/SingleplayerMenu.lua
r7922 r7928 14 14 15 15 --buttons are arranged in a 1x2 matrix 16 P:initButtons(1, 2)17 18 16 P:setButton(1, 1, { 19 17 ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
Note: See TracChangeset
for help on using the changeset viewer.