Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7749 was 7732, checked in by konrad, 14 years ago

Credits Menu is now scrollable

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1-- MultiplayerMenu.lua
2
3local P = createMenuSheet("MultiplayerMenu")
4
5P.buttonList = {}
6
7--joinMode is 1 for choice "LAN" and 2 for "Internet"
8--initial status 0
9P.joinMode = 0
10
11function P.onLoad()
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"),
17            ["function"]  = P.MultiplayerJoinButton_clicked
18    }
19    P.buttonList[1] = item
20
21    local item = {
22            ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"),
23            ["function"]  = P.MultiplayerHostButton_clicked
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
32end
33
34function P.onShow()
35    P.showServerList()
36
37    --indices to iterate through buttonlist
38    P.oldindex = -2
39    P.index = -1
40end
41
42function P.LanButton_clicked(e)
43    P.joinMode = 1
44end
45
46function P.InternetButton_clicked(e)
47    P.joinMode = 2
48end
49
50function P.MultiplayerHostButton_clicked(e)
51    showMenuSheet("HostMenu", true)
52end
53
54
55function P.MultiplayerJoinButton_clicked(e)
56    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()   
57
58    if P.joinMode == 2 then
59        if choice then
60            local client = orxonox.Client:getInstance()
61            local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
62            client:setDestination( P.serverList[index][2], 55556 )
63        else
64            return
65        end
66        orxonox.execute("startClient")
67        hideAllMenuSheets()
68    else
69        --wait for Sandro's function
70    end
71
72end
73
74function P.MultiplayerBackButton_clicked(e)
75    hideMenuSheet(P.name)
76end
77
78function P.showServerList()
79    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
80    CEGUI.toListbox(listbox):resetList()
81    local discovery = orxonox.LANDiscovery:getInstance()
82    discovery:discover()
83    P.serverList = {}
84    local index = 0
85    local servername = ""
86    local serverip = ""
87    while true do
88        servername = discovery:getServerListItemName(index)
89        if servername == "" then
90            break
91        end
92        serverip = discovery:getServerListItemIP(index)
93        if serverip == "" then
94          break
95        end
96        table.insert(P.serverList, {servername, serverip})
97        index = index + 1
98    end
99    index = 1
100    for k,v in pairs(P.serverList) do
101        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
102        item:setID(index)
103        index = index + 1
104        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
105        CEGUI.toListbox(listbox):addItem(item)
106    end
107end
108
109function P.onKeyPressed() 
110    buttonIteratorHelper(P.buttonList, code, P, 2, 2)
111end
112
113return P
114
Note: See TracBrowser for help on using the repository browser.