Changeset 7801 for code/trunk/data/gui/scripts/MultiplayerMenu.lua
- Timestamp:
- Dec 22, 2010, 7:24:24 PM (13 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
r7732 r7801 6 6 7 7 --joinMode is 1 for choice "LAN" and 2 for "Internet" 8 --initial status 09 P.joinMode = 08 --initial status 1 9 P.joinMode = 1 10 10 11 11 function P.onLoad() … … 33 33 34 34 function P.onShow() 35 P.showServerList()35 --P.showServerList() 36 36 37 37 --indices to iterate through buttonlist 38 38 P.oldindex = -2 39 39 P.index = -1 40 41 if P.joinMode == 1 then 42 local window = winMgr:getWindow("orxonox/MultiplayerLanButton") 43 local button = tolua.cast(window,"CEGUI::RadioButton") 44 button:setSelected(true) 45 end 46 if P.joinMode == 2 then 47 local window = winMgr:getWindow("orxonox/MultiplayerInternetButton") 48 local button = tolua.cast(window,"CEGUI::RadioButton") 49 button:setSelected(true) 50 end 40 51 end 41 52 42 53 function P.LanButton_clicked(e) 54 local we = CEGUI.toWindowEventArgs(e) 55 local button = tolua.cast(we.window,"CEGUI::RadioButton") 43 56 P.joinMode = 1 57 if button:isSelected() == true then 58 P.showServerList() 59 end 44 60 end 45 61 46 62 function P.InternetButton_clicked(e) 63 local we = CEGUI.toWindowEventArgs(e) 64 local button = tolua.cast(we.window,"CEGUI::RadioButton") 47 65 P.joinMode = 2 66 if button:isSelected() == true then 67 P.showServerList() 68 end 48 69 end 49 70 … … 55 76 function P.MultiplayerJoinButton_clicked(e) 56 77 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() 78 if choice then 79 local client = orxonox.Client:getInstance() 80 local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID() 81 client:setDestination( P.serverList[index][2], 55556 ) 68 82 else 69 --wait for Sandro's function83 return 70 84 end 71 85 orxonox.execute("startClient") 86 hideAllMenuSheets() 72 87 end 73 88 … … 77 92 78 93 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 98 end 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) 106 end 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 107 158 end 108 159
Note: See TracChangeset
for help on using the changeset viewer.