Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7663


Ignore:
Timestamp:
Nov 24, 2010, 3:33:26 PM (13 years ago)
Author:
konrad
Message:

key handling in some menu sheets has been added.

Location:
code/branches/menu/data/gui/scripts
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/menu/data/gui/scripts/CreditsMenu.lua

    r6746 r7663  
    22
    33local P = createMenuSheet("CreditsMenu")
     4
     5P.buttonList = {}
     6
     7function P.onLoad()
     8    local item = {
     9            ["button"] = winMgr:getWindow("orxonox/CreditsBackButton"),
     10            ["function"]  = P.CreditsBackButton_clicked
     11    }
     12    P.buttonList[1] = item
     13end
     14
     15function P.onShow()
     16    P.oldindex = -2
     17    P.index = -1
     18end
    419
    520function P.CreditsBackButton_clicked(e)
     
    722end
    823
     24function P.onKeyPressed()
     25    buttonIteratorHelper(P.buttonList, code, P, 1, 1)
     26end
     27
    928return P
    1029
  • code/branches/menu/data/gui/scripts/GUITools.lua

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

    r7608 r7663  
    44P.loadAlong = { "SingleplayerMenu", "MultiplayerMenu", "SettingsMenu", "CreditsMenu" }
    55
    6 P.index = 0
     6P.buttonList = {}
     7
     8P.testArray = {}
     9
     10
     11function P.onLoad()
     12    local item = {
     13            ["button"] = winMgr:getWindow("orxonox/QuickGameTestButton"),
     14            ["function"]  = P.QuickGameTestButton_clicked
     15    }
     16    table.insert(P.buttonList,item)
     17
     18    item = {
     19            ["button"] = winMgr:getWindow("orxonox/SingleplayerButton"),
     20            ["function"]  = P.SingleplayerButton_clicked
     21    }
     22    table.insert(P.buttonList,item)
     23
     24    item = {
     25            ["button"] = winMgr:getWindow("orxonox/MultiplayerButton"),
     26            ["function"]  = P.MultiplayerButton_clicked
     27    }
     28    table.insert(P.buttonList,item)
     29
     30    item = {
     31            ["button"] = winMgr:getWindow("orxonox/SettingsButton"),
     32            ["function"]  = P.SettingsButton_clicked
     33    }
     34    table.insert(P.buttonList,item)
     35
     36    item = {
     37            ["button"] = winMgr:getWindow("orxonox/CreditsButton"),
     38            ["function"]  = P.CreditsButton_clicked
     39    }
     40    table.insert(P.buttonList,item)
     41
     42    item = {
     43            ["button"] = winMgr:getWindow("orxonox/ExitButton"),
     44            ["function"]  = P.ExitButton_clicked
     45    }
     46    table.insert(P.buttonList,item)
     47end
     48
     49function P.onShow()
     50    P.oldindex = -2
     51    P.index = -1
     52end
    753
    854-- events for MainMenu
     
    1056    hideAllMenuSheets()
    1157    orxonox.execute("startGame")
    12 end
    13 
    14 function P.onShow()
    15 
    1658end
    1759
     
    3678end
    3779
    38 function P.onKeyPressed()
    39     --local we = tolua.cast(e, "CEGUI::KeyEventArgs")
    40     cout(0, code)
    41     if code == "15" then
    42         P.index = P.index + 1
    43         local window = winMgr:getWindow("orxonox/MainMenuBackground")
    44         if P.index == window:getChildCount() then
    45             P.index = 1
    46         end
    47         local child = window:getChildAtIdx(P.index-1)
    48         child:setProperty("NormalImageRightEdge", string.sub(child:getProperty("NormalImageRightEdge"),1,-7) .. "Highlight")
    49         child:setProperty("NormalImageLeftEdge", string.sub(child:getProperty("NormalImageLeftEdge"),1,-7) .. "Highlight")
    50         child:setProperty("NormalImageBackground", string.sub(child:getProperty("NormalImageBackground"),1,-7) .. "Highlight")
    51     elseif code == "28" and P.index ~= 0 then
    52         if P.index == 1 then
    53             P.QuickGameTestButton_clicked()
    54         elseif P.index == 2 then
    55             P.SingleplayerButton_clicked()
    56         elseif P.index == 3 then
    57             P.MultiplayerButton_clicked()
    58         elseif P.index == 4 then
    59             P.SettingsButton_clicked()
    60         elseif P.index == 5 then
    61             P.CreditsButton_clicked()
    62         elseif P.index == 6 then
    63             P.ExitButton_clicked()
    64         end
     80
     81--[[
     82list = {}
     83local item =
     84{
     85    ["button"] = buttonWindow,
     86    ["function"]  = buttonFunction,
     87}
     88table.insert(list, item)
     89item = list[i]
     90
     91for i,item in pairs(list) do
     92    button = item["button"]
     93end
     94
     95--]]
     96--[[
     97function createList()
     98    list = {}
     99
     100    local j
     101    while j < P.loadAlong
     102        local item =
     103        {
     104            ["button"] = buttonWindow,
     105            ["function"]  = buttonFunction,
     106        }
     107        table.insert(list, item)
    65108    end
     109
     110--]]
     111
     112function P.onKeyPressed()
     113    cout(0,code)
     114    buttonIteratorHelper(P.buttonList, code, P, 6, 1)
     115    --indexTester(P.buttonList,code,P,6,1)
    66116end
    67117
    68118return P
     119
  • code/branches/menu/data/gui/scripts/MultiplayerMenu.lua

    r7587 r7663  
    33local P = createMenuSheet("MultiplayerMenu")
    44
     5P.buttonList = {}
     6
    57function P.onLoad()
    6     P.multiplayerMode = "startClient"
     8    P.multiplayerMode = "startClient"
     9
     10    local item = {
     11            ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton2"),
     12            ["function"]  = P.MultiplayerJoinButton_clicked
     13    }
     14    P.buttonList[1] = item
     15
     16    local item = {
     17            ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton2"),
     18            ["function"]  = P.MultiplayerHostButton_clicked
     19    }
     20    P.buttonList[2] = item
     21
     22    local item = {
     23            ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"),
     24            ["function"]  = P.MultiplayerBackButton_clicked
     25    }
     26    P.buttonList[4] = item
     27
    728end
    829
    930function P.onShow()
    1031    P.showServerList()
     32    P.oldindex = -2
     33    P.index = -1
    1134end
    1235
     
    109132end
    110133
     134function P.onKeyPressed()
     135    cout(0,code)
     136    buttonIteratorHelper(P.buttonList, code, P, 2, 2)
     137    --indexTester(P.buttonList,code,P,2,3)
     138end
     139
    111140return P
    112141
  • code/branches/menu/data/gui/scripts/SettingsMenu.lua

    r7163 r7663  
    33local P = createMenuSheet("SettingsMenu")
    44P.loadAlong = { "ControlsMenu", "AudioMenu", "GraphicsMenu" }
     5
     6P.buttonList = {}
     7
     8function P.onLoad()
     9    --"Gameplay" and "Multiplayer Options" are not integrated in the list
     10   
     11    local item = {
     12            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/GraphicsButton"),
     13            ["function"]  = P.SettingsGraphicsButton_clicked
     14    }
     15    P.buttonList[2] = item
     16
     17    local item = {
     18            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/AudioButton"),
     19            ["function"]  = P.SettingsAudioButton_clicked
     20    }
     21    P.buttonList[4] = item
     22
     23
     24    local item = {
     25            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/ControlsButton"),
     26            ["function"]  = P.SettingsControlsButton_clicked
     27    }
     28    P.buttonList[5] = item
     29
     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 = {
     37            ["button"] = winMgr:getWindow("orxonox/SettingsMenu/SettingsBackButton"),
     38            ["function"]  = P.SettingsBackButton_clicked
     39    }
     40    P.buttonList[7] = item
     41
     42end
     43
     44function P.onShow()
     45    P.oldindex = 3
     46    P.index = 2
     47end
    548
    649function P.SettingsGameplayButton_clicked(e)
     
    3275end
    3376
     77function P.onKeyPressed()
     78    cout(0,code)
     79    buttonIteratorHelper(P.buttonList, code, P, 4, 2)
     80    --indexTester(P.buttonList,code,P,4,2)
     81end
     82
    3483return P
    3584
Note: See TracChangeset for help on using the changeset viewer.