-- SOBSelectionMenu.lua local P = createMenuSheet("SOBSelectionMenu") P.activeTabIndexes = {} P.scrollbarWidth = 13 P.SOBList = {} selectedlevel = {} function P.onLoad() --orxonox.execute("set orxobrosfile [open {../levels/SOBlevels/.orxobroslevels} w+]") --orxonox.execute("foreach line [glob -directory ../levels/SOBlevels/`SOB*] { regexp {.*/(.*)\\..*} $line matchall match1; puts $orxobrosfile $match1 }") --orxonox.execute("close $orxobrosfile") P.createFilterTab("SuperOrxoBros Levels") end function P.createSOBList() --generates list with tagged shipmodels P.SOBList = {} file = io.open("../levels/SOBlevels/.orxobroslevels") if file ~= nil then for line in file:lines() do --checks if shipmodel is included in level file P.SOBList[#P.SOBList+1] = string.upper(line) end end -- file.close() -- TODO: investigate why close() seems to crash? end function P.update() --updates listbox with found models P.createSOBList() listbox:resetList() --orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true) local tabIndexes = {} for k,v in pairs(P.SOBList) do --TODO: only add ship if is in the right filter tab --if tag == nil or v:hasStartingShip(tag) then local item = CEGUI.createListboxTextItem(v) item:setSelectionBrushImage(menuImageSet .. "/MultiListSelectionBrush") listbox:addItem(item) table.insert(tabIndexes, k) --orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription()) --end end table.insert(P.activeTabIndexes, tabIndexes) end function P.createFilterTab(name) -- generates filter tab and list box, sets handler for selection changes tabName = "SOBSelectionLevelTab" -- create new tab window with desired name listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName)) listbox:setText(name) listbox:setProperty("MaxSize", "{{1,0},{1,0}}") --[[TODO: smaller list if image and description is implemented. listbox:setProperty("Area", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}") --]] listbox:setProperty("Area", "{{0,0},{0,0},{1,0},{1,0}}") -- fill listbox with items P.update() -- listen to selection changes orxonox.GUIManager:subscribeEventHelper(listbox, "SelectionChanged", P.name..".SOBSelectionSelectionChanged") local tabControl = P.window:getChild("SOBSelectionWindow/SOBSelectionTabControl") orxonox.GUIManager:subscribeEventHelper(tabControl, "SelectionChanged", P.name..".SOBSelectionSelectionChanged") if listbox:getItemCount() > 0 then tabControl:addChild(listbox) end end function P.SOBSelectionGetSelectedModel() --returns selected model, if available. -- choose the active listbox local tabControl = CEGUI.toTabControl(P.window:getChild("SOBSelectionWindow/SOBSelectionTabControl")) local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) local choice = listbox:getFirstSelectedItem() if choice ~= nil then -- get the right tab and the right index local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1] local index = tabIndexes[listbox:getItemIndex(choice)+1] return P.SOBList[index] else return nil end end function P.SOBSelectionGetSelectedLevel() -- choose the active listbox local tabControl = CEGUI.toTabControl(P.window:getChild("SOBSelectionWindow/SOBSelectionTabControl")) local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) local choice = listbox:getFirstSelectedItem() if choice ~= nil then -- get the right tab and the right index local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1] local index = tabIndexes[listbox:getItemIndex(choice)+1] return P.SOBList[index] else return nil end end function P.SOBSelectionSelectionChanged(e) --[[ TODO: Get image and description from template file local levelImage = P.window:getChild("orxonox/ShipSelectionLevelImage") local levelDescription = P.window:getChild("orxonox/ShipSelectionLevelDescription") local configButton = P.window:getChild("orxonox/ShipSelectionConfigButton") local level = P.ShipSelectionGetSelectedModel() if level ~= nil then --local levelXMLFilename = selectedlevel:getXMLFilename() --local imageName = selectedlevel:getScreenshot() -- set the screenshot and the description for the selected level --levelImage:setProperty("Image", levelXMLFilename..imageName.."/full_image") --levelDescription:setText(level:getDescription()) -- only enable config button for "gametype" levels --if level:hasTag("gametype") then -- configButton:setProperty("Disabled", "False") --else -- configButton:setProperty("Disabled", "True") --end else -- also take care of "no level selected" levelImage:setProperty("Image", nil) levelDescription:setText("") end --]] end function P.SOBSelectionStartButton_clicked(e) --selectedlevel = P.SOBSelectionGetSelectedModel --if (selectedlevel ~= nil and P.SOBSelectionGetSelectedModel() ~= nil) then -- orxonox.execute("startGame " .. selectedlevel:getXMLFilename()) -- hideAllMenuSheets() if (P.SOBSelectionGetSelectedModel() == "SOB1") then orxonox.execute("startGame " .. "SOBlevels/SOB1.oxw") hideAllMenuSheets() elseif (P.SOBSelectionGetSelectedModel() == "SOB2") then orxonox.execute("startGame " .. "SOBlevels/SOB2.oxw") hideAllMenuSheets() elseif (P.SOBSelectionGetSelectedModel() == "SOB3") then orxonox.execute("startGame " .. "SOBlevels/SOB3.oxw") hideAllMenuSheets() elseif (P.SOBSelectionGetSelectedModel() == "SOB4") then orxonox.execute("startGame " .. "SOBlevels/SOB4.oxw") hideAllMenuSheets() elseif (P.SOBSelectionGetSelectedModel() == "SOB5") then orxonox.execute("startGame " .. "SOBlevels/SOB5.oxw") hideAllMenuSheets() elseif (P.SOBSelectionGetSelectedModel() == "SOB6") then orxonox.execute("startGame " .. "SOBlevels/SOB6.oxw") hideAllMenuSheets() else -- orxonox.execute(P.SOBSelectionGetSelectedModel) orxonox.execute("orxout user_warning no ship model selected or no tagged shipmodel installed") end end --[[ TODO: function P.ShipSelectionConfigButton_clicked(e) local level = P.ShipSelectionGetSelectedModel() if level ~= nil then local configMenu = showMenuSheet("ShipSelectionConfigMenu") configMenu:loadConfig(level) end end --]] function P.SOBSelectionBackButton_clicked(e) orxonox.execute("keyESC") end return P