Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7922


Ignore:
Timestamp:
Feb 20, 2011, 12:47:57 AM (13 years ago)
Author:
landauf
Message:

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

Location:
code/branches/usability/data/gui/scripts
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/data/gui/scripts/AudioMenu.lua

    r7689 r7922  
    22
    33local P = createMenuSheet("AudioMenu")
    4 
    5 P.buttonList = {}
    6 
    7 function P.onShow()
    8     P.oldindex = -2
    9     P.index = -1
    10 end
    114
    125function P.onLoad()
     
    5043    end
    5144
    52     local item = {
     45    P:initButtons(1, 1)
     46    P:setButton(1, 1, {
    5347            ["button"] = winMgr:getWindow("orxonox/AudioBackButton"),
    54             ["function"]  = P.AudioBackButton_clicked
    55     }
    56     P.buttonList[1] = item
     48            ["callback"]  = P.AudioBackButton_clicked
     49    })
    5750end
    5851
     
    185178end
    186179
    187 function P.onKeyPressed()
    188     buttonIteratorHelper(P.buttonList, code, P, 1, 1)
    189 end
    190 
    191180return P
    192181
  • code/branches/usability/data/gui/scripts/ControlsMenu.lua

    r7689 r7922  
    22
    33local P = createMenuSheet("ControlsMenu")
    4 P.buttonList = {}
    54P.loadAlong = { "MouseControlsMenu", "KeyBindMenu" }
    65
    76function P.onLoad()
    8     P.multiplayerMode = "startClient" 
     7    P.multiplayerMode = "startClient"
    98
    109    --buttons are arranged in a 3x1 matrix:
    11     local item = {
     10    P:initButtons(3, 1)
     11
     12    P:setButton(1, 1, {
    1213            ["button"] = winMgr:getWindow("orxonox/MouseControlsButton"),
    13             ["function"]  = P.ControlsMouseControlsButton_clicked
    14     }
    15     P.buttonList[1] = item
     14            ["callback"]  = P.ControlsMouseControlsButton_clicked
     15    })
    1616
    17     local item = {
     17    P:setButton(2, 1, {
    1818            ["button"] = winMgr:getWindow("orxonox/KeybindingsButton"),
    19             ["function"]  = P.ControlsKeyboardControlsButton_clicked
    20     }
    21     P.buttonList[2] = item
     19            ["callback"]  = P.ControlsKeyboardControlsButton_clicked
     20    })
    2221
    23     local item = {
     22    P:setButton(3, 1, {
    2423            ["button"] = winMgr:getWindow("orxonox/ControlsBackButton"),
    25             ["function"]  = P.ControlsBackButton_clicked
    26     }
    27     P.buttonList[3] = item
    28 
    29 end
    30 
    31 function P.onShow()
    32     --indices to iterate through buttonlist
    33     P.oldindex = -2
    34     P.index = -1
     24            ["callback"]  = P.ControlsBackButton_clicked
     25    })
    3526end
    3627
     
    4738end
    4839
    49 function P.onKeyPressed()
    50     buttonIteratorHelper(P.buttonList, code, P, 3, 1)
    51 end
    52 
    5340return P
    5441
  • code/branches/usability/data/gui/scripts/CreditsMenu.lua

    r7732 r7922  
    33local P = createMenuSheet("CreditsMenu")
    44
    5 P.buttonList = {}
    65P.scrollbarWidth = 13
    76
    87function P.onLoad()
    9     local item = {
     8    P:initButtons(1, 1)
     9    P:setButton(1, 1, {
    1010            ["button"] = winMgr:getWindow("orxonox/CreditsBackButton"),
    11             ["function"]  = P.CreditsBackButton_clicked
    12     }
    13     P.buttonList[1] = item
     11            ["callback"]  = P.CreditsBackButton_clicked
     12    })
    1413end
    1514
    1615function P.onShow()
    17     --indices to iterate through buttonlist
    18     P.oldindex = -2
    19     P.index = -1
    20 
    2116    local description = winMgr:getWindow("orxonox/CreditsText")
    2217    description:setProperty("HorzFormatting", "WordWrapLeftAligned")
     
    3328end
    3429
    35 function P.onKeyPressed()
    36     buttonIteratorHelper(P.buttonList, code, P, 1, 1)
    37 end
    38 
    3930return P
    4031
  • code/branches/usability/data/gui/scripts/DecisionPopup.lua

    r7726 r7922  
    33local P = createMenuSheet("DecisionPopup")
    44
    5 P.buttonList = {}
    6 
    7 function P.onShow()
    8     --indices to iterate through buttonlist
    9     P.oldindex = -2
    10     P.index = -1
    11 end
    12 
    135function P.onLoad()
    146
    157    --button are arranged in a 1x2 matrix
    16     local item = {
     8    P:initButtons(1, 2)
     9
     10    P:setButton(1, 1, {
    1711            ["button"] = winMgr:getWindow("orxonox/DecisionPopup_button_yes"),
    18             ["function"]  = P.button_yes
    19     }
    20     P.buttonList[1] = item
     12            ["callback"]  = P.button_yes
     13    })
    2114
    22     local item = {
     15    P:setButton(1, 2, {
    2316            ["button"] = winMgr:getWindow("orxonox/DecisionPopup_button_no"),
    24             ["function"]  = P.button_no
    25     }
    26     P.buttonList[2] = item
     17            ["callback"]  = P.button_no
     18    })
     19end
    2720
     21function P.onShow()
     22    P:setSelection(1, 1)
    2823end
    2924
     
    5146end
    5247
    53 function P.onKeyPressed()
    54     buttonIteratorHelper(P.buttonList, code, P, 1, 2)
    55 end
    56 
    5748return P
    5849
  • code/branches/usability/data/gui/scripts/GUISheet.lua

    r7689 r7922  
    1616end
    1717
     18-- Override this function if you need to do work on show
     19function P:onShow()
     20end
     21
     22-- Override this function if you need to do work on hide
     23function P:onHide()
     24end
     25
     26-- Override this function if you need to do work just after the sheet has been hidden
     27function P:onAfterHide()
     28end
     29
    1830-- show function for the GUI
    1931function P:show()
     
    2133    self.bVisible = true
    2234
     35    -- set the selected button's state
     36    if self.buttons and self:hasSelection() then
     37        self:setButtonStateSelected()
     38    end
     39
    2340    self:onShow()
    24 end
    25 
    26 -- Override this function if you need to do work on show
    27 function P:onShow()
    2841end
    2942
     
    3649end
    3750
    38 -- Override this function if you need to do work on hide
    39 function P:onHide()
    40 end
    41 
    42 -- Override this function if you need to do work just after the sheet has been hidden
    4351function P:afterHide()
     52    -- reset the selected button
     53    if self.buttons then
     54        self:resetSelection()
     55    end
     56
     57    self:onAfterHide()
    4458end
    4559
     
    6478end
    6579
    66 function P:onKeyPressed(e)
     80-- Handles key pressed while the gui sheed is displayed
     81function P:keyPressed()
     82    if self.buttons then
     83        if code == "208" then     -- key down
     84            self:moveSelection(1, 0)
     85        elseif code == "200" then -- key up
     86            self:moveSelection(-1, 0)
     87        elseif code == "205" then -- key right
     88            self:moveSelection(0, 1)
     89        elseif code == "203" then -- key left
     90            self:moveSelection(0, -1)
     91        elseif code == "28"  then -- key enter
     92            self:pressSelectedButton()
     93        end
     94    end
     95
     96    self.onKeyPressed()
     97end
     98
     99-- Override this function if you want to ract on keystrokes
     100function P:onKeyPressed()
     101end
     102
     103
     104-------------------------------------------------------------------------------
     105-- Keyboard control -----------------------------------------------------------
     106-------------------------------------------------------------------------------
     107
     108-- Initializes the buttons table, used to control the menu with the keyboard
     109function P:initButtons(rows, columns)
     110    self.rows = rows
     111    self.columns = columns
     112    self.buttons = {}
     113    self.selectedRow = 0
     114    self.selectedColumn = 0
     115end
     116
     117-- Defines the button for a given position in the table. The upper-left button is at position (1, 1)
     118function P:setButton(row, column, button)
     119    assert(self.rows ~= nil and self.columns ~= nil and self.buttons ~= nil, "You have to call initButtons() before using setButton()")
     120    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 .. ")")
     121
     122    self.buttons[(row - 1) * self.columns + (column - 1)] = button
     123end
     124
     125-- Returns the button at a given position in the table. The upper-left button is at position (1, 1)
     126function P:getButton(row, column)
     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 .. ")")
     128
     129    return self.buttons[(row - 1) * self.columns + (column - 1)]
     130end
     131
     132-- Returns the selected button
     133function P:getSelectedButton()
     134    assert(self.selectedRow > 0 and self.selectedColumn > 0, "no button selected")
     135
     136    return self:getButton(self.selectedRow, self.selectedColumn)
     137end
     138
     139-- Presses the selected button if any
     140function P:pressSelectedButton()
     141    if self:hasSelection() then
     142        self:getSelectedButton().callback()
     143    end
     144end
     145
     146-- Sets the selection to a given row and column. The upper-left button is at position (1, 1)
     147function P:setSelection(row, column)
     148    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 .. ")")
     149
     150    if self:hasSelection() then
     151        self:setButtonStateNormal()
     152    end
     153
     154    self.selectedRow = row
     155    self.selectedColumn = column
     156
     157    self:setButtonStateSelected()
     158end
     159
     160-- Moves the selection by a given number of rows and columns (positive values mean increasing row/column, negative values mean decreasing row/column)
     161function P:moveSelection(relRow, relColumn)
     162    -- if there's no selection yet, prepare it such that the selection enters the table from the desired side
     163    if self:hasSelection() == false then
     164        -- note: we assume either relRow or relColumn is 0, thus no diagonal movement. therefore the following checks can be separated
     165        if relRow > 0 then
     166            self.selectedRow = 0
     167            self.selectedColumn = 1
     168        elseif relRow < 0 then
     169            self.selectedRow = self.rows + 1
     170            self.selectedColumn = 1
     171        end
     172
     173        if relColumn > 0 then
     174            self.selectedRow = 1
     175            self.selectedColumn = 0
     176        elseif relColumn < 0 then
     177            self.selectedRow = 1
     178            self.selectedColumn = self.columns + 1
     179        end
     180    else
     181        self:setButtonStateNormal()
     182    end
     183
     184    -- move the selection according to the parameters
     185    self.selectedRow = self.selectedRow + relRow
     186    self.selectedColumn = self.selectedColumn + relColumn
     187
     188    -- wrap around on overflow
     189    while self.selectedRow > self.rows do
     190        self.selectedRow = self.selectedRow - self.rows
     191    end
     192    while self.selectedColumn > self.columns do
     193        self.selectedColumn = self.selectedColumn - self.columns
     194    end
     195
     196    -- wrap around on underflow
     197    while self.selectedRow <= 0 do
     198        self.selectedRow = self.selectedRow + self.rows
     199    end
     200    while self.selectedColumn <= 0 do
     201        self.selectedColumn = self.selectedColumn + self.columns
     202    end
     203
     204    -- if the button is deactivated, call this function again
     205    if self:getSelectedButton() == nil then
     206        self:moveSelection(relRow, relColumn)
     207    else
     208        self:setButtonStateSelected()
     209    end
     210end
     211
     212-- Resets the selection
     213function P:resetSelection()
     214    if self:hasSelection() then
     215        self:setButtonStateNormal()
     216    end
     217
     218    self.selectedRow = 0
     219    self.selectedColumn = 0
     220end
     221
     222-- Determines if a button is selected
     223function P:hasSelection()
     224    if self.selectedRow == 0 or self.selectedColumn == 0 then
     225        return false
     226    else
     227        return true
     228    end
     229end
     230
     231-- Sets the selected button's state to normal
     232function P:setButtonStateNormal()
     233    self:setButtonState("Normal")
     234end
     235
     236-- Sets the selected button's state to selected
     237function P:setButtonStateSelected()
     238    self:setButtonState("Selected")
     239end
     240
     241-- Sets the selected button's state to pushed
     242function P:setButtonStatePushed()
     243    self:setButtonState("Pushed")
     244end
     245
     246-- Sets the selected button's state
     247function P:setButtonState(state)
     248    if self:getSelectedButton() then
     249        local element = self:getSelectedButton().button
     250        local offset = getElementStateOffset(element)
     251
     252        if offset then
     253            element:setProperty("NormalImageRightEdge",  string.sub(element:getProperty("NormalImageRightEdge"),  1, offset) .. state)
     254            element:setProperty("NormalImageLeftEdge",   string.sub(element:getProperty("NormalImageLeftEdge"),   1, offset) .. state)
     255            element:setProperty("NormalImageBackground", string.sub(element:getProperty("NormalImageBackground"), 1, offset) .. state)
     256        end
     257    end
     258end
     259
     260-- Gets the offset of the button's current state
     261function getElementStateOffset(element)
     262    local property = element:getProperty("NormalImageRightEdge")
     263
     264    if string.sub(property, string.len(property) - 5, string.len(property)) == "Normal" then
     265        return -7
     266    elseif string.sub(property, string.len(property) - 7, string.len(property)) == "Selected" then
     267        return -9
     268    elseif string.sub(property, string.len(property) - 5, string.len(property)) == "Pushed" then
     269        return -7
     270    else
     271        return nil
     272    end
    67273end
    68274
  • code/branches/usability/data/gui/scripts/GUITools.lua

    r7913 r7922  
    5454    return height
    5555end
    56 
    57 --function to iterate through a menu sheet by using arrowkeys
    58 
    59 --@arguments:
    60 --  list: 2-dimensional table, arguments are items that contain a button and its function
    61 --        !!note: each button can only be in the list once!!
    62 --  code: code of any key on the keyboard
    63 --  P: menusheet
    64 --  n: number of rows of the buttontable
    65 --  m: number of colums of the buttontable
    66 
    67 function buttonIteratorHelper(list, code, P, n, m)
    68 
    69     --after a key (down,up,left,right) is pressed the index of the current button has to be updated   
    70 
    71     --key down
    72     if code == "208" then
    73         if P.index < 0 then     -- initial status
    74             P.index = 0
    75             P.oldindex = -1
    76         else
    77             P.oldindex = P.index
    78             P.index = (P.index + m) % (m*n)     --modulo operation works as a "wrap around" in the button menu
    79                                                
    80             while list[P.index+1] == nil do     
    81                 P.oldindex = P.index
    82                 P.index = (P.index + m) % (m*n)
    83             end
    84         end
    85 
    86     --key up
    87     elseif code == "200" then
    88         if P.index < 0 then
    89             P.index = 0
    90             P.oldindex = -1
    91         elseif(P.index == 0) then
    92             P.oldindex = P.index
    93             P.index = m*n-m
    94 
    95             while list[P.index+1] == nil do
    96                 P.oldindex = P.index
    97                 P.index = (P.index-m)%(m*n)
    98             end
    99         else
    100             P.oldindex = P.index
    101             P.index = (P.index -m) % (m*n)
    102 
    103             while list[P.index+1] == nil do
    104                 P.oldindex = P.index
    105                 P.index = (P.index-m)%(m*n)
    106             end
    107         end
    108 
    109     --key right
    110     elseif code == "205" then
    111         if P.index < 0 then
    112             P.index = 0
    113             P.oldindex = -1
    114         elseif (P.index+1) % m == 0 then     -- we are at the right-end of a row
    115             P.oldindex = P.index
    116             P.index = P.index + 1 -m
    117 
    118             while list[P.index+1] == nil do
    119                 P.oldindex = P.index
    120                 P.index = P.index + 1
    121             end
    122         else
    123             P.oldindex = P.index
    124             P.index = P.index + 1
    125 
    126             while list[P.index+1] == nil do
    127                 if (P.index+1) % m == 0 then     -- we are at the right-end of a row
    128                     P.oldindex = P.index
    129                     P.index = P.index + 1-m
    130 
    131                 else   
    132                     P.oldindex = P.index
    133                     P.index = P.index + 1
    134                 end
    135             end
    136         end   
    137 
    138     --key left
    139     elseif code == "203" then
    140         if P.index < 0 then
    141             P.index = 0
    142             P.oldindex = -1
    143         elseif P.index % m == 0 then         -- we are at the left-end of a row
    144             P.oldindex = P.index
    145             P.index = P.index +m-1
    146 
    147             while list[P.index+1] == nil do
    148                 P.oldindex = P.index
    149                 P.index = P.index -1
    150             end
    151         else
    152             P.oldindex = P.index
    153             P.index = P.index -1
    154 
    155             while list[P.index+1] == nil do
    156                 if P.index % m == 0 then     -- we are at the left-end of a row
    157                     P.oldindex = P.index
    158                     P.index = P.index -1 + m
    159                 else               
    160                     P.oldindex = P.index
    161                     P.index = P.index -1
    162                 end
    163             end   
    164         end
    165     end
    166        
    167     --to update the new current button
    168     if (code == "208" or code == "200" or code == "203" or code == "205") and P.oldindex~= P.index then
    169 
    170         local system = CEGUI.System:getSingleton()
    171         local window = winMgr:getWindow("orxonox/MainMenuBackground")
    172 
    173         local item = list[P.index+1]
    174         local child = item["button"]
    175         local s = child:getProperty("NormalImageRightEdge")
    176 
    177         --teste ob der Button nicht schon gehighlightet ist
    178         if string.sub(s,string.len(s)-8,string.len(s)) == "Highlight" then
    179             --nop
    180         else
    181             child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-7) .. "Highlight")
    182             child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-7) .. "Highlight")
    183             child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-7) .. "Highlight")
    184             if P.oldindex >= 0 then
    185                 if list[P.oldindex+1] ~= nil then
    186                     local item = list[P.oldindex+1]
    187                     local oldChild = item["button"]
    188                     oldChild:setProperty("NormalImageRightEdge", string.sub(oldChild:getProperty("NormalImageRightEdge"),1,-10) .. "Normal")
    189                     oldChild:setProperty("NormalImageLeftEdge", string.sub(oldChild:getProperty("NormalImageLeftEdge"),1,-10) .. "Normal")
    190                     oldChild:setProperty("NormalImageBackground", string.sub(oldChild:getProperty("NormalImageBackground"),1,-10) .. "Normal")
    191                 end
    192             end
    193         end
    194 
    195         --for every highlighted button check if index is on its position. If not, set imageproperty on "normal"
    196         local i = 1
    197         while i < (n*m) do
    198             if i == P.index +1 then
    199                 i = i+1
    200             else
    201                 if list[i] ~= nil then
    202                 local item = list[i]
    203                 local child = item["button"]
    204                 local s = child:getProperty("NormalImageRightEdge")
    205                     if string.sub(s,string.len(s)-8,string.len(s)) == "Highlight" then
    206                         child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-10) .. "Normal")
    207                         child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-10) .. "Normal")
    208                         child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-10) .. "Normal")
    209                     end
    210                 end
    211             end
    212                 i=i+1
    213         end
    214     end 
    215 
    216     --enter
    217     if code == "28" and P.index >= 0 then
    218         local item = list[P.index+1]
    219         local child = item["button"]
    220         child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-10) .. "Normal")
    221         child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-10) .. "Normal")
    222         child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-10) .. "Normal")
    223 
    224         local foo = item["function"]
    225         foo()
    226     end
    227 
    228 end
    229 
    230 --write index and oldindex on the console
    231 --works like buttonIteratorHelper
    232 function indexTester(list,code,P,n,m)
    233     --key down
    234     if code == "208" then
    235         if P.index < 0 then     -- initial status
    236             P.index = 0
    237             P.oldindex = -1
    238         else
    239             P.oldindex = P.index
    240             P.index = (P.index + m) % (m*n)
    241 
    242             while list[P.index+1] == nil do
    243                 P.oldindex = P.index
    244                 P.index = (P.index + m) % (m*n)
    245             end
    246         end
    247 
    248     --key up
    249     elseif code == "200" then
    250         if P.index < 0 then
    251             P.index = 0
    252             P.oldindex = -1
    253         elseif(P.index == 0) then
    254             P.oldindex = P.index
    255             P.index = m*n-m
    256 
    257             while list[P.index+1] == nil do
    258                 P.oldindex = P.index
    259                 P.index = (P.index-m)%(m*n)
    260             end
    261         else
    262             P.oldindex = P.index
    263             P.index = (P.index -m) % (m*n)
    264 
    265             while list[P.index+1] == nil do
    266                 P.oldindex = P.index
    267                 P.index = P.index -m
    268             end
    269         end
    270 
    271     --key right
    272     elseif code == "205" then
    273         if P.index < 0 then
    274             P.index = 0
    275             P.oldindex = -1
    276         elseif (P.index+1) % m == 0 then     -- we are at the right-end of a row
    277             P.oldindex = P.index
    278             P.index = P.index + 1 -m
    279 
    280             while list[P.index+1] == nil do
    281                 P.oldindex = P.index
    282                 P.index = P.index + 1
    283             end
    284         else
    285             P.oldindex = P.index
    286             P.index = P.index + 1
    287 
    288             while list[P.index+1] == nil do
    289                 if (P.index+1) % m == 0 then     -- we are at the right-end of a row
    290                     P.oldindex = P.index
    291                     P.index = P.index + 1-m
    292 
    293                 else   
    294                     P.oldindex = P.index
    295                     P.index = P.index + 1
    296                 end
    297             end
    298         end   
    299 
    300     --key left
    301     elseif code == "203" then
    302         if P.index < 0 then
    303             P.index = 0
    304             P.oldindex = -1
    305         elseif P.index % m == 0 then         -- we are at the left-end of a row
    306             P.oldindex = P.index
    307             P.index = P.index +m-1
    308 
    309             while list[P.index+1] == nil do
    310                 P.oldindex = P.index
    311                 P.index = P.index -1
    312             end
    313         else
    314             P.oldindex = P.index
    315             P.index = P.index -1
    316 
    317             while list[P.index+1] == nil do
    318                 if P.index % m == 0 then     -- we are at the left-end of a row
    319                     P.oldindex = P.index
    320                     P.index = P.index -1 + m
    321                 else               
    322                     P.oldindex = P.index
    323                     P.index = P.index -1
    324                 end
    325             end   
    326         end
    327     end   
    328 
    329     cout(0, P.oldindex)
    330     cout(0, P.index)
    331 
    332 end
    333 
    334 
    335 
    336 
  • code/branches/usability/data/gui/scripts/GraphicsMenu.lua

    r7801 r7922  
    33local P = createMenuSheet("GraphicsMenu")
    44
    5 P.buttonList = {}
    65P.schemeList = {"TaharezGreen", "Orxonox"}
    7 
    8 function P.onShow()
    9     --indices to iterate through buttonlist (trivial in this menu sheet)
    10     P.oldindex = -2
    11     P.index = -1
    12 end
    136
    147function P.onLoad()
     
    9386    block = false
    9487
    95     local item = {
     88    P:initButtons(1, 1)
     89    P:setButton(1, 1, {
    9690            ["button"] = winMgr:getWindow("orxonox/GraphicsBackButton"),
    97             ["function"]  = P.GraphicsBackButton_clicked
    98     }
    99     P.buttonList[1] = item
     91            ["callback"]  = P.GraphicsBackButton_clicked
     92    })
    10093
    10194    local dropbox = winMgr:getWindow("orxonox/ThemeDropBox")
     
    233226end
    234227
    235 function P.onKeyPressed()
    236     buttonIteratorHelper(P.buttonList, code, P, 1, 1)
    237 end
    238 
    239228return P
    240229
  • code/branches/usability/data/gui/scripts/HostMenu.lua

    r7887 r7922  
    55P.multiplayerMode = "startServer"
    66
    7 P.buttonList = {}
    87P.levelList = {}
    98P.itemList = {}
     
    1110
    1211function P.onLoad()
    13     P.multiplayerMode = "startServer" 
     12    P.multiplayerMode = "startServer"
    1413    local window = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
    1514    local button = tolua.cast(window,"CEGUI::Checkbox")
     
    1716    P.createLevelList()
    1817
    19     local item = {
     18    P:initButtons(1, 2)
     19
     20    P:setButton(1, 1, {
    2021            ["button"] = winMgr:getWindow("orxonox/HostMenuStartButton"),
    21             ["function"]  = P.HostMenuStartButton_clicked
    22     }
    23     P.buttonList[1] = item
     22            ["callback"]  = P.HostMenuStartButton_clicked
     23    })
    2424
    25     local item = {
     25    P:setButton(1, 2, {
    2626            ["button"] = winMgr:getWindow("orxonox/HostMenuBackButton"),
    27             ["function"]  = P.HostMenuBackButton_clicked
    28     }
    29     P.buttonList[2] = item
     27            ["callback"]  = P.HostMenuBackButton_clicked
     28    })
    3029end
    3130
     
    4443        P.createLevelList()
    4544    end
    46 
    47     P.oldindex = -2
    48     P.index = -1
    49 
    5045end
    5146
     
    9792end
    9893
    99 function P.HostMenuStartButton_clicked(e)   
     94function P.HostMenuStartButton_clicked(e)
    10095    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/HostMenuListbox"))
    10196    local choice = listbox:getFirstSelectedItem()
     
    119114end
    120115
    121 function P.onKeyPressed()
    122     buttonIteratorHelper(P.buttonList, code, P, 1, 2)
    123 end
    124 
    125116return P
  • code/branches/usability/data/gui/scripts/InGameMenu.lua

    r7877 r7922  
    44P.loadAlong = { "DecisionPopup" }
    55
    6 P.buttonList = {}
    7 
    86function P.onLoad()
    9     P.multiplayerMode = "startClient" 
     7    P.multiplayerMode = "startClient"
    108
    119    --button are arranged in a 4x1 matrix, the left lower item is nil
    12     local item = {
     10    P:initButtons(4, 1)
     11
     12    P:setButton(1, 1, {
    1313            ["button"] = winMgr:getWindow("orxonox/InGameMenu_ReturnButton"),
    14             ["function"]  = P.button_settings_clicked
    15     }
    16     P.buttonList[1] = item
     14            ["callback"]  = P.button_return_clicked
     15    })
    1716
    18     local item = {
     17    P:setButton(2, 1, {
    1918            ["button"] = winMgr:getWindow("orxonox/InGameMenu_MainMenuButton"),
    20             ["function"]  = P.button_mainmenu_clicked
    21     }
    22     P.buttonList[2] = item
     19            ["callback"]  = P.button_mainmenu_clicked
     20    })
    2321
    24     local item = {
     22    P:setButton(3, 1, {
    2523            ["button"] = winMgr:getWindow("orxonox/InGameMenu_SettingsButton"),
    26             ["function"]  = P.button_settings_clicked
    27     }
    28     P.buttonList[3] = item
     24            ["callback"]  = P.button_settings_clicked
     25    })
    2926
    30     local item = {
     27    P:setButton(4, 1, {
    3128            ["button"] = winMgr:getWindow("orxonox/InGameMenu_QuitButton"),
    32             ["function"]  = P.button_quit_clicked
    33     }
    34     P.buttonList[4] = item
    35 
     29            ["callback"]  = P.button_quit_clicked
     30    })
    3631end
    3732
    3833function P.onShow()
    39     --indices to iterate through buttonlist
    40     P.oldindex = -2
    41     P.index = -1
     34    if P:hasSelection() == false then
     35        P:setSelection(1, 1)
     36    end
    4237end
    4338
     
    6459        hideMenuSheet("InGameMenu")
    6560        orxonox.execute("exit")
    66     else 
     61    else
    6762        P.onShow()
    6863    end
    6964end
    7065
    71 function P.onKeyPressed()
    72     buttonIteratorHelper(P.buttonList, code, P, 4, 1)
    73 end
    74 
    7566return P
    7667
  • code/branches/usability/data/gui/scripts/MainMenu.lua

    r7689 r7922  
    44P.loadAlong = { "SingleplayerMenu", "MultiplayerMenu", "SettingsMenu", "CreditsMenu" }
    55
    6 P.buttonList = {}
    7 
    86function P.onLoad()
    97    --buttons are arranged in a 6x1 Matrix (list)
    10     local item = {
     8    P:initButtons(6, 1)
     9
     10    P:setButton(1, 1, {
    1111            ["button"] = winMgr:getWindow("orxonox/QuickGameTestButton"),
    12             ["function"]  = P.QuickGameTestButton_clicked
    13     }
    14     table.insert(P.buttonList,item)
     12            ["callback"]  = P.QuickGameTestButton_clicked
     13    })
    1514
    16     item = {
     15    P:setButton(2, 1, {
    1716            ["button"] = winMgr:getWindow("orxonox/SingleplayerButton"),
    18             ["function"]  = P.SingleplayerButton_clicked
    19     }
    20     table.insert(P.buttonList,item)
     17            ["callback"]  = P.SingleplayerButton_clicked
     18    })
    2119
    22     item = {
     20    P:setButton(3, 1, {
    2321            ["button"] = winMgr:getWindow("orxonox/MultiplayerButton"),
    24             ["function"]  = P.MultiplayerButton_clicked
    25     }
    26     table.insert(P.buttonList,item)
     22            ["callback"]  = P.MultiplayerButton_clicked
     23    })
    2724
    28     item = {
     25    P:setButton(4, 1, {
    2926            ["button"] = winMgr:getWindow("orxonox/SettingsButton"),
    30             ["function"]  = P.SettingsButton_clicked
    31     }
    32     table.insert(P.buttonList,item)
     27            ["callback"]  = P.SettingsButton_clicked
     28    })
    3329
    34     item = {
     30    P:setButton(5, 1, {
    3531            ["button"] = winMgr:getWindow("orxonox/CreditsButton"),
    36             ["function"]  = P.CreditsButton_clicked
    37     }
    38     table.insert(P.buttonList,item)
     32            ["callback"]  = P.CreditsButton_clicked
     33    })
    3934
    40     item = {
     35    P:setButton(6, 1, {
    4136            ["button"] = winMgr:getWindow("orxonox/ExitButton"),
    42             ["function"]  = P.ExitButton_clicked
    43     }
    44     table.insert(P.buttonList,item)
    45 end
    46 
    47 function P.onShow()
    48     --indices to iterate through buttonlist
    49     P.oldindex = -2
    50     P.index = -1
     37            ["callback"]  = P.ExitButton_clicked
     38    })
    5139end
    5240
     
    7765end
    7866
    79 function P.onKeyPressed()
    80     buttonIteratorHelper(P.buttonList, code, P, 6, 1)
    81 end
    82 
    8367return P
    8468
  • code/branches/usability/data/gui/scripts/MultiplayerMenu.lua

    r7916 r7922  
    22
    33local P = createMenuSheet("MultiplayerMenu")
    4 
    5 P.buttonList = {}
    64
    75--joinMode is 1 for choice "LAN" and 2 for "Internet"
     
    1311
    1412    --button are arranged in a 2x2 matrix, the left lower item is nil
    15     local item = {
     13    P:initButtons(2, 2)
     14
     15    P:setButton(1, 1, {
    1616            ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"),
    17             ["function"]  = P.MultiplayerJoinButton_clicked
    18     }
    19     P.buttonList[1] = item
     17            ["callback"]  = P.MultiplayerJoinButton_clicked
     18    })
    2019
    21     local item = {
     20    P:setButton(1, 2, {
    2221            ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"),
    23             ["function"]  = P.MultiplayerHostButton_clicked
    24     }
    25     P.buttonList[2] = item
     22            ["callback"]  = P.MultiplayerHostButton_clicked
     23    })
    2624
    27     local item = {
     25    P:setButton(2, 2, {
    2826            ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"),
    29             ["function"]  = P.MultiplayerBackButton_clicked
    30     }
    31     P.buttonList[4] = item
     27            ["callback"]  = P.MultiplayerBackButton_clicked
     28    })
    3229end
    3330
    3431function P.onShow()
    3532    --P.showServerList()
    36 
    37     --indices to iterate through buttonlist
    38     P.oldindex = -2
    39     P.index = -1
    4033
    4134    if P.joinMode == 1 then
     
    158151end
    159152
    160 function P.onKeyPressed()
    161     buttonIteratorHelper(P.buttonList, code, P, 2, 2)
    162 end
    163 
    164153return P
    165154
  • code/branches/usability/data/gui/scripts/NotificationLayer.lua

    r7887 r7922  
    4646end
    4747
    48 -- Pushes an input notification to the input queue. 
     48-- Pushes an input notification to the input queue.
    4949function P.pushNotification(queueName, notification)
    5050    local queue = P.queueList[queueName]
     
    333333
    334334-- Is called after the sheet has been hidden.
    335 function P.afterHide()
     335function P.onAfterHide()
    336336    -- If we leave the edit mode we show the sheet again.
    337337    if P.editMode then
  • code/branches/usability/data/gui/scripts/SettingsMenu.lua

    r7689 r7922  
    44P.loadAlong = { "ControlsMenu", "AudioMenu", "GraphicsMenu" }
    55
    6 P.buttonList = {}
    7 
    86function P.onLoad()
    97    --"Gameplay" and "Multiplayer Options" are not integrated in the list
    108    --buttons are arranged in a 4x2 matrix. The lower-right element is not in the matrix!
    11     local item = {
     9    P:initButtons(4, 2)
     10
     11    P:setButton(1, 2, {
    1212            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/GraphicsButton"),
    13             ["function"]  = P.SettingsGraphicsButton_clicked
    14     }
    15     P.buttonList[2] = item
     13            ["callback"]  = P.SettingsGraphicsButton_clicked
     14    })
    1615
    17     local item = {
     16    P:setButton(2, 2, {
    1817            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/AudioButton"),
    19             ["function"]  = P.SettingsAudioButton_clicked
    20     }
    21     P.buttonList[4] = item
     18            ["callback"]  = P.SettingsAudioButton_clicked
     19    })
    2220
     21    P:setButton(3, 1, {
     22            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/ControlsButton"),
     23            ["callback"]  = P.SettingsControlsButton_clicked
     24    })
    2325
    24     local item = {
    25             ["button"] = winMgr:getWindow("orxonox/SettingsMenu/ControlsButton"),
    26             ["function"]  = P.SettingsControlsButton_clicked
    27     }
    28     P.buttonList[5] = item
     26    P:setButton(3, 2, {
     27            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/MiscellaneousButton"),
     28            ["callback"]  = P.SettingsMiscellaneousButton_clicked
     29    })
    2930
    30     local item = {
    31             ["button"] = winMgr:getWindow("orxonox/SettingsMenu/MiscellaneousButton"),
    32             ["function"]  = P.SettingsMiscellaneousButton_clicked
    33     }
    34     P.buttonList[6] = item
    35 
    36     local item = {
     31    P:setButton(4, 1, {
    3732            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/SettingsBackButton"),
    38             ["function"]  = P.SettingsBackButton_clicked
    39     }
    40     P.buttonList[7] = item
    41 
    42 end
    43 
    44 function P.onShow()
    45     --indices to iterate through buttonlist
    46     P.oldindex = 3
    47     P.index = 2
     33            ["callback"]  = P.SettingsBackButton_clicked
     34    })
    4835end
    4936
     
    7663end
    7764
    78 function P.onKeyPressed()
    79     buttonIteratorHelper(P.buttonList, code, P, 4, 2)
    80 end
    81 
    8265return P
    8366
  • code/branches/usability/data/gui/scripts/SheetManager.lua

    r7689 r7922  
    126126        end
    127127    end
    128    
     128
    129129    menuSheet:show()
    130130    menuSheetsRoot:activate()
     
    179179        inputMgr:leaveState(sheetTuple.sheet.inputState)
    180180    end
    181    
     181
    182182    -- CURSOR SHOWING
    183183    local i = activeMenuSheets.size
     
    245245        end
    246246    end
    247     sheet.sheet:onKeyPressed()
     247    sheet.sheet:keyPressed()
    248248end
    249249
  • code/branches/usability/data/gui/scripts/SingleplayerMenu.lua

    r7876 r7922  
    33local P = createMenuSheet("SingleplayerMenu")
    44
    5 P.buttonList = {}
    65P.levelList = {}
    76P.itemList = {}
     
    1514
    1615    --buttons are arranged in a 1x2 matrix
    17     local item = {
     16    P:initButtons(1, 2)
     17
     18    P:setButton(1, 1, {
    1819            ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
    19             ["function"]  = P.SingleplayerStartButton_clicked
    20     }
    21     P.buttonList[1] = item
     20            ["callback"]  = P.SingleplayerStartButton_clicked
     21    })
    2222
    23     local item = {
     23    P:setButton(1, 2, {
    2424            ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
    25             ["function"]  = P.SingleplayerBackButton_clicked
    26     }
    27     P.buttonList[2] = item
     25            ["callback"]  = P.SingleplayerBackButton_clicked
     26    })
    2827end
    2928
     
    6160end
    6261
    63 function P.onShow()
    64     --indices to iterate through buttonlist
    65     P.oldindex = -2
    66     P.index = -1
    67 end
    68 
    6962function P.SingleplayerStartButton_clicked(e)
    7063    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
     
    9386end
    9487
    95 function P.onKeyPressed()
    96     buttonIteratorHelper(P.buttonList, code, P, 1, 2)
    97 end
    98 
    9988return P
    10089
Note: See TracChangeset for help on using the changeset viewer.