1 | -- SingleplayerMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("SingleplayerMenu") |
---|
4 | |
---|
5 | P.buttonList = {} |
---|
6 | |
---|
7 | function 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 | |
---|
45 | end |
---|
46 | |
---|
47 | function P.onShow() |
---|
48 | --indices to iterate through buttonlist |
---|
49 | P.oldindex = -2 |
---|
50 | P.index = -1 |
---|
51 | end |
---|
52 | |
---|
53 | function 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 |
---|
60 | end |
---|
61 | |
---|
62 | function P.SingleplayerBackButton_clicked(e) |
---|
63 | hideMenuSheet(P.name) |
---|
64 | end |
---|
65 | |
---|
66 | function P.onKeyPressed() |
---|
67 | buttonIteratorHelper(P.buttonList, code, P, 1, 2) |
---|
68 | end |
---|
69 | |
---|
70 | return P |
---|
71 | |
---|