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