Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/Presentation_FS17/data/gui/scripts/MultiplayerMenu.lua @ 12357

Last change on this file since 12357 was 10622, checked in by landauf, 9 years ago

merged branch presentationFS15merge back to trunk

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
1-- MultiplayerMenu.lua
2
3local P = createMenuSheet("MultiplayerMenu")
4
5--joinMode is 1 for choice "LAN" and 2 for "Internet"
6--initial status 1
7P.joinMode = 1
8
9function P.onLoad()
10    P.multiplayerMode = "startClient"
11
12    --button are arranged in a 3x2 matrix, Join and Host buttons are in the upper left and middle, the back button in the lower right of the table
13    P:setButton(1, 1, {
14            ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"),
15            ["callback"]  = P.MultiplayerJoinButton_clicked
16    })
17
18    P:setButton(1, 2, {
19            ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"),
20            ["callback"]  = P.MultiplayerHostButton_clicked
21    })
22
23    P:setButton(2, 3, {
24            ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"),
25            ["callback"]  = P.MultiplayerBackButton_clicked
26    })
27end
28
29function P.onShow()
30    --P.showServerList()
31
32    if P.joinMode == 1 then
33        local window = winMgr:getWindow("orxonox/MultiplayerLanButton")
34        local button = tolua.cast(window,"CEGUI::RadioButton")
35        button:setSelected(true)
36    end
37    if P.joinMode == 2 then
38        local window = winMgr:getWindow("orxonox/MultiplayerInternetButton")
39        local button = tolua.cast(window,"CEGUI::RadioButton")
40        button:setSelected(true)
41    end
42end
43
44function P.LanButton_clicked(e)
45    local we = CEGUI.toWindowEventArgs(e)
46    local button = tolua.cast(we.window,"CEGUI::RadioButton")
47    P.joinMode = 1
48    if button:isSelected() == true then
49        P.showServerList()
50    end
51end
52
53function P.InternetButton_clicked(e)
54    local we = CEGUI.toWindowEventArgs(e)
55    local button = tolua.cast(we.window,"CEGUI::RadioButton")
56    P.joinMode = 2
57    if button:isSelected() == true then
58        P.showServerList()
59    end
60end
61
62function P.MultiplayerHostButton_clicked(e)
63    showMenuSheet("HostMenu", true)
64end
65
66
67function P.MultiplayerJoinButton_clicked(e)
68    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
69    local destination = nil
70    if choice then
71        local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
72        destination = P.serverList[index][1]
73    else
74        return
75    end
76    orxonox.execute("startClient " .. destination)
77    hideAllMenuSheets()
78end
79
80function P.MultiplayerBackButton_clicked(e)
81    hideMenuSheet(P.name)
82end
83
84function P.showServerList()
85    -- LAN Discovery
86    if P.joinMode == 1 then
87        local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
88        CEGUI.toListbox(listbox):resetList()
89        local discovery = orxonox.LANDiscovery:getInstance()
90        discovery:discover()
91        P.serverList = {}
92        local index = 0
93        local servername = ""
94        local serverip = ""
95        local serverrtt = ""
96        local playernumber = ""
97        while true do
98            servername = discovery:getServerListItemName(index)
99            if servername == "" then
100                break
101            end
102            serverip = discovery:getServerListItemIP(index)
103            if serverip == "" then
104                break
105            end
106            --serverrtt = discovery:getServerListItemRTT(index)
107            playernumber = discovery:getServerListItemPlayerNumber(index)
108
109            table.insert(P.serverList, {serverip, servername, playernumber})
110            index = index + 1
111        end
112        index = 1
113        for k,v in pairs(P.serverList) do
114            local item = CEGUI.createListboxTextItem("IP: " .. v[1] .. " Name: " .. v[2] .. " Players: " .. v[3])
115            item:setID(index)
116            index = index + 1
117            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
118            CEGUI.toListbox(listbox):addItem(item)
119        end
120    -- WAN Discovery
121    elseif P.joinMode == 2 then
122        local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
123        CEGUI.toListbox(listbox):resetList()
124        local discovery = orxonox.WANDiscovery()
125        orxout("discovering." )
126        discovery:discover()
127        orxout("discovered." )
128        P.serverList = {}
129        local index = 0
130        local servername = ""
131        local serverip = ""
132        local serverrtt = ""
133        local playernumber = ""
134        while true do
135            servername = discovery:getServerListItemName(index)
136            if servername == "" then
137                break
138            end
139            serverip = discovery:getServerListItemIP(index)
140            if serverip == "" then
141                break
142            end
143            --serverrtt = discovery:getServerListItemRTT(index)
144            playernumber = discovery:getServerListItemPlayerNumber(index)
145
146            table.insert(P.serverList, {serverip, servername, playernumber})
147            index = index + 1
148        end
149        index = 1
150        for k,v in pairs(P.serverList) do
151            local item = CEGUI.createListboxTextItem("IP: " .. v[1] .. " Name: " .. v[2] .. " Players: " .. v[3])
152            item:setID(index)
153            index = index + 1
154            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
155            CEGUI.toListbox(listbox):addItem(item)
156        end
157    end
158
159end
160
161return P
Note: See TracBrowser for help on using the repository browser.