Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 22, 2010, 7:24:24 PM (13 years ago)
Author:
dafrick
Message:

Merging presentation2 branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/data/gui/scripts/MultiplayerMenu.lua

    r7732 r7801  
    66
    77--joinMode is 1 for choice "LAN" and 2 for "Internet"
    8 --initial status 0
    9 P.joinMode = 0
     8--initial status 1
     9P.joinMode = 1
    1010
    1111function P.onLoad()
     
    3333
    3434function P.onShow()
    35     P.showServerList()
     35    --P.showServerList()
    3636
    3737    --indices to iterate through buttonlist
    3838    P.oldindex = -2
    3939    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
    4051end
    4152
    4253function P.LanButton_clicked(e)
     54    local we = CEGUI.toWindowEventArgs(e)
     55    local button = tolua.cast(we.window,"CEGUI::RadioButton")
    4356    P.joinMode = 1
     57    if button:isSelected() == true then
     58            P.showServerList()
     59    end
    4460end
    4561
    4662function P.InternetButton_clicked(e)
     63    local we = CEGUI.toWindowEventArgs(e)
     64    local button = tolua.cast(we.window,"CEGUI::RadioButton")
    4765    P.joinMode = 2
     66    if button:isSelected() == true then
     67            P.showServerList()
     68        end
    4869end
    4970
     
    5576function P.MultiplayerJoinButton_clicked(e)
    5677    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 )
    6882    else
    69         --wait for Sandro's function
     83        return
    7084    end
    71 
     85    orxonox.execute("startClient")
     86    hideAllMenuSheets()
    7287end
    7388
     
    7792
    7893function 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       
    107158end
    108159
Note: See TracChangeset for help on using the changeset viewer.