Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 14, 2011, 2:12:11 PM (13 years ago)
Author:
smerkli
Message:

Merged menue

Location:
code/branches/presentation2011
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2011

  • code/branches/presentation2011/data/gui/scripts/SingleplayerMenu.lua

    r8706 r8977  
    44
    55P.levelList = {}
    6 P.itemList = {}
    7 P.showAll = false
     6P.activeTabIndexes = {}
     7P.scrollbarWidth = 13
    88
    99function P.onLoad()
    10     local window = winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox")
    11     local button = tolua.cast(window,"CEGUI::Checkbox")
    12     button:setSelected(false)
    1310    P.createLevelList()
    14 
    15     --buttons are arranged in a 1x2 matrix
     11   
     12    -- create tabs with desired tab as argument (nil for all)
     13    P.createFilterTab("Gametypes", "gametype")
     14    P.createFilterTab("Missions", "mission")
     15    P.createFilterTab("Minigames", "minigame")
     16    P.createFilterTab("Showcases", "showcase")
     17    P.createFilterTab("Presentations", "presentation")
     18    P.createFilterTab("Tests", "test")
     19    P.createFilterTab("Show All", nil)
     20   
     21    -- update description and screenshot boxes
     22    P.SingleplayerSelectionChanged()
     23   
     24    --buttons are arranged in a 1x3 matrix
    1625    P:setButton(1, 1, {
    1726            ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
     
    2029
    2130    P:setButton(1, 2, {
     31            ["button"] = winMgr:getWindow("orxonox/SingleplayerConfigButton"),
     32            ["callback"]  = P.SingleplayerConfigButton_clicked
     33    })
     34
     35    P:setButton(1, 3, {
    2236            ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
    2337            ["callback"]  = P.SingleplayerBackButton_clicked
     
    2539end
    2640
    27 function P.onShow()
    28     if P.showAll ~= orxonox.GUIManager:inDevMode() then
    29         local window = winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox")
    30         local button = tolua.cast(window,"CEGUI::Checkbox")
    31         P.showAll = not P.showAll
    32         button:setSelected(P.showAll)
    33         P.createLevelList()
    34     end
    35 end
    36 
    3741function P.createLevelList()
    3842    P.levelList = {}
    39     P.itemList = {}
    40     local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
    41     listbox:resetList()
    42     orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
    43     local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
    4443    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
    4544    local index = 0
     
    4847        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
    4948        if level ~= nil then
    50             if P.showAll or not level:hasTag("test") then
    51                 table.insert(P.levelList, level)
     49            local levelXMLFilename = level:getXMLFilename()
     50            -- create an imageset for each screenshot
     51            local imageName = level:getScreenshot()
     52            if imageName ~= "" then
     53                CEGUI.ImagesetManager:getSingleton():createImagesetFromImageFile(levelXMLFilename..imageName, imageName)
     54            else
     55                CEGUI.ImagesetManager:getSingleton():createImagesetFromImageFile(levelXMLFilename..imageName, "noscreenshot.png")
    5256            end
     57            table.insert(P.levelList, level)
    5358        end
    5459        index = index + 1
    5560    end
     61end
    5662
     63function P.createFilterTab(name, tag)
     64    -- create unique tab window name
     65    local tabName = "orxonox/SingleplayerLevelTab"
     66    if tag ~= nil then
     67        tabName = tabName..tag
     68    end
     69    -- create new tab window with desired name
     70    local listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName))
     71    listbox:setText(name)
     72    listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}")
     73    listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}")
     74    -- fill listbox with items
     75    listbox:resetList()
     76    orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
     77    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
     78    local tabIndexes = {}
    5779    for k,v in pairs(P.levelList) do
    58         local item = CEGUI.createListboxTextItem(v:getName())
    59         item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
    60         listbox:addItem(item)
    61         if v:getXMLFilename() == preselect then
    62             listbox:setItemSelectState(item, true)
     80        -- only add level if it has desired tag
     81        if tag == nil or v:hasTag(tag) then
     82            local item = CEGUI.createListboxTextItem(v:getName())
     83            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
     84            listbox:addItem(item)
     85            table.insert(tabIndexes, k)
     86            if v:getXMLFilename() == preselect then
     87                listbox:setItemSelectState(item, true)
     88            end
     89            orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription())
    6390        end
    64         P.itemList[k] = listbox:getListboxItemFromIndex(k-1)
    65         orxonox.GUIManager:setTooltipTextHelper(P.itemList[k], v:getDescription())
     91    end
     92    table.insert(P.activeTabIndexes, tabIndexes)
     93    -- listen to selection changes
     94    orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".SingleplayerSelectionChanged")
     95    local tabControl = winMgr:getWindow("orxonox/SingleplayerTabControl")
     96    orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".SingleplayerSelectionChanged")
     97    if listbox:getItemCount() > 0 then
     98        tabControl:addChildWindow(tabName)
     99    end
     100end
     101
     102function P.SingleplayerGetSelectedLevel()
     103    -- choose the active listbox
     104    local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/SingleplayerTabControl"))
     105    local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex()))
     106    local choice = listbox:getFirstSelectedItem()
     107    if choice ~= nil then
     108        -- get the right tab and the right index
     109        local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1]
     110        local index = tabIndexes[listbox:getItemIndex(choice)+1]
     111        return P.levelList[index]
     112    else
     113        return nil
     114    end
     115end
     116
     117function P.SingleplayerSelectionChanged(e)
     118    local levelImage = winMgr:getWindow("orxonox/SingleplayerLevelImage")
     119    local levelDescription = winMgr:getWindow("orxonox/SingleplayerLevelDescription")
     120    local configButton = winMgr:getWindow("orxonox/SingleplayerConfigButton")
     121    local level = P.SingleplayerGetSelectedLevel()
     122    if level ~= nil then
     123        local levelXMLFilename = level:getXMLFilename()
     124        local imageName = level:getScreenshot()
     125        -- set the screenshot and the description for the selected level
     126        levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image")
     127        levelDescription:setText(level:getDescription())
     128        -- only enable config button for "gametype" levels
     129        if level:hasTag("gametype") then
     130            configButton:setProperty("Disabled", "False")
     131        else
     132            configButton:setProperty("Disabled", "True")
     133        end
     134    else
     135        -- also take care of "no level selected"
     136        levelImage:setProperty("Image", nil)
     137        levelDescription:setText("")
     138        configButton:setProperty("Disabled", "True")
    66139    end
    67140end
    68141
    69142function P.SingleplayerStartButton_clicked(e)
    70     local listbox = CEGUI.toListbox(winMgr:getWindow("orxonox/SingleplayerLevelListbox"))
    71     local choice = listbox:getFirstSelectedItem()
    72     if choice ~= nil then
    73         local index = listbox:getItemIndex(choice)
    74         local level = P.levelList[index+1]
    75         if level ~= nil then
    76             orxonox.execute("startGame " .. level:getXMLFilename())
    77             hideAllMenuSheets()
    78         end
     143    local level = P.SingleplayerGetSelectedLevel()
     144    if level ~= nil then
     145        orxonox.execute("startGame " .. level:getXMLFilename())
     146        hideAllMenuSheets()
    79147    end
    80148end
    81149
    82 function P.SingleplayerShowAll_clicked(e)
    83     local checkbox = tolua.cast(winMgr:getWindow("orxonox/SingleplayerShowAllCheckbox"), "CEGUI::Checkbox")
    84     local show = checkbox:isSelected()
    85     if show ~= P.showAll then
    86         P.showAll = show
    87         P.createLevelList()
    88    end
     150function P.SingleplayerConfigButton_clicked(e)
     151    local level = P.SingleplayerGetSelectedLevel()
     152    if level ~= nil then
     153        local configMenu = showMenuSheet("SingleplayerConfigMenu")
     154        configMenu:loadConfig(level)
     155    end
    89156end
    90157
     
    94161
    95162return P
    96 
Note: See TracChangeset for help on using the changeset viewer.