Changeset 8079 for code/trunk/data/gui/scripts/MultiplayerMenu.lua
- Timestamp:
- Mar 15, 2011, 9:47:11 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/data/gui/scripts/MultiplayerMenu.lua
r7876 r8079 2 2 3 3 local P = createMenuSheet("MultiplayerMenu") 4 5 P.buttonList = {}6 4 7 5 --joinMode is 1 for choice "LAN" and 2 for "Internet" … … 10 8 11 9 function P.onLoad() 12 P.multiplayerMode = "startClient" 10 P.multiplayerMode = "startClient" 13 11 14 --button are arranged in a 2x2 matrix, the left lower item is nil15 local item ={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, { 16 14 ["button"] = winMgr:getWindow("orxonox/MultiplayerJoinButton"), 17 ["function"] = P.MultiplayerJoinButton_clicked 18 } 19 P.buttonList[1] = item 15 ["callback"] = P.MultiplayerJoinButton_clicked 16 }) 20 17 21 local item ={18 P:setButton(1, 2, { 22 19 ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"), 23 ["function"] = P.MultiplayerHostButton_clicked 24 } 25 P.buttonList[2] = item 20 ["callback"] = P.MultiplayerHostButton_clicked 21 }) 26 22 27 local item ={23 P:setButton(2, 3, { 28 24 ["button"] = winMgr:getWindow("orxonox/MultiplayerBackButton"), 29 ["function"] = P.MultiplayerBackButton_clicked 30 } 31 P.buttonList[4] = item 25 ["callback"] = P.MultiplayerBackButton_clicked 26 }) 32 27 end 33 28 … … 35 30 --P.showServerList() 36 31 37 --indices to iterate through buttonlist38 P.oldindex = -239 P.index = -140 41 32 if P.joinMode == 1 then 42 33 local window = winMgr:getWindow("orxonox/MultiplayerLanButton") … … 56 47 P.joinMode = 1 57 48 if button:isSelected() == true then 58 49 P.showServerList() 59 50 end 60 51 end … … 65 56 P.joinMode = 2 66 57 if button:isSelected() == true then 67 68 58 P.showServerList() 59 end 69 60 end 70 61 … … 92 83 93 84 function P.showServerList() 94 -- LAN Discovery 95 if P.joinMode == 1 then 96 local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") 97 CEGUI.toListbox(listbox):resetList() 98 local discovery = orxonox.LANDiscovery:getInstance() 99 discovery:discover() 100 P.serverList = {} 101 local index = 0 102 local servername = "" 103 local serverip = "" 104 while true do 105 servername = discovery:getServerListItemName(index) 106 if servername == "" then 107 break 108 end 109 serverip = discovery:getServerListItemIP(index) 110 if serverip == "" then 111 break 112 end 113 table.insert(P.serverList, {servername, serverip}) 114 index = index + 1 115 end 116 index = 1 117 for k,v in pairs(P.serverList) do 118 local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) 119 item:setID(index) 120 index = index + 1 121 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 122 CEGUI.toListbox(listbox):addItem(item) 123 end 124 -- WAN Discovery 125 elseif P.joinMode == 2 then 126 local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") 127 CEGUI.toListbox(listbox):resetList() 128 local discovery = orxonox.WANDiscovery:getInstance() 129 cout(0, "discovering.\n" ) 130 discovery:discover() 131 cout(0, "discovered.\n" ) 132 P.serverList = {} 133 local index = 0 134 local servername = "" 135 local serverip = "" 136 while true do 137 servername = discovery:getServerListItemName(index) 138 if servername == "" then 139 break 140 end 141 serverip = discovery:getServerListItemIP(index) 142 if serverip == "" then 143 break 144 end 145 table.insert(P.serverList, {servername, serverip}) 146 index = index + 1 147 end 148 index = 1 149 for k,v in pairs(P.serverList) do 150 local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) 151 item:setID(index) 152 index = index + 1 153 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 154 CEGUI.toListbox(listbox):addItem(item) 155 end 156 end 157 158 end 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 = "" 95 while true do 96 servername = discovery:getServerListItemName(index) 97 if servername == "" then 98 break 99 end 100 serverip = discovery:getServerListItemIP(index) 101 if serverip == "" then 102 break 103 end 104 table.insert(P.serverList, {servername, serverip}) 105 index = index + 1 106 end 107 index = 1 108 for k,v in pairs(P.serverList) do 109 local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) 110 item:setID(index) 111 index = index + 1 112 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 113 CEGUI.toListbox(listbox):addItem(item) 114 end 115 -- WAN Discovery 116 elseif P.joinMode == 2 then 117 local listbox = winMgr:getWindow("orxonox/MultiplayerListbox") 118 CEGUI.toListbox(listbox):resetList() 119 local discovery = orxonox.WANDiscovery:getInstance() 120 cout(0, "discovering.\n" ) 121 discovery:discover() 122 cout(0, "discovered.\n" ) 123 P.serverList = {} 124 local index = 0 125 local servername = "" 126 local serverip = "" 127 while true do 128 servername = discovery:getServerListItemName(index) 129 if servername == "" then 130 break 131 end 132 serverip = discovery:getServerListItemIP(index) 133 if serverip == "" then 134 break 135 end 136 table.insert(P.serverList, {servername, serverip}) 137 index = index + 1 138 end 139 index = 1 140 for k,v in pairs(P.serverList) do 141 local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] ) 142 item:setID(index) 143 index = index + 1 144 item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") 145 CEGUI.toListbox(listbox):addItem(item) 146 end 147 end 159 148 160 function P.onKeyPressed()161 buttonIteratorHelper(P.buttonList, code, P, 2, 2)162 149 end 163 150
Note: See TracChangeset
for help on using the changeset viewer.