Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Merged releasetodo, containing a new way to describe and tag levels, back to trunk.

  • Property svn:eol-style set to native
File size: 5.3 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        local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
19        checkbox:setProperty("Disabled", "True")
20        P.showServerList()
21    end
22    if P.multiplayerMode == "startServer" then
23        local window = winMgr:getWindow("orxonox/MultiplayerHostButton")
24        local button = tolua.cast(window,"CEGUI::RadioButton")
25        button:setSelected(true)
26        local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
27        checkbox:setProperty("Disabled", "False")
28        P.showLevelList()
29    end
30    if P.multiplayerMode == "startDedicated" then
31        local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
32        local button = tolua.cast(window,"CEGUI::RadioButton")
33        button:setSelected(true)
34        local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
35        checkbox:setProperty("Disabled", "True")
36        P.showLevelList()
37    end
38end
39
40function P.MultiplayerJoinButton_clicked(e)
41    P.multiplayerMode = "startClient"
42    local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
43    checkbox:setProperty("Disabled", "True")
44    P.showServerList()
45end
46
47function P.MultiplayerHostButton_clicked(e)
48    P.multiplayerMode = "startServer"
49    local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
50    checkbox:setProperty("Disabled", "False")
51    P.showLevelList()
52end
53
54function P.MultiplayerDedicatedButton_clicked(e)
55    P.multiplayerMode = "startDedicated"
56    local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
57    checkbox:setProperty("Disabled", "True")
58    P.showLevelList()
59end
60
61function P.MultiplayerShowAll_clicked(e)
62    local checkbox = tolua.cast(winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox"), "CEGUI::Checkbox")
63    local show = checkbox:isSelected()
64    if show ~= P.showAll then
65        P.showAll = show
66        P.createLevelList()
67    end
68end
69
70function P.MultiplayerStartButton_clicked(e)
71    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
72    if P.multiplayerMode == "startClient" then
73        if choice then
74            local client = orxonox.Client:getInstance()
75            local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
76            client:setDestination( P.serverList[index][2], 55556 )
77        else
78            return
79        end
80    else
81        if choice then
82            orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
83        else
84            return
85        end
86    end
87    orxonox.execute(P.multiplayerMode)
88    hideAllMenuSheets()
89end
90
91function P.MultiplayerBackButton_clicked(e)
92    hideMenuSheet(P.name)
93end
94
95function P.showLevelList()
96    P.createLevelList()
97end
98
99function P.createLevelList()
100    P.levelList = {}
101    P.itemList = {}
102    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/MultiplayerListbox"))
103    listbox:resetList()
104    orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
105    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
106    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
107    local index = 0
108    local level = nil
109    while index < size do
110        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
111        if level ~= nil then
112            if P.showAll or not level:hasTag("test") then
113                table.insert(P.levelList, level)
114            end
115        end
116        index = index + 1
117    end
118    --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename.
119    --table.sort(levelList)
120    for k,v in pairs(P.levelList) do
121        local item = CEGUI.createListboxTextItem(v:getName())
122        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
123        listbox:addItem(item)
124        if v:getXMLFilename() == preselect then
125            listbox:setItemSelectState(item, true)
126        end
127        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
128        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
129    end
130end
131
132function P.showServerList()
133    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
134    CEGUI.toListbox(listbox):resetList()
135    local discovery = orxonox.LANDiscovery:getInstance()
136    discovery:discover()
137    P.serverList = {}
138    local index = 0
139    local servername = ""
140    local serverip = ""
141    while true do
142        servername = discovery:getServerListItemName(index)
143        if servername == "" then
144            break
145        end
146        serverip = discovery:getServerListItemIP(index)
147        if serverip == "" then
148          break
149        end
150        table.insert(P.serverList, {servername, serverip})
151        index = index + 1
152    end
153    index = 1
154    for k,v in pairs(P.serverList) do
155        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
156        item:setID(index)
157        index = index + 1
158        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
159        CEGUI.toListbox(listbox):addItem(item)
160    end
161end
162
163return P
164
Note: See TracBrowser for help on using the repository browser.