[9045] | 1 | -- ShipSelectionMenu.lua |
---|
| 2 | |
---|
| 3 | local P = createMenuSheet("ShipSelectionMenu") |
---|
| 4 | P.activeTabIndexes = {} |
---|
| 5 | P.scrollbarWidth = 13 |
---|
[9074] | 6 | P.shipList = {} |
---|
[9045] | 7 | function P.onLoad() |
---|
[9074] | 8 | --orxonox.execute("orxout internal_warning Ships= " .. selectedlevel:hasShip("abcdef")) |
---|
| 9 | local dircmd = "ls ../levels/templates/ -l | awk '{print $9}' | grep \"spaceship\" | sed -e 's/\\.[a-zA-Z]*$//'" -- go to spaceships folder and generate a list of installed shipmodels. |
---|
| 10 | os.execute(dircmd .. " > ../levels/templates/.shipmodels") --saves output in a textfile |
---|
| 11 | --[[ Program a Windows Version here: |
---|
| 12 | if string.sub(package.config,1,1) == '\\' then |
---|
| 13 | -- Windows |
---|
| 14 | dircmd = "dir /b/s" |
---|
| 15 | end]] |
---|
[9045] | 16 | |
---|
[9074] | 17 | P.shipList = {} |
---|
| 18 | --[[for f in io.lines("../levels/templates/.shipmodels") do |
---|
| 19 | if selectedlevel:hasShip(f) then |
---|
| 20 | P.shipList[#P.shipList+1] = f |
---|
| 21 | table.insert(P.shipList, f) |
---|
| 22 | end |
---|
| 23 | end--]] |
---|
| 24 | P.shipList[1]="spaceshipAssff" |
---|
| 25 | P.shipList[2]="spaceshipGhost" |
---|
| 26 | P.shipList[3]="spaceshipPirate" |
---|
| 27 | P.createFilterTab("Show All") |
---|
| 28 | --[[list = winMgr:createWindow("MenuWidgets/Listbox", "listbox") |
---|
| 29 | item = CEGUI.createListboxTextItem("Text") |
---|
| 30 | CEGUI.toListbox(list):addItem(item) |
---|
| 31 | list:enable()--]] |
---|
[9045] | 32 | end |
---|
[9057] | 33 | |
---|
[9074] | 34 | function P.createShipList() |
---|
| 35 | |
---|
[9057] | 36 | |
---|
[9045] | 37 | end |
---|
| 38 | |
---|
[9057] | 39 | |
---|
| 40 | |
---|
[9074] | 41 | function P.createFilterTab(name) |
---|
| 42 | |
---|
| 43 | --[[-- create unique tab window name |
---|
| 44 | orxonox.execute("orxout user_warning test") |
---|
| 45 | local tabName = "orxonox/SchipSelectionLevelTab" |
---|
| 46 | -- create new tab window with desired name |
---|
| 47 | local listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName)) |
---|
| 48 | listbox:setText(name) |
---|
| 49 | listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}") |
---|
| 50 | listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}") |
---|
| 51 | -- fill listbox with items |
---|
| 52 | listbox:resetList() |
---|
| 53 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
| 54 | local preselect = "spaceshipAssff" |
---|
| 55 | local tabIndexes = {} |
---|
| 56 | for k,v in pairs(P.shipList) do |
---|
| 57 | --for i = 1 ,#P.shipList,1 do |
---|
| 58 | -- only add level if it has desired tag |
---|
| 59 | --if v:hasShip(Ship) then |
---|
| 60 | local item = CEGUI.createListboxTextItem("asbsergse") |
---|
| 61 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 62 | listbox:addItem(item) |
---|
| 63 | table.insert(tabIndexes, k) |
---|
| 64 | if v:getXMLFilename() == preselect then |
---|
| 65 | listbox:setItemSelectState(item, true) |
---|
| 66 | end |
---|
| 67 | --orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription()) |
---|
| 68 | -- end |
---|
| 69 | end |
---|
| 70 | table.insert(P.activeTabIndexes, tabIndexes) |
---|
| 71 | -- listen to selection changes |
---|
| 72 | orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".SingleplayerSelectionChanged") |
---|
| 73 | local tabControl = winMgr:getWindow("orxonox/SingleplayerTabControl") |
---|
| 74 | orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".SingleplayerSelectionChanged") |
---|
| 75 | if listbox:getItemCount() > 0 then |
---|
| 76 | tabControl:addChildWindow(tabName) |
---|
| 77 | end--]] |
---|
[9045] | 78 | -- create unique tab window name |
---|
[9074] | 79 | |
---|
[9045] | 80 | local tabName = "orxonox/ShipSelectionLevelTab" |
---|
| 81 | -- create new tab window with desired name |
---|
| 82 | local listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName)) |
---|
| 83 | listbox:setText(name) |
---|
| 84 | listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}") |
---|
| 85 | listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}") |
---|
| 86 | -- fill listbox with items |
---|
| 87 | listbox:resetList() |
---|
| 88 | orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
| 89 | local preselect = orxonox.LevelManager:getInstance():getDefaultLevel() |
---|
| 90 | local tabIndexes = {} |
---|
[9074] | 91 | for k,v in pairs(P.shipList) do |
---|
[9045] | 92 | -- only add level if it has desired tag |
---|
[9074] | 93 | --if tag == nil or v:hasShip(tag) then |
---|
| 94 | local item = CEGUI.createListboxTextItem(v) |
---|
[9045] | 95 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 96 | listbox:addItem(item) |
---|
| 97 | table.insert(tabIndexes, k) |
---|
[9074] | 98 | --[[if v:getXMLFilename() == preselect then |
---|
[9045] | 99 | listbox:setItemSelectState(item, true) |
---|
[9074] | 100 | end--]] |
---|
| 101 | --orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription()) |
---|
| 102 | --end |
---|
[9045] | 103 | end |
---|
| 104 | table.insert(P.activeTabIndexes, tabIndexes) |
---|
| 105 | -- listen to selection changes |
---|
| 106 | orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".ShipSelectionSelectionChanged") |
---|
| 107 | local tabControl = winMgr:getWindow("orxonox/ShipSelectionTabControl") |
---|
| 108 | orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".ShipSelectionSelectionChanged") |
---|
| 109 | if listbox:getItemCount() > 0 then |
---|
| 110 | tabControl:addChildWindow(tabName) |
---|
| 111 | end |
---|
| 112 | end |
---|
| 113 | |
---|
| 114 | function P.ShipSelectionGetSelectedLevel() |
---|
| 115 | -- choose the active listbox |
---|
| 116 | local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/ShipSelectionTabControl")) |
---|
| 117 | local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) |
---|
| 118 | local choice = listbox:getFirstSelectedItem() |
---|
| 119 | if choice ~= nil then |
---|
| 120 | -- get the right tab and the right index |
---|
| 121 | local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1] |
---|
| 122 | local index = tabIndexes[listbox:getItemIndex(choice)+1] |
---|
| 123 | return P.levelList[index] |
---|
| 124 | else |
---|
| 125 | return nil |
---|
| 126 | end |
---|
| 127 | end |
---|
| 128 | |
---|
| 129 | function P.ShipSelectionSelectionChanged(e) |
---|
| 130 | local levelImage = winMgr:getWindow("orxonox/ShipSelectionLevelImage") |
---|
| 131 | local levelDescription = winMgr:getWindow("orxonox/ShipSelectionLevelDescription") |
---|
| 132 | local configButton = winMgr:getWindow("orxonox/ShipSelectionConfigButton") |
---|
| 133 | local level = P.ShipSelectionGetSelectedLevel() |
---|
| 134 | if level ~= nil then |
---|
| 135 | local levelXMLFilename = level:getXMLFilename() |
---|
| 136 | local imageName = level:getScreenshot() |
---|
| 137 | -- set the screenshot and the description for the selected level |
---|
| 138 | levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image") |
---|
| 139 | levelDescription:setText(level:getDescription()) |
---|
| 140 | -- only enable config button for "gametype" levels |
---|
| 141 | if level:hasTag("gametype") then |
---|
| 142 | configButton:setProperty("Disabled", "False") |
---|
| 143 | else |
---|
| 144 | configButton:setProperty("Disabled", "True") |
---|
| 145 | end |
---|
| 146 | else |
---|
| 147 | -- also take care of "no level selected" |
---|
| 148 | levelImage:setProperty("Image", nil) |
---|
| 149 | levelDescription:setText("") |
---|
| 150 | configButton:setProperty("Disabled", "True") |
---|
| 151 | end |
---|
| 152 | end |
---|
| 153 | --]] |
---|
| 154 | function P.ShipSelectionStartButton_clicked(e) |
---|
| 155 | |
---|
[9074] | 156 | if selectedlevel ~= nil then |
---|
| 157 | orxonox.execute("startGame " .. selectedlevel:getXMLFilename()) |
---|
[9046] | 158 | hideAllMenuSheets() |
---|
| 159 | else |
---|
| 160 | orxonox.execute("keyESC") |
---|
[9045] | 161 | end |
---|
| 162 | end |
---|
| 163 | |
---|
| 164 | function P.ShipSelectionConfigButton_clicked(e) |
---|
| 165 | --[[ |
---|
| 166 | local level = P.ShipSelectionGetSelectedLevel() |
---|
| 167 | if level ~= nil then |
---|
| 168 | local configMenu = showMenuSheet("ShipSelectionConfigMenu") |
---|
| 169 | configMenu:loadConfig(level) |
---|
| 170 | end |
---|
| 171 | --]] |
---|
| 172 | end |
---|
| 173 | |
---|
| 174 | function P.ShipSelectionBackButton_clicked(e) |
---|
[9074] | 175 | --hideAllMenuSheets() |
---|
[9046] | 176 | orxonox.execute("keyESC") |
---|
[9045] | 177 | end |
---|
| 178 | |
---|
| 179 | return P |
---|