Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 1, 2010, 3:00:19 PM (13 years ago)
Author:
dafrick
Message:

Merging menu branch to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r7648 r7689  
    33local P = createMenuSheet("MultiplayerMenu")
    44
    5 P.levelList = {}
    6 P.itemList = {}
    7 P.showAll = false
     5P.buttonList = {}
    86
    97function P.onLoad()
    10     P.multiplayerMode = "startClient"
     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"),
     13            ["function"]  = P.MultiplayerJoinButton2_clicked
     14    }
     15    P.buttonList[1] = item
     16
     17    local item = {
     18            ["button"] = winMgr:getWindow("orxonox/MultiplayerHostButton"),
     19            ["function"]  = P.MultiplayerHostButton2_clicked
     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
    1129end
    1230
    1331function P.onShow()
    14     if P.multiplayerMode == "startClient" then
    15         local window = winMgr:getWindow("orxonox/MultiplayerJoinButton")
    16         local button = tolua.cast(window,"CEGUI::RadioButton")
    17         button:setSelected(true)
    18         local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
    19         checkbox:setProperty("Disabled", "True")
    20         P.showServerList()
    21     end
    22     if P.multiplayerMode == "startServer" then
    23         local window = winMgr:getWindow("orxonox/MultiplayerHostButton")
    24         local button = tolua.cast(window,"CEGUI::RadioButton")
    25         button:setSelected(true)
    26         local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
    27         checkbox:setProperty("Disabled", "False")
    28         P.showLevelList()
    29     end
    30     if P.multiplayerMode == "startDedicated" then
    31         local window = winMgr:getWindow("orxonox/MultiplayerDedicatedButton")
    32         local button = tolua.cast(window,"CEGUI::RadioButton")
    33         button:setSelected(true)
    34         local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
    35         checkbox:setProperty("Disabled", "True")
    36         P.showLevelList()
    37     end
    38 end
     32    P.showServerList()
    3933
    40 function P.MultiplayerJoinButton_clicked(e)
    41     P.multiplayerMode = "startClient"
    42     local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
    43     checkbox:setProperty("Disabled", "True")
    44     P.showServerList()
     34    --indices to iterate through buttonlist
     35    P.oldindex = -2
     36    P.index = -1
    4537end
    4638
    4739function P.MultiplayerHostButton_clicked(e)
    48     P.multiplayerMode = "startServer"
    49     local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
    50     checkbox:setProperty("Disabled", "False")
    51     P.showLevelList()
     40    showMenuSheet("HostMenu", true)
    5241end
    5342
    54 function P.MultiplayerDedicatedButton_clicked(e)
    55     P.multiplayerMode = "startDedicated"
    56     local checkbox = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
    57     checkbox:setProperty("Disabled", "True")
    58     P.showLevelList()
    59 end
    6043
    61 function P.MultiplayerShowAll_clicked(e)
    62     local checkbox = tolua.cast(winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox"), "CEGUI::Checkbox")
    63     local show = checkbox:isSelected()
    64     if show ~= P.showAll then
    65         P.showAll = show
    66         P.createLevelList()
     44function P.MultiplayerJoinButton_clicked(e)
     45    local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
     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 )
     50    else
     51        return
    6752    end
    68 end
    69 
    70 function P.MultiplayerStartButton_clicked(e)
    71     local choice = winMgr:getWindow("orxonox/MultiplayerListbox"):getFirstSelectedItem()
    72     if P.multiplayerMode == "startClient" then
    73         if choice then
    74             local client = orxonox.Client:getInstance()
    75             local index = tolua.cast(choice, "CEGUI::ListboxItem"):getID()
    76             client:setDestination( P.serverList[index][2], 55556 )
    77         else
    78             return
    79         end
    80     else
    81         if choice then
    82             orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
    83         else
    84             return
    85         end
    86     end
    87     orxonox.execute(P.multiplayerMode)
     53    orxonox.execute("startClient")
    8854    hideAllMenuSheets()
    8955end
     
    9157function P.MultiplayerBackButton_clicked(e)
    9258    hideMenuSheet(P.name)
    93 end
    94 
    95 function P.showLevelList()
    96     P.createLevelList()
    97 end
    98 
    99 function P.createLevelList()
    100     P.levelList = {}
    101     P.itemList = {}
    102     local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/MultiplayerListbox"))
    103     listbox:resetList()
    104     orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
    105     local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
    106     local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
    107     local index = 0
    108     local level = nil
    109     while index < size do
    110         level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
    111         if level ~= nil then
    112             if P.showAll or not level:hasTag("test") then
    113                 table.insert(P.levelList, level)
    114             end
    115         end
    116         index = index + 1
    117     end
    118     --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename.
    119     --table.sort(levelList)
    120     for k,v in pairs(P.levelList) do
    121         local item = CEGUI.createListboxTextItem(v:getName())
    122         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
    123         listbox:addItem(item)
    124         if v:getXMLFilename() == preselect then
    125             listbox:setItemSelectState(item, true)
    126         end
    127         P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
    128         orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
    129     end
    13059end
    13160
     
    16190end
    16291
     92function P.onKeyPressed()
     93    buttonIteratorHelper(P.buttonList, code, P, 2, 2)
     94end
     95
    16396return P
    16497
Note: See TracChangeset for help on using the changeset viewer.