Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

key handling in some menu sheets has been added.

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