[6363] | 1 | -- MultiplayerMenu.lua |
---|
| 2 | |
---|
[6746] | 3 | local P = createMenuSheet("MultiplayerMenu") |
---|
[6363] | 4 | |
---|
[7732] | 5 | --joinMode is 1 for choice "LAN" and 2 for "Internet" |
---|
[7801] | 6 | --initial status 1 |
---|
| 7 | P.joinMode = 1 |
---|
[7732] | 8 | |
---|
[6746] | 9 | function P.onLoad() |
---|
[8079] | 10 | P.multiplayerMode = "startClient" |
---|
[7689] | 11 | |
---|
[8079] | 12 | --button are arranged in a 3x2 matrix, Join and Host buttons are in the upper left and middle, the back button in the lower right of the table |
---|
| 13 | P:setButton(1, 1, { |
---|
[7689] | 14 | ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"), |
---|
[8079] | 15 | ["callback"] = P.MultiplayerJoinButton_clicked |
---|
| 16 | }) |
---|
[7689] | 17 | |
---|
[8079] | 18 | P:setButton(1, 2, { |
---|
[7689] | 19 | ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"), |
---|
[8079] | 20 | ["callback"] = P.MultiplayerHostButton_clicked |
---|
| 21 | }) |
---|
[7689] | 22 | |
---|
[8079] | 23 | P:setButton(2, 3, { |
---|
[7689] | 24 | ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"), |
---|
[8079] | 25 | ["callback"] = P.MultiplayerBackButton_clicked |
---|
| 26 | }) |
---|
[7163] | 27 | end |
---|
| 28 | |
---|
| 29 | function P.onShow() |
---|
[7801] | 30 | --P.showServerList() |
---|
[7163] | 31 | |
---|
[7801] | 32 | if P.joinMode == 1 then |
---|
| 33 | local window = winMgr:getWindow("orxonox/MultiplayerLanButton") |
---|
| 34 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
| 35 | button:setSelected(true) |
---|
| 36 | end |
---|
| 37 | if P.joinMode == 2 then |
---|
| 38 | local window = winMgr:getWindow("orxonox/MultiplayerInternetButton") |
---|
| 39 | local button = tolua.cast(window,"CEGUI::RadioButton") |
---|
| 40 | button:setSelected(true) |
---|
| 41 | end |
---|
[7163] | 42 | end |
---|
| 43 | |
---|
[7732] | 44 | function P.LanButton_clicked(e) |
---|
[7801] | 45 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 46 | local button = tolua.cast(we.window,"CEGUI::RadioButton") |
---|
[7732] | 47 | P.joinMode = 1 |
---|
[7801] | 48 | if button:isSelected() == true then |
---|
[8079] | 49 | P.showServerList() |
---|
[7801] | 50 | end |
---|
[7732] | 51 | end |
---|
| 52 | |
---|
| 53 | function P.InternetButton_clicked(e) |
---|
[7801] | 54 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 55 | local button = tolua.cast(we.window,"CEGUI::RadioButton") |
---|
[7732] | 56 | P.joinMode = 2 |
---|
[7801] | 57 | if button:isSelected() == true then |
---|
[8079] | 58 | P.showServerList() |
---|
| 59 | end |
---|
[7732] | 60 | end |
---|
| 61 | |
---|
[7163] | 62 | function P.MultiplayerHostButton_clicked(e) |
---|
[7689] | 63 | showMenuSheet("HostMenu", true) |
---|
[7163] | 64 | end |
---|
| 65 | |
---|
| 66 | |
---|
[7689] | 67 | function P.MultiplayerJoinButton_clicked(e) |
---|
[7876] | 68 | local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem() |
---|
| 69 | local destination = nil |
---|
[7801] | 70 | if choice then |
---|
| 71 | local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() |
---|
[7876] | 72 | destination = P.serverList[index][2] |
---|
[7163] | 73 | else |
---|
[7801] | 74 | return |
---|
[7163] | 75 | end |
---|
[7876] | 76 | orxonox.execute("startClient " .. destination) |
---|
[7801] | 77 | hideAllMenuSheets() |
---|
[7163] | 78 | end |
---|
| 79 | |
---|
| 80 | function P.MultiplayerBackButton_clicked(e) |
---|
| 81 | hideMenuSheet(P.name) |
---|
| 82 | end |
---|
| 83 | |
---|
| 84 | function P.showServerList() |
---|
[8079] | 85 | -- LAN Discovery |
---|
| 86 | if P.joinMode == 1 then |
---|
| 87 | local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") |
---|
| 88 | CEGUI.toListbox(listbox):resetList() |
---|
| 89 | local discovery = orxonox.LANDiscovery:getInstance() |
---|
| 90 | discovery:discover() |
---|
| 91 | P.serverList = {} |
---|
| 92 | local index = 0 |
---|
| 93 | local servername = "" |
---|
| 94 | local serverip = "" |
---|
[10334] | 95 | local serverrtt = "" |
---|
[8079] | 96 | while true do |
---|
| 97 | servername = discovery:getServerListItemName(index) |
---|
| 98 | if servername == "" then |
---|
| 99 | break |
---|
| 100 | end |
---|
| 101 | serverip = discovery:getServerListItemIP(index) |
---|
| 102 | if serverip == "" then |
---|
| 103 | break |
---|
| 104 | end |
---|
[10334] | 105 | serverrtt = discovery:getServerListItemRTT(index) |
---|
| 106 | |
---|
| 107 | table.insert(P.serverList, {servername, serverip, serverrtt}) |
---|
[8079] | 108 | index = index + 1 |
---|
| 109 | end |
---|
| 110 | index = 1 |
---|
| 111 | for k,v in pairs(P.serverList) do |
---|
[10334] | 112 | local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] .. " Ping: " .. v[3] .."ms" ) |
---|
[8079] | 113 | item:setID(index) |
---|
| 114 | index = index + 1 |
---|
| 115 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 116 | CEGUI.toListbox(listbox):addItem(item) |
---|
| 117 | end |
---|
| 118 | -- WAN Discovery |
---|
| 119 | elseif P.joinMode == 2 then |
---|
| 120 | local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") |
---|
| 121 | CEGUI.toListbox(listbox):resetList() |
---|
[8858] | 122 | local discovery = orxonox.WANDiscovery() |
---|
| 123 | orxout("discovering." ) |
---|
[8079] | 124 | discovery:discover() |
---|
[8858] | 125 | orxout("discovered." ) |
---|
[8079] | 126 | P.serverList = {} |
---|
| 127 | local index = 0 |
---|
| 128 | local servername = "" |
---|
| 129 | local serverip = "" |
---|
[10334] | 130 | local serverrtt = "" |
---|
[8079] | 131 | while true do |
---|
| 132 | servername = discovery:getServerListItemName(index) |
---|
| 133 | if servername == "" then |
---|
| 134 | break |
---|
| 135 | end |
---|
| 136 | serverip = discovery:getServerListItemIP(index) |
---|
| 137 | if serverip == "" then |
---|
| 138 | break |
---|
| 139 | end |
---|
[10334] | 140 | serverrtt = discovery:getServerListItemRTT(index) |
---|
| 141 | |
---|
| 142 | table.insert(P.serverList, {servername, serverip, serverrtt}) |
---|
[8079] | 143 | index = index + 1 |
---|
| 144 | end |
---|
| 145 | index = 1 |
---|
| 146 | for k,v in pairs(P.serverList) do |
---|
[10334] | 147 | local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] .. " Ping: " .. v[3] .."ms" ) |
---|
[8079] | 148 | item:setID(index) |
---|
| 149 | index = index + 1 |
---|
| 150 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 151 | CEGUI.toListbox(listbox):addItem(item) |
---|
| 152 | end |
---|
| 153 | end |
---|
[6363] | 154 | |
---|
[7689] | 155 | end |
---|
| 156 | |
---|
[6363] | 157 | return P |
---|