1 | -- HostMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("HostMenu") |
---|
4 | |
---|
5 | P.multiplayerMode = "startServer" |
---|
6 | |
---|
7 | P.levelList = {} |
---|
8 | P.itemList = {} |
---|
9 | P.showAll = false |
---|
10 | |
---|
11 | function P.onLoad() |
---|
12 | P.multiplayerMode = "startServer" |
---|
13 | local window = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") |
---|
14 | local button = tolua.cast(window,"CEGUI::Checkbox") |
---|
15 | button:setSelected(false) |
---|
16 | P.createLevelList() |
---|
17 | |
---|
18 | P:setButton(1, 1, { |
---|
19 | ["button"] = winMgr:getWindow("orxonox/HostMenuStartButton"), |
---|
20 | ["callback"] = P.HostMenuStartButton_clicked |
---|
21 | }) |
---|
22 | |
---|
23 | P:setButton(1, 2, { |
---|
24 | ["button"] = winMgr:getWindow("orxonox/HostMenuBackButton"), |
---|
25 | ["callback"] = P.HostMenuBackButton_clicked |
---|
26 | }) |
---|
27 | end |
---|
28 | |
---|
29 | function P.onShow() |
---|
30 | if P.showAll ~= orxonox.GUIManager:inDevMode() then |
---|
31 | local window = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") |
---|
32 | local button = tolua.cast(window,"CEGUI::Checkbox") |
---|
33 | --P.showAll = not P.showAll |
---|
34 | button:setSelected(P.showAll) |
---|
35 | end |
---|
36 | |
---|
37 | if P.multiplayerMode == "startServer" then |
---|
38 | local window = winMgr:getWindow("orxonox/HostMenuHostButton") |
---|
39 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
40 | button:setSelected(true) |
---|
41 | P.createLevelList() |
---|
42 | end |
---|
43 | |
---|
44 | if P.multiplayerMode == "startDedicated" then |
---|
45 | local window = winMgr:getWindow("orxonox/HostMenuDedicatedButton") |
---|
46 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
47 | button:setSelected(true) |
---|
48 | P.createLevelList() |
---|
49 | end |
---|
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") and not level:hasTag("singleplayer") 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.execute(P.multiplayerMode .. " " .. level:getXMLFilename()) |
---|
107 | hideAllMenuSheets() |
---|
108 | end |
---|
109 | end |
---|
110 | end |
---|
111 | |
---|
112 | function P.MultiplayerShowAll_clicked(e) |
---|
113 | local checkbox = tolua.cast(winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox"), "CEGUI::Checkbox") |
---|
114 | local show = checkbox:isSelected() |
---|
115 | if show ~= P.showAll then |
---|
116 | P.showAll = show |
---|
117 | P.createLevelList() |
---|
118 | end |
---|
119 | end |
---|
120 | |
---|
121 | return P |
---|