[5661] | 1 | -- MainMenu.lua |
---|
[5491] | 2 | |
---|
[5661] | 3 | BasicGUI = require("BasicGUI") |
---|
| 4 | local P = BasicGUI:new() --inherit everything from the gui package |
---|
| 5 | if _REQUIREDNAME == nil then |
---|
| 6 | MainMenu = P |
---|
| 7 | else |
---|
| 8 | _G[_REQUIREDNAME] = P |
---|
| 9 | end |
---|
[5491] | 10 | |
---|
[5661] | 11 | P.filename = "MainMenu" |
---|
| 12 | P.layoutString = "MainMenu.layout" |
---|
[5491] | 13 | |
---|
[5523] | 14 | function P:init() |
---|
[5527] | 15 | listbox = winMgr:getWindow("orxonox/LevelListbox") |
---|
[5578] | 16 | preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
[5583] | 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 |
---|
[5532] | 31 | item = CEGUI.createListboxTextItem(v) |
---|
[5527] | 32 | item:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush") |
---|
| 33 | CEGUI.toListbox(listbox):addItem(item) |
---|
[5532] | 34 | if v .. ".oxw" == preselect then |
---|
| 35 | listbox:setItemSelectState(item, true) |
---|
| 36 | end |
---|
[5527] | 37 | end |
---|
[5491] | 38 | end |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | -- events for mainmenu |
---|
| 42 | function P.button_quit_clicked(e) |
---|
[5527] | 43 | hideGUI() |
---|
| 44 | orxonox.CommandExecutor:execute("exit") |
---|
[5491] | 45 | end |
---|
| 46 | |
---|
| 47 | function P.button_standalone_clicked(e) |
---|
[5527] | 48 | choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() |
---|
| 49 | if choice then |
---|
[5578] | 50 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
[5527] | 51 | orxonox.CommandExecutor:execute("startGame") |
---|
| 52 | toggleGUI() |
---|
| 53 | end |
---|
[5491] | 54 | end |
---|
| 55 | |
---|
| 56 | function P.button_server_clicked(e) |
---|
[5566] | 57 | choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() |
---|
| 58 | if choice then |
---|
[5578] | 59 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
[5566] | 60 | orxonox.CommandExecutor:execute("startServer") |
---|
| 61 | toggleGUI() |
---|
| 62 | end |
---|
[5491] | 63 | end |
---|
| 64 | |
---|
| 65 | function P.button_dedicated_clicked(e) |
---|
[5566] | 66 | choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() |
---|
| 67 | if choice then |
---|
[5578] | 68 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
[5566] | 69 | orxonox.CommandExecutor:execute("startDedicated") |
---|
| 70 | toggleGUI() |
---|
| 71 | end |
---|
[5491] | 72 | end |
---|
| 73 | |
---|
| 74 | function P.button_client_clicked(e) |
---|
[5566] | 75 | choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() |
---|
| 76 | if choice then |
---|
[5578] | 77 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
[5566] | 78 | orxonox.CommandExecutor:execute("startClient") |
---|
| 79 | toggleGUI() |
---|
| 80 | end |
---|
[5491] | 81 | end |
---|
| 82 | |
---|
[5527] | 83 | function P.listbox_level_selectionchanged(e) |
---|
| 84 | if winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() then |
---|
| 85 | winMgr:getWindow("orxonox/StandaloneButton"):enable() |
---|
| 86 | else |
---|
| 87 | winMgr:getWindow("orxonox/StandaloneButton"):disable() |
---|
| 88 | end |
---|
| 89 | end |
---|
| 90 | |
---|
[5661] | 91 | return P |
---|
[5491] | 92 | |
---|