[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() |
---|
| 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 |
---|
| 43 | end |
---|
| 44 | |
---|
[7689] | 45 | function 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 |
---|
| 76 | end |
---|
| 77 | |
---|
[7587] | 78 | function P.HostMenuBuildServerButton_clicked(e) |
---|
| 79 | P.multiplayerMode = "startServer" |
---|
[7689] | 80 | P.createLevelList() |
---|
[7587] | 81 | end |
---|
| 82 | |
---|
| 83 | function P.HostMenuDedicatedButton_clicked(e) |
---|
| 84 | P.multiplayerMode = "startDedicated" |
---|
[7689] | 85 | P.createLevelList() |
---|
[7587] | 86 | end |
---|
| 87 | |
---|
| 88 | function P.HostMenuBackButton_clicked(e) |
---|
| 89 | hideMenuSheet(P.name) |
---|
| 90 | end |
---|
| 91 | |
---|
[7922] | 92 | function 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] | 103 | end |
---|
| 104 | |
---|
[7689] | 105 | function 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] | 112 | end |
---|
| 113 | |
---|
| 114 | return P |
---|