Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/data/gui/scripts/MultiplayerMenu.lua @ 7924

Last change on this file since 7924 was 7924, checked in by landauf, 13 years ago
  • the "back" button of MultiplayerMenu and SettingsMenu now fills the whole row at the bottom, so it can be accessed from both columns by pressing 'down'
  • added keyboard support for KeyBindMenu, MiscConfigMenu, and MouseControlsMenu
  • Property svn:eol-style set to native
File size: 4.6 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 2x2 matrix, the lower items are both the back button
13    P:initButtons(2, 2)
14
15    P:setButton(1, 1, {
16            ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"),
17            ["callback"]  = P.MultiplayerJoinButton_clicked
18    })
19
20    P:setButton(1, 2, {
21            ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"),
22            ["callback"]  = P.MultiplayerHostButton_clicked
23    })
24
25    P:setButton(2, 1, {
26            ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"),
27            ["callback"]  = P.MultiplayerBackButton_clicked
28    })
29
30    P:setButton(2, 2, P:getButton(2, 1))
31end
32
33function P.onShow()
34    --P.showServerList()
35
36    if P.joinMode == 1 then
37        local window = winMgr:getWindow("orxonox/MultiplayerLanButton")
38        local button = tolua.cast(window,"CEGUI::RadioButton")
39        button:setSelected(true)
40    end
41    if P.joinMode == 2 then
42        local window = winMgr:getWindow("orxonox/MultiplayerInternetButton")
43        local button = tolua.cast(window,"CEGUI::RadioButton")
44        button:setSelected(true)
45    end
46end
47
48function P.LanButton_clicked(e)
49    local we = CEGUI.toWindowEventArgs(e)
50    local button = tolua.cast(we.window,"CEGUI::RadioButton")
51    P.joinMode = 1
52    if button:isSelected() == true then
53        P.showServerList()
54    end
55end
56
57function P.InternetButton_clicked(e)
58    local we = CEGUI.toWindowEventArgs(e)
59    local button = tolua.cast(we.window,"CEGUI::RadioButton")
60    P.joinMode = 2
61    if button:isSelected() == true then
62        P.showServerList()
63    end
64end
65
66function P.MultiplayerHostButton_clicked(e)
67    showMenuSheet("HostMenu", true)
68end
69
70
71function P.MultiplayerJoinButton_clicked(e)
72    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
73    local destination = nil
74    if choice then
75        local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
76        destination = P.serverList[index][2]
77    else
78        return
79    end
80    orxonox.execute("startClient " .. destination)
81    hideAllMenuSheets()
82end
83
84function P.MultiplayerBackButton_clicked(e)
85    hideMenuSheet(P.name)
86end
87
88function P.showServerList()
89    -- LAN Discovery
90    if P.joinMode == 1 then
91        local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
92        CEGUI.toListbox(listbox):resetList()
93        local discovery = orxonox.LANDiscovery:getInstance()
94        discovery:discover()
95        P.serverList = {}
96        local index = 0
97        local servername = ""
98        local serverip = ""
99        while true do
100            servername = discovery:getServerListItemName(index)
101            if servername == "" then
102                break
103            end
104            serverip = discovery:getServerListItemIP(index)
105            if serverip == "" then
106                break
107            end
108            table.insert(P.serverList, {servername, serverip})
109            index = index + 1
110        end
111        index = 1
112        for k,v in pairs(P.serverList) do
113            local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
114            item:setID(index)
115            index = index + 1
116            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
117            CEGUI.toListbox(listbox):addItem(item)
118        end
119    -- WAN Discovery
120    elseif P.joinMode == 2 then
121        local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
122        CEGUI.toListbox(listbox):resetList()
123        local discovery = orxonox.WANDiscovery:getInstance()
124        cout(0, "discovering.\n" )
125        discovery:discover()
126        cout(0, "discovered.\n" )
127        P.serverList = {}
128        local index = 0
129        local servername = ""
130        local serverip = ""
131        while true do
132            servername = discovery:getServerListItemName(index)
133            if servername == "" then
134                break
135            end
136            serverip = discovery:getServerListItemIP(index)
137            if serverip == "" then
138                break
139            end
140            table.insert(P.serverList, {servername, serverip})
141            index = index + 1
142        end
143        index = 1
144        for k,v in pairs(P.serverList) do
145            local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
146            item:setID(index)
147            index = index + 1
148            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
149            CEGUI.toListbox(listbox):addItem(item)
150        end
151    end
152
153end
154
155return P
156
Note: See TracBrowser for help on using the repository browser.