1 | -- SingleplayerMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("SingleplayerMenu") |
---|
4 | |
---|
5 | P.levelList = {} |
---|
6 | P.itemList = {} |
---|
7 | |
---|
8 | function P.onLoad() |
---|
9 | P.createLevelList(nil) |
---|
10 | |
---|
11 | --buttons are arranged in a 1x2 matrix |
---|
12 | P:setButton(1, 1, { |
---|
13 | ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"), |
---|
14 | ["callback"] = P.SingleplayerStartButton_clicked |
---|
15 | }) |
---|
16 | |
---|
17 | P:setButton(1, 2, { |
---|
18 | ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"), |
---|
19 | ["callback"] = P.SingleplayerBackButton_clicked |
---|
20 | }) |
---|
21 | end |
---|
22 | |
---|
23 | function P.createLevelList(tag) |
---|
24 | P.levelList = {} |
---|
25 | P.itemList = {} |
---|
26 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")) |
---|
27 | listbox:resetList() |
---|
28 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
29 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
30 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
31 | local index = 0 |
---|
32 | local level = nil |
---|
33 | while index < size do |
---|
34 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
35 | if level ~= nil then |
---|
36 | if tag == nil then |
---|
37 | table.insert(P.levelList, level) |
---|
38 | elseif level:hasTag(tag) then |
---|
39 | table.insert(P.levelList, level) |
---|
40 | end |
---|
41 | end |
---|
42 | index = index + 1 |
---|
43 | end |
---|
44 | |
---|
45 | for k,v in pairs(P.levelList) do |
---|
46 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
47 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
48 | listbox:addItem(item) |
---|
49 | if v:getXMLFilename() == preselect then |
---|
50 | listbox:setItemSelectState(item, true) |
---|
51 | end |
---|
52 | P.itemList[k] = listbox:getListboxItemFromIndex(k-1) |
---|
53 | orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription()) |
---|
54 | end |
---|
55 | end |
---|
56 | |
---|
57 | function P.SingleplayerStartButton_clicked(e) |
---|
58 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox")) |
---|
59 | local choice = listbox:getFirstSelectedItem() |
---|
60 | if choice ~= nil then |
---|
61 | local index = listbox:getItemIndex(choice) |
---|
62 | local level = P.levelList[index+1] |
---|
63 | if level ~= nil then |
---|
64 | orxonox.execute("startGame " .. level:getXMLFilename()) |
---|
65 | hideAllMenuSheets() |
---|
66 | end |
---|
67 | end |
---|
68 | end |
---|
69 | |
---|
70 | function P.SingleplayerBackButton_clicked(e) |
---|
71 | hideMenuSheet(P.name) |
---|
72 | end |
---|
73 | |
---|
74 | return P |
---|
75 | |
---|