1 | -- MultiplayerMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("MultiplayerMenu") |
---|
4 | |
---|
5 | P.buttonList = {} |
---|
6 | |
---|
7 | function P.onLoad() |
---|
8 | P.multiplayerMode = "startClient" |
---|
9 | |
---|
10 | local item = { |
---|
11 | ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton2"), |
---|
12 | ["function"] = P.MultiplayerJoinButton_clicked |
---|
13 | } |
---|
14 | P.buttonList[1] = item |
---|
15 | |
---|
16 | local item = { |
---|
17 | ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton2"), |
---|
18 | ["function"] = P.MultiplayerHostButton_clicked |
---|
19 | } |
---|
20 | P.buttonList[2] = item |
---|
21 | |
---|
22 | local item = { |
---|
23 | ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"), |
---|
24 | ["function"] = P.MultiplayerBackButton_clicked |
---|
25 | } |
---|
26 | P.buttonList[4] = item |
---|
27 | |
---|
28 | end |
---|
29 | |
---|
30 | function P.onShow() |
---|
31 | P.showServerList() |
---|
32 | P.oldindex = -2 |
---|
33 | P.index = -1 |
---|
34 | end |
---|
35 | |
---|
36 | function P.MultiplayerJoinButton_clicked(e) |
---|
37 | P.multiplayerMode = "startClient" |
---|
38 | P.showServerList() |
---|
39 | end |
---|
40 | |
---|
41 | function P.MultiplayerHostButton_clicked(e) |
---|
42 | P.multiplayerMode = "startServer" |
---|
43 | P.showLevelList() |
---|
44 | end |
---|
45 | |
---|
46 | function P.MultiplayerDedicatedButton_clicked(e) |
---|
47 | P.multiplayerMode = "startDedicated" |
---|
48 | P.showLevelList() |
---|
49 | end |
---|
50 | |
---|
51 | function P.MultiplayerHostButton2_clicked(e) |
---|
52 | showMenuSheet("HostMenu", true) |
---|
53 | end |
---|
54 | |
---|
55 | |
---|
56 | function P.MultiplayerJoinButton2_clicked(e) |
---|
57 | local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem() |
---|
58 | if choice then |
---|
59 | local client = orxonox.Client:getInstance() |
---|
60 | local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() |
---|
61 | client:setDestination( P.serverList[index][2], 55556 ) |
---|
62 | else |
---|
63 | return |
---|
64 | end |
---|
65 | orxonox.execute("startClient") |
---|
66 | hideAllMenuSheets() |
---|
67 | end |
---|
68 | |
---|
69 | function P.MultiplayerBackButton_clicked(e) |
---|
70 | hideMenuSheet(P.name) |
---|
71 | end |
---|
72 | |
---|
73 | function P.showLevelList() |
---|
74 | local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") |
---|
75 | CEGUI.toListbox(listbox):resetList() |
---|
76 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
77 | orxonox.LevelManager:getInstance():compileAvailableLevelList() |
---|
78 | local levelList = {} |
---|
79 | local index = 0 |
---|
80 | local level = "" |
---|
81 | while true do |
---|
82 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
83 | if level == "" then |
---|
84 | break |
---|
85 | end |
---|
86 | table.insert(levelList, level) |
---|
87 | index = index + 1 |
---|
88 | end |
---|
89 | table.sort(levelList) |
---|
90 | index = 1 |
---|
91 | for k,v in pairs(levelList) do |
---|
92 | local item = CEGUI.createListboxTextItem(v) |
---|
93 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
94 | item:setID(index) |
---|
95 | index = index + 1 |
---|
96 | CEGUI.toListbox(listbox):addItem(item) |
---|
97 | if v .. ".oxw" == preselect then |
---|
98 | listbox:setItemSelectState(item, true) |
---|
99 | end |
---|
100 | end |
---|
101 | end |
---|
102 | |
---|
103 | function P.showServerList() |
---|
104 | local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") |
---|
105 | CEGUI.toListbox(listbox):resetList() |
---|
106 | local discovery = orxonox.LANDiscovery:getInstance() |
---|
107 | discovery:discover() |
---|
108 | P.serverList = {} |
---|
109 | local index = 0 |
---|
110 | local servername = "" |
---|
111 | local serverip = "" |
---|
112 | while true do |
---|
113 | servername = discovery:getServerListItemName(index) |
---|
114 | if servername == "" then |
---|
115 | break |
---|
116 | end |
---|
117 | serverip = discovery:getServerListItemIP(index) |
---|
118 | if serverip == "" then |
---|
119 | break |
---|
120 | end |
---|
121 | table.insert(P.serverList, {servername, serverip}) |
---|
122 | index = index + 1 |
---|
123 | end |
---|
124 | index = 1 |
---|
125 | for k,v in pairs(P.serverList) do |
---|
126 | local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) |
---|
127 | item:setID(index) |
---|
128 | index = index + 1 |
---|
129 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
130 | CEGUI.toListbox(listbox):addItem(item) |
---|
131 | end |
---|
132 | end |
---|
133 | |
---|
134 | function P.onKeyPressed() |
---|
135 | cout(0,code) |
---|
136 | buttonIteratorHelper(P.buttonList, code, P, 2, 2) |
---|
137 | --indexTester(P.buttonList,code,P,2,3) |
---|
138 | end |
---|
139 | |
---|
140 | return P |
---|
141 | |
---|