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