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