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