[6363] | 1 | -- MultiplayerMenu.lua |
---|
| 2 | |
---|
[6746] | 3 | local P = createMenuSheet("MultiplayerMenu") |
---|
[6363] | 4 | |
---|
[7689] | 5 | P.buttonList = {} |
---|
[7648] | 6 | |
---|
[7732] | 7 | --joinMode is 1 for choice "LAN" and 2 for "Internet" |
---|
| 8 | --initial status 0 |
---|
| 9 | P.joinMode = 0 |
---|
| 10 | |
---|
[6746] | 11 | function P.onLoad() |
---|
[7689] | 12 | P.multiplayerMode = "startClient" |
---|
| 13 | |
---|
| 14 | --button are arranged in a 2x2 matrix, the left lower item is nil |
---|
| 15 | local item = { |
---|
| 16 | ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"), |
---|
[7690] | 17 | ["function"] = P.MultiplayerJoinButton_clicked |
---|
[7689] | 18 | } |
---|
| 19 | P.buttonList[1] = item |
---|
| 20 | |
---|
| 21 | local item = { |
---|
| 22 | ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"), |
---|
[7690] | 23 | ["function"] = P.MultiplayerHostButton_clicked |
---|
[7689] | 24 | } |
---|
| 25 | P.buttonList[2] = item |
---|
| 26 | |
---|
| 27 | local item = { |
---|
| 28 | ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"), |
---|
| 29 | ["function"] = P.MultiplayerBackButton_clicked |
---|
| 30 | } |
---|
| 31 | P.buttonList[4] = item |
---|
[7163] | 32 | end |
---|
| 33 | |
---|
| 34 | function P.onShow() |
---|
[7689] | 35 | P.showServerList() |
---|
[7163] | 36 | |
---|
[7689] | 37 | --indices to iterate through buttonlist |
---|
| 38 | P.oldindex = -2 |
---|
| 39 | P.index = -1 |
---|
[7163] | 40 | end |
---|
| 41 | |
---|
[7732] | 42 | function P.LanButton_clicked(e) |
---|
| 43 | P.joinMode = 1 |
---|
| 44 | end |
---|
| 45 | |
---|
| 46 | function P.InternetButton_clicked(e) |
---|
| 47 | P.joinMode = 2 |
---|
| 48 | end |
---|
| 49 | |
---|
[7163] | 50 | function P.MultiplayerHostButton_clicked(e) |
---|
[7689] | 51 | showMenuSheet("HostMenu", true) |
---|
[7163] | 52 | end |
---|
| 53 | |
---|
| 54 | |
---|
[7689] | 55 | function P.MultiplayerJoinButton_clicked(e) |
---|
[7732] | 56 | local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem() |
---|
| 57 | |
---|
| 58 | if P.joinMode == 2 then |
---|
| 59 | if choice then |
---|
| 60 | local client = orxonox.Client:getInstance() |
---|
| 61 | local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() |
---|
| 62 | client:setDestination( P.serverList[index][2], 55556 ) |
---|
| 63 | else |
---|
| 64 | return |
---|
| 65 | end |
---|
| 66 | orxonox.execute("startClient") |
---|
| 67 | hideAllMenuSheets() |
---|
[7163] | 68 | else |
---|
[7732] | 69 | --wait for Sandro's function |
---|
[7163] | 70 | end |
---|
[7732] | 71 | |
---|
[7163] | 72 | end |
---|
| 73 | |
---|
| 74 | function P.MultiplayerBackButton_clicked(e) |
---|
| 75 | hideMenuSheet(P.name) |
---|
| 76 | end |
---|
| 77 | |
---|
| 78 | function P.showServerList() |
---|
| 79 | local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") |
---|
| 80 | CEGUI.toListbox(listbox):resetList() |
---|
| 81 | local discovery = orxonox.LANDiscovery:getInstance() |
---|
| 82 | discovery:discover() |
---|
| 83 | P.serverList = {} |
---|
| 84 | local index = 0 |
---|
| 85 | local servername = "" |
---|
| 86 | local serverip = "" |
---|
| 87 | while true do |
---|
| 88 | servername = discovery:getServerListItemName(index) |
---|
| 89 | if servername == "" then |
---|
| 90 | break |
---|
| 91 | end |
---|
| 92 | serverip = discovery:getServerListItemIP(index) |
---|
| 93 | if serverip == "" then |
---|
| 94 | break |
---|
| 95 | end |
---|
| 96 | table.insert(P.serverList, {servername, serverip}) |
---|
| 97 | index = index + 1 |
---|
[6363] | 98 | end |
---|
[7163] | 99 | index = 1 |
---|
| 100 | for k,v in pairs(P.serverList) do |
---|
| 101 | local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) |
---|
| 102 | item:setID(index) |
---|
| 103 | index = index + 1 |
---|
| 104 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 105 | CEGUI.toListbox(listbox):addItem(item) |
---|
[6363] | 106 | end |
---|
| 107 | end |
---|
| 108 | |
---|
[7689] | 109 | function P.onKeyPressed() |
---|
| 110 | buttonIteratorHelper(P.buttonList, code, P, 2, 2) |
---|
| 111 | end |
---|
| 112 | |
---|
[6363] | 113 | return P |
---|
| 114 | |
---|