1 | -- mainmenu_2.lua |
---|
2 | gui = require("gui") |
---|
3 | local P = gui:new() --inherit everything from the gui package |
---|
4 | |
---|
5 | mainmenu_2 = P |
---|
6 | |
---|
7 | P.filename = "mainmenu_2" |
---|
8 | P.layoutString = "MainMenu_2.layout" |
---|
9 | |
---|
10 | function P:init() |
---|
11 | listbox = winMgr:getWindow("orxonox/LevelListbox") |
---|
12 | preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
13 | orxonox.LevelManager:getInstance():compileAvailableLevelList() |
---|
14 | local levelList = {} |
---|
15 | local index = 0 |
---|
16 | local level = "" |
---|
17 | while true do |
---|
18 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
19 | if level == "" then |
---|
20 | break |
---|
21 | end |
---|
22 | table.insert(levelList, level) |
---|
23 | index = index + 1 |
---|
24 | end |
---|
25 | table.sort(levelList) |
---|
26 | for k,v in pairs(levelList) do |
---|
27 | item = CEGUI.createListboxTextItem(v) |
---|
28 | item:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush") |
---|
29 | CEGUI.toListbox(listbox):addItem(item) |
---|
30 | if v .. ".oxw" == preselect then |
---|
31 | listbox:setItemSelectState(item, true) |
---|
32 | end |
---|
33 | end |
---|
34 | end |
---|
35 | |
---|
36 | |
---|
37 | -- events for mainmenu |
---|
38 | function P.button_quit_clicked(e) |
---|
39 | hideGUI() |
---|
40 | orxonox.CommandExecutor:execute("exit") |
---|
41 | end |
---|
42 | |
---|
43 | function P.button_standalone_clicked(e) |
---|
44 | choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() |
---|
45 | if choice then |
---|
46 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
47 | orxonox.CommandExecutor:execute("startGame") |
---|
48 | toggleGUI() |
---|
49 | end |
---|
50 | end |
---|
51 | |
---|
52 | function P.button_server_clicked(e) |
---|
53 | choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() |
---|
54 | if choice then |
---|
55 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
56 | orxonox.CommandExecutor:execute("startServer") |
---|
57 | toggleGUI() |
---|
58 | end |
---|
59 | end |
---|
60 | |
---|
61 | function P.button_dedicated_clicked(e) |
---|
62 | choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() |
---|
63 | if choice then |
---|
64 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
65 | orxonox.CommandExecutor:execute("startDedicated") |
---|
66 | toggleGUI() |
---|
67 | end |
---|
68 | end |
---|
69 | |
---|
70 | function P.button_client_clicked(e) |
---|
71 | choice = winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() |
---|
72 | if choice then |
---|
73 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
74 | orxonox.CommandExecutor:execute("startClient") |
---|
75 | toggleGUI() |
---|
76 | end |
---|
77 | end |
---|
78 | |
---|
79 | function P.listbox_level_selectionchanged(e) |
---|
80 | if winMgr:getWindow("orxonox/LevelListbox"):getFirstSelectedItem() then |
---|
81 | winMgr:getWindow("orxonox/StandaloneButton"):enable() |
---|
82 | else |
---|
83 | winMgr:getWindow("orxonox/StandaloneButton"):disable() |
---|
84 | end |
---|
85 | end |
---|
86 | |
---|
87 | return mainmenu_2 |
---|
88 | |
---|