Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/releasetodo/data/gui/scripts/MultiplayerMenu.lua @ 7627

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

Now we have the level description as tooltip. Unforunately for this to work i had to write two additional wrappers for CEGUI lua functions, so I guess it's time to start investigating why some CEGUI functions work in lua and some don't.

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