Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 15, 2011, 9:47:11 PM (14 years ago)
Author:
landauf
Message:

merged usability branch back to trunk

incomplete summary of the changes in this branch:

  • enhanced keyboard navigation in GUIs
  • implemented new graphics menu and changeable window size at runtime
  • added developer mode
  • HUD shows if game is paused, game pauses if ingame menu is opened
  • removed a few obsolete commands and hid some that are more for internal use
  • numpad works in console and gui
  • faster loading of level info
  • enhanced usage of compositors (Shader class)
  • improved camera handling, configurable FOV and aspect ratio
Location:
code/trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/data/gui/scripts/AudioMenu.lua

    r7689 r8079  
    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:setButton(1, 1, {
    5346            ["button"] = winMgr:getWindow("orxonox/AudioBackButton"),
    54             ["function"]  = P.AudioBackButton_clicked
    55     }
    56     P.buttonList[1] = item
     47            ["callback"]  = P.AudioBackButton_clicked
     48    })
    5749end
    5850
     
    185177end
    186178
    187 function P.onKeyPressed()
    188     buttonIteratorHelper(P.buttonList, code, P, 1, 1)
    189 end
    190 
    191179return P
    192180
  • code/trunk/data/gui/scripts/ControlsMenu.lua

    r7689 r8079  
    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:setButton(1, 1, {
    1211            ["button"] = winMgr:getWindow("orxonox/MouseControlsButton"),
    13             ["function"]  = P.ControlsMouseControlsButton_clicked
    14     }
    15     P.buttonList[1] = item
     12            ["callback"]  = P.ControlsMouseControlsButton_clicked
     13    })
    1614
    17     local item = {
     15    P:setButton(2, 1, {
    1816            ["button"] = winMgr:getWindow("orxonox/KeybindingsButton"),
    19             ["function"]  = P.ControlsKeyboardControlsButton_clicked
    20     }
    21     P.buttonList[2] = item
     17            ["callback"]  = P.ControlsKeyboardControlsButton_clicked
     18    })
    2219
    23     local item = {
     20    P:setButton(3, 1, {
    2421            ["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
     22            ["callback"]  = P.ControlsBackButton_clicked
     23    })
    3524end
    3625
     
    4736end
    4837
    49 function P.onKeyPressed()
    50     buttonIteratorHelper(P.buttonList, code, P, 3, 1)
    51 end
    52 
    5338return P
    5439
  • code/trunk/data/gui/scripts/CreditsMenu.lua

    r7732 r8079  
    33local P = createMenuSheet("CreditsMenu")
    44
    5 P.buttonList = {}
    65P.scrollbarWidth = 13
    76
    87function P.onLoad()
    9     local item = {
     8    P:setButton(1, 1, {
    109            ["button"] = winMgr:getWindow("orxonox/CreditsBackButton"),
    11             ["function"]  = P.CreditsBackButton_clicked
    12     }
    13     P.buttonList[1] = item
     10            ["callback"]  = P.CreditsBackButton_clicked
     11    })
    1412end
    1513
    1614function P.onShow()
    17     --indices to iterate through buttonlist
    18     P.oldindex = -2
    19     P.index = -1
    20 
    2115    local description = winMgr:getWindow("orxonox/CreditsText")
    2216    description:setProperty("HorzFormatting", "WordWrapLeftAligned")
     
    3327end
    3428
    35 function P.onKeyPressed()
    36     buttonIteratorHelper(P.buttonList, code, P, 1, 1)
    37 end
    38 
    3929return P
    4030
  • code/trunk/data/gui/scripts/DecisionPopup.lua

    r7726 r8079  
    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:setButton(1, 1, {
    179            ["button"] = winMgr:getWindow("orxonox/DecisionPopup_button_yes"),
    18             ["function"]  = P.button_yes
    19     }
    20     P.buttonList[1] = item
     10            ["callback"]  = P.button_yes
     11    })
    2112
    22     local item = {
     13    P:setButton(1, 2, {
    2314            ["button"] = winMgr:getWindow("orxonox/DecisionPopup_button_no"),
    24             ["function"]  = P.button_no
    25     }
    26     P.buttonList[2] = item
     15            ["callback"]  = P.button_no
     16    })
     17end
    2718
     19function P.onShow()
     20    P:setSelection(1, 1)
    2821end
    2922
     
    5144end
    5245
    53 function P.onKeyPressed()
    54     buttonIteratorHelper(P.buttonList, code, P, 1, 2)
    55 end
    56 
    5746return P
    5847
  • code/trunk/data/gui/scripts/GUISheet.lua

    r7689 r8079  
    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 on quit
     27function P:onQuit()
     28end
     29
     30-- Override this function if you want to react on keystrokes
     31function P:onKeyPressed()
     32end
     33
     34-- Override this function if you want to update the gui after the window was resized
     35function P:onWindowResized()
     36end
     37
    1838-- show function for the GUI
    1939function P:show()
     
    2141    self.bVisible = true
    2242
     43    -- set the selected button's state
     44    self:setSelectedButtonsStateToSelected()
     45
    2346    self:onShow()
    24 end
    25 
    26 -- Override this function if you need to do work on show
    27 function P:onShow()
    2847end
    2948
     
    3655end
    3756
    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
    43 function P:afterHide()
     57function P:quit()
     58    -- reset the selected button
     59    if self.buttons then
     60        self:resetSelection()
     61    end
     62
     63    self:onQuit()
    4464end
    4565
     
    6484end
    6585
    66 function P:onKeyPressed(e)
     86-- Handles key pressed while the gui sheed is displayed
     87function P:keyPressed()
     88    if self.buttons then
     89        if code == "208" then     -- key down
     90            self:moveSelectionRow(1)
     91        elseif code == "200" then -- key up
     92            self:moveSelectionRow(-1)
     93        elseif code == "205" then -- key right
     94            self:moveSelectionColumn(1)
     95        elseif code == "203" then -- key left
     96            self:moveSelectionColumn(-1)
     97        elseif code == "28" or code == "156"  then -- key enter or key numpad enter
     98            self:pressSelectedButton()
     99        end
     100    end
     101
     102    self:onKeyPressed()
     103end
     104
     105function P:windowResized()
     106    self:onWindowResized()
     107end
     108
     109
     110-------------------------------------------------------------------------------
     111-- Keyboard control -----------------------------------------------------------
     112-------------------------------------------------------------------------------
     113
     114-- Initializes the buttons table, used to control the menu with the keyboard
     115function P:initButtons(rows, columns)
     116    self.rows = rows
     117    self.columns = columns
     118    self.buttons = {}
     119    self.selectedRow = 0
     120    self.selectedColumn = 0
     121    self.ratio = 1
     122end
     123
     124-- 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)
     125function P:setRatio(ratio)
     126    self.ratio = ratio
     127end
     128
     129-- Defines the button for a given position in the table. The upper-left button is at position (1, 1)
     130function P:setButton(row, column, button)
     131    if not self.buttons then
     132        -- init the table
     133        self:initButtons(row, column)
     134    elseif row > self.rows or column > self.columns then
     135        -- rearrange the table
     136        local maxRows = math.max(self.rows, row)
     137        local maxColumns = math.max(self.columns, column)
     138
     139        for r = self.rows, 1, -1 do
     140            for c = self.columns, 1, -1 do
     141                local b = self:getButton(r, c)
     142                if b then
     143                    self.buttons[(r - 1) * self.columns + (c - 1)] = nil
     144                    self.buttons[(r - 1) * maxColumns + (c - 1)] = b
     145                end
     146            end
     147        end
     148
     149        self.rows = maxRows
     150        self.columns = maxColumns
     151    end
     152
     153    self.buttons[(row - 1) * self.columns + (column - 1)] = button
     154end
     155
     156-- Returns the button at a given position in the table. The upper-left button is at position (1, 1)
     157function P:getButton(row, column)
     158    if self.buttons then
     159        return self.buttons[(row - 1) * self.columns + (column - 1)]
     160    else
     161        return nil
     162    end
     163end
     164
     165-- Returns the selected button
     166function P:getSelectedButton()
     167    if self:hasSelection() then
     168        return self:getButton(self.selectedRow, self.selectedColumn)
     169    else
     170        return nil
     171    end
     172end
     173
     174-- Presses the selected button if any
     175function P:pressSelectedButton()
     176    if self:getSelectedButton() then
     177        self.pressedEnter = true
     178        self:getSelectedButton().callback()
     179        self.pressedEnter = false
     180    end
     181end
     182
     183-- Sets the selection to a given row and column. The upper-left button is at position (1, 1)
     184function P:setSelection(row, column)
     185    if not self.buttons then
     186        return
     187    end
     188
     189    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 .. ")")
     190
     191    self:setSelectedButtonsStateToNormal()
     192
     193    self.selectedRow = row
     194    self.selectedColumn = column
     195
     196    self:setSelectedButtonsStateToSelected()
     197end
     198
     199-- Sets the selection to the button closest to the given row and column. The upper-left button is at position (1, 1)
     200function P:setSelectionNear(row, column)
     201    if not self.buttons then
     202        return
     203    end
     204
     205    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 .. ")")
     206
     207    if self:getButton(row, column) then
     208        self:setSelection(row, column)
     209    else
     210        local min = 1000000
     211        local minRow, minColumn
     212
     213        for r = 1, self.rows do
     214            for c = 1, self.columns do
     215                if self:getButton(r, c) then
     216                    local distance = math.sqrt((row - r)^2 + ((column - c) * self.ratio)^2)
     217                    if distance < min then
     218                        min = distance; minRow = r; minColumn = c
     219                    end
     220                end
     221            end
     222        end
     223
     224        if minRow and minColumn then
     225            self:setSelection(minRow, minColumn)
     226        else
     227            self:resetSelection()
     228        end
     229    end
     230end
     231
     232-- Moves the selection by a given number of rows (a positive value means down, a negative value means up)
     233function P:moveSelectionRow(relRow)
     234    self:moveSelection(relRow, "selectedRow", "selectedColumn", "rows", "columns", true)
     235end
     236
     237-- Moves the selection by a given number of columns (a positive value means right, a negative value means left)
     238function P:moveSelectionColumn(relColumn)
     239    self:moveSelection(relColumn, "selectedColumn", "selectedRow", "columns", "rows", false)
     240end
     241
     242-- Generic move function, the values are determined at runtime depending on the arguments
     243function P:moveSelection(relMove, selectedThis, selectedOther, limitThis, limitOther, isRow)
     244    if not self.buttons then
     245        return
     246    end
     247
     248    -- if there's no selection yet, prepare it such that the selection enters the table from the desired side
     249    if self.selectedRow > 0 or self.selectedColumn > 0 then
     250        self:setSelectedButtonsStateToNormal()
     251    else
     252        if relMove > 0 then
     253            self[selectedThis] = 0
     254            self[selectedOther] = 1
     255        elseif relMove < 0 then
     256            self[selectedThis] = self[limitThis] + 1
     257            self[selectedOther] = 1
     258        else
     259            return
     260        end
     261    end
     262
     263    -- move the selection according to the parameters
     264    self[selectedThis] = self[selectedThis] + relMove
     265
     266    -- wrap around on overflow or underflow
     267    while self[selectedThis] > self[limitThis] do self[selectedThis] = self[selectedThis] - self[limitThis] end
     268    while self[selectedThis] <= 0              do self[selectedThis] = self[selectedThis] + self[limitThis] end
     269
     270    -- if the button is deactivated, search the button closest to the desired location
     271    if self:getSelectedButton() == nil then
     272        local min = 1000000
     273        local minV1, minV2
     274        local limit, step
     275
     276        if relMove > 0 then
     277            limit = self[limitThis]
     278            step = 1
     279        else
     280            limit = 1
     281            step = -1
     282        end
     283
     284        for v1 = self[selectedThis], limit, step do
     285            for v2 = 1, self[limitOther] do
     286                local button
     287                if isRow == true then
     288                    button = self:getButton(v1, v2)
     289                else
     290                    button = self:getButton(v2, v1)
     291                end
     292                if button then
     293                    local distance
     294                    if isRow == true then
     295                        distance = math.sqrt((self[selectedThis] - v1)^2 + ((self[selectedOther] - v2) * self.ratio)^2)
     296                    else
     297                        distance = math.sqrt(((self[selectedThis] - v1) * self.ratio)^2 + (self[selectedOther] - v2)^2)
     298                    end
     299                    if distance < min then
     300                        min = distance; minV1 = v1; minV2 = v2
     301                    end
     302                end
     303            end
     304        end
     305
     306        if minV1 and minV2 then
     307            self[selectedThis] = minV1
     308            self[selectedOther] = minV2
     309        elseif self:hasButtons() then
     310            -- no suitable button found - wrap around and search again
     311            if relMove > 0 then
     312                self[selectedThis] = 0
     313            else
     314                self[selectedThis] = self[limitThis] + 1
     315            end
     316            self:moveSelection(relMove, selectedThis, selectedOther, limitThis, limitOther, isRow)
     317        end
     318    end
     319
     320    self:setSelectedButtonsStateToSelected()
     321end
     322
     323-- Resets the selection
     324function P:resetSelection()
     325    self:setSelectedButtonsStateToNormal()
     326
     327    self.selectedRow = 0
     328    self.selectedColumn = 0
     329end
     330
     331-- Checks if there's at least one button in the table
     332function P:hasButtons()
     333    local count = 0
     334    for r = 1, self.rows do
     335        for c = 1, self.columns do
     336            if self:getButton(r, c) then
     337                count = count + 1
     338            end
     339        end
     340    end
     341
     342    return (count > 0)
     343end
     344
     345-- Determines if a button is selected
     346function P:hasSelection()
     347    if self.selectedRow and self.selectedRow > 0 and self.selectedColumn and self.selectedColumn > 0 then
     348        return true
     349    else
     350        return false
     351    end
     352end
     353
     354-- Sets the selected button's state to normal
     355function P:setSelectedButtonsStateToNormal()
     356    self:setSelectedButtonsState("Normal")
     357end
     358
     359-- Sets the selected button's state to selected
     360function P:setSelectedButtonsStateToSelected()
     361    self:setSelectedButtonsState("Selected")
     362end
     363
     364-- Sets the selected button's state to pushed
     365function P:setSelectedButtonsStateToPushed()
     366    self:setSelectedButtonsState("Pushed")
     367end
     368
     369-- Sets the selected button's state
     370function P:setSelectedButtonsState(state)
     371    if self:getSelectedButton() then
     372        local element = self:getSelectedButton().button
     373        local offset = getElementStateOffset(element)
     374
     375        if offset then
     376            element:setProperty("NormalImageRightEdge",  string.sub(element:getProperty("NormalImageRightEdge"),  1, offset) .. state)
     377            element:setProperty("NormalImageLeftEdge",   string.sub(element:getProperty("NormalImageLeftEdge"),   1, offset) .. state)
     378            element:setProperty("NormalImageBackground", string.sub(element:getProperty("NormalImageBackground"), 1, offset) .. state)
     379        end
     380    end
     381end
     382
     383-- Gets the offset of the button's current state
     384function getElementStateOffset(element)
     385    local property = element:getProperty("NormalImageRightEdge")
     386
     387    if string.sub(property, string.len(property) - 5, string.len(property)) == "Normal" then
     388        return -7
     389    elseif string.sub(property, string.len(property) - 7, string.len(property)) == "Selected" then
     390        return -9
     391    elseif string.sub(property, string.len(property) - 5, string.len(property)) == "Pushed" then
     392        return -7
     393    else
     394        return nil
     395    end
    67396end
    68397
  • code/trunk/data/gui/scripts/GUITools.lua

    r7913 r8079  
    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/trunk/data/gui/scripts/GraphicsMenu.lua

    r7801 r8079  
    33local P = createMenuSheet("GraphicsMenu")
    44
    5 P.buttonList = {}
     5P.resolutionList = {"custom", "640 x 480", "720 x 480", "720 x 576", "800 x 600", "1024 x 600", "1024 x 768", "1152 x 864", "1280 x 720", "1280 x 800", "1280 x 960", "1280 x 1024", "1360 x 768", "1440 x 900", "1600 x 900", "1600 x 1200", "1680 x 1050"}
    66P.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
    13 
    14 function P.onLoad()
    15     block = true
    16     file = orxonox.PathConfig:getConfigPathString() .. orxonox.getConfig("GraphicsManager", "ogreConfigFile_")
    17     search_mode = 0
    18     f = io.open(file, "r")
    19     firstline = f:read("*line")
    20     rendersystem = string.sub(firstline, 15)
    21     for line in f:lines() do
    22         if search_mode == 0 then
    23             if string.find(line, rendersystem) ~= nil then
    24                 search_mode = 1
    25             end
     7P.fsaaList = {"0", "2", "4", "8", "8 [Quality]"}
     8P.particleLodList = {"None", "Low", "Normal", "High"}
     9
     10function P:onLoad()
     11    -------------------
     12    -- Button matrix --
     13    -------------------
     14
     15    P:setButton(1, 1, {
     16            ["button"] = winMgr:getWindow("orxonox/GraphicsOkButton"),
     17            ["callback"]  = P.callback_Ok_Clicked
     18    })
     19
     20    P:setButton(1, 2, {
     21            ["button"] = winMgr:getWindow("orxonox/GraphicsCancelButton"),
     22            ["callback"]  = P.callback_Cancel_Clicked
     23    })
     24
     25    -- place apply button at the bottom in the matrix, even though it's in fact at the top, to make the OK button highlighted by default
     26    P:setButton(2, 1, {
     27            ["button"] = winMgr:getWindow("orxonox/Display/Resolution/Apply"),
     28            ["callback"]  = P.callback_Apply_Clicked
     29    })
     30
     31    -----------------
     32    -- Combo boxes --
     33    -----------------
     34
     35    -- resolution combobox
     36    local resolutionCombobox = winMgr:getWindow("orxonox/Display/Resolution/Combobox")
     37    CEGUI.toCombobox(resolutionCombobox):setReadOnly(true)
     38
     39    for k,v in pairs(P.resolutionList) do
     40        local item = CEGUI.createListboxTextItem(v)
     41        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     42        resolutionCombobox:addItem(item)
     43    end
     44
     45    -- themes combobox
     46    local themeCombobox = winMgr:getWindow("orxonox/Display/Theme/Combobox")
     47    CEGUI.toCombobox(themeCombobox):setReadOnly(true)
     48
     49    for k,v in pairs(P.schemeList) do
     50        local item = CEGUI.createListboxTextItem(v)
     51        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     52        themeCombobox:addItem(item)
     53    end
     54
     55    -- fsaa combobox
     56    local fsaaCombobox = winMgr:getWindow("orxonox/Display/More/FSAA")
     57    CEGUI.toCombobox(fsaaCombobox):setReadOnly(true)
     58
     59    for k,v in pairs(P.fsaaList) do
     60        local item = CEGUI.createListboxTextItem(v)
     61        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     62        fsaaCombobox:addItem(item)
     63    end
     64
     65    -- particle lod combobox
     66    local particleLodCombobox = winMgr:getWindow("orxonox/Settings/ParticleLodCombobox")
     67    CEGUI.toCombobox(particleLodCombobox):setReadOnly(true)
     68
     69    for k,v in pairs(P.particleLodList) do
     70        local item = CEGUI.createListboxTextItem(v)
     71        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     72        particleLodCombobox:addItem(item)
     73    end
     74end
     75
     76function P:onShow()
     77    -----------------
     78    -- Display tab --
     79    -----------------
     80
     81    -- fullscreen checkbox / resolution combobox / resolution editboxes
     82    self:onWindowResized()
     83
     84    -- apply button
     85    self.updateApplyButton()
     86
     87    -- aspect ratio editbox
     88    local aspectRatioEditbox = winMgr:getWindow("orxonox/Display/Resolution/AspectRatio")
     89    local currentAspectRatio = orxonox.CommandExecutor:query("getConfig Camera aspectRatio_")
     90    aspectRatioEditbox:setText(currentAspectRatio)
     91
     92    -- themes combobox
     93    local themeCombobox = winMgr:getWindow("orxonox/Display/Theme/Combobox")
     94    local currentTheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_")
     95
     96    for i = 0, themeCombobox:getDropList():getItemCount() - 1 do
     97        local item = themeCombobox:getListboxItemFromIndex(i)
     98        themeCombobox:setItemSelectState(item, (item:getText() == currentTheme))
     99    end
     100
     101    -- vsync checkbox
     102    local vsyncCheckbox = winMgr:getWindow("orxonox/Display/More/VSync")
     103    local hasVSync = orxonox.GraphicsManager:getInstance():hasVSyncEnabled()
     104    CEGUI.toCheckbox(vsyncCheckbox):setSelected(hasVSync)
     105
     106    -- fsaa combobox
     107    local fsaaCombobox = winMgr:getWindow("orxonox/Display/More/FSAA")
     108    local currentFSAAMode = orxonox.GraphicsManager:getInstance():getFSAAMode()
     109
     110    for i = 0, fsaaCombobox:getDropList():getItemCount() - 1 do
     111        local item = fsaaCombobox:getListboxItemFromIndex(i)
     112        fsaaCombobox:setItemSelectState(item, (item:getText() == currentFSAAMode))
     113    end
     114
     115    -- notice
     116    self:updateRedLabel()
     117
     118    ------------------
     119    -- Settings tab --
     120    ------------------
     121
     122    -- fov editbox
     123    local fovEditbox = winMgr:getWindow("orxonox/Settings/Fov")
     124    local currentFov = orxonox.CommandExecutor:query("getConfig Camera fov_")
     125    fovEditbox:setText(currentFov)
     126
     127    -- fps limit editbox
     128    local fpsEditbox = winMgr:getWindow("orxonox/Settings/FpsLimit")
     129    local currentFpsLimit = orxonox.CommandExecutor:query("getConfig GraphicsSettings fpsLimit")
     130    fpsEditbox:setText(currentFpsLimit)
     131
     132    -- particle lod combobox
     133    local particleLodCombobox = winMgr:getWindow("orxonox/Settings/ParticleLodCombobox")
     134    local currentParticleLod = orxonox.CommandExecutor:query("getConfig GraphicsSettings particlesDetailLevel")
     135
     136    if currentParticleLod == "" then
     137        particleLodCombobox:disable()
     138    else
     139        particleLodCombobox:enable()
     140
     141        for i = 0, particleLodCombobox:getDropList():getItemCount() - 1 do
     142            local item = particleLodCombobox:getListboxItemFromIndex(i)
     143            particleLodCombobox:setItemSelectState(item, (tostring(i) == currentParticleLod))
    26144        end
    27         if search_mode == 1 then
    28             if string.sub(line, 1, 11) == "Full Screen" then
    29                 if string.sub(line, 13) == "Yes" then
    30                     fullscreen = true
    31                 else
    32                     fullscreen = false
    33                 end
    34             end
    35             if string.sub(line, 1, 10) == "Video Mode" then
    36                 if string.match(line, "@") == "@" then
    37                     resolution = string.sub(line, 12, string.find(line, "@")-2)
    38                 else
    39                     resolution = string.sub(line, 12)
    40                 end
    41                 break
    42             end
     145    end
     146
     147    -- mesh lod checkbox
     148    local meshLodCheckbox = winMgr:getWindow("orxonox/Settings/MeshLodCheckbox")
     149    local hasMeshLod = orxonox.CommandExecutor:query("getConfig GraphicsSettings enableMeshLoD")
     150    if hasMeshLod == "true" then
     151        hasMeshLod = true
     152    elseif hasMeshLod == "false" then
     153        hasMeshLod = false
     154    end
     155    CEGUI.toCheckbox(meshLodCheckbox):setSelected(hasMeshLod)
     156
     157    -- motion blur checkbox
     158    local motionBlurCheckbox = winMgr:getWindow("orxonox/Settings/MotionBlurCheckbox")
     159    local hasMotionBlur = orxonox.CommandExecutor:query("getConfig GraphicsSettings enableMotionBlur")
     160    if hasMotionBlur == "true" then
     161        hasMotionBlur = true
     162    elseif hasMotionBlur == "false" then
     163        hasMotionBlur = false
     164    end
     165    CEGUI.toCheckbox(motionBlurCheckbox):setSelected(hasMotionBlur)
     166end
     167
     168function P:onWindowResized()
     169    -- fullscreen checkbox
     170    local fullscreenCheckbox = winMgr:getWindow("orxonox/Display/Resolution/Fullscreen")
     171    local isFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
     172    CEGUI.toCheckbox(fullscreenCheckbox):setSelected(isFullscreen)
     173
     174    -- resolution combobox
     175    local resolutionCombobox = winMgr:getWindow("orxonox/Display/Resolution/Combobox")
     176
     177    local currentWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
     178    local currentHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
     179
     180    if P.forceResolutionEditboxes then
     181        currentWidth = P.newWidth
     182        currentHeight = P.newHeight
     183        P.forceResolutionEditboxes = false
     184    end
     185
     186    local currentResolution = currentWidth .. " x " .. currentHeight
     187
     188    for i = 0, resolutionCombobox:getDropList():getItemCount() - 1 do
     189        local item = resolutionCombobox:getListboxItemFromIndex(i)
     190        resolutionCombobox:setItemSelectState(item, item:getText() == currentResolution)
     191    end
     192
     193    -- resolution editboxes
     194    self.updateResolutionEditboxes()
     195end
     196
     197----------------------
     198-- Helper functions --
     199----------------------
     200
     201-- updates the text of the resolution checkboxes and checks if they should be enabled (only if the "custom" resolution was selected)
     202function P.updateResolutionEditboxes()
     203    -- resolution combobox
     204    local resolutionCombobox = winMgr:getWindow("orxonox/Display/Resolution/Combobox")
     205
     206    local currentWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
     207    local currentHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
     208
     209    -- resolution editboxes
     210    local widthEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxWidth")
     211    local heightEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxHeight")
     212    widthEditbox:disable()
     213    heightEditbox:disable()
     214
     215    -- selected combobox item
     216    local item = resolutionCombobox:getSelectedItem()
     217    if item then
     218        local itemText = item:getText()
     219        if itemText ~= "custom" then
     220            currentWidth = string.sub(itemText, 1, string.find(itemText, "x") - 2)
     221            currentHeight = string.sub(itemText, string.find(itemText, "x") + 2)
     222        else
     223            widthEditbox:enable()
     224            heightEditbox:enable()
    43225        end
    44226    end
    45     f:close()
    46     local fullscreenwindow = tolua.cast(winMgr:getWindow("orxonox/FullscreenCheckbox"),"CEGUI::Checkbox")
    47     fullscreenwindow:setSelected(fullscreen)
    48     listboxwindow = winMgr:getWindow("orxonox/ResolutionListbox")
    49     local resolutionList = {}
    50     table.insert(resolutionList, "640 x 480")
    51     table.insert(resolutionList, "720 x 480")
    52     table.insert(resolutionList, "720 x 576")
    53     table.insert(resolutionList, "800 x 480")
    54     table.insert(resolutionList, "800 x 600")
    55     table.insert(resolutionList, "1024 x 480")
    56     table.insert(resolutionList, "1024 x 600")
    57     table.insert(resolutionList, "1024 x 768")
    58     table.insert(resolutionList, "1152 x 864")
    59     table.insert(resolutionList, "1280 x 720")
    60     table.insert(resolutionList, "1280 x 768")
    61     table.insert(resolutionList, "1440 x 900")
    62     for k,v in pairs(resolutionList) do
    63         item = CEGUI.createListboxTextItem(v)
    64         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
    65         CEGUI.toListbox(listboxwindow):addItem(item)
    66     end
    67     if resolution == "640 x 480" then
    68         listboxwindow:setItemSelectState(0,true)
    69     elseif resolution == "720 x 480" then
    70         listboxwindow:setItemSelectState(1,true)
    71     elseif resolution == "720 x 576" then
    72         listboxwindow:setItemSelectState(2,true)
    73     elseif resolution == "800 x 480" then
    74         listboxwindow:setItemSelectState(3,true)
    75     elseif resolution == "800 x 600" then
    76         listboxwindow:setItemSelectState(4,true)
    77     elseif resolution == "1024 x 480" then
    78         listboxwindow:setItemSelectState(5,true)
    79     elseif resolution == "1024 x 600" then
    80         listboxwindow:setItemSelectState(6,true)
    81     elseif resolution == "1024 x 768" then
    82         listboxwindow:setItemSelectState(7,true)
    83     elseif resolution == "1152 x 864" then
    84         listboxwindow:setItemSelectState(8,true)
    85     elseif resolution == "1280 x 720" then
    86         listboxwindow:setItemSelectState(9,true)
    87     elseif resolution == "1280 x 768" then
    88         listboxwindow:setItemSelectState(10,true)
    89     elseif resolution == "1440 x 900" then
    90         listboxwindow:setItemSelectState(11,true)
    91     end
    92     scrollbar_active = false
    93     block = false
    94 
    95     local item = {
    96             ["button"] = winMgr:getWindow("orxonox/GraphicsBackButton"),
    97             ["function"]  = P.GraphicsBackButton_clicked
    98     }
    99     P.buttonList[1] = item
    100 
    101     local dropbox = winMgr:getWindow("orxonox/ThemeDropBox")
    102     local scheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_")
    103     for k,v in pairs(P.schemeList) do
    104         local item = CEGUI.createListboxTextItem(P.schemeList[k])
    105         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
    106         CEGUI.toListbox(dropbox):addItem(item)
    107         if v == scheme then
    108             dropbox:setItemSelectState(item, true)
    109         end
    110     end
    111 
    112 end
    113 
    114 function P.ThemeDropBox_changed(e)
    115     local dropbox = winMgr:getWindow("orxonox/ThemeDropBox")
    116     local listbox = CEGUI.toListbox(dropbox)
    117     local choice = listbox:getFirstSelectedItem()
    118     local index = 0
    119     if choice ~= nil then
    120         index = listbox:getItemIndex(choice)
    121     end
    122     orxonox.CommandExecutor:execute("config GUIManager guiScheme_ " .. P.schemeList[index+1])
    123 end
    124 
    125 function P.GraphicsResolutionListbox_changed(e)
    126     if listboxwindow:isItemSelected(0) then
    127         resolution = "640 x 480"
    128     elseif listboxwindow:isItemSelected(1) then
    129         resolution = "720 x 480"
    130     elseif listboxwindow:isItemSelected(2) then
    131         resolution = "720 x 576"
    132     elseif listboxwindow:isItemSelected(3) then
    133         resolution = "800 x 480"
    134     elseif listboxwindow:isItemSelected(4) then
    135         resolution = "800 x 600"
    136     elseif listboxwindow:isItemSelected(5) then
    137         resolution = "1024 x 480"
    138     elseif listboxwindow:isItemSelected(6) then
    139         resolution = "1024 x 600"
    140     elseif listboxwindow:isItemSelected(7) then
    141         resolution = "1024 x 768"
    142     elseif listboxwindow:isItemSelected(8) then
    143         resolution = "1152 x 864"
    144     elseif listboxwindow:isItemSelected(9) then
    145         resolution = "1280 x 720"
    146     elseif listboxwindow:isItemSelected(10) then
    147         resolution = "1280 x 768"
    148     elseif listboxwindow:isItemSelected(11) then
    149         resolution = "1440 x 900"
    150     end
    151     search_mode = 0
    152     f = io.open(file, "r")
    153     firstline = f:read("*line")
    154     text = firstline .. "\n"
    155     rendersystem = string.sub(firstline, 15)
    156     for line in f:lines() do
    157         if search_mode == 0 then
    158             if string.find(line, rendersystem) ~= nil then
    159                 search_mode = 1
    160             end
    161         end
    162         if search_mode == 1 then
    163             if string.sub(line, 1, 10) == "Video Mode" then
    164                 if string.match(line, "@") == "@" then
    165                     line = "Video Mode=" .. resolution .. string.sub(line, string.find(line, "@")-1)
    166                 else
    167                     line = "Video Mode=" .. resolution
    168                 end
    169                 search_mode = 2
    170             end
    171         end
    172         text = text .. line .. "\n"
    173     end
    174     f:close()
    175     f = io.open(file, "w")
    176     f:write(text)
    177     f:close()
    178 end
    179 
    180 function P.GraphicsBrightnessScrollbar_changed(e)
    181     if scrollbar_active == false then
    182         -- brightness
    183         logMessage(0, "event: brightness")
    184     end
    185 end
    186 
    187 function P.GraphicsBrightnessScrollbar_started(e)
    188     scrollbar_active = true
    189 end
    190 
    191 function P.GraphicsBrightnessScrollbar_ended(e)
    192     -- brightness
    193     logMessage(0, "event: brightness")
    194     scrollbar_active = false
    195 end
    196 
    197 function P.GraphicsFullscreenCheckbox_clicked(e)
    198     if block == false then
    199         search_mode = 0
    200         f = io.open(file, "r")
    201         firstline = f:read("*line")
    202         text = firstline .. "\n"
    203         rendersystem = string.sub(firstline, 15)
    204         for line in f:lines() do
    205             if search_mode == 0 then
    206                 if string.find(line, rendersystem) ~= nil then
    207                     search_mode = 1
    208                 end
    209             end
    210             if search_mode == 1 then
    211                 if string.sub(line, 1, 11) == "Full Screen" then
    212                     if fullscreen == true then
    213                         line = "Full Screen=No"
    214                         fullscreen = false
    215                     else
    216                         line = "Full Screen=Yes"
    217                         fullscreen = true
    218                     end
    219                     search_mode = 2
    220                 end
    221             end
    222             text = text .. line .. "\n"
    223         end
    224         f:close()
    225         f = io.open(file, "w")
    226         f:write(text)
    227         f:close()
    228     end
    229 end
    230 
    231 function P.GraphicsBackButton_clicked(e)
     227
     228    widthEditbox:setText(currentWidth)
     229    heightEditbox:setText(currentHeight)
     230end
     231
     232-- checks if the apply button should be enabled or disabled (only enabled if the current settings are different from the selected values)
     233function P.updateApplyButton()
     234    -- fullscreen checkbox
     235    local fullscreenCheckbox = winMgr:getWindow("orxonox/Display/Resolution/Fullscreen")
     236    local isFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
     237    local fullscreenChanged = (isFullscreen ~= CEGUI.toCheckbox(fullscreenCheckbox):isSelected())
     238
     239    -- resolution editboxes
     240    local widthEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxWidth")
     241    local heightEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxHeight")
     242    local currentWidth = tostring(orxonox.GraphicsManager:getInstance():getWindowWidth())
     243    local currentHeight = tostring(orxonox.GraphicsManager:getInstance():getWindowHeight())
     244    local widthChanged = (currentWidth ~= widthEditbox:getText())
     245    local heightChanged = (currentHeight ~= heightEditbox:getText())
     246    local resolutionEditboxesEnabled = not widthEditbox:isDisabled()
     247
     248    -- apply button
     249    local applyButton = winMgr:getWindow("orxonox/Display/Resolution/Apply")
     250
     251    if fullscreenChanged or widthChanged or heightChanged or resolutionEditboxesEnabled then
     252        applyButton:enable()
     253    else
     254        applyButton:disable()
     255    end
     256end
     257
     258function P.updateRedLabel()
     259    -- theme
     260    local themeCombobox = winMgr:getWindow("orxonox/Display/Theme/Combobox")
     261    local currentTheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_")
     262    local themeChanged = (currentTheme ~= themeCombobox:getText())
     263
     264    -- vsync
     265    local vsyncCheckbox = winMgr:getWindow("orxonox/Display/More/VSync")
     266    local hasVSync = orxonox.GraphicsManager:getInstance():hasVSyncEnabled()
     267    local vsyncChanged = (hasVSync ~= CEGUI.toCheckbox(vsyncCheckbox):isSelected())
     268
     269    -- fsaa
     270    local fsaaCombobox = winMgr:getWindow("orxonox/Display/More/FSAA")
     271    local currentFSAAMode = orxonox.GraphicsManager:getInstance():getFSAAMode()
     272    local fsaaChanged = (currentFSAAMode ~= fsaaCombobox:getText())
     273
     274    local needRestart = themeChanged or vsyncChanged or fsaaChanged
     275
     276    local notice = winMgr:getWindow("orxonox/Display/Notice")
     277    notice:setVisible(not needRestart)
     278    local noticeRed = winMgr:getWindow("orxonox/Display/NoticeRed")
     279    noticeRed:setVisible(needRestart)
     280end
     281
     282---------------------
     283-- Event callbacks --
     284---------------------
     285
     286-- resolution
     287
     288function P.callback_FullscreenCheckbox_CheckStateChanged(e)
     289    P.updateApplyButton()
     290end
     291
     292function P.callback_ResolutionCombobox_ListSelectionAccepted(e)
     293    P.updateResolutionEditboxes()
     294end
     295
     296function P.callback_ResolutionEditboxWidth_TextChanged(e)
     297    P.updateApplyButton()
     298end
     299
     300function P.callback_ResolutionEditboxHeight_TextChanged(e)
     301    P.updateApplyButton()
     302end
     303
     304-- theme
     305
     306function P.callback_ThemeCombobox_ListSelectionAccepted(e)
     307    P.updateRedLabel()
     308end
     309
     310-- vsync
     311
     312function P.callback_VSyncCheckbox_CheckStateChanged(e)
     313    P.updateRedLabel()
     314end
     315
     316-- fsaa
     317
     318function P.callback_FSAACombobox_ListSelectionAccepted(e)
     319    P.updateRedLabel()
     320end
     321
     322-- buttons
     323
     324function P.callback_Apply_Clicked(e)
     325    -- resolution
     326    local fullscreenCheckbox = winMgr:getWindow("orxonox/Display/Resolution/Fullscreen")
     327    local checkedFullscreen = tostring(CEGUI.toCheckbox(fullscreenCheckbox):isSelected())
     328
     329    local widthEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxWidth")
     330    local heightEditbox = winMgr:getWindow("orxonox/Display/Resolution/EditboxHeight")
     331
     332    P.newWidth = widthEditbox:getText()
     333    P.newHeight = heightEditbox:getText()
     334    P.forceResolutionEditboxes = true
     335
     336    -- start revert timer
     337    P.oldWidth = orxonox.GraphicsManager:getInstance():getWindowWidth()
     338    P.oldHeight = orxonox.GraphicsManager:getInstance():getWindowHeight()
     339    P.oldFullscreen = orxonox.GraphicsManager:getInstance():isFullScreen()
     340
     341    P.revertTimerHandle = orxonox.CommandExecutor:query("delayreal 10 {hideGUI DecisionPopup; GraphicsManager setScreenResolution " .. P.oldWidth .. " " .. P.oldHeight .. " " .. tostring(P.oldFullscreen) .. "; config Core lastLevelTimestamp_ [expr [getConfig Core ogreConfigTimestamp_] + 1]}")
     342
     343    -- change settings
     344    orxonox.CommandExecutor:execute("GraphicsManager setScreenResolution " .. P.newWidth .. " " .. P.newHeight .. " " .. checkedFullscreen)
     345
     346    P.updateApplyButton()
     347
     348    -- prompt for confirmation
     349    openDecisionPopup("Do you want to keep these settings? (Settings will be reverted in 10 seconds if not accepted)", GraphicsMenu.callback_ApplyDecisionPopup)
     350    if checkedFullscreen then
     351        showCursor()
     352    end
     353end
     354
     355function P.callback_ApplyDecisionPopup(pressedOK)
     356    orxonox.CommandExecutor:execute("killdelay " .. P.revertTimerHandle)
     357
     358    if not pressedOK then
     359        orxonox.CommandExecutor:execute("GraphicsManager setScreenResolution " .. P.oldWidth .. " " .. P.oldHeight .. " " .. tostring(P.oldFullscreen))
     360        P:onShow()
     361    end
     362
     363    -- update timestamp to avoid showing the ogre config dialog again after the user accepted or reverted the resolution
     364    orxonox.CommandExecutor:execute("config Core lastLevelTimestamp_ [expr [getConfig Core ogreConfigTimestamp_] + 1]")
     365end
     366
     367function P.callback_Ok_Clicked(e)
     368    -- aspect ratio
     369    local aspectRatioEditbox = winMgr:getWindow("orxonox/Display/Resolution/AspectRatio")
     370    orxonox.CommandExecutor:execute("config Camera aspectRatio_ " .. aspectRatioEditbox:getText())
     371
     372    -- theme
     373    local themeCombobox = winMgr:getWindow("orxonox/Display/Theme/Combobox")
     374    orxonox.CommandExecutor:execute("config GUIManager guiScheme_ " .. themeCombobox:getText())
     375
     376    -- vsync
     377    local vsyncCheckbox = winMgr:getWindow("orxonox/Display/More/VSync")
     378    local hasVSync = orxonox.GraphicsManager:getInstance():hasVSyncEnabled()
     379    if hasVSync ~= CEGUI.toCheckbox(vsyncCheckbox):isSelected() then
     380        orxonox.CommandExecutor:execute("GraphicsManager setVSync " .. tostring(CEGUI.toCheckbox(vsyncCheckbox):isSelected()))
     381    end
     382
     383    -- fsaa
     384    local fsaaCombobox = winMgr:getWindow("orxonox/Display/More/FSAA")
     385    local currentFSAAMode = orxonox.GraphicsManager:getInstance():getFSAAMode()
     386    if currentFSAAMode ~= fsaaCombobox:getText() then
     387        orxonox.CommandExecutor:execute("GraphicsManager setFSAA {" .. fsaaCombobox:getText() .. "}") -- enclose argument in { ... } because it can contain [brackets] (conflicts with tcl)
     388    end
     389
     390    -- fov
     391    local fovEditbox = winMgr:getWindow("orxonox/Settings/Fov")
     392    orxonox.CommandExecutor:execute("config Camera fov_ " .. fovEditbox:getText())
     393
     394    -- fps limit
     395    local fpsEditbox = winMgr:getWindow("orxonox/Settings/FpsLimit")
     396    orxonox.CommandExecutor:execute("config GraphicsSettings fpsLimit " .. fpsEditbox:getText())
     397
     398    -- particle lod
     399    local particleLodCombobox = winMgr:getWindow("orxonox/Settings/ParticleLodCombobox")
     400    local item = particleLodCombobox:getSelectedItem()
     401    if item then
     402        orxonox.CommandExecutor:execute("config GraphicsSettings particlesDetailLevel " .. particleLodCombobox:getItemIndex(item))
     403    end
     404
     405    -- mesh lod
     406    local meshLodCheckbox = winMgr:getWindow("orxonox/Settings/MeshLodCheckbox")
     407    orxonox.CommandExecutor:execute("config GraphicsSettings enableMeshLoD " .. tostring(CEGUI.toCheckbox(meshLodCheckbox):isSelected()))
     408
     409    -- motion blur
     410    local motionBlurCheckbox = winMgr:getWindow("orxonox/Settings/MotionBlurCheckbox")
     411    orxonox.CommandExecutor:execute("config GraphicsSettings enableMotionBlur " .. tostring(CEGUI.toCheckbox(motionBlurCheckbox):isSelected()))
     412
    232413    hideMenuSheet(P.name)
    233414end
    234415
    235 function P.onKeyPressed()
    236     buttonIteratorHelper(P.buttonList, code, P, 1, 1)
     416function P.callback_Cancel_Clicked(e)
     417    hideMenuSheet(P.name)
    237418end
    238419
  • code/trunk/data/gui/scripts/HostMenu.lua

    r7887 r8079  
    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:setButton(1, 1, {
    2019            ["button"] = winMgr:getWindow("orxonox/HostMenuStartButton"),
    21             ["function"]  = P.HostMenuStartButton_clicked
    22     }
    23     P.buttonList[1] = item
     20            ["callback"]  = P.HostMenuStartButton_clicked
     21    })
    2422
    25     local item = {
     23    P:setButton(1, 2, {
    2624            ["button"] = winMgr:getWindow("orxonox/HostMenuBackButton"),
    27             ["function"]  = P.HostMenuBackButton_clicked
    28     }
    29     P.buttonList[2] = item
     25            ["callback"]  = P.HostMenuBackButton_clicked
     26    })
    3027end
    3128
    3229function P.onShow()
     30    if P.showAll ~= orxonox.GUIManager:inDevMode() then
     31        local window = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
     32        local button = tolua.cast(window,"CEGUI::Checkbox")
     33        P.showAll = not P.showAll
     34        button:setSelected(P.showAll)
     35    end
     36
    3337    if P.multiplayerMode == "startServer" then
    3438        local window = winMgr:getWindow("orxonox/HostMenuHostButton")
     
    4448        P.createLevelList()
    4549    end
    46 
    47     P.oldindex = -2
    48     P.index = -1
    49 
    5050end
    5151
     
    9797end
    9898
    99 function P.HostMenuStartButton_clicked(e)   
     99function P.HostMenuStartButton_clicked(e)
    100100    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/HostMenuListbox"))
    101101    local choice = listbox:getFirstSelectedItem()
     
    119119end
    120120
    121 function P.onKeyPressed()
    122     buttonIteratorHelper(P.buttonList, code, P, 1, 2)
    123 end
    124 
    125121return P
  • code/trunk/data/gui/scripts/InGameMenu.lua

    r7877 r8079  
    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:setButton(1, 1, {
    1311            ["button"] = winMgr:getWindow("orxonox/InGameMenu_ReturnButton"),
    14             ["function"]  = P.button_settings_clicked
    15     }
    16     P.buttonList[1] = item
     12            ["callback"]  = P.button_return_clicked
     13    })
    1714
    18     local item = {
     15    P:setButton(2, 1, {
    1916            ["button"] = winMgr:getWindow("orxonox/InGameMenu_MainMenuButton"),
    20             ["function"]  = P.button_mainmenu_clicked
    21     }
    22     P.buttonList[2] = item
     17            ["callback"]  = P.button_mainmenu_clicked
     18    })
    2319
    24     local item = {
     20    P:setButton(3, 1, {
    2521            ["button"] = winMgr:getWindow("orxonox/InGameMenu_SettingsButton"),
    26             ["function"]  = P.button_settings_clicked
    27     }
    28     P.buttonList[3] = item
     22            ["callback"]  = P.button_settings_clicked
     23    })
    2924
    30     local item = {
     25    P:setButton(4, 1, {
    3126            ["button"] = winMgr:getWindow("orxonox/InGameMenu_QuitButton"),
    32             ["function"]  = P.button_quit_clicked
    33     }
    34     P.buttonList[4] = item
    35 
     27            ["callback"]  = P.button_quit_clicked
     28    })
    3629end
    3730
    3831function P.onShow()
    39     --indices to iterate through buttonlist
    40     P.oldindex = -2
    41     P.index = -1
     32    if P:hasSelection() == false then
     33        P:setSelection(1, 1)
     34    end
     35
     36    orxonox.execute("setPause 1")
     37end
     38
     39function P.onQuit()
     40    orxonox.execute("setPause 0")
    4241end
    4342
     
    6463        hideMenuSheet("InGameMenu")
    6564        orxonox.execute("exit")
    66     else 
     65    else
    6766        P.onShow()
    6867    end
    6968end
    7069
    71 function P.onKeyPressed()
    72     buttonIteratorHelper(P.buttonList, code, P, 4, 1)
    73 end
    74 
    7570return P
    7671
  • code/trunk/data/gui/scripts/KeyBindMenu.lua

    r7403 r8079  
    2626    table.insert(commandList, "NewHumanController changeMode")
    2727    table.insert(commandList, "switchCamera")
    28     table.insert(commandList, "openConsole")
     28    table.insert(commandList, "InGameConsole openConsole")
    2929    table.insert(commandList, "OverlayGroup toggleVisibility Debug")
    3030    table.insert(commandList, "OverlayGroup toggleVisibility Stats")
     
    3535    table.insert(commandList, "mouseLook")
    3636    table.insert(commandList, "pause")
     37    table.insert(commandList, "printScreen")
     38    if orxonox.GUIManager:inDevMode() then
     39        table.insert(commandList, "printScreenHD 3")
     40    end
    3741
    3842    nameList = {}
     
    6569    table.insert(nameList, "Look Around")
    6670    table.insert(nameList, "Pause")
     71    table.insert(nameList, "Screenshot")
     72    if orxonox.GUIManager:inDevMode() then
     73        table.insert(nameList, "HD screenshot")
     74    end
    6775
    6876    linesList = {}
     
    100108    local funct = luaState:createLuaFunctor("KeyBindMenu.callback()")
    101109    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
     110
     111    P:setButton(1, 1, {
     112            ["button"] = winMgr:getWindow("orxonox/KeyBindBackButton"),
     113            ["callback"]  = P.KeyBindBackButton_clicked
     114    })
    102115end
    103116
  • code/trunk/data/gui/scripts/MainMenu.lua

    r7689 r8079  
    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:setButton(1, 1, {
    119            ["button"] = winMgr:getWindow("orxonox/QuickGameTestButton"),
    12             ["function"]  = P.QuickGameTestButton_clicked
    13     }
    14     table.insert(P.buttonList,item)
     10            ["callback"]  = P.QuickGameTestButton_clicked
     11    })
    1512
    16     item = {
     13    P:setButton(2, 1, {
    1714            ["button"] = winMgr:getWindow("orxonox/SingleplayerButton"),
    18             ["function"]  = P.SingleplayerButton_clicked
    19     }
    20     table.insert(P.buttonList,item)
     15            ["callback"]  = P.SingleplayerButton_clicked
     16    })
    2117
    22     item = {
     18    P:setButton(3, 1, {
    2319            ["button"] = winMgr:getWindow("orxonox/MultiplayerButton"),
    24             ["function"]  = P.MultiplayerButton_clicked
    25     }
    26     table.insert(P.buttonList,item)
     20            ["callback"]  = P.MultiplayerButton_clicked
     21    })
    2722
    28     item = {
     23    P:setButton(4, 1, {
    2924            ["button"] = winMgr:getWindow("orxonox/SettingsButton"),
    30             ["function"]  = P.SettingsButton_clicked
    31     }
    32     table.insert(P.buttonList,item)
     25            ["callback"]  = P.SettingsButton_clicked
     26    })
    3327
    34     item = {
     28    P:setButton(5, 1, {
    3529            ["button"] = winMgr:getWindow("orxonox/CreditsButton"),
    36             ["function"]  = P.CreditsButton_clicked
    37     }
    38     table.insert(P.buttonList,item)
     30            ["callback"]  = P.CreditsButton_clicked
     31    })
    3932
    40     item = {
     33    P:setButton(6, 1, {
    4134            ["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
     35            ["callback"]  = P.ExitButton_clicked
     36    })
    5137end
    5238
     
    7763end
    7864
    79 function P.onKeyPressed()
    80     buttonIteratorHelper(P.buttonList, code, P, 6, 1)
    81 end
    82 
    8365return P
    8466
  • code/trunk/data/gui/scripts/MiscConfigMenu.lua

    r7403 r8079  
    3535    table.insert(P.commandList, "HumanPlayer nick_")
    3636    table.insert(P.commandList, "ChatOverlay displayTime_")
     37    table.insert(P.commandList, "Core bDevMode_")
    3738
    3839    P.nameList = {}
     
    5455    table.insert(P.nameList, "Playername")
    5556    table.insert(P.nameList, "Chat: display time")
     57    table.insert(P.nameList, "Developer's Mode")
    5658
    5759    P.linesList = {}
     
    8587    P.createLines()
    8688
     89    P:setButton(1, 1, {
     90            ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigBackButton"),
     91            ["callback"]  = P.MiscConfigBackButton_clicked
     92    })
    8793end
    8894
  • code/trunk/data/gui/scripts/MouseControlsMenu.lua

    r6746 r8079  
    3232        invert_active = false
    3333    end
     34
     35    P:setButton(1, 1, {
     36            ["button"] = winMgr:getWindow("orxonox/MouseControlsBackButton"),
     37            ["callback"]  = P.MouseControlsBackButton_clicked
     38    })
    3439end
    3540
  • code/trunk/data/gui/scripts/MultiplayerMenu.lua

    r7876 r8079  
    22
    33local P = createMenuSheet("MultiplayerMenu")
    4 
    5 P.buttonList = {}
    64
    75--joinMode is 1 for choice "LAN" and 2 for "Internet"
     
    108
    119function P.onLoad()
    12     P.multiplayerMode = "startClient" 
     10    P.multiplayerMode = "startClient"
    1311
    14     --button are arranged in a 2x2 matrix, the left lower item is nil
    15     local item = {
     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
     13    P:setButton(1, 1, {
    1614            ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"),
    17             ["function"]  = P.MultiplayerJoinButton_clicked
    18     }
    19     P.buttonList[1] = item
     15            ["callback"]  = P.MultiplayerJoinButton_clicked
     16    })
    2017
    21     local item = {
     18    P:setButton(1, 2, {
    2219            ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"),
    23             ["function"]  = P.MultiplayerHostButton_clicked
    24     }
    25     P.buttonList[2] = item
     20            ["callback"]  = P.MultiplayerHostButton_clicked
     21    })
    2622
    27     local item = {
     23    P:setButton(2, 3, {
    2824            ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"),
    29             ["function"]  = P.MultiplayerBackButton_clicked
    30     }
    31     P.buttonList[4] = item
     25            ["callback"]  = P.MultiplayerBackButton_clicked
     26    })
    3227end
    3328
     
    3530    --P.showServerList()
    3631
    37     --indices to iterate through buttonlist
    38     P.oldindex = -2
    39     P.index = -1
    40    
    4132    if P.joinMode == 1 then
    4233        local window = winMgr:getWindow("orxonox/MultiplayerLanButton")
     
    5647    P.joinMode = 1
    5748    if button:isSelected() == true then
    58             P.showServerList()
     49        P.showServerList()
    5950    end
    6051end
     
    6556    P.joinMode = 2
    6657    if button:isSelected() == true then
    67             P.showServerList()
    68         end
     58        P.showServerList()
     59    end
    6960end
    7061
     
    9283
    9384function P.showServerList()
    94         -- LAN Discovery
    95         if P.joinMode == 1 then
    96                 local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
    97                 CEGUI.toListbox(listbox):resetList()
    98                 local discovery = orxonox.LANDiscovery:getInstance()
    99                 discovery:discover()
    100                 P.serverList = {}
    101                 local index = 0
    102                 local servername = ""
    103                 local serverip = ""
    104                 while true do
    105                     servername = discovery:getServerListItemName(index)
    106                     if servername == "" then
    107                         break
    108                     end
    109                     serverip = discovery:getServerListItemIP(index)
    110                     if serverip == "" then
    111                       break
    112                     end
    113                     table.insert(P.serverList, {servername, serverip})
    114                     index = index + 1
    115                 end
    116                 index = 1
    117                 for k,v in pairs(P.serverList) do
    118                     local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
    119                     item:setID(index)
    120                     index = index + 1
    121                     item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
    122                     CEGUI.toListbox(listbox):addItem(item)
    123                 end
    124         -- WAN Discovery
    125         elseif P.joinMode == 2 then
    126                 local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
    127                 CEGUI.toListbox(listbox):resetList()
    128                 local discovery = orxonox.WANDiscovery:getInstance()
    129                 cout(0, "discovering.\n" )
    130                 discovery:discover()
    131                 cout(0, "discovered.\n" )
    132                 P.serverList = {}
    133                 local index = 0
    134                 local servername = ""
    135                 local serverip = ""
    136                 while true do
    137                     servername = discovery:getServerListItemName(index)
    138                     if servername == "" then
    139                         break
    140                     end
    141                     serverip = discovery:getServerListItemIP(index)
    142                     if serverip == "" then
    143                       break
    144                     end
    145                     table.insert(P.serverList, {servername, serverip})
    146                     index = index + 1
    147                 end
    148                 index = 1
    149                 for k,v in pairs(P.serverList) do
    150                     local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
    151                     item:setID(index)
    152                     index = index + 1
    153                     item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
    154                     CEGUI.toListbox(listbox):addItem(item)
    155                 end
    156         end
    157        
    158 end
     85    -- LAN Discovery
     86    if P.joinMode == 1 then
     87        local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
     88        CEGUI.toListbox(listbox):resetList()
     89        local discovery = orxonox.LANDiscovery:getInstance()
     90        discovery:discover()
     91        P.serverList = {}
     92        local index = 0
     93        local servername = ""
     94        local serverip = ""
     95        while true do
     96            servername = discovery:getServerListItemName(index)
     97            if servername == "" then
     98                break
     99            end
     100            serverip = discovery:getServerListItemIP(index)
     101            if serverip == "" then
     102                break
     103            end
     104            table.insert(P.serverList, {servername, serverip})
     105            index = index + 1
     106        end
     107        index = 1
     108        for k,v in pairs(P.serverList) do
     109            local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
     110            item:setID(index)
     111            index = index + 1
     112            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     113            CEGUI.toListbox(listbox):addItem(item)
     114        end
     115    -- WAN Discovery
     116    elseif P.joinMode == 2 then
     117        local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
     118        CEGUI.toListbox(listbox):resetList()
     119        local discovery = orxonox.WANDiscovery:getInstance()
     120        cout(0, "discovering.\n" )
     121        discovery:discover()
     122        cout(0, "discovered.\n" )
     123        P.serverList = {}
     124        local index = 0
     125        local servername = ""
     126        local serverip = ""
     127        while true do
     128            servername = discovery:getServerListItemName(index)
     129            if servername == "" then
     130                break
     131            end
     132            serverip = discovery:getServerListItemIP(index)
     133            if serverip == "" then
     134                break
     135            end
     136            table.insert(P.serverList, {servername, serverip})
     137            index = index + 1
     138        end
     139        index = 1
     140        for k,v in pairs(P.serverList) do
     141            local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
     142            item:setID(index)
     143            index = index + 1
     144            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     145            CEGUI.toListbox(listbox):addItem(item)
     146        end
     147    end
    159148
    160 function P.onKeyPressed()
    161     buttonIteratorHelper(P.buttonList, code, P, 2, 2)
    162149end
    163150
  • code/trunk/data/gui/scripts/NotificationLayer.lua

    r7887 r8079  
    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.onQuit()
    336336    -- If we leave the edit mode we show the sheet again.
    337337    if P.editMode then
  • code/trunk/data/gui/scripts/SettingsMenu.lua

    r7689 r8079  
    44P.loadAlong = { "ControlsMenu", "AudioMenu", "GraphicsMenu" }
    55
    6 P.buttonList = {}
    7 
    86function P.onLoad()
    97    --"Gameplay" and "Multiplayer Options" are not integrated in the list
    10     --buttons are arranged in a 4x2 matrix. The lower-right element is not in the matrix!
    11     local item = {
     8    --buttons are arranged in a 4x2 matrix.
     9    P:setButton(1, 2, {
    1210            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/GraphicsButton"),
    13             ["function"]  = P.SettingsGraphicsButton_clicked
    14     }
    15     P.buttonList[2] = item
     11            ["callback"]  = P.SettingsGraphicsButton_clicked
     12    })
    1613
    17     local item = {
     14    P:setButton(2, 2, {
    1815            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/AudioButton"),
    19             ["function"]  = P.SettingsAudioButton_clicked
    20     }
    21     P.buttonList[4] = item
     16            ["callback"]  = P.SettingsAudioButton_clicked
     17    })
    2218
     19    P:setButton(3, 1, {
     20            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/ControlsButton"),
     21            ["callback"]  = P.SettingsControlsButton_clicked
     22    })
    2323
    24     local item = {
    25             ["button"] = winMgr:getWindow("orxonox/SettingsMenu/ControlsButton"),
    26             ["function"]  = P.SettingsControlsButton_clicked
    27     }
    28     P.buttonList[5] = item
     24    P:setButton(3, 2, {
     25            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/MiscellaneousButton"),
     26            ["callback"]  = P.SettingsMiscellaneousButton_clicked
     27    })
    2928
    30     local item = {
    31             ["button"] = winMgr:getWindow("orxonox/SettingsMenu/MiscellaneousButton"),
    32             ["function"]  = P.SettingsMiscellaneousButton_clicked
    33     }
    34     P.buttonList[6] = item
     29    P:setButton(4, 1, {
     30            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/SettingsBackButton"),
     31            ["callback"]  = P.SettingsBackButton_clicked
     32    })
    3533
    36     local item = {
    37             ["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
     34    P:setButton(4, 2, P:getButton(4, 1))
    4835end
    4936
     
    7663end
    7764
    78 function P.onKeyPressed()
    79     buttonIteratorHelper(P.buttonList, code, P, 4, 2)
    80 end
    81 
    8265return P
    8366
  • code/trunk/data/gui/scripts/SheetManager.lua

    r7689 r8079  
    88local mainMenuLoaded = false
    99orxonox.GUIManager:subscribeEventHelper(menuSheetsRoot, "KeyDown", "keyPressed")
    10 
    11 -----------------------
    12 --- Local functions ---
    13 -----------------------
    14 
    15 local function hideCursor()
    16     if cursor:isVisible() then
    17         cursor:hide()
    18     end
    19 end
    20 
    21 local function showCursor()
    22     if not cursor:isVisible() and inputMgr:isMouseExclusive() then
    23         cursor:show()
    24     end
    25 end
    26 
     10orxonox.GUIManager:subscribeEventHelper(menuSheetsRoot, "Sized", "windowResized")
    2711
    2812------------------------
    2913--- Global functions ---
    3014------------------------
     15
     16function hideCursor()
     17    if cursor:isVisible() then
     18        cursor:hide()
     19    end
     20end
     21
     22function showCursor()
     23    if not cursor:isVisible() and inputMgr:isMouseExclusive() then
     24        cursor:show()
     25    end
     26end
    3127
    3228-- Loads the GUI with the specified name
     
    9389        ["sheet"]          = menuSheet,
    9490        ["bHidePrevious"]  = bHidePrevious,
    95         ["bNoInput"]       = bNoInput
     91        ["bNoInput"]       = bNoInput,
     92        ["name"]           = name
    9693    }
    9794    table.insert(activeMenuSheets, sheetTuple) -- indexed array access
     
    121118
    122119    -- Hide all previous sheets if necessary
     120    local previous
    123121    if bHidePrevious then
    124122        for i = 1, activeMenuSheets.size - 1 do
    125             activeMenuSheets[i].sheet:hide()
    126         end
    127     end
    128    
     123            previous = activeMenuSheets[i].sheet
     124            previous:hide()
     125        end
     126    end
     127
    129128    menuSheet:show()
    130129    menuSheetsRoot:activate()
     130
     131    -- select first button if the menu was opened with the keyboard
     132    if previous and previous.pressedEnter and menuSheet:hasSelection() == false then
     133        menuSheet:setSelectionNear(1, 1)
     134    end
    131135
    132136    return menuSheet
     
    179183        inputMgr:leaveState(sheetTuple.sheet.inputState)
    180184    end
    181    
     185
    182186    -- CURSOR SHOWING
    183187    local i = activeMenuSheets.size
     
    200204    end
    201205
    202     sheetTuple.sheet:afterHide()
     206    sheetTuple.sheet:quit()
    203207end
    204208
     
    242246            keyESC()
    243247        elseif code == "0"then
    244             orxonox.CommandExecutor:execute("openConsole")
    245         end
    246     end
    247     sheet.sheet:onKeyPressed()
     248            orxonox.CommandExecutor:execute("InGameConsole openConsole")
     249        end
     250    end
     251    sheet.sheet:keyPressed()
     252end
     253
     254function windowResized(e)
     255    for name, sheet in pairs(loadedSheets) do
     256        if orxonox.GraphicsManager:getInstance():isFullScreen() or sheet.tShowCursor == TriBool.False then
     257            inputMgr:setMouseExclusive(sheet.inputState, TriBool.True)
     258        else
     259            inputMgr:setMouseExclusive(sheet.inputState, TriBool.False)
     260        end
     261    end
     262    local sheetTuple = activeMenuSheets[activeMenuSheets.size]
     263    if sheetTuple then
     264        if orxonox.GraphicsManager:getInstance():isFullScreen() and sheetTuple.sheet.tShowCursor ~= TriBool.False then
     265            showCursor()
     266        else
     267            hideCursor()
     268        end
     269        sheetTuple.sheet:windowResized()
     270    end
    248271end
    249272
     
    276299end
    277300
     301function getGUIFirstActive(name, bHidePrevious, bNoInput)
     302    local sheet = activeMenuSheets.topSheetTuple
     303    -- If the topmost gui sheet has the input name
     304    if sheet ~= nil and sheet.name == name then
     305        guiMgr:toggleGUIHelper(name, bHidePrevious, bNoInput, false);
     306    else
     307        guiMgr:toggleGUIHelper(name, bHidePrevious, bNoInput, true);
     308    end
     309end
     310
    278311----------------------
    279312--- Initialisation ---
  • code/trunk/data/gui/scripts/SingleplayerMenu.lua

    r7876 r8079  
    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:setButton(1, 1, {
    1817            ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
    19             ["function"]  = P.SingleplayerStartButton_clicked
    20     }
    21     P.buttonList[1] = item
     18            ["callback"]  = P.SingleplayerStartButton_clicked
     19    })
    2220
    23     local item = {
     21    P:setButton(1, 2, {
    2422            ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
    25             ["function"]  = P.SingleplayerBackButton_clicked
    26     }
    27     P.buttonList[2] = item
     23            ["callback"]  = P.SingleplayerBackButton_clicked
     24    })
     25end
     26
     27function P.onShow()
     28    if P.showAll ~= orxonox.GUIManager:inDevMode() then
     29        local window = winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox")
     30        local button = tolua.cast(window,"CEGUI::Checkbox")
     31        P.showAll = not P.showAll
     32        button:setSelected(P.showAll)
     33        P.createLevelList()
     34    end
    2835end
    2936
     
    4754        index = index + 1
    4855    end
    49     --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename.
    50     --table.sort(levelList)
    5156    for k,v in pairs(P.levelList) do
    5257        local item = CEGUI.createListboxTextItem(v:getName())
     
    5964        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
    6065    end
    61 end
    62 
    63 function P.onShow()
    64     --indices to iterate through buttonlist
    65     P.oldindex = -2
    66     P.index = -1
    6766end
    6867
     
    9392end
    9493
    95 function P.onKeyPressed()
    96     buttonIteratorHelper(P.buttonList, code, P, 1, 2)
    97 end
    98 
    9994return P
    10095
Note: See TracChangeset for help on using the changeset viewer.