Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/SingleplayerMenu.lua @ 12106

Last change on this file since 12106 was 11797, checked in by landauf, 7 years ago

updated CreditsMenu.lua and SingleplayerMenu.lua to cegui 0.8

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