Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 28, 2010, 8:29:32 PM (14 years ago)
Author:
scheusso
Message:

some new features:
-Orxonox servers announce themselves now inside a LAN (and can provide some information (e.g. server name, etc.) to the client )
-Orxonox clients discover the servers inside the LAN and list them in the menu

Location:
code/branches/presentation3/data/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/data/gui/layouts/MultiplayerMenu.layout

    r6746 r7161  
    1616            <Property Name="VertFormatting" Value="TopAligned" />
    1717            <Property Name="UnifiedAreaRect" Value="{{0.25,0},{0.2875,0},{0.75,0},{0.6375,0}}" />
    18             <Window Type="MenuWidgets/Listbox" Name="orxonox/MultiplayerLevelListbox" >
     18            <Window Type="MenuWidgets/Listbox" Name="orxonox/MultiplayerListbox" >
    1919                <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
    2020                <Property Name="UnifiedAreaRect" Value="{{0.05,0},{0.15,0},{0.95,0},{0.8,0}}" />
  • code/branches/presentation3/data/gui/scripts/MultiplayerMenu.lua

    r6746 r7161  
    44
    55function P.onLoad()
    6     listbox = winMgr:getWindow("orxonox/MultiplayerLevelListbox")
    7     preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
     6    P.multiplayerMode = "startClient"
     7end
     8
     9function P.onShow()
     10    if P.multiplayerMode == "startClient" then
     11        local window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
     12        local button = tolua.cast(window,"CEGUI::RadioButton")
     13        button:setSelected(true)
     14        P.showServerList()
     15    end
     16    if P.multiplayerMode == "startServer" then
     17        local window = winMgr:getWindow("orxonox/MultiplayerHostButton")
     18        local button = tolua.cast(window,"CEGUI::RadioButton")
     19        button:setSelected(true)
     20        P.showLevelList()
     21    end
     22    if P.multiplayerMode == "startDedicated" then
     23        local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
     24        local button = tolua.cast(window,"CEGUI::RadioButton")
     25        button:setSelected(true)
     26        P.showLevelList()
     27    end
     28end
     29
     30function P.MultiplayerJoinButton_clicked(e)
     31    P.multiplayerMode = "startClient"
     32    P.showServerList()
     33end
     34
     35function P.MultiplayerHostButton_clicked(e)
     36    P.multiplayerMode = "startServer"
     37    P.showLevelList()
     38end
     39
     40function P.MultiplayerDedicatedButton_clicked(e)
     41    P.multiplayerMode = "startDedicated"
     42    P.showLevelList()
     43end
     44
     45function P.MultiplayerStartButton_clicked(e)
     46    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
     47    if P.multiplayerMode == "startClient" then
     48        if choice then
     49            local client = orxonox.Client:getInstance()
     50            local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
     51            client:setDestination( P.serverList[index][2], 55556 )
     52        else
     53            return
     54        end
     55    else
     56        if choice then
     57            orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
     58        else
     59            return
     60        end
     61    end
     62    orxonox.execute(P.multiplayerMode)
     63    hideAllMenuSheets()
     64end
     65
     66function P.MultiplayerBackButton_clicked(e)
     67    hideMenuSheet(P.name)
     68end
     69
     70function P.showLevelList()
     71    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
     72    CEGUI.toListbox(listbox):resetList()
     73    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
    874    orxonox.LevelManager:getInstance():compileAvailableLevelList()
    975    local levelList = {}
     
    1985    end
    2086    table.sort(levelList)
     87    index = 1
    2188    for k,v in pairs(levelList) do
    22         item = CEGUI.createListboxTextItem(v)
     89        local item = CEGUI.createListboxTextItem(v)
    2390        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     91        item:setID(index)
     92        index = index + 1
    2493        CEGUI.toListbox(listbox):addItem(item)
    2594        if v .. ".oxw" == preselect then
     
    2796        end
    2897    end
    29     local multiplayerMode = "startClient"
    30     if multiplayerMode == "startClient" then
    31         window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
    32         button = tolua.cast(window,"CEGUI::RadioButton")
    33         button:setSelected(true)
    3498    end
    35     if multiplayerMode == "startServer" then
    36         window = winMgr:getWindow("orxonox/MultiplayerHostButton")
    37         button = tolua.cast(window,"CEGUI::RadioButton")
    38         button:setSelected(true)
     99   
     100function P.showServerList()
     101    local listbox = winMgr:getWindow("orxonox/MultiplayerListbox")
     102    CEGUI.toListbox(listbox):resetList()
     103    local discovery = orxonox.LANDiscovery:getInstance()
     104    discovery:discover()
     105    P.serverList = {}
     106    local index = 0
     107    local servername = ""
     108    local serverip = ""
     109    while true do
     110        servername = discovery:getServerListItemName(index)
     111        if servername == "" then
     112            break
     113        end
     114        serverip = discovery:getServerListItemIP(index)
     115        if serverip == "" then
     116          break
     117        end
     118        table.insert(P.serverList, {servername, serverip})
     119        index = index + 1
    39120    end
    40     if multiplayerMode == "startDedicated" then
    41         window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
    42         button = tolua.cast(window,"CEGUI::RadioButton")
    43         button:setSelected(true)
     121    index = 1
     122    for k,v in pairs(P.serverList) do
     123        local item = CEGUI.createListboxTextItem( v[1] .. ": " .. v[2] )
     124        item:setID(index)
     125        index = index + 1
     126        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     127        CEGUI.toListbox(listbox):addItem(item)
    44128    end
    45 end
    46 
    47 function P.MultiplayerJoinButton_clicked(e)
    48     multiplayerMode = "startClient"
    49 end
    50 
    51 function P.MultiplayerHostButton_clicked(e)
    52     multiplayerMode = "startServer"
    53 end
    54 
    55 function P.MultiplayerDedicatedButton_clicked(e)
    56     multiplayerMode = "startDedicated"
    57 end
    58 
    59 function P.MultiplayerStartButton_clicked(e)
    60     local choice = winMgr:getWindow("orxonox/MultiplayerLevelListbox"):getFirstSelectedItem()
    61     if choice then
    62         orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
    63         orxonox.execute(multiplayerMode)
    64         hideAllMenuSheets()
    65     end
    66 end
    67 
    68 function P.MultiplayerBackButton_clicked(e)
    69     hideMenuSheet(P.name)
    70129end
    71130
Note: See TracChangeset for help on using the changeset viewer.