Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/data/gui/scripts/HostMenu.lua @ 12068

Last change on this file since 12068 was 11799, checked in by landauf, 7 years ago

updated HostMenu.lua, MultiplayerMenu.lua, ShipSelectionMenu.lua, SingleplayerConfigMenu.lua to cegui 0.8

  • Property svn:eol-style set to native
File size: 3.9 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()
[8079]12    P.multiplayerMode = "startServer"
[11799]13    local window = P.window:getChild("HostMenuWindow/MultiplayerShowAllCheckbox")
14    local button = tolua.cast(window,"CEGUI::ToggleButton")
[7689]15    button:setSelected(false)
16    P.createLevelList()
[7687]17
[8079]18    P:setButton(1, 1, {
[11799]19            ["button"] = P.window:getChild("HostMenuStartButton"),
[8079]20            ["callback"]  = P.HostMenuStartButton_clicked
21    })
[7687]22
[8079]23    P:setButton(1, 2, {
[11799]24            ["button"] = P.window:getChild("HostMenuBackButton"),
[8079]25            ["callback"]  = P.HostMenuBackButton_clicked
26    })
[7687]27end
28
[7587]29function P.onShow()
[8079]30    if P.showAll ~= orxonox.GUIManager:inDevMode() then
[11799]31        local window = P.window:getChild("HostMenuWindow/MultiplayerShowAllCheckbox")
32        local button = tolua.cast(window,"CEGUI::ToggleButton")
[8079]33        P.showAll = not P.showAll
34        button:setSelected(P.showAll)
35    end
36
[7587]37    if P.multiplayerMode == "startServer" then
[11799]38        local window = P.window:getChild("HostMenuWindow/HostMenuHostButton")
[7587]39        local button = tolua.cast(window,"CEGUI::RadioButton")
40        button:setSelected(true)
[7689]41        P.createLevelList()
[7587]42    end
43
44    if P.multiplayerMode == "startDedicated" then
[11799]45        local window = P.window:getChild("HostMenuWindow/HostMenuDedicatedButton")
[7587]46        local button = tolua.cast(window,"CEGUI::RadioButton")
47        button:setSelected(true)
[7689]48        P.createLevelList()
[7587]49    end
50end
51
[7689]52function P.createLevelList()
53    P.levelList = {}
54    P.itemList = {}
[11799]55    local listbox = CEGUI.toListbox(P.window:getChild("HostMenuWindow/HostMenuListbox"))
[7689]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())
[11795]75        item:setSelectionBrushImage(menuImageSet .. "/MultiListSelectionBrush")
[7689]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
[8079]99function P.HostMenuStartButton_clicked(e)
[11799]100    local listbox = CEGUI.toListbox(P.window:getChild("HostMenuWindow/HostMenuListbox"))
[7689]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)
[11799]113    local checkbox = tolua.cast(P.window:getChild("HostMenuWindow/MultiplayerShowAllCheckbox"), "CEGUI::ToggleButton")
[7689]114    local show = checkbox:isSelected()
115    if show ~= P.showAll then
116        P.showAll = show
117        P.createLevelList()
118   end
[7587]119end
120
121return P
Note: See TracBrowser for help on using the repository browser.