[6206] | 1 | -- MultiplayerMenu.lua |
---|
| 2 | |
---|
| 3 | BasicGUI = require("BasicGUI") |
---|
| 4 | local P = BasicGUI:new() --inherit everything from the gui package |
---|
| 5 | if _REQUIREDNAME == nil then |
---|
| 6 | MultiplayerMenu = P |
---|
| 7 | else |
---|
| 8 | _G[_REQUIREDNAME] = P |
---|
| 9 | end |
---|
| 10 | |
---|
| 11 | P.filename = "MultiplayerMenu" |
---|
| 12 | P.layoutString = "MultiplayerMenu.layout" |
---|
| 13 | |
---|
| 14 | function 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 |
---|
| 54 | end |
---|
| 55 | |
---|
| 56 | function P.MultiplayerJoinButton_clicked(e) |
---|
| 57 | multiplayerMode = "startClient" |
---|
| 58 | end |
---|
| 59 | |
---|
| 60 | function P.MultiplayerHostButton_clicked(e) |
---|
| 61 | multiplayerMode = "startServer" |
---|
| 62 | end |
---|
| 63 | |
---|
| 64 | function P.MultiplayerDedicatedButton_clicked(e) |
---|
| 65 | multiplayerMode = "startDedicated" |
---|
| 66 | end |
---|
| 67 | |
---|
| 68 | function P.MultiplayerStartButton_clicked(e) |
---|
| 69 | local choice = winMgr:getWindow("orxonox/MultiplayerLevelListbox"):getFirstSelectedItem() |
---|
| 70 | if choice then |
---|
| 71 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
| 72 | orxonox.CommandExecutor:execute(multiplayerMode) |
---|
| 73 | hideAllGUIs() |
---|
| 74 | end |
---|
| 75 | end |
---|
| 76 | |
---|
| 77 | function P.MultiplayerBackButton_clicked(e) |
---|
| 78 | hideGUI(P.filename) |
---|
| 79 | end |
---|
| 80 | |
---|
| 81 | return P |
---|
| 82 | |
---|