[6363] | 1 | -- MultiplayerMenu.lua |
---|
| 2 | |
---|
[6746] | 3 | local P = createMenuSheet("MultiplayerMenu") |
---|
[6363] | 4 | |
---|
[6746] | 5 | function P.onLoad() |
---|
[7163] | 6 | P.multiplayerMode = "startClient" |
---|
| 7 | end |
---|
| 8 | |
---|
| 9 | function P.onShow() |
---|
[7587] | 10 | P.showServerList() |
---|
[7163] | 11 | end |
---|
| 12 | |
---|
| 13 | function P.MultiplayerJoinButton_clicked(e) |
---|
| 14 | P.multiplayerMode = "startClient" |
---|
| 15 | P.showServerList() |
---|
| 16 | end |
---|
| 17 | |
---|
| 18 | function P.MultiplayerHostButton_clicked(e) |
---|
| 19 | P.multiplayerMode = "startServer" |
---|
| 20 | P.showLevelList() |
---|
| 21 | end |
---|
| 22 | |
---|
| 23 | function P.MultiplayerDedicatedButton_clicked(e) |
---|
| 24 | P.multiplayerMode = "startDedicated" |
---|
| 25 | P.showLevelList() |
---|
| 26 | end |
---|
| 27 | |
---|
[7587] | 28 | function P.MultiplayerHostButton2_clicked(e) |
---|
| 29 | showMenuSheet("HostMenu", true) |
---|
| 30 | end |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | function P.MultiplayerJoinButton2_clicked(e) |
---|
[7163] | 34 | local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem() |
---|
[7587] | 35 | if choice then |
---|
| 36 | local client = orxonox.Client:getInstance() |
---|
| 37 | local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() |
---|
| 38 | client:setDestination( P.serverList[index][2], 55556 ) |
---|
[7163] | 39 | else |
---|
[7587] | 40 | return |
---|
[7163] | 41 | end |
---|
[7587] | 42 | orxonox.execute("startClient") |
---|
[7163] | 43 | hideAllMenuSheets() |
---|
| 44 | end |
---|
| 45 | |
---|
| 46 | function P.MultiplayerBackButton_clicked(e) |
---|
| 47 | hideMenuSheet(P.name) |
---|
| 48 | end |
---|
| 49 | |
---|
| 50 | function P.showLevelList() |
---|
| 51 | local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") |
---|
| 52 | CEGUI.toListbox(listbox):resetList() |
---|
| 53 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
[6363] | 54 | orxonox.LevelManager:getInstance():compileAvailableLevelList() |
---|
| 55 | local levelList = {} |
---|
| 56 | local index = 0 |
---|
| 57 | local level = "" |
---|
| 58 | while true do |
---|
| 59 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
| 60 | if level == "" then |
---|
| 61 | break |
---|
| 62 | end |
---|
| 63 | table.insert(levelList, level) |
---|
| 64 | index = index + 1 |
---|
| 65 | end |
---|
| 66 | table.sort(levelList) |
---|
[7163] | 67 | index = 1 |
---|
[6363] | 68 | for k,v in pairs(levelList) do |
---|
[7163] | 69 | local item = CEGUI.createListboxTextItem(v) |
---|
[6746] | 70 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
[7163] | 71 | item:setID(index) |
---|
| 72 | index = index + 1 |
---|
[6363] | 73 | CEGUI.toListbox(listbox):addItem(item) |
---|
| 74 | if v .. ".oxw" == preselect then |
---|
| 75 | listbox:setItemSelectState(item, true) |
---|
| 76 | end |
---|
| 77 | end |
---|
| 78 | end |
---|
[7163] | 79 | |
---|
| 80 | function P.showServerList() |
---|
| 81 | local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") |
---|
| 82 | CEGUI.toListbox(listbox):resetList() |
---|
| 83 | local discovery = orxonox.LANDiscovery:getInstance() |
---|
| 84 | discovery:discover() |
---|
| 85 | P.serverList = {} |
---|
| 86 | local index = 0 |
---|
| 87 | local servername = "" |
---|
| 88 | local serverip = "" |
---|
| 89 | while true do |
---|
| 90 | servername = discovery:getServerListItemName(index) |
---|
| 91 | if servername == "" then |
---|
| 92 | break |
---|
| 93 | end |
---|
| 94 | serverip = discovery:getServerListItemIP(index) |
---|
| 95 | if serverip == "" then |
---|
| 96 | break |
---|
| 97 | end |
---|
| 98 | table.insert(P.serverList, {servername, serverip}) |
---|
| 99 | index = index + 1 |
---|
[6363] | 100 | end |
---|
[7163] | 101 | index = 1 |
---|
| 102 | for k,v in pairs(P.serverList) do |
---|
| 103 | local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) |
---|
| 104 | item:setID(index) |
---|
| 105 | index = index + 1 |
---|
| 106 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 107 | CEGUI.toListbox(listbox):addItem(item) |
---|
[6363] | 108 | end |
---|
| 109 | end |
---|
| 110 | |
---|
| 111 | return P |
---|
| 112 | |
---|