Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/HostMenu.lua @ 8011

Last change on this file since 8011 was 7887, checked in by landauf, 14 years ago

eol-style native

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