Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/menue/data/gui/scripts/SingleplayerMenu.lua @ 9215

Last change on this file since 9215 was 8964, checked in by baermatt, 13 years ago

Cleaned up the miscellaneous menu and added possibility to cancel.

  • Property svn:eol-style set to native
File size: 6.0 KB
RevLine 
[6363]1-- SingleplayerMenu.lua
2
[6746]3local P = createMenuSheet("SingleplayerMenu")
[6363]4
[7648]5P.levelList = {}
[8912]6P.activeTabIndexes = {}
7P.scrollbarWidth = 13
[7648]8
[6746]9function P.onLoad()
[8894]10    P.createLevelList()
11   
12    -- create tabs with desired tab as argument (nil for all)
[8931]13    P.createFilterTab("Gametypes", "gametype")
[8927]14    P.createFilterTab("Missions", "mission")
[8931]15    P.createFilterTab("Minigames", "minigame")
[8894]16    P.createFilterTab("Showcases", "showcase")
17    P.createFilterTab("Presentations", "presentation")
[8927]18    P.createFilterTab("Tests", "test")
[8912]19    P.createFilterTab("Show All", nil)
[8927]20   
[8964]21    -- update description and screenshot boxes
22    P.SingleplayerSelectionChanged()
[8927]23   
[8912]24    --buttons are arranged in a 1x3 matrix
[8079]25    P:setButton(1, 1, {
[7689]26            ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"),
[8079]27            ["callback"]  = P.SingleplayerStartButton_clicked
28    })
[7689]29
[8079]30    P:setButton(1, 2, {
[8912]31            ["button"] = winMgr:getWindow("orxonox/SingleplayerConfigButton"),
32            ["callback"]  = P.SingleplayerConfigButton_clicked
33    })
34
35    P:setButton(1, 3, {
[7689]36            ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"),
[8079]37            ["callback"]  = P.SingleplayerBackButton_clicked
38    })
[7648]39end
40
[8894]41function P.createLevelList()
[7648]42    P.levelList = {}
43    local size = orxonox.LevelManager:getInstance():getNumberOfLevels()
[6363]44    local index = 0
[7648]45    local level = nil
46    while index < size do
47        level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
48        if level ~= nil then
[8912]49            local levelXMLFilename = level:getXMLFilename()
[8964]50            -- create an imageset for each screenshot
[8912]51            local imageName = level:getScreenshot()
52            if imageName ~= "" then
53                CEGUI.ImagesetManager:getSingleton():createImagesetFromImageFile(levelXMLFilename..imageName, imageName)
54            else
[8914]55                CEGUI.ImagesetManager:getSingleton():createImagesetFromImageFile(levelXMLFilename..imageName, "noscreenshot.png")
[8912]56            end
[8894]57            table.insert(P.levelList, level)
[7648]58        end
59        index = index + 1
[6363]60    end
[8894]61end
[8706]62
[8894]63function P.createFilterTab(name, tag)
64    -- create unique tab window name
[8912]65    local tabName = "orxonox/SingleplayerLevelTab"
[8894]66    if tag ~= nil then
67        tabName = tabName..tag
68    end
[8927]69    -- create new tab window with desired name
[8912]70    local listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName))
71    listbox:setText(name)
72    listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}")
[8927]73    listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}")
[8894]74    -- fill listbox with items
75    listbox:resetList()
76    orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
77    local preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
[8912]78    local tabIndexes = {}
[7648]79    for k,v in pairs(P.levelList) do
[8894]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)
[8912]85            table.insert(tabIndexes, k)
[8894]86            if v:getXMLFilename() == preselect then
87                listbox:setItemSelectState(item, true)
88            end
89            orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription())
[6363]90        end
91    end
[8912]92    table.insert(P.activeTabIndexes, tabIndexes)
[8964]93    -- listen to selection changes
94    orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".SingleplayerSelectionChanged")
[8927]95    local tabControl = winMgr:getWindow("orxonox/SingleplayerTabControl")
[8964]96    orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".SingleplayerSelectionChanged")
[8927]97    if listbox:getItemCount() > 0 then
98        tabControl:addChildWindow(tabName)
99    end
[6363]100end
101
[8912]102function P.SingleplayerGetSelectedLevel()
[8894]103    -- choose the active listbox
104    local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/SingleplayerTabControl"))
105    local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex()))
[7648]106    local choice = listbox:getFirstSelectedItem()
107    if choice ~= nil then
[8964]108        -- get the right tab and the right index
[8912]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
[6363]114    end
115end
116
[8964]117function P.SingleplayerSelectionChanged(e)
[8927]118    local levelImage = winMgr:getWindow("orxonox/SingleplayerLevelImage")
119    local levelDescription = winMgr:getWindow("orxonox/SingleplayerLevelDescription")
[8945]120    local configButton = winMgr:getWindow("orxonox/SingleplayerConfigButton")
[8912]121    local level = P.SingleplayerGetSelectedLevel()
122    if level ~= nil then
123        local levelXMLFilename = level:getXMLFilename()
124        local imageName = level:getScreenshot()
[8964]125        -- set the screenshot and the description for the selected level
[8912]126        levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image")
127        levelDescription:setText(level:getDescription())
[8964]128        -- only enable config button for "gametype" levels
[8945]129        if level:hasTag("gametype") then
130            configButton:setProperty("Disabled", "False")
131        else
132            configButton:setProperty("Disabled", "True")
133        end
[8927]134    else
[8964]135        -- also take care of "no level selected"
[8927]136        levelImage:setProperty("Image", nil)
137        levelDescription:setText("")
[8945]138        configButton:setProperty("Disabled", "True")
[8912]139    end
140end
141
142function P.SingleplayerStartButton_clicked(e)
143    local level = P.SingleplayerGetSelectedLevel()
144    if level ~= nil then
145        orxonox.execute("startGame " .. level:getXMLFilename())
146        hideAllMenuSheets()
147    end
148end
149
150function P.SingleplayerConfigButton_clicked(e)
[8938]151    local level = P.SingleplayerGetSelectedLevel()
152    if level ~= nil then
[8964]153        local configMenu = showMenuSheet("SingleplayerConfigMenu")
154        configMenu:loadConfig(level)
[8938]155    end
[8912]156end
157
[6363]158function P.SingleplayerBackButton_clicked(e)
[6746]159    hideMenuSheet(P.name)
[6363]160end
161
162return P
Note: See TracBrowser for help on using the repository browser.