[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() |
---|
[9282] | 8 | orxonox.execute("set shipmodelsfile [open {../levels/templates/.shipmodels} w+]") |
---|
| 9 | orxonox.execute("foreach line [glob -directory ../levels/templates/ spaceship*] { regexp {.*/(.*)\\..*} $line matchall match1; puts $shipmodelsfile $match1 }") |
---|
| 10 | orxonox.execute("close $shipmodelsfile") |
---|
| 11 | P.createFilterTab("All Ships") |
---|
[9201] | 12 | end |
---|
[9045] | 13 | |
---|
[9201] | 14 | function P.createShipList() --generates list with tagged shipmodels |
---|
[9282] | 15 | P.shipList = {} |
---|
| 16 | file = io.open("../levels/templates/.shipmodels") |
---|
| 17 | if file ~= nil then |
---|
| 18 | for line in file:lines() do --checks if shipmodel is included in level file |
---|
| 19 | if selectedlevel:hasStartingShip(string.lower(line)) then |
---|
| 20 | P.shipList[#P.shipList+1] = string.lower(line) |
---|
| 21 | end |
---|
| 22 | end |
---|
| 23 | --file.close() -- TODO: investigate why close() seems to crash? |
---|
[9272] | 24 | end |
---|
[9045] | 25 | end |
---|
[9057] | 26 | |
---|
[9201] | 27 | function P.update() --updates listbox with found models |
---|
| 28 | P.createShipList() |
---|
[9045] | 29 | listbox:resetList() |
---|
[9201] | 30 | --orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
[9045] | 31 | local tabIndexes = {} |
---|
[9074] | 32 | for k,v in pairs(P.shipList) do |
---|
[9201] | 33 | --TODO: only add ship if is in the right filter tab |
---|
[9281] | 34 | --if tag == nil or v:hasStartingShip(tag) then |
---|
[9074] | 35 | local item = CEGUI.createListboxTextItem(v) |
---|
[9045] | 36 | item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush") |
---|
| 37 | listbox:addItem(item) |
---|
| 38 | table.insert(tabIndexes, k) |
---|
[9074] | 39 | --orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription()) |
---|
| 40 | --end |
---|
[9045] | 41 | end |
---|
| 42 | table.insert(P.activeTabIndexes, tabIndexes) |
---|
[9201] | 43 | end |
---|
| 44 | |
---|
| 45 | function P.createFilterTab(name) -- generates filter tab and list box, sets handler for selection changes |
---|
| 46 | tabName = "orxonox/ShipSelectionLevelTab" |
---|
| 47 | -- create new tab window with desired name |
---|
[9272] | 48 | listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName)) |
---|
[9201] | 49 | listbox:setText(name) |
---|
| 50 | listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}") |
---|
[9272] | 51 | --[[TODO: smaller list if image and description is implemented. |
---|
| 52 | listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}") --]] |
---|
[9201] | 53 | listbox:setProperty("UnifiedAreaRect", "{{0,0},{0,0},{1,0},{1,0}}") |
---|
| 54 | -- fill listbox with items |
---|
| 55 | P.update() |
---|
[9045] | 56 | -- listen to selection changes |
---|
| 57 | orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".ShipSelectionSelectionChanged") |
---|
| 58 | local tabControl = winMgr:getWindow("orxonox/ShipSelectionTabControl") |
---|
| 59 | orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".ShipSelectionSelectionChanged") |
---|
| 60 | if listbox:getItemCount() > 0 then |
---|
| 61 | tabControl:addChildWindow(tabName) |
---|
| 62 | end |
---|
| 63 | end |
---|
| 64 | |
---|
[9201] | 65 | function P.ShipSelectionGetSelectedModel() --returns selected model, if available. |
---|
[9045] | 66 | -- choose the active listbox |
---|
| 67 | local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/ShipSelectionTabControl")) |
---|
| 68 | local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) |
---|
| 69 | local choice = listbox:getFirstSelectedItem() |
---|
| 70 | if choice ~= nil then |
---|
| 71 | -- get the right tab and the right index |
---|
| 72 | local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1] |
---|
| 73 | local index = tabIndexes[listbox:getItemIndex(choice)+1] |
---|
[9157] | 74 | return P.shipList[index] |
---|
[9045] | 75 | else |
---|
| 76 | return nil |
---|
| 77 | end |
---|
| 78 | end |
---|
| 79 | |
---|
| 80 | function P.ShipSelectionSelectionChanged(e) |
---|
[9201] | 81 | --[[ TODO: Get image and description from template file |
---|
[9045] | 82 | local levelImage = winMgr:getWindow("orxonox/ShipSelectionLevelImage") |
---|
| 83 | local levelDescription = winMgr:getWindow("orxonox/ShipSelectionLevelDescription") |
---|
| 84 | local configButton = winMgr:getWindow("orxonox/ShipSelectionConfigButton") |
---|
[9157] | 85 | local level = P.ShipSelectionGetSelectedModel() |
---|
[9045] | 86 | if level ~= nil then |
---|
[9157] | 87 | --local levelXMLFilename = selectedlevel:getXMLFilename() |
---|
| 88 | --local imageName = selectedlevel:getScreenshot() |
---|
[9045] | 89 | -- set the screenshot and the description for the selected level |
---|
[9157] | 90 | --levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image") |
---|
| 91 | --levelDescription:setText(level:getDescription()) |
---|
[9045] | 92 | -- only enable config button for "gametype" levels |
---|
[9157] | 93 | --if level:hasTag("gametype") then |
---|
| 94 | -- configButton:setProperty("Disabled", "False") |
---|
| 95 | --else |
---|
| 96 | -- configButton:setProperty("Disabled", "True") |
---|
| 97 | --end |
---|
[9045] | 98 | else |
---|
| 99 | -- also take care of "no level selected" |
---|
| 100 | levelImage:setProperty("Image", nil) |
---|
| 101 | levelDescription:setText("") |
---|
| 102 | end |
---|
[9201] | 103 | --]] |
---|
[9045] | 104 | end |
---|
[9127] | 105 | |
---|
[9045] | 106 | function P.ShipSelectionStartButton_clicked(e) |
---|
| 107 | |
---|
[9201] | 108 | if (selectedlevel ~= nil and P.ShipSelectionGetSelectedModel() ~= nil) then |
---|
[9281] | 109 | selectedlevel:selectStartingShip(P.ShipSelectionGetSelectedModel()) |
---|
[9127] | 110 | orxonox.execute("startGame " .. "_temp.oxw") |
---|
[9046] | 111 | hideAllMenuSheets() |
---|
| 112 | else |
---|
[9272] | 113 | orxonox.execute("orxout user_warning no ship model selected or no tagged shipmodel installed") |
---|
[9045] | 114 | end |
---|
| 115 | end |
---|
| 116 | |
---|
[9201] | 117 | --[[ TODO: function P.ShipSelectionConfigButton_clicked(e) |
---|
| 118 | |
---|
[9157] | 119 | local level = P.ShipSelectionGetSelectedModel() |
---|
[9045] | 120 | if level ~= nil then |
---|
| 121 | local configMenu = showMenuSheet("ShipSelectionConfigMenu") |
---|
| 122 | configMenu:loadConfig(level) |
---|
| 123 | end |
---|
[9201] | 124 | end |
---|
[9045] | 125 | --]] |
---|
| 126 | |
---|
[9201] | 127 | |
---|
[9045] | 128 | function P.ShipSelectionBackButton_clicked(e) |
---|
[9046] | 129 | orxonox.execute("keyESC") |
---|
[9272] | 130 | end |
---|
[9045] | 131 | |
---|
| 132 | return P |
---|