-- HighscoreMenu.lua local P = createMenuSheet("HighscoreMenu") P.scrollbarWidth = 13 P.nameList = {} P.scoreList = {} P.linesList = {} P.sampleWindow = nil P.lineHeight = 0 P.playerWidth = 0 P.editboxWidth = 0 P.resetWidth = 0 P.spaceWidth = 0 function P.onLoad() P.nameList = {} table.insert(P.nameList, "firsttestPlayer") table.insert(P.nameList, "secondtestPlayer") P.scoreList = {} table.insert(P.scoreList, 120) table.insert(P.scoreList, 20) P.linesList = {} --Calculate design parameters: P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/SampleWindow") P.sampleWindow:setText("SampleText") -- create tabs with desired tab as argument (nil for all) P.createFilterTab("Gametypes", "gametype") P.createFilterTab("Missions", "mission") --P.createFilterTab("Minigames", "minigame") --P.createFilterTab("Showcases", "showcase") --P.createFilterTab("Presentations", "presentation") --P.createFilterTab("Tests", "test") --P.createFilterTab("Show All", nil) -- update description and screenshot boxes --P.SingleplayerSelectionChanged() local size = getMinTextSize(P.sampleWindow) P.lineHeight = size[1] P.playerWidth = 0 for k,v in pairs(P.scoreList) do P.sampleWindow:setText(P.nameList[k]) size = getMinTextSize(P.sampleWindow) if size[2] > P.playerWidth then P.playerWidth = size[2] end end P.sampleWindow:setText("reset") size = getMinTextSize(P.sampleWindow) P.resetWidth = size[2]+20 P.spaceWidth = 10 local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane") size = pane:getViewableArea() P.editboxWidth = size:getWidth() - P.playerWidth - P.resetWidth - 5*P.spaceWidth P.createLines() P:setButton(1, 1, { ["button"] = winMgr:getWindow("orxonox/HighscoreBackButton"), ["callback"] = P.HighscoreBackButton_clicked }) end function P.onShow() --local description = winMgr:getWindow("orxonox/HighscoreText") --height = getStaticTextWindowHeight(description) --description:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -P.scrollbarWidth), CEGUI.UDim(0.0, height))) end function P.createFilterTab(name, tag) -- create unique tab window name local tabName = "orxonox/HighscoreLevelTab" if tag ~= nil then tabName = tabName..tag end -- create new tab window with desired name local default = CEGUI.toListbox(winMgr:createWindow("DefaultWindow", tabName)) default:setText(name) local tabControl = winMgr:getWindow("orxonox/HighscoreTabControl") orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".HighscoreSelectionChanged") --if listbox:getItemCount() > 0 then tabControl:addChildWindow(tabName) --end end function P.HighscoreGetSelectedLevel() -- choose the active listbox local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/HighscoreTabControl")) 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.levelList[index] else return nil end end function P.HighscoreSelectionChanged(e) local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane") pane:moveToFront() --[[local levelDescription = winMgr:getWindow("orxonox/SingleplayerLevelDescription") local configButton = winMgr:getWindow("orxonox/SingleplayerConfigButton") local level = P.HighscoreGetSelectedLevel() if level ~= nil then local levelXMLFilename = level:getXMLFilename() local imageName = level:getScreenshot() -- set the screenshot and the description for the selected level levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image: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", "") levelDescription:setText("") configButton:setProperty("Disabled", "True") end --]] end function P.createLine(k,tag) local tabName = k if tag ~= nil then tabName = tabName..tag end -- content window for the entire line local line = winMgr:createWindow("DefaultWindow", "orxonox/HighscoreMenuPane/Score" .. tabName) line:setHeight(CEGUI.UDim(0, P.lineHeight)) line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1)))) local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane") local half = (pane:getViewableArea()):getWidth() * 0.5 local offset = half * 0.01 -- config name local player = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/HighscoreMenuPane/Score" .. tabName .. "/Player") player:setText(P.nameList[k]) player:setSize(CEGUI.UVector2(CEGUI.UDim(0, half-offset), CEGUI.UDim(1, 0))) player:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) line:addChildWindow(player) -- config value (editable) local playerValue = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/HighscoreMenuPane/Score" .. tabName .. "/Value") --playerValue:setProperty("ReadOnly", "set:False") --local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])SS playerValue:setText(P.scoreList[k]) playerValue:setSize(CEGUI.UVector2(CEGUI.UDim(0, half-offset), CEGUI.UDim(1, 0))) playerValue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, half+offset), CEGUI.UDim(0, 0))) -- enable the reset button if the value changed orxonox.GUIManager:subscribeEventHelper(playerValue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted") line:addChildWindow(playerValue) line:setWidth(CEGUI.UDim(0, 2*half)) return line end function P.createLines() local window = winMgr:getWindow("orxonox/HighscoreMenuPane") for k,v in pairs(P.scoreList) do local line = P.createLine(k,nil) table.insert(P.linesList, line) window:addChildWindow(line) end local pane = tolua.cast(window, "CEGUI::ScrollablePane") pane:setVerticalStepSize(getScrollingStepSize(window)) end function P.HighscoreBackButton_clicked(e) hideMenuSheet(P.name) end return P