Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/masterserver/data/gui/scripts/MultiplayerMenu.lua @ 7632

Last change on this file since 7632 was 7632, checked in by smerkli, 14 years ago

oops, forgot to rename the new lua function.

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1-- MultiplayerMenu.lua
2
3local P = createMenuSheet("MultiplayerMenu")
4
5function P.onLoad()
6    P.multiplayerMode = "startClient"
7end
8
9function P.onShow()
10    if P.multiplayerMode == "startClient" then
11        local window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
12        local button = tolua.cast(window,"CEGUI::RadioButton")
13        button:setSelected(true)
14        P.showServerList()
15    end
16    if P.multiplayerMode == "startServer" then
17        local window = winMgr:getWindow("orxonox/MultiplayerHostButton")
18        local button = tolua.cast(window,"CEGUI::RadioButton")
19        button:setSelected(true)
20        P.showLevelList()
21    end
22    if P.multiplayerMode == "startDedicated" then
23        local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
24        local button = tolua.cast(window,"CEGUI::RadioButton")
25        button:setSelected(true)
26        P.showLevelList()
27    end
28end
29
30function P.MultiplayerJoinButton_clicked(e)
31    P.multiplayerMode = "startClient"
32    P.showServerList()
33end
34
35function P.MultiplayerHostButton_clicked(e)
36    P.multiplayerMode = "startServer"
37    P.showLevelList()
38end
39
40function P.MultiplayerDedicatedButton_clicked(e)
41    P.multiplayerMode = "startDedicated"
42    P.showLevelList()
43end
44
45function P.MultiplayerStartButton_clicked(e)
46    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
47    if P.multiplayerMode == "startClient" then
48        if choice then
49            local client = orxonox.Client:getInstance()
50            local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
51            client:setDestination( P.serverList[index][2], 55556 )
52        else
53            return
54        end
55    else
56        if choice then
57            orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
58        else
59            return
60        end
61    end
62    orxonox.execute(P.multiplayerMode)
63    hideAllMenuSheets()
64end
65
66function P.MultiplayerBackButton_clicked(e)
67    hideMenuSheet(P.name)
68end
69
70function P.showLevelList()
71    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
72    CEGUI.toListbox(listbox):resetList()
73    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
74    orxonox.LevelManager:getInstance():compileAvailableLevelList()
75    local levelList = {}
76    local index = 0
77    local level = ""
78    while true do
79        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
80        if level == "" then
81            break
82        end
83        table.insert(levelList, level)
84        index = index + 1
85    end
86    table.sort(levelList)
87    index = 1
88    for k,v in pairs(levelList) do
89        local item = CEGUI.createListboxTextItem(v)
90        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
91        item:setID(index)
92        index = index + 1
93        CEGUI.toListbox(listbox):addItem(item)
94        if v .. ".oxw" == preselect then
95            listbox:setItemSelectState(item, true)
96        end
97    end
98    end
99   
100function P.showServerList()
101    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
102    CEGUI.toListbox(listbox):resetList()
103    local discovery = orxonox.LANDiscovery:getInstance()
104    discovery:discover()
105    P.serverList = {}
106    local index = 0
107    local servername = ""
108    local serverip = ""
109    while true do
110        servername = discovery:getServerListItemName(index)
111        if servername == "" then
112            break
113        end
114        serverip = discovery:getServerListItemIP(index)
115        if serverip == "" then
116          break
117        end
118        table.insert(P.serverList, {servername, serverip})
119        index = index + 1
120    end
121    index = 1
122    for k,v in pairs(P.serverList) do
123        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
124        item:setID(index)
125        index = index + 1
126        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
127        CEGUI.toListbox(listbox):addItem(item)
128    end
129end
130
131
132-- same as above, but use WAN Discovery
133function P.showServerListWAN()
134    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
135    CEGUI.toListbox(listbox):resetList()
136    local discovery = orxonox.WANDiscovery:getInstance()
137    discovery:discover()
138    P.serverList = {}
139    local index = 0
140    local servername = ""
141    local serverip = ""
142    while true do
143        servername = discovery:getServerListItemName(index)
144        if servername == "" then
145            break
146        end
147        serverip = discovery:getServerListItemIP(index)
148        if serverip == "" then
149          break
150        end
151        table.insert(P.serverList, {servername, serverip})
152        index = index + 1
153    end
154    index = 1
155    for k,v in pairs(P.serverList) do
156        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
157        item:setID(index)
158        index = index + 1
159        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
160        CEGUI.toListbox(listbox):addItem(item)
161    end
162end
163
164return P
165
Note: See TracBrowser for help on using the repository browser.