Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/environment/data/gui/scripts/MultiplayerMenu.lua @ 8474

Last change on this file since 8474 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

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