Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menu/data/gui/scripts/MultiplayerMenu.lua @ 7587

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

changes in the multiplayer menu, 2 buttons instead of 3: host and join separated.

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1-- MultiplayerMenu.lua
2
3local P = createMenuSheet("MultiplayerMenu")
4
5function P.onLoad()
6    P.multiplayerMode = "startClient"
7end
8
9function P.onShow()
10    P.showServerList()
11end
12
13function P.MultiplayerJoinButton_clicked(e)
14    P.multiplayerMode = "startClient"
15    P.showServerList()
16end
17
18function P.MultiplayerHostButton_clicked(e)
19    P.multiplayerMode = "startServer"
20    P.showLevelList()
21end
22
23function P.MultiplayerDedicatedButton_clicked(e)
24    P.multiplayerMode = "startDedicated"
25    P.showLevelList()
26end
27
28function P.MultiplayerHostButton2_clicked(e)
29    showMenuSheet("HostMenu", true)
30end
31
32
33function P.MultiplayerJoinButton2_clicked(e)
34    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
35    if choice then
36        local client = orxonox.Client:getInstance()
37        local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
38        client:setDestination( P.serverList[index][2], 55556 )
39    else
40        return
41    end
42    orxonox.execute("startClient")
43    hideAllMenuSheets()
44end
45
46function P.MultiplayerBackButton_clicked(e)
47    hideMenuSheet(P.name)
48end
49
50function P.showLevelList()
51    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
52    CEGUI.toListbox(listbox):resetList()
53    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
54    orxonox.LevelManager:getInstance():compileAvailableLevelList()
55    local levelList = {}
56    local index = 0
57    local level = ""
58    while true do
59        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
60        if level == "" then
61            break
62        end
63        table.insert(levelList, level)
64        index = index + 1
65    end
66    table.sort(levelList)
67    index = 1
68    for k,v in pairs(levelList) do
69        local item = CEGUI.createListboxTextItem(v)
70        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
71        item:setID(index)
72        index = index + 1
73        CEGUI.toListbox(listbox):addItem(item)
74        if v .. ".oxw" == preselect then
75            listbox:setItemSelectState(item, true)
76        end
77    end
78    end
79   
80function P.showServerList()
81    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
82    CEGUI.toListbox(listbox):resetList()
83    local discovery = orxonox.LANDiscovery:getInstance()
84    discovery:discover()
85    P.serverList = {}
86    local index = 0
87    local servername = ""
88    local serverip = ""
89    while true do
90        servername = discovery:getServerListItemName(index)
91        if servername == "" then
92            break
93        end
94        serverip = discovery:getServerListItemIP(index)
95        if serverip == "" then
96          break
97        end
98        table.insert(P.serverList, {servername, serverip})
99        index = index + 1
100    end
101    index = 1
102    for k,v in pairs(P.serverList) do
103        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
104        item:setID(index)
105        index = index + 1
106        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
107        CEGUI.toListbox(listbox):addItem(item)
108    end
109end
110
111return P
112
Note: See TracBrowser for help on using the repository browser.