Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menu/data/gui/scripts/SingleplayerMenu.lua @ 7687

Last change on this file since 7687 was 7687, checked in by konrad, 13 years ago

—function to iterate throgh a menusheet by using arrowkeys is added

  • Property svn:eol-style set to native
File size: 1.9 KB
RevLine 
[6363]1-- SingleplayerMenu.lua
2
[6746]3local P = createMenuSheet("SingleplayerMenu")
[6363]4
[7687]5P.buttonList = {}
6
[6746]7function P.onLoad()
[6363]8    listbox = winMgr:getWindow("orxonox/SingleplayerLevelListbox")
9    preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
10    orxonox.LevelManager:getInstance():compileAvailableLevelList()
11    local levelList = {}
12    local index = 0
13    local level = ""
14    while true do
15      level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
16      if level == "" then
17        break
18      end
19      table.insert(levelList, level)
20      index = index + 1
21    end
22    table.sort(levelList)
23    for k,v in pairs(levelList) do
[6388]24        item = CEGUI.createListboxTextItem(v)
[6746]25        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
[6363]26        CEGUI.toListbox(listbox):addItem(item)
27        if v .. ".oxw" == preselect then
28            listbox:setItemSelectState(item, true)
29        end
30    end
[7163]31
[7687]32    --buttons are arranged in a 1x2 matrix
33    local item = {
34            ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
35            ["function"]  = P.SingleplayerStartButton_clicked
36    }
37    P.buttonList[1] = item
38
39    local item = {
40            ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
41            ["function"]  = P.SingleplayerBackButton_clicked
42    }
43    P.buttonList[2] = item
44
[6363]45end
46
[7687]47function P.onShow()
48    --indices to iterate through buttonlist
49    P.oldindex = -2
50    P.index = -1
51end
52
[6363]53function P.SingleplayerStartButton_clicked(e)
[6754]54    local choice = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")):getFirstSelectedItem()
[6363]55    if choice then
56        orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
[6403]57        orxonox.execute("startGame")
[6746]58        hideAllMenuSheets()
[6363]59    end
60end
61
62function P.SingleplayerBackButton_clicked(e)
[6746]63    hideMenuSheet(P.name)
[6363]64end
65
[7687]66function P.onKeyPressed() 
67    buttonIteratorHelper(P.buttonList, code, P, 1, 2)
68end
69
[6363]70return P
71
Note: See TracBrowser for help on using the repository browser.