Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/MultiplayerMenu.lua @ 7687

Last change on this file since 7687 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
RevLine 
[6363]1-- MultiplayerMenu.lua
2
[6746]3local P = createMenuSheet("MultiplayerMenu")
[6363]4
[7648]5P.levelList = {}
6P.itemList = {}
7P.showAll = false
8
[6746]9function P.onLoad()
[7163]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)
[7648]18        local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
19        checkbox:setProperty("Disabled", "True")
[7163]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)
[7648]26        local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
27        checkbox:setProperty("Disabled", "False")
[7163]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)
[7648]34        local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
35        checkbox:setProperty("Disabled", "True")
[7163]36        P.showLevelList()
37    end
38end
39
40function P.MultiplayerJoinButton_clicked(e)
41    P.multiplayerMode = "startClient"
[7648]42    local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
43    checkbox:setProperty("Disabled", "True")
[7163]44    P.showServerList()
45end
46
47function P.MultiplayerHostButton_clicked(e)
48    P.multiplayerMode = "startServer"
[7648]49    local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
50    checkbox:setProperty("Disabled", "False")
[7163]51    P.showLevelList()
52end
53
54function P.MultiplayerDedicatedButton_clicked(e)
55    P.multiplayerMode = "startDedicated"
[7648]56    local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
57    checkbox:setProperty("Disabled", "True")
[7163]58    P.showLevelList()
59end
60
[7648]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
[7163]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()
[7648]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)
[7163]105    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
[7648]106    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
[6363]107    local index = 0
[7648]108    local level = nil
109    while index < size do
[6363]110        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
[7648]111        if level ~= nil then
112            if P.showAll or not level:hasTag("test") then
113                table.insert(P.levelList, level)
114            end
[6363]115        end
116        index = index + 1
117    end
[7648]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())
[6746]122        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
[7648]123        listbox:addItem(item)
124        if v:getXMLFilename() == preselect then
[6363]125            listbox:setItemSelectState(item, true)
126        end
[7648]127        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
128        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
[6363]129    end
[7648]130end
131
[7163]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
[6363]152    end
[7163]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)
[6363]160    end
161end
162
163return P
164
Note: See TracBrowser for help on using the repository browser.