Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

done for today, didn't get bug to leave, and connect doesn't quite work yet.

  • Property svn:eol-style set to native
File size: 5.0 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.showServerListmeow()
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.showServerList()
134    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
135    CEGUI.toListbox(listbox):resetList()
136    local discovery = orxonox.WANDiscovery:getInstance()
137    cout(0, "discovering.\n" )
138    discovery:discover()
139    cout(0, "discovered.\n" )
140    P.serverList = {}
141    local index = 0
142    local servername = ""
143    local serverip = ""
144    while true do
145        servername = discovery:getServerListItemName(index)
146        if servername == "" then
147            break
148        end
149        serverip = discovery:getServerListItemIP(index)
150        if serverip == "" then
151          break
152        end
153        table.insert(P.serverList, {servername, serverip})
154        index = index + 1
155    end
156    index = 1
157    for k,v in pairs(P.serverList) do
158        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
159        item:setID(index)
160        index = index + 1
161        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
162        CEGUI.toListbox(listbox):addItem(item)
163    end
164end
165
166return P
167
Note: See TracBrowser for help on using the repository browser.