Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Merging menu branch to trunk.

Location:
code/trunk
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r7687 r7689  
    66
    77P.buttonList = {}
     8P.levelList = {}
     9P.itemList = {}
     10P.showAll = false
    811
    912function P.onLoad()
    10     P.multiplayerMode = "startClient"
     13    P.multiplayerMode = "startServer"
     14    local window = winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox")
     15    local button = tolua.cast(window,"CEGUI::Checkbox")
     16    button:setSelected(false)
     17    P.createLevelList()
    1118
    1219    local item = {
     
    2835        local button = tolua.cast(window,"CEGUI::RadioButton")
    2936        button:setSelected(true)
    30         P.showLevelList()
     37        P.createLevelList()
    3138    end
    3239
     
    3542        local button = tolua.cast(window,"CEGUI::RadioButton")
    3643        button:setSelected(true)
    37         P.showLevelList()
     44        P.createLevelList()
    3845    end
    3946
     
    4350end
    4451
     52function P.createLevelList()
     53    P.levelList = {}
     54    P.itemList = {}
     55    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/HostMenuListbox"))
     56    listbox:resetList()
     57    orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
     58    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
     59    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
     60    local index = 0
     61    local level = nil
     62    while index < size do
     63        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
     64        if level ~= nil then
     65            if P.showAll or not level:hasTag("test") then
     66                table.insert(P.levelList, level)
     67            end
     68        end
     69        index = index + 1
     70    end
     71    --TODO: Reintroduce sorting, if needed. At the moment it's sorted by filename.
     72    --table.sort(levelList)
     73    for k,v in pairs(P.levelList) do
     74        local item = CEGUI.createListboxTextItem(v:getName())
     75        item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     76        listbox:addItem(item)
     77        if v:getXMLFilename() == preselect then
     78            listbox:setItemSelectState(item, true)
     79        end
     80        P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
     81        orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
     82    end
     83end
     84
    4585function P.HostMenuBuildServerButton_clicked(e)
    4686    P.multiplayerMode = "startServer"
    47     P.showLevelList()
     87    P.createLevelList()
    4888end
    4989
    5090function P.HostMenuDedicatedButton_clicked(e)
    5191    P.multiplayerMode = "startDedicated"
    52     P.showLevelList()
     92    P.createLevelList()
    5393end
    5494
     
    5797end
    5898
    59 function P.HostMenuStartButton_clicked(e)
    60     local choice = winMgr:getWindow("orxonox/HostMenuListbox"):getFirstSelectedItem()
    61         if choice then
    62             orxonox.LevelManager:getInstance():setDefaultLevel(choice:getText() .. ".oxw")
    63         else
    64             return
    65         end
    66     orxonox.execute(P.multiplayerMode)
    67     hideAllMenuSheets()
    68 end
    69 
    70 
    71 
    72 function P.showLevelList()
    73     local listbox = winMgr:getWindow("orxonox/HostMenuListbox")
    74     CEGUI.toListbox(listbox):resetList()
    75     local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
    76     orxonox.LevelManager:getInstance():compileAvailableLevelList()
    77     local levelList = {}
    78     local index = 0
    79     local level = ""
    80     while true do
    81         level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
    82         if level == "" then
    83             break
    84         end
    85         table.insert(levelList, level)
    86         index = index + 1
    87     end
    88     table.sort(levelList)
    89     index = 1
    90     for k,v in pairs(levelList) do
    91         local item = CEGUI.createListboxTextItem(v)
    92         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
    93         item:setID(index)
    94         index = index + 1
    95         CEGUI.toListbox(listbox):addItem(item)
    96         if v .. ".oxw" == preselect then
    97             listbox:setItemSelectState(item, true)
     99function P.HostMenuStartButton_clicked(e)   
     100    local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/HostMenuListbox"))
     101    local choice = listbox:getFirstSelectedItem()
     102    if choice ~= nil then
     103        local index = listbox:getItemIndex(choice)
     104        local level = P.levelList[index+1]
     105        if level ~= nil then
     106            orxonox.LevelManager:getInstance():setDefaultLevel(level:getXMLFilename())
     107            orxonox.execute(P.multiplayerMode)
     108            hideAllMenuSheets()
    98109        end
    99110    end
    100111end
    101112
     113function P.MultiplayerShowAll_clicked(e)
     114    local checkbox = tolua.cast(winMgr:getWindow("orxonox/MultiplayerShowAllCheckbox"), "CEGUI::Checkbox")
     115    local show = checkbox:isSelected()
     116    if show ~= P.showAll then
     117        P.showAll = show
     118        P.createLevelList()
     119   end
     120end
    102121
    103122function P.onKeyPressed()
     
    105124end
    106125
    107 
    108 
    109126return P
Note: See TracChangeset for help on using the changeset viewer.