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
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"
8--initial status 0
9P.joinMode = 0
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()
[7689]35    P.showServerList()
[7163]36
[7689]37    --indices to iterate through buttonlist
38    P.oldindex = -2
39    P.index = -1
[7163]40end
41
[7732]42function P.LanButton_clicked(e)
43    P.joinMode = 1
44end
45
46function P.InternetButton_clicked(e)
47    P.joinMode = 2
48end
49
[7163]50function P.MultiplayerHostButton_clicked(e)
[7689]51    showMenuSheet("HostMenu", true)
[7163]52end
53
54
[7689]55function P.MultiplayerJoinButton_clicked(e)
[7732]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()
[7163]68    else
[7732]69        --wait for Sandro's function
[7163]70    end
[7732]71
[7163]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
[6363]98    end
[7163]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)
[6363]106    end
107end
108
[7689]109function P.onKeyPressed() 
110    buttonIteratorHelper(P.buttonList, code, P, 2, 2)
111end
112
[6363]113return P
114
Note: See TracBrowser for help on using the repository browser.