Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7922 was 7922, checked in by landauf, 13 years ago

implemented new keyboard control of menu buttons with these new features:

  • more intuitive placement of buttons in table (row/column format instead of linear index)
  • no need to overwrite onShow() and onKeyPressed() functions, no need for P.buttonList
  • highlights the selected button in a different layout than mouse hovering
  • remembers the selection while moving through the menu hierarchy, but resets it if the menu is closed
  • allows preselected button (for example "Yes" in decision popup)
  • when opening a menu, the first selected button is not always the upper left, but instead depends on the pressed key (e.g. the 'up' key selects the button at the bottom, while the 'down' key selects the button at the top. once a button is selected, the keys behave as usual)

+ fixed wrong callback function in ingame menu

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