Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/usability/data/gui/scripts/HostMenu.lua @ 8040

Last change on this file since 8040 was 8040, checked in by dafrick, 13 years ago

Developer's mode. Is a ConfigValue, by default on except in release mode. If on it should help the developer, if off, it should obscure things we don't want the user to have to deal with.
So far it ticks the showAll button in the Singleplayer and Host menu, if on. It also sets the start countdown to 0 if on.
If you have some more ideas on how to make life easier for both developers and users, feel free to implement it yourself ot mention it to me.

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1-- HostMenu.lua
2
3local P = createMenuSheet("HostMenu")
4
5P.multiplayerMode = "startServer"
6
7P.levelList = {}
8P.itemList = {}
9P.showAll = false
10
11function P.onLoad()
12    P.multiplayerMode = "startServer"
13    local window = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
14    local button = tolua.cast(window,"CEGUI::Checkbox")
15    button:setSelected(false)
16    P.createLevelList()
17
18    P:setButton(1, 1, {
19            ["button"] = winMgr:getWindow("orxonox/HostMenuStartButton"),
20            ["callback"]  = P.HostMenuStartButton_clicked
21    })
22
23    P:setButton(1, 2, {
24            ["button"] = winMgr:getWindow("orxonox/HostMenuBackButton"),
25            ["callback"]  = P.HostMenuBackButton_clicked
26    })
27end
28
29function P.onShow()
30    if P.showAll ~= orxonox.GUIManager:inDevMode() then
31        local window = winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox")
32        local button = tolua.cast(window,"CEGUI::Checkbox")
33        P.showAll = not P.showAll
34        button:setSelected(P.showAll)
35        P.createLevelList()
36    end
37end
38
39function P.onShow()
40    if P.showAll ~= orxonox.GUIManager:inDevMode() then
41        local window = winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox")
42        local button = tolua.cast(window,"CEGUI::Checkbox")
43        P.showAll = not P.showAll
44        button:setSelected(P.showAll)
45    end
46
47    if P.multiplayerMode == "startServer" then
48        local window = winMgr:getWindow("orxonox/HostMenuHostButton")
49        local button = tolua.cast(window,"CEGUI::RadioButton")
50        button:setSelected(true)
51        P.createLevelList()
52    end
53
54    if P.multiplayerMode == "startDedicated" then
55        local window = winMgr:getWindow("orxonox/HostMenuDedicatedButton")
56        local button = tolua.cast(window,"CEGUI::RadioButton")
57        button:setSelected(true)
58        P.createLevelList()
59    end
60end
61
62function P.createLevelList()
63    P.levelList = {}
64    P.itemList = {}
65    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/HostMenuListbox"))
66    listbox:resetList()
67    orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
68    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
69    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
70    local index = 0
71    local level = nil
72    while index < size do
73        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
74        if level ~= nil then
75            if P.showAll or not level:hasTag("test") then
76                table.insert(P.levelList, level)
77            end
78        end
79        index = index + 1
80    end
81    --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename.
82    --table.sort(levelList)
83    for k,v in pairs(P.levelList) do
84        local item = CEGUI.createListboxTextItem(v:getName())
85        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
86        listbox:addItem(item)
87        if v:getXMLFilename() == preselect then
88            listbox:setItemSelectState(item, true)
89        end
90        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
91        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
92    end
93end
94
95function P.HostMenuBuildServerButton_clicked(e)
96    P.multiplayerMode = "startServer"
97    P.createLevelList()
98end
99
100function P.HostMenuDedicatedButton_clicked(e)
101    P.multiplayerMode = "startDedicated"
102    P.createLevelList()
103end
104
105function P.HostMenuBackButton_clicked(e)
106    hideMenuSheet(P.name)
107end
108
109function P.HostMenuStartButton_clicked(e)
110    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/HostMenuListbox"))
111    local choice = listbox:getFirstSelectedItem()
112    if choice ~= nil then
113        local index = listbox:getItemIndex(choice)
114        local level = P.levelList[index+1]
115        if level ~= nil then
116            orxonox.execute(P.multiplayerMode .. " " .. level:getXMLFilename())
117            hideAllMenuSheets()
118        end
119    end
120end
121
122function P.MultiplayerShowAll_clicked(e)
123    local checkbox = tolua.cast(winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox"), "CEGUI::Checkbox")
124    local show = checkbox:isSelected()
125    if show ~= P.showAll then
126        P.showAll = show
127        P.createLevelList()
128   end
129end
130
131return P
Note: See TracBrowser for help on using the repository browser.