1 | -- HostMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("HostMenu") |
---|
4 | |
---|
5 | P.multiplayerMode = "startServer" |
---|
6 | |
---|
7 | P.buttonList = {} |
---|
8 | P.levelList = {} |
---|
9 | P.itemList = {} |
---|
10 | P.showAll = false |
---|
11 | |
---|
12 | function P.onLoad() |
---|
13 | P.multiplayerMode = "startServer" |
---|
14 | local window = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") |
---|
15 | local button = tolua.cast(window,"CEGUI::Checkbox") |
---|
16 | button:setSelected(false) |
---|
17 | P.createLevelList() |
---|
18 | |
---|
19 | local item = { |
---|
20 | ["button"] = winMgr:getWindow("orxonox/HostMenuStartButton"), |
---|
21 | ["function"] = P.HostMenuStartButton_clicked |
---|
22 | } |
---|
23 | P.buttonList[1] = item |
---|
24 | |
---|
25 | local item = { |
---|
26 | ["button"] = winMgr:getWindow("orxonox/HostMenuBackButton"), |
---|
27 | ["function"] = P.HostMenuBackButton_clicked |
---|
28 | } |
---|
29 | P.buttonList[2] = item |
---|
30 | end |
---|
31 | |
---|
32 | function P.onShow() |
---|
33 | if P.multiplayerMode == "startServer" then |
---|
34 | local window = winMgr:getWindow("orxonox/HostMenuHostButton") |
---|
35 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
36 | button:setSelected(true) |
---|
37 | P.createLevelList() |
---|
38 | end |
---|
39 | |
---|
40 | if P.multiplayerMode == "startDedicated" then |
---|
41 | local window = winMgr:getWindow("orxonox/HostMenuDedicatedButton") |
---|
42 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
43 | button:setSelected(true) |
---|
44 | P.createLevelList() |
---|
45 | end |
---|
46 | |
---|
47 | P.oldindex = -2 |
---|
48 | P.index = -1 |
---|
49 | |
---|
50 | end |
---|
51 | |
---|
52 | function P.createLevelList() |
---|
53 | P.levelList = {} |
---|
54 | P.itemList = {} |
---|
55 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/HostMenuListbox")) |
---|
56 | listbox:resetList() |
---|
57 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
58 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
59 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
60 | local index = 0 |
---|
61 | local level = nil |
---|
62 | while index < size do |
---|
63 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
64 | if level ~= nil then |
---|
65 | if P.showAll or not level:hasTag("test") then |
---|
66 | table.insert(P.levelList, level) |
---|
67 | end |
---|
68 | end |
---|
69 | index = index + 1 |
---|
70 | end |
---|
71 | --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename. |
---|
72 | --table.sort(levelList) |
---|
73 | for k,v in pairs(P.levelList) do |
---|
74 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
75 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
76 | listbox:addItem(item) |
---|
77 | if v:getXMLFilename() == preselect then |
---|
78 | listbox:setItemSelectState(item, true) |
---|
79 | end |
---|
80 | P.itemList[k] = listbox:getListboxItemFromIndex(k-1) |
---|
81 | orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription()) |
---|
82 | end |
---|
83 | end |
---|
84 | |
---|
85 | function P.HostMenuBuildServerButton_clicked(e) |
---|
86 | P.multiplayerMode = "startServer" |
---|
87 | P.createLevelList() |
---|
88 | end |
---|
89 | |
---|
90 | function P.HostMenuDedicatedButton_clicked(e) |
---|
91 | P.multiplayerMode = "startDedicated" |
---|
92 | P.createLevelList() |
---|
93 | end |
---|
94 | |
---|
95 | function P.HostMenuBackButton_clicked(e) |
---|
96 | hideMenuSheet(P.name) |
---|
97 | end |
---|
98 | |
---|
99 | function P.HostMenuStartButton_clicked(e) |
---|
100 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/HostMenuListbox")) |
---|
101 | local choice = listbox:getFirstSelectedItem() |
---|
102 | if choice ~= nil then |
---|
103 | local index = listbox:getItemIndex(choice) |
---|
104 | local level = P.levelList[index+1] |
---|
105 | if level ~= nil then |
---|
106 | orxonox.LevelManager:getInstance():setDefaultLevel(level:getXMLFilename()) |
---|
107 | orxonox.execute(P.multiplayerMode) |
---|
108 | hideAllMenuSheets() |
---|
109 | end |
---|
110 | end |
---|
111 | end |
---|
112 | |
---|
113 | function P.MultiplayerShowAll_clicked(e) |
---|
114 | local checkbox = tolua.cast(winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox"), "CEGUI::Checkbox") |
---|
115 | local show = checkbox:isSelected() |
---|
116 | if show ~= P.showAll then |
---|
117 | P.showAll = show |
---|
118 | P.createLevelList() |
---|
119 | end |
---|
120 | end |
---|
121 | |
---|
122 | function P.onKeyPressed() |
---|
123 | buttonIteratorHelper(P.buttonList, code, P, 1, 2) |
---|
124 | end |
---|
125 | |
---|
126 | return P |
---|