[6363] | 1 | -- MultiplayerMenu.lua |
---|
| 2 | |
---|
[6746] | 3 | local P = createMenuSheet("MultiplayerMenu") |
---|
[6363] | 4 | |
---|
[7626] | 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) |
---|
| 18 | P.showServerList() |
---|
| 19 | end |
---|
| 20 | if P.multiplayerMode == "startServer" then |
---|
| 21 | local window = winMgr:getWindow("orxonox/MultiplayerHostButton") |
---|
| 22 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
| 23 | button:setSelected(true) |
---|
| 24 | P.showLevelList() |
---|
| 25 | end |
---|
| 26 | if P.multiplayerMode == "startDedicated" then |
---|
| 27 | local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton") |
---|
| 28 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
| 29 | button:setSelected(true) |
---|
| 30 | P.showLevelList() |
---|
| 31 | end |
---|
| 32 | end |
---|
| 33 | |
---|
| 34 | function P.MultiplayerJoinButton_clicked(e) |
---|
| 35 | P.multiplayerMode = "startClient" |
---|
| 36 | P.showServerList() |
---|
| 37 | end |
---|
| 38 | |
---|
| 39 | function P.MultiplayerHostButton_clicked(e) |
---|
| 40 | P.multiplayerMode = "startServer" |
---|
| 41 | P.showLevelList() |
---|
| 42 | end |
---|
| 43 | |
---|
| 44 | function P.MultiplayerDedicatedButton_clicked(e) |
---|
| 45 | P.multiplayerMode = "startDedicated" |
---|
| 46 | P.showLevelList() |
---|
| 47 | end |
---|
| 48 | |
---|
| 49 | function P.MultiplayerStartButton_clicked(e) |
---|
| 50 | local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem() |
---|
| 51 | if P.multiplayerMode == "startClient" then |
---|
| 52 | if choice then |
---|
| 53 | local client = orxonox.Client:getInstance() |
---|
| 54 | local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() |
---|
| 55 | client:setDestination( P.serverList[index][2], 55556 ) |
---|
| 56 | else |
---|
| 57 | return |
---|
| 58 | end |
---|
| 59 | else |
---|
| 60 | if choice then |
---|
| 61 | orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw") |
---|
| 62 | else |
---|
| 63 | return |
---|
| 64 | end |
---|
| 65 | end |
---|
| 66 | orxonox.execute(P.multiplayerMode) |
---|
| 67 | hideAllMenuSheets() |
---|
| 68 | end |
---|
| 69 | |
---|
| 70 | function P.MultiplayerBackButton_clicked(e) |
---|
| 71 | hideMenuSheet(P.name) |
---|
| 72 | end |
---|
| 73 | |
---|
| 74 | function P.showLevelList() |
---|
[7626] | 75 | P.createLevelList() |
---|
| 76 | end |
---|
| 77 | |
---|
| 78 | function P.createLevelList() |
---|
| 79 | P.levelList = {} |
---|
| 80 | P.itemList = {} |
---|
| 81 | local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/MultiplayerListbox")) |
---|
| 82 | listbox:resetList() |
---|
[7627] | 83 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
[7163] | 84 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
[7626] | 85 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
[6363] | 86 | local index = 0 |
---|
[7626] | 87 | local level = nil |
---|
| 88 | while index < size do |
---|
[6363] | 89 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
[7626] | 90 | if level ~= nil then |
---|
| 91 | if P.showAll or not level:hasTag("test") then |
---|
| 92 | table.insert(P.levelList, level) |
---|
| 93 | end |
---|
[6363] | 94 | end |
---|
| 95 | index = index + 1 |
---|
| 96 | end |
---|
[7626] | 97 | --TODO: Reintroduce sorting, if needed. |
---|
| 98 | --table.sort(levelList) |
---|
| 99 | for k,v in pairs(P.levelList) do |
---|
| 100 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
[6746] | 101 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
[7626] | 102 | listbox:addItem(item) |
---|
| 103 | if v:getXMLFilename() == preselect then |
---|
[6363] | 104 | listbox:setItemSelectState(item, true) |
---|
| 105 | end |
---|
[7626] | 106 | P.itemList[k] = listbox:getListboxItemFromIndex(k-1) |
---|
| 107 | --TODO: The description as tooltip would be nice. |
---|
[7627] | 108 | --local lItem = P.itemList[k] |
---|
[7626] | 109 | --lItem:setTooltipText(v:getDescription()) |
---|
[7627] | 110 | orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription()) |
---|
[6363] | 111 | end |
---|
[7626] | 112 | end |
---|
| 113 | |
---|
[7163] | 114 | function P.showServerList() |
---|
| 115 | local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") |
---|
| 116 | CEGUI.toListbox(listbox):resetList() |
---|
| 117 | local discovery = orxonox.LANDiscovery:getInstance() |
---|
| 118 | discovery:discover() |
---|
| 119 | P.serverList = {} |
---|
| 120 | local index = 0 |
---|
| 121 | local servername = "" |
---|
| 122 | local serverip = "" |
---|
| 123 | while true do |
---|
| 124 | servername = discovery:getServerListItemName(index) |
---|
| 125 | if servername == "" then |
---|
| 126 | break |
---|
| 127 | end |
---|
| 128 | serverip = discovery:getServerListItemIP(index) |
---|
| 129 | if serverip == "" then |
---|
| 130 | break |
---|
| 131 | end |
---|
| 132 | table.insert(P.serverList, {servername, serverip}) |
---|
| 133 | index = index + 1 |
---|
[6363] | 134 | end |
---|
[7163] | 135 | index = 1 |
---|
| 136 | for k,v in pairs(P.serverList) do |
---|
| 137 | local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) |
---|
| 138 | item:setID(index) |
---|
| 139 | index = index + 1 |
---|
| 140 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 141 | CEGUI.toListbox(listbox):addItem(item) |
---|
[6363] | 142 | end |
---|
| 143 | end |
---|
| 144 | |
---|
| 145 | return P |
---|
| 146 | |
---|