[6363] | 1 | -- SingleplayerMenu.lua |
---|
| 2 | |
---|
[6746] | 3 | local P = createMenuSheet("SingleplayerMenu") |
---|
[9348] | 4 | P.loadAlong = {"ShipSelectionMenu"} |
---|
[7648] | 5 | P.levelList = {} |
---|
[9016] | 6 | P.activeTabIndexes = {} |
---|
| 7 | P.scrollbarWidth = 13 |
---|
[9348] | 8 | selectedlevel = {} -- level for ship selection |
---|
[7648] | 9 | |
---|
[6746] | 10 | function 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 | |
---|
[9016] | 25 | --buttons are arranged in a 1x3 matrix |
---|
[8079] | 26 | P:setButton(1, 1, { |
---|
[7689] | 27 | ["button"] = winMgr:getWindow("orxonox/SingleplayerStartButton"), |
---|
[8079] | 28 | ["callback"] = P.SingleplayerStartButton_clicked |
---|
| 29 | }) |
---|
[7689] | 30 | |
---|
[8079] | 31 | P:setButton(1, 2, { |
---|
[9016] | 32 | ["button"] = winMgr:getWindow("orxonox/SingleplayerConfigButton"), |
---|
| 33 | ["callback"] = P.SingleplayerConfigButton_clicked |
---|
| 34 | }) |
---|
| 35 | |
---|
| 36 | P:setButton(1, 3, { |
---|
[7689] | 37 | ["button"] = winMgr:getWindow("orxonox/SingleplayerBackButton"), |
---|
[8079] | 38 | ["callback"] = P.SingleplayerBackButton_clicked |
---|
| 39 | }) |
---|
[7648] | 40 | end |
---|
| 41 | |
---|
| 42 | function P.createLevelList() |
---|
| 43 | P.levelList = {} |
---|
| 44 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
[6363] | 45 | local index = 0 |
---|
[7648] | 46 | local level = nil |
---|
| 47 | while index < size do |
---|
| 48 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
[9348] | 49 | if (level ~= nil and level:getXMLFilename() ~= "_temp.oxw") then |
---|
[9016] | 50 | local levelXMLFilename = level:getXMLFilename() |
---|
| 51 | -- create an imageset for each screenshot |
---|
| 52 | local imageName = level:getScreenshot() |
---|
| 53 | if imageName ~= "" then |
---|
[9050] | 54 | CEGUI.ImagesetManager:getSingleton():createFromImageFile(levelXMLFilename..imageName, imageName) |
---|
[9016] | 55 | else |
---|
[9050] | 56 | CEGUI.ImagesetManager:getSingleton():createFromImageFile(levelXMLFilename..imageName, "noscreenshot.png") |
---|
[7648] | 57 | end |
---|
[9016] | 58 | table.insert(P.levelList, level) |
---|
[7648] | 59 | end |
---|
| 60 | index = index + 1 |
---|
[6363] | 61 | end |
---|
[9016] | 62 | end |
---|
[8706] | 63 | |
---|
[9016] | 64 | function P.createFilterTab(name, tag) |
---|
| 65 | -- create unique tab window name |
---|
| 66 | local tabName = "orxonox/SingleplayerLevelTab" |
---|
| 67 | if tag ~= nil then |
---|
| 68 | tabName = tabName..tag |
---|
| 69 | end |
---|
| 70 | -- create new tab window with desired name |
---|
| 71 | local listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName)) |
---|
| 72 | listbox:setText(name) |
---|
| 73 | listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}") |
---|
| 74 | listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}") |
---|
| 75 | -- fill listbox with items |
---|
| 76 | listbox:resetList() |
---|
| 77 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
| 78 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
| 79 | local tabIndexes = {} |
---|
[7648] | 80 | for k,v in pairs(P.levelList) do |
---|
[9016] | 81 | -- only add level if it has desired tag |
---|
| 82 | if tag == nil or v:hasTag(tag) then |
---|
| 83 | local item = CEGUI.createListboxTextItem(v:getName()) |
---|
| 84 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 85 | listbox:addItem(item) |
---|
| 86 | table.insert(tabIndexes, k) |
---|
| 87 | if v:getXMLFilename() == preselect then |
---|
| 88 | listbox:setItemSelectState(item, true) |
---|
| 89 | end |
---|
| 90 | orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription()) |
---|
[6363] | 91 | end |
---|
| 92 | end |
---|
[9016] | 93 | table.insert(P.activeTabIndexes, tabIndexes) |
---|
| 94 | -- listen to selection changes |
---|
| 95 | orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".SingleplayerSelectionChanged") |
---|
| 96 | local tabControl = winMgr:getWindow("orxonox/SingleplayerTabControl") |
---|
| 97 | orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".SingleplayerSelectionChanged") |
---|
| 98 | if listbox:getItemCount() > 0 then |
---|
| 99 | tabControl:addChildWindow(tabName) |
---|
| 100 | end |
---|
[6363] | 101 | end |
---|
| 102 | |
---|
[9016] | 103 | function P.SingleplayerGetSelectedLevel() |
---|
| 104 | -- choose the active listbox |
---|
| 105 | local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/SingleplayerTabControl")) |
---|
| 106 | local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) |
---|
[7648] | 107 | local choice = listbox:getFirstSelectedItem() |
---|
| 108 | if choice ~= nil then |
---|
[9016] | 109 | -- get the right tab and the right index |
---|
| 110 | local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1] |
---|
| 111 | local index = tabIndexes[listbox:getItemIndex(choice)+1] |
---|
| 112 | return P.levelList[index] |
---|
| 113 | else |
---|
| 114 | return nil |
---|
| 115 | end |
---|
| 116 | end |
---|
| 117 | |
---|
| 118 | function P.SingleplayerSelectionChanged(e) |
---|
| 119 | local levelImage = winMgr:getWindow("orxonox/SingleplayerLevelImage") |
---|
| 120 | local levelDescription = winMgr:getWindow("orxonox/SingleplayerLevelDescription") |
---|
| 121 | local configButton = winMgr:getWindow("orxonox/SingleplayerConfigButton") |
---|
| 122 | local level = P.SingleplayerGetSelectedLevel() |
---|
| 123 | if level ~= nil then |
---|
| 124 | local levelXMLFilename = level:getXMLFilename() |
---|
| 125 | local imageName = level:getScreenshot() |
---|
| 126 | -- set the screenshot and the description for the selected level |
---|
| 127 | levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image") |
---|
| 128 | levelDescription:setText(level:getDescription()) |
---|
| 129 | -- only enable config button for "gametype" levels |
---|
| 130 | if level:hasTag("gametype") then |
---|
| 131 | configButton:setProperty("Disabled", "False") |
---|
| 132 | else |
---|
| 133 | configButton:setProperty("Disabled", "True") |
---|
[7648] | 134 | end |
---|
[9016] | 135 | else |
---|
| 136 | -- also take care of "no level selected" |
---|
[9251] | 137 | levelImage:setProperty("Image", "") |
---|
[9016] | 138 | levelDescription:setText("") |
---|
| 139 | configButton:setProperty("Disabled", "True") |
---|
[6363] | 140 | end |
---|
| 141 | end |
---|
| 142 | |
---|
[9016] | 143 | function P.SingleplayerStartButton_clicked(e) |
---|
[9348] | 144 | selectedlevel = P.SingleplayerGetSelectedLevel() |
---|
| 145 | if selectedlevel ~= nil then |
---|
| 146 | if selectedlevel:hasTag("shipselection") then |
---|
| 147 | local shipSelectionMenu = showMenuSheet("ShipSelectionMenu", true) |
---|
| 148 | shipSelectionMenu:update() |
---|
| 149 | else |
---|
| 150 | orxonox.execute("startGame " .. selectedlevel:getXMLFilename()) |
---|
| 151 | hideAllMenuSheets() |
---|
| 152 | end |
---|
[9016] | 153 | end |
---|
[7648] | 154 | end |
---|
| 155 | |
---|
[9016] | 156 | function P.SingleplayerConfigButton_clicked(e) |
---|
| 157 | local level = P.SingleplayerGetSelectedLevel() |
---|
| 158 | if level ~= nil then |
---|
| 159 | local configMenu = showMenuSheet("SingleplayerConfigMenu") |
---|
| 160 | configMenu:loadConfig(level) |
---|
| 161 | end |
---|
| 162 | end |
---|
| 163 | |
---|
[6363] | 164 | function P.SingleplayerBackButton_clicked(e) |
---|
[6746] | 165 | hideMenuSheet(P.name) |
---|
[6363] | 166 | end |
---|
| 167 | |
---|
| 168 | return P |
---|