Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menu/data/gui/scripts/HostMenu.lua @ 7587

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

changes in the multiplayer menu, 2 buttons instead of 3: host and join separated.

File size: 2.2 KB
Line 
1-- HostMenu.lua
2
3local P = createMenuSheet("HostMenu")
4
5P.multiplayerMode = "startServer"
6
7function P.onShow()
8    if P.multiplayerMode == "startServer" then
9        local window = winMgr:getWindow("orxonox/HostMenuHostButton")
10        local button = tolua.cast(window,"CEGUI::RadioButton")
11        button:setSelected(true)
12        P.showLevelList()
13    end
14
15    if P.multiplayerMode == "startDedicated" then
16        local window = winMgr:getWindow("orxonox/HostMenuDedicatedButton")
17        local button = tolua.cast(window,"CEGUI::RadioButton")
18        button:setSelected(true)
19        P.showLevelList()
20    end
21
22end
23
24function P.HostMenuBuildServerButton_clicked(e)
25    P.multiplayerMode = "startServer"
26    P.showLevelList()
27end
28
29function P.HostMenuDedicatedButton_clicked(e)
30    P.multiplayerMode = "startDedicated"
31    P.showLevelList()
32end
33
34function P.HostMenuBackButton_clicked(e)
35    hideMenuSheet(P.name)
36end
37
38function P.HostMenuStartButton_clicked(e)
39    local choice = winMgr:getWindow("orxonox/HostMenuListbox"):getFirstSelectedItem()
40        if choice then
41            orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
42        else
43            return
44        end
45    orxonox.execute(P.multiplayerMode)
46    hideAllMenuSheets()
47end
48
49
50
51function P.showLevelList()
52    local listbox = winMgr:getWindow("orxonox/HostMenuListbox")
53    CEGUI.toListbox(listbox):resetList()
54    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
55    orxonox.LevelManager:getInstance():compileAvailableLevelList()
56    local levelList = {}
57    local index = 0
58    local level = ""
59    while true do
60        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
61        if level == "" then
62            break
63        end
64        table.insert(levelList, level)
65        index = index + 1
66    end
67    table.sort(levelList)
68    index = 1
69    for k,v in pairs(levelList) do
70        local item = CEGUI.createListboxTextItem(v)
71        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
72        item:setID(index)
73        index = index + 1
74        CEGUI.toListbox(listbox):addItem(item)
75        if v .. ".oxw" == preselect then
76            listbox:setItemSelectState(item, true)
77        end
78    end
79end
80
81
82
83return P
Note: See TracBrowser for help on using the repository browser.