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