Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lastmanstanding2/data/gui/scripts/MultiplayerMenu.lua @ 8141

Last change on this file since 8141 was 7690, checked in by dafrick, 14 years ago

Adjusting some small thing that got forgotten while merging.

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1-- MultiplayerMenu.lua
2
3local P = createMenuSheet("MultiplayerMenu")
4
5P.buttonList = {}
6
7function P.onLoad()
8    P.multiplayerMode = "startClient" 
9
10    --button are arranged in a 2x2 matrix, the left lower item is nil
11    local item = {
12            ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"),
13            ["function"]  = P.MultiplayerJoinButton_clicked
14    }
15    P.buttonList[1] = item
16
17    local item = {
18            ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"),
19            ["function"]  = P.MultiplayerHostButton_clicked
20    }
21    P.buttonList[2] = item
22
23    local item = {
24            ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"),
25            ["function"]  = P.MultiplayerBackButton_clicked
26    }
27    P.buttonList[4] = item
28
29end
30
31function P.onShow()
32    P.showServerList()
33
34    --indices to iterate through buttonlist
35    P.oldindex = -2
36    P.index = -1
37end
38
39function P.MultiplayerHostButton_clicked(e)
40    showMenuSheet("HostMenu", true)
41end
42
43
44function P.MultiplayerJoinButton_clicked(e)
45    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
46    if choice then
47        local client = orxonox.Client:getInstance()
48        local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
49        client:setDestination( P.serverList[index][2], 55556 )
50    else
51        return
52    end
53    orxonox.execute("startClient")
54    hideAllMenuSheets()
55end
56
57function P.MultiplayerBackButton_clicked(e)
58    hideMenuSheet(P.name)
59end
60
61function P.showServerList()
62    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
63    CEGUI.toListbox(listbox):resetList()
64    local discovery = orxonox.LANDiscovery:getInstance()
65    discovery:discover()
66    P.serverList = {}
67    local index = 0
68    local servername = ""
69    local serverip = ""
70    while true do
71        servername = discovery:getServerListItemName(index)
72        if servername == "" then
73            break
74        end
75        serverip = discovery:getServerListItemIP(index)
76        if serverip == "" then
77          break
78        end
79        table.insert(P.serverList, {servername, serverip})
80        index = index + 1
81    end
82    index = 1
83    for k,v in pairs(P.serverList) do
84        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
85        item:setID(index)
86        index = index + 1
87        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
88        CEGUI.toListbox(listbox):addItem(item)
89    end
90end
91
92function P.onKeyPressed() 
93    buttonIteratorHelper(P.buttonList, code, P, 2, 2)
94end
95
96return P
97
Note: See TracBrowser for help on using the repository browser.