Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/kicklib/data/gui/scripts/HostMenu.lua @ 8071

Last change on this file since 8071 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
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.multiplayerMode == "startServer" then
31        local window = winMgr:getWindow("orxonox/HostMenuHostButton")
32        local button = tolua.cast(window,"CEGUI::RadioButton")
33        button:setSelected(true)
34        P.createLevelList()
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)
41        P.createLevelList()
42    end
43end
44
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
78function P.HostMenuBuildServerButton_clicked(e)
79    P.multiplayerMode = "startServer"
80    P.createLevelList()
81end
82
83function P.HostMenuDedicatedButton_clicked(e)
84    P.multiplayerMode = "startDedicated"
85    P.createLevelList()
86end
87
88function P.HostMenuBackButton_clicked(e)
89    hideMenuSheet(P.name)
90end
91
92function P.HostMenuStartButton_clicked(e)
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
99            orxonox.execute(P.multiplayerMode .. " " .. level:getXMLFilename())
100            hideAllMenuSheets()
101        end
102    end
103end
104
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
112end
113
114return P
Note: See TracBrowser for help on using the repository browser.