Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7983 was 7928, checked in by landauf, 14 years ago

more improvements for keyboard control of menus:

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