Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7721 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
RevLine 
[6363]1-- MultiplayerMenu.lua
2
[6746]3local P = createMenuSheet("MultiplayerMenu")
[6363]4
[7689]5P.buttonList = {}
[7648]6
[6746]7function P.onLoad()
[7689]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"),
[7690]13            ["function"]  = P.MultiplayerJoinButton_clicked
[7689]14    }
15    P.buttonList[1] = item
16
17    local item = {
18            ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"),
[7690]19            ["function"]  = P.MultiplayerHostButton_clicked
[7689]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
[7163]29end
30
31function P.onShow()
[7689]32    P.showServerList()
[7163]33
[7689]34    --indices to iterate through buttonlist
35    P.oldindex = -2
36    P.index = -1
[7163]37end
38
39function P.MultiplayerHostButton_clicked(e)
[7689]40    showMenuSheet("HostMenu", true)
[7163]41end
42
43
[7689]44function P.MultiplayerJoinButton_clicked(e)
[7163]45    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
[7689]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 )
[7163]50    else
[7689]51        return
[7163]52    end
[7689]53    orxonox.execute("startClient")
[7163]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
[6363]81    end
[7163]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)
[6363]89    end
90end
91
[7689]92function P.onKeyPressed() 
93    buttonIteratorHelper(P.buttonList, code, P, 2, 2)
94end
95
[6363]96return P
97
Note: See TracBrowser for help on using the repository browser.