Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/MultiplayerMenu.lua @ 7940

Last change on this file since 7940 was 7876, checked in by dafrick, 14 years ago

Extending startGame and similar console commands, now also the level to be started (or in case of startClient, the destination) can be specified (but doesn't have to).
Additionally startMainMenu is now in GSLevel and can only be executed in a Level, as opposed to only in the MainMenu as it was before.
Added changeGame console command which works in a level in standalone mode to change to a different level.

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