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