[12177] | 1 | -- SOBSelectionMenu.lua |
---|
| 2 | |
---|
| 3 | local P = createMenuSheet("SOBSelectionMenu") |
---|
| 4 | P.activeTabIndexes = {} |
---|
| 5 | P.scrollbarWidth = 13 |
---|
| 6 | P.SOBList = {} |
---|
| 7 | selectedlevel = {} |
---|
| 8 | function P.onLoad() |
---|
| 9 | --orxonox.execute("set orxobrosfile [open {../levels/SOBlevels/.orxobroslevels} w+]") |
---|
| 10 | --orxonox.execute("foreach line [glob -directory ../levels/SOBlevels/`SOB*] { regexp {.*/(.*)\\..*} $line matchall match1; puts $orxobrosfile $match1 }") |
---|
| 11 | --orxonox.execute("close $orxobrosfile") |
---|
| 12 | P.createFilterTab("SuperOrxoBros Levels") |
---|
| 13 | end |
---|
| 14 | |
---|
| 15 | function P.createSOBList() --generates list with tagged shipmodels |
---|
| 16 | P.SOBList = {} |
---|
| 17 | file = io.open("../levels/SOBlevels/.orxobroslevels") |
---|
| 18 | if file ~= nil then |
---|
| 19 | for line in file:lines() do --checks if shipmodel is included in level file |
---|
| 20 | P.SOBList[#P.SOBList+1] = string.upper(line) |
---|
| 21 | end |
---|
| 22 | end |
---|
| 23 | -- file.close() -- TODO: investigate why close() seems to crash? |
---|
| 24 | end |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | function P.update() --updates listbox with found models |
---|
| 28 | P.createSOBList() |
---|
| 29 | listbox:resetList() |
---|
| 30 | --orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) |
---|
| 31 | local tabIndexes = {} |
---|
| 32 | for k,v in pairs(P.SOBList) do |
---|
| 33 | --TODO: only add ship if is in the right filter tab |
---|
| 34 | --if tag == nil or v:hasStartingShip(tag) then |
---|
| 35 | local item = CEGUI.createListboxTextItem(v) |
---|
| 36 | item:setSelectionBrushImage(menuImageSet .. "/MultiListSelectionBrush") |
---|
| 37 | listbox:addItem(item) |
---|
| 38 | table.insert(tabIndexes, k) |
---|
| 39 | --orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription()) |
---|
| 40 | --end |
---|
| 41 | end |
---|
| 42 | table.insert(P.activeTabIndexes, tabIndexes) |
---|
| 43 | end |
---|
| 44 | |
---|
| 45 | function P.createFilterTab(name) -- generates filter tab and list box, sets handler for selection changes |
---|
| 46 | tabName = "SOBSelectionLevelTab" |
---|
| 47 | -- create new tab window with desired name |
---|
| 48 | listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName)) |
---|
| 49 | listbox:setText(name) |
---|
| 50 | listbox:setProperty("MaxSize", "{{1,0},{1,0}}") |
---|
| 51 | --[[TODO: smaller list if image and description is implemented. |
---|
| 52 | listbox:setProperty("Area", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}") --]] |
---|
| 53 | listbox:setProperty("Area", "{{0,0},{0,0},{1,0},{1,0}}") |
---|
| 54 | -- fill listbox with items |
---|
| 55 | P.update() |
---|
| 56 | -- listen to selection changes |
---|
| 57 | orxonox.GUIManager:subscribeEventHelper(listbox, "SelectionChanged", P.name..".SOBSelectionSelectionChanged") |
---|
| 58 | local tabControl = P.window:getChild("SOBSelectionWindow/SOBSelectionTabControl") |
---|
| 59 | orxonox.GUIManager:subscribeEventHelper(tabControl, "SelectionChanged", P.name..".SOBSelectionSelectionChanged") |
---|
| 60 | if listbox:getItemCount() > 0 then |
---|
| 61 | tabControl:addChild(listbox) |
---|
| 62 | end |
---|
| 63 | end |
---|
| 64 | |
---|
| 65 | function P.SOBSelectionGetSelectedModel() --returns selected model, if available. |
---|
| 66 | -- choose the active listbox |
---|
| 67 | local tabControl = CEGUI.toTabControl(P.window:getChild("SOBSelectionWindow/SOBSelectionTabControl")) |
---|
| 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] |
---|
| 74 | return P.SOBList[index] |
---|
| 75 | else |
---|
| 76 | return nil |
---|
| 77 | end |
---|
| 78 | end |
---|
| 79 | |
---|
| 80 | function P.SOBSelectionGetSelectedLevel() |
---|
| 81 | -- choose the active listbox |
---|
| 82 | local tabControl = CEGUI.toTabControl(P.window:getChild("SOBSelectionWindow/SOBSelectionTabControl")) |
---|
| 83 | local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) |
---|
| 84 | local choice = listbox:getFirstSelectedItem() |
---|
| 85 | if choice ~= nil then |
---|
| 86 | -- get the right tab and the right index |
---|
| 87 | local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1] |
---|
| 88 | local index = tabIndexes[listbox:getItemIndex(choice)+1] |
---|
| 89 | return P.SOBList[index] |
---|
| 90 | else |
---|
| 91 | return nil |
---|
| 92 | end |
---|
| 93 | end |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | function P.SOBSelectionSelectionChanged(e) |
---|
| 97 | --[[ TODO: Get image and description from template file |
---|
| 98 | local levelImage = P.window:getChild("orxonox/ShipSelectionLevelImage") |
---|
| 99 | local levelDescription = P.window:getChild("orxonox/ShipSelectionLevelDescription") |
---|
| 100 | local configButton = P.window:getChild("orxonox/ShipSelectionConfigButton") |
---|
| 101 | local level = P.ShipSelectionGetSelectedModel() |
---|
| 102 | if level ~= nil then |
---|
| 103 | --local levelXMLFilename = selectedlevel:getXMLFilename() |
---|
| 104 | --local imageName = selectedlevel:getScreenshot() |
---|
| 105 | -- set the screenshot and the description for the selected level |
---|
| 106 | --levelImage:setProperty("Image", levelXMLFilename..imageName.."/full_image") |
---|
| 107 | --levelDescription:setText(level:getDescription()) |
---|
| 108 | -- only enable config button for "gametype" levels |
---|
| 109 | --if level:hasTag("gametype") then |
---|
| 110 | -- configButton:setProperty("Disabled", "False") |
---|
| 111 | --else |
---|
| 112 | -- configButton:setProperty("Disabled", "True") |
---|
| 113 | --end |
---|
| 114 | else |
---|
| 115 | -- also take care of "no level selected" |
---|
| 116 | levelImage:setProperty("Image", nil) |
---|
| 117 | levelDescription:setText("") |
---|
| 118 | end |
---|
| 119 | --]] |
---|
| 120 | end |
---|
| 121 | |
---|
| 122 | function P.SOBSelectionStartButton_clicked(e) |
---|
| 123 | --selectedlevel = P.SOBSelectionGetSelectedModel |
---|
| 124 | --if (selectedlevel ~= nil and P.SOBSelectionGetSelectedModel() ~= nil) then |
---|
| 125 | -- orxonox.execute("startGame " .. selectedlevel:getXMLFilename()) |
---|
| 126 | -- hideAllMenuSheets() |
---|
| 127 | if (P.SOBSelectionGetSelectedModel() == "SOB1") then |
---|
| 128 | orxonox.execute("startGame " .. "SOBlevels/SOB1.oxw") |
---|
| 129 | hideAllMenuSheets() |
---|
| 130 | elseif (P.SOBSelectionGetSelectedModel() == "SOB2") then |
---|
| 131 | orxonox.execute("startGame " .. "SOBlevels/SOB2.oxw") |
---|
| 132 | hideAllMenuSheets() |
---|
| 133 | elseif (P.SOBSelectionGetSelectedModel() == "SOB3") then |
---|
| 134 | orxonox.execute("startGame " .. "SOBlevels/SOB3.oxw") |
---|
| 135 | hideAllMenuSheets() |
---|
| 136 | elseif (P.SOBSelectionGetSelectedModel() == "SOB4") then |
---|
| 137 | orxonox.execute("startGame " .. "SOBlevels/SOB4.oxw") |
---|
| 138 | hideAllMenuSheets() |
---|
| 139 | elseif (P.SOBSelectionGetSelectedModel() == "SOB5") then |
---|
| 140 | orxonox.execute("startGame " .. "SOBlevels/SOB5.oxw") |
---|
| 141 | hideAllMenuSheets() |
---|
| 142 | elseif (P.SOBSelectionGetSelectedModel() == "SOB6") then |
---|
| 143 | orxonox.execute("startGame " .. "SOBlevels/SOB6.oxw") |
---|
| 144 | hideAllMenuSheets() |
---|
| 145 | else |
---|
| 146 | -- orxonox.execute(P.SOBSelectionGetSelectedModel) |
---|
| 147 | orxonox.execute("orxout user_warning no ship model selected or no tagged shipmodel installed") |
---|
| 148 | end |
---|
| 149 | end |
---|
| 150 | |
---|
| 151 | --[[ TODO: function P.ShipSelectionConfigButton_clicked(e) |
---|
| 152 | |
---|
| 153 | local level = P.ShipSelectionGetSelectedModel() |
---|
| 154 | if level ~= nil then |
---|
| 155 | local configMenu = showMenuSheet("ShipSelectionConfigMenu") |
---|
| 156 | configMenu:loadConfig(level) |
---|
| 157 | end |
---|
| 158 | end |
---|
| 159 | --]] |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | function P.SOBSelectionBackButton_clicked(e) |
---|
| 163 | orxonox.execute("keyESC") |
---|
| 164 | end |
---|
| 165 | |
---|
| 166 | return P |
---|
| 167 | |
---|
| 168 | |
---|