1 | -- HostMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("HostMenu") |
---|
4 | |
---|
5 | P.multiplayerMode = "startServer" |
---|
6 | |
---|
7 | P.buttonList = {} |
---|
8 | |
---|
9 | function P.onLoad() |
---|
10 | P.multiplayerMode = "startClient" |
---|
11 | |
---|
12 | local item = { |
---|
13 | ["button"] = winMgr:getWindow("orxonox/HostMenuStartButton"), |
---|
14 | ["function"] = P.HostMenuStartButton_clicked |
---|
15 | } |
---|
16 | P.buttonList[1] = item |
---|
17 | |
---|
18 | local item = { |
---|
19 | ["button"] = winMgr:getWindow("orxonox/HostMenuBackButton"), |
---|
20 | ["function"] = P.HostMenuBackButton_clicked |
---|
21 | } |
---|
22 | P.buttonList[2] = item |
---|
23 | end |
---|
24 | |
---|
25 | function P.onShow() |
---|
26 | if P.multiplayerMode == "startServer" then |
---|
27 | local window = winMgr:getWindow("orxonox/HostMenuHostButton") |
---|
28 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
29 | button:setSelected(true) |
---|
30 | P.showLevelList() |
---|
31 | end |
---|
32 | |
---|
33 | if P.multiplayerMode == "startDedicated" then |
---|
34 | local window = winMgr:getWindow("orxonox/HostMenuDedicatedButton") |
---|
35 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
36 | button:setSelected(true) |
---|
37 | P.showLevelList() |
---|
38 | end |
---|
39 | |
---|
40 | P.oldindex = -2 |
---|
41 | P.index = -1 |
---|
42 | |
---|
43 | end |
---|
44 | |
---|
45 | function P.HostMenuBuildServerButton_clicked(e) |
---|
46 | P.multiplayerMode = "startServer" |
---|
47 | P.showLevelList() |
---|
48 | end |
---|
49 | |
---|
50 | function P.HostMenuDedicatedButton_clicked(e) |
---|
51 | P.multiplayerMode = "startDedicated" |
---|
52 | P.showLevelList() |
---|
53 | end |
---|
54 | |
---|
55 | function P.HostMenuBackButton_clicked(e) |
---|
56 | hideMenuSheet(P.name) |
---|
57 | end |
---|
58 | |
---|
59 | function P.HostMenuStartButton_clicked(e) |
---|
60 | local choice = winMgr:getWindow("orxonox/HostMenuListbox"):getFirstSelectedItem() |
---|
61 | if choice then |
---|
62 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
63 | else |
---|
64 | return |
---|
65 | end |
---|
66 | orxonox.execute(P.multiplayerMode) |
---|
67 | hideAllMenuSheets() |
---|
68 | end |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | function P.showLevelList() |
---|
73 | local listbox = winMgr:getWindow("orxonox/HostMenuListbox") |
---|
74 | CEGUI.toListbox(listbox):resetList() |
---|
75 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
76 | orxonox.LevelManager:getInstance():compileAvailableLevelList() |
---|
77 | local levelList = {} |
---|
78 | local index = 0 |
---|
79 | local level = "" |
---|
80 | while true do |
---|
81 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
82 | if level == "" then |
---|
83 | break |
---|
84 | end |
---|
85 | table.insert(levelList, level) |
---|
86 | index = index + 1 |
---|
87 | end |
---|
88 | table.sort(levelList) |
---|
89 | index = 1 |
---|
90 | for k,v in pairs(levelList) do |
---|
91 | local item = CEGUI.createListboxTextItem(v) |
---|
92 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
93 | item:setID(index) |
---|
94 | index = index + 1 |
---|
95 | CEGUI.toListbox(listbox):addItem(item) |
---|
96 | if v .. ".oxw" == preselect then |
---|
97 | listbox:setItemSelectState(item, true) |
---|
98 | end |
---|
99 | end |
---|
100 | end |
---|
101 | |
---|
102 | |
---|
103 | function P.onKeyPressed() |
---|
104 | buttonIteratorHelper(P.buttonList, code, P, 1, 2) |
---|
105 | end |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | return P |
---|