[6363] | 1 | -- MultiplayerMenu.lua |
---|
| 2 | |
---|
[6746] | 3 | local P = createMenuSheet("MultiplayerMenu") |
---|
[6363] | 4 | |
---|
[7648] | 5 | P.levelList = {} |
---|
| 6 | P.itemList = {} |
---|
| 7 | P.showAll = false |
---|
| 8 | |
---|
[6746] | 9 | function P.onLoad() |
---|
[7163] | 10 | P.multiplayerMode = "startClient" |
---|
| 11 | end |
---|
| 12 | |
---|
| 13 | function P.onShow() |
---|
| 14 | if P.multiplayerMode == "startClient" then |
---|
| 15 | local window = winMgr:getWindow("orxonox/MultiplayerJoinButton") |
---|
| 16 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
| 17 | button:setSelected(true) |
---|
[7648] | 18 | local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") |
---|
| 19 | checkbox:setProperty("Disabled", "True") |
---|
[7163] | 20 | P.showServerList() |
---|
| 21 | end |
---|
| 22 | if P.multiplayerMode == "startServer" then |
---|
| 23 | local window = winMgr:getWindow("orxonox/MultiplayerHostButton") |
---|
| 24 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
| 25 | button:setSelected(true) |
---|
[7648] | 26 | local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") |
---|
| 27 | checkbox:setProperty("Disabled", "False") |
---|
[7163] | 28 | P.showLevelList() |
---|
| 29 | end |
---|
| 30 | if P.multiplayerMode == "startDedicated" then |
---|
| 31 | local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton") |
---|
| 32 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
| 33 | button:setSelected(true) |
---|
[7648] | 34 | local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") |
---|
| 35 | checkbox:setProperty("Disabled", "True") |
---|
[7163] | 36 | P.showLevelList() |
---|
| 37 | end |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | function P.MultiplayerJoinButton_clicked(e) |
---|
| 41 | P.multiplayerMode = "startClient" |
---|
[7648] | 42 | local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") |
---|
| 43 | checkbox:setProperty("Disabled", "True") |
---|
[7163] | 44 | P.showServerList() |
---|
| 45 | end |
---|
| 46 | |
---|
| 47 | function P.MultiplayerHostButton_clicked(e) |
---|
| 48 | P.multiplayerMode = "startServer" |
---|
[7648] | 49 | local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") |
---|
| 50 | checkbox:setProperty("Disabled", "False") |
---|
[7163] | 51 | P.showLevelList() |
---|
| 52 | end |
---|
| 53 | |
---|
| 54 | function P.MultiplayerDedicatedButton_clicked(e) |
---|
| 55 | P.multiplayerMode = "startDedicated" |
---|
[7648] | 56 | local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox") |
---|
| 57 | checkbox:setProperty("Disabled", "True") |
---|
[7163] | 58 | P.showLevelList() |
---|
| 59 | end |
---|
| 60 | |
---|
[7648] | 61 | function P.MultiplayerShowAll_clicked(e) |
---|
| 62 | local checkbox = tolua.cast(winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox"), "CEGUI::Checkbox") |
---|
| 63 | local show = checkbox:isSelected() |
---|
| 64 | if show ~= P.showAll then |
---|
| 65 | P.showAll = show |
---|
| 66 | P.createLevelList() |
---|
| 67 | end |
---|
| 68 | end |
---|
| 69 | |
---|
[7163] | 70 | function P.MultiplayerStartButton_clicked(e) |
---|
| 71 | local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem() |
---|
| 72 | if P.multiplayerMode == "startClient" then |
---|
| 73 | if choice then |
---|
| 74 | local client = orxonox.Client:getInstance() |
---|
| 75 | local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() |
---|
| 76 | client:setDestination( P.serverList[index][2], 55556 ) |
---|
| 77 | else |
---|
| 78 | return |
---|
| 79 | end |
---|
| 80 | else |
---|
| 81 | if choice then |
---|
| 82 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
| 83 | else |
---|
| 84 | return |
---|
| 85 | end |
---|
| 86 | end |
---|
| 87 | orxonox.execute(P.multiplayerMode) |
---|
| 88 | hideAllMenuSheets() |
---|
| 89 | end |
---|
| 90 | |
---|
| 91 | function P.MultiplayerBackButton_clicked(e) |
---|
| 92 | hideMenuSheet(P.name) |
---|
| 93 | end |
---|
| 94 | |
---|
| 95 | function P.showLevelList() |
---|
[7648] | 96 | P.createLevelList() |
---|
| 97 | end |
---|
| 98 | |
---|
| 99 | function P.createLevelList() |
---|
| 100 | P.levelList = {} |
---|
| 101 | P.itemList = {} |
---|
| 102 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/MultiplayerListbox")) |
---|
| 103 | listbox:resetList() |
---|
| 104 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
[7163] | 105 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
[7648] | 106 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
[6363] | 107 | local index = 0 |
---|
[7648] | 108 | local level = nil |
---|
| 109 | while index < size do |
---|
[6363] | 110 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
[7648] | 111 | if level ~= nil then |
---|
| 112 | if P.showAll or not level:hasTag("test") then |
---|
| 113 | table.insert(P.levelList, level) |
---|
| 114 | end |
---|
[6363] | 115 | end |
---|
| 116 | index = index + 1 |
---|
| 117 | end |
---|
[7648] | 118 | --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename. |
---|
| 119 | --table.sort(levelList) |
---|
| 120 | for k,v in pairs(P.levelList) do |
---|
| 121 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
[6746] | 122 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
[7648] | 123 | listbox:addItem(item) |
---|
| 124 | if v:getXMLFilename() == preselect then |
---|
[6363] | 125 | listbox:setItemSelectState(item, true) |
---|
| 126 | end |
---|
[7648] | 127 | P.itemList[k] = listbox:getListboxItemFromIndex(k-1) |
---|
| 128 | orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription()) |
---|
[6363] | 129 | end |
---|
[7648] | 130 | end |
---|
| 131 | |
---|
[7163] | 132 | function P.showServerList() |
---|
| 133 | local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") |
---|
| 134 | CEGUI.toListbox(listbox):resetList() |
---|
| 135 | local discovery = orxonox.LANDiscovery:getInstance() |
---|
| 136 | discovery:discover() |
---|
| 137 | P.serverList = {} |
---|
| 138 | local index = 0 |
---|
| 139 | local servername = "" |
---|
| 140 | local serverip = "" |
---|
| 141 | while true do |
---|
| 142 | servername = discovery:getServerListItemName(index) |
---|
| 143 | if servername == "" then |
---|
| 144 | break |
---|
| 145 | end |
---|
| 146 | serverip = discovery:getServerListItemIP(index) |
---|
| 147 | if serverip == "" then |
---|
| 148 | break |
---|
| 149 | end |
---|
| 150 | table.insert(P.serverList, {servername, serverip}) |
---|
| 151 | index = index + 1 |
---|
[6363] | 152 | end |
---|
[7163] | 153 | index = 1 |
---|
| 154 | for k,v in pairs(P.serverList) do |
---|
| 155 | local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) |
---|
| 156 | item:setID(index) |
---|
| 157 | index = index + 1 |
---|
| 158 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 159 | CEGUI.toListbox(listbox):addItem(item) |
---|
[6363] | 160 | end |
---|
| 161 | end |
---|
| 162 | |
---|
| 163 | return P |
---|
| 164 | |
---|