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, 14 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
Line 
1-- SingleplayerMenu.lua
2
3local P = createMenuSheet("SingleplayerMenu")
4
5P.buttonList = {}
6
7function P.onLoad()
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
24        item = CEGUI.createListboxTextItem(v)
25        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
26        CEGUI.toListbox(listbox):addItem(item)
27        if v .. ".oxw" == preselect then
28            listbox:setItemSelectState(item, true)
29        end
30    end
31
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
45end
46
47function P.onShow()
48    --indices to iterate through buttonlist
49    P.oldindex = -2
50    P.index = -1
51end
52
53function P.SingleplayerStartButton_clicked(e)
54    local choice = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")):getFirstSelectedItem()
55    if choice then
56        orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
57        orxonox.execute("startGame")
58        hideAllMenuSheets()
59    end
60end
61
62function P.SingleplayerBackButton_clicked(e)
63    hideMenuSheet(P.name)
64end
65
66function P.onKeyPressed() 
67    buttonIteratorHelper(P.buttonList, code, P, 1, 2)
68end
69
70return P
71
Note: See TracBrowser for help on using the repository browser.