Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/data/gui/scripts/NewMultiplayerMenu.lua @ 6176

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

Made NewMultiplayerMenu and NewSingleplayerMenu work. Also added hideALLGUIs functionality in InitialiseGUI

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