Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gamestate/data/gui/scripts/MultiplayerMenu.lua @ 6459

Last change on this file since 6459 was 6459, checked in by rgrieder, 15 years ago

Simplified BasicGUI construction. Just give the name of the GUI as argument. The rest will be deduced.

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1-- MultiplayerMenu.lua
2
3BasicGUI = require("BasicGUI")
4local P = BasicGUI:new("MultiplayerMenu")
5if _REQUIREDNAME == nil then
6    MultiplayerMenu = P
7else
8    _G[_REQUIREDNAME] = P
9end
10
11function P:init()
12    listbox = winMgr:getWindow("orxonox/MultiplayerLevelListbox")
13    preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
14    orxonox.LevelManager:getInstance():compileAvailableLevelList()
15    local levelList = {}
16    local index = 0
17    local level = ""
18    while true do
19        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
20        if level == "" then
21            break
22        end
23        table.insert(levelList, level)
24        index = index + 1
25    end
26    table.sort(levelList)
27    for k,v in pairs(levelList) do
28        item = CEGUI.createListboxTextItem(v)
29        item:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush")
30        CEGUI.toListbox(listbox):addItem(item)
31        if v .. ".oxw" == preselect then
32            listbox:setItemSelectState(item, true)
33        end
34    end
35    local multiplayerMode = "startClient"
36    if multiplayerMode == "startClient" then
37        window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
38        button = tolua.cast(window,"CEGUI::RadioButton")
39        button:setSelected(true)
40    end
41    if multiplayerMode == "startServer" then
42        window = winMgr:getWindow("orxonox/MultiplayerHostButton")
43        button = tolua.cast(window,"CEGUI::RadioButton")
44        button:setSelected(true)
45    end
46    if multiplayerMode == "startDedicated" then
47        window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
48        button = tolua.cast(window,"CEGUI::RadioButton")
49        button:setSelected(true)
50    end
51end
52
53function P.MultiplayerJoinButton_clicked(e)
54    multiplayerMode = "startClient"
55end
56
57function P.MultiplayerHostButton_clicked(e)
58    multiplayerMode = "startServer"
59end
60
61function P.MultiplayerDedicatedButton_clicked(e)
62    multiplayerMode = "startDedicated"
63end
64
65function P.MultiplayerStartButton_clicked(e)
66    local choice = winMgr:getWindow("orxonox/MultiplayerLevelListbox"):getFirstSelectedItem()
67    if choice then
68        orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
69        orxonox.execute(multiplayerMode)
70        hideAllGUIs()
71    end
72end
73
74function P.MultiplayerBackButton_clicked(e)
75    hideGUI(P.filename)
76end
77
78return P
79
Note: See TracBrowser for help on using the repository browser.