[11235] | 1 | -- HighscoreMenu.lua |
---|
| 2 | |
---|
| 3 | local P = createMenuSheet("HighscoreMenu") |
---|
| 4 | |
---|
| 5 | P.scrollbarWidth = 13 |
---|
| 6 | P.nameList = {} |
---|
| 7 | P.scoreList = {} |
---|
| 8 | P.linesList = {} |
---|
[11265] | 9 | P.levelList = {} |
---|
[11235] | 10 | |
---|
| 11 | P.sampleWindow = nil |
---|
| 12 | |
---|
| 13 | P.lineHeight = 0 |
---|
| 14 | P.playerWidth = 0 |
---|
| 15 | P.editboxWidth = 0 |
---|
| 16 | P.resetWidth = 0 |
---|
| 17 | P.spaceWidth = 0 |
---|
[11254] | 18 | P.imageHeight = 50 |
---|
| 19 | P.textHeight = 30 |
---|
[11235] | 20 | |
---|
| 21 | function P.onLoad() |
---|
[11265] | 22 | P.createLevelList() |
---|
[11235] | 23 | P.nameList = {} |
---|
[11304] | 24 | |
---|
[11235] | 25 | P.scoreList = {} |
---|
| 26 | |
---|
[11304] | 27 | for i=1,20 do |
---|
| 28 | table.insert(P.nameList, "Player "..i) |
---|
| 29 | table.insert(P.scoreList, i) |
---|
| 30 | |
---|
| 31 | end |
---|
| 32 | |
---|
[11235] | 33 | P.linesList = {} |
---|
| 34 | |
---|
| 35 | |
---|
[11245] | 36 | -- create tabs with desired tab as argument (nil for all) |
---|
| 37 | |
---|
[11265] | 38 | for k,v in pairs(P.levelList) do |
---|
| 39 | -- only add level if it has desired tag |
---|
| 40 | if tag == nil or v:hasTag(tag) then |
---|
| 41 | P.createFilterTab(v:getName(), v:getName()) |
---|
| 42 | end |
---|
[11267] | 43 | local highscores = v:getHighscores() |
---|
| 44 | orxonox.CommandExecutor:execute("log test:".. highscores) |
---|
| 45 | |
---|
[11265] | 46 | end |
---|
[11245] | 47 | --P.createFilterTab("Minigames", "minigame") |
---|
| 48 | --P.createFilterTab("Showcases", "showcase") |
---|
| 49 | --P.createFilterTab("Presentations", "presentation") |
---|
| 50 | --P.createFilterTab("Tests", "test") |
---|
| 51 | --P.createFilterTab("Show All", nil) |
---|
| 52 | |
---|
[11235] | 53 | |
---|
| 54 | end |
---|
| 55 | |
---|
| 56 | function P.onShow() |
---|
| 57 | --local description = winMgr:getWindow("orxonox/HighscoreText") |
---|
| 58 | |
---|
| 59 | --height = getStaticTextWindowHeight(description) |
---|
| 60 | --description:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, -P.scrollbarWidth), CEGUI.UDim(0.0, height))) |
---|
| 61 | end |
---|
[11265] | 62 | function P.createLevelList() |
---|
| 63 | P.levelList = {} |
---|
| 64 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
| 65 | local index = 0 |
---|
| 66 | local level = nil |
---|
| 67 | while index < size do |
---|
| 68 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
| 69 | if (level ~= nil and level:getXMLFilename() ~= "_temp.oxw" and level:hasTag("minigame")) then |
---|
| 70 | local levelXMLFilename = level:getXMLFilename() |
---|
| 71 | -- create an imageset for each screenshot |
---|
| 72 | local imageName = level:getScreenshot() |
---|
| 73 | if imageName ~= "" then |
---|
| 74 | CEGUI.ImagesetManager:getSingleton():createFromImageFile(levelXMLFilename..imageName, imageName) |
---|
| 75 | else |
---|
| 76 | CEGUI.ImagesetManager:getSingleton():createFromImageFile(levelXMLFilename..imageName, "noscreenshot.png") |
---|
| 77 | end |
---|
| 78 | table.insert(P.levelList, level) |
---|
| 79 | end |
---|
| 80 | index = index + 1 |
---|
| 81 | end |
---|
| 82 | end |
---|
[11245] | 83 | function P.createFilterTab(name, tag) |
---|
| 84 | -- create unique tab window name |
---|
| 85 | local tabName = "orxonox/HighscoreLevelTab" |
---|
| 86 | if tag ~= nil then |
---|
| 87 | tabName = tabName..tag |
---|
| 88 | end |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | -- create new tab window with desired name |
---|
[11254] | 92 | local default = (winMgr:createWindow("DefaultWindow", tabName)) |
---|
[11245] | 93 | default:setText(name) |
---|
[11254] | 94 | default:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}") |
---|
| 95 | default:setProperty("UnifiedAreaRect", "{{0,0},{0,0},{1,0},{1,0}}") |
---|
| 96 | local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", tabName .. "pane") |
---|
| 97 | pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,0),CEGUI.UDim(1,0))) |
---|
| 98 | default:addChildWindow(pane) |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | local offset = 2 |
---|
| 102 | for k,v in pairs(P.scoreList) do |
---|
| 103 | local line = P.createPickupEntry(tabName .. k,k,tag) |
---|
| 104 | table.insert(P.linesList, line) |
---|
| 105 | line:setYPosition(CEGUI.UDim(0,offset)) |
---|
| 106 | offset = offset + line:getHeight():asAbsolute(1)+2 |
---|
| 107 | pane:addChildWindow(line) |
---|
| 108 | end |
---|
| 109 | |
---|
[11245] | 110 | |
---|
| 111 | local tabControl = winMgr:getWindow("orxonox/HighscoreTabControl") |
---|
| 112 | orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".HighscoreSelectionChanged") |
---|
| 113 | --if listbox:getItemCount() > 0 then |
---|
[11254] | 114 | tabControl:addChildWindow(default) |
---|
[11245] | 115 | --end |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | end |
---|
[11254] | 119 | function P.createPickupEntry(parent,k,tag) |
---|
| 120 | |
---|
| 121 | local name = "orxonox/HiscoreEntry" .. parent |
---|
[11245] | 122 | |
---|
[11254] | 123 | local item = winMgr:createWindow("DefaultWindow", name) |
---|
| 124 | item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, P.imageHeight))) |
---|
| 125 | item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) |
---|
| 126 | |
---|
| 127 | local player = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Player") |
---|
| 128 | player:setText(P.nameList[k].. tag) |
---|
| 129 | player:setPosition(CEGUI.UVector2(CEGUI.UDim(0.005,0), CEGUI.UDim(0,0))) |
---|
| 130 | player:setSize(CEGUI.UVector2(CEGUI.UDim(0.49, 0), CEGUI.UDim(0, P.imageHeight))) |
---|
| 131 | |
---|
| 132 | item:addChildWindow(player) |
---|
| 133 | |
---|
| 134 | local score = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Score") |
---|
| 135 | score:setText(P.scoreList[k]) |
---|
| 136 | score:setPosition(CEGUI.UVector2(CEGUI.UDim(0.5,0), CEGUI.UDim(0,0))) |
---|
| 137 | score:setSize(CEGUI.UVector2(CEGUI.UDim(0.495, 0), CEGUI.UDim(0, P.imageHeight))) |
---|
| 138 | |
---|
| 139 | item:addChildWindow(score) |
---|
| 140 | |
---|
| 141 | return item |
---|
| 142 | end |
---|
[11245] | 143 | function P.HighscoreGetSelectedLevel() |
---|
| 144 | -- choose the active listbox |
---|
| 145 | local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/HighscoreTabControl")) |
---|
| 146 | local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) |
---|
| 147 | local choice = listbox:getFirstSelectedItem() |
---|
| 148 | if choice ~= nil then |
---|
| 149 | -- get the right tab and the right index |
---|
| 150 | local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1] |
---|
| 151 | local index = tabIndexes[listbox:getItemIndex(choice)+1] |
---|
| 152 | return P.levelList[index] |
---|
| 153 | else |
---|
| 154 | return nil |
---|
| 155 | end |
---|
| 156 | end |
---|
| 157 | |
---|
| 158 | function P.HighscoreSelectionChanged(e) |
---|
[11254] | 159 | --local pane = tolua.cast(winMgr:getWindow("orxonox/HighscoreMenuPane"), "CEGUI::ScrollablePane") |
---|
| 160 | --pane:moveToFront() |
---|
[11245] | 161 | --[[local levelDescription = winMgr:getWindow("orxonox/SingleplayerLevelDescription") |
---|
| 162 | local configButton = winMgr:getWindow("orxonox/SingleplayerConfigButton") |
---|
| 163 | local level = P.HighscoreGetSelectedLevel() |
---|
| 164 | if level ~= nil then |
---|
| 165 | local levelXMLFilename = level:getXMLFilename() |
---|
| 166 | local imageName = level:getScreenshot() |
---|
| 167 | -- set the screenshot and the description for the selected level |
---|
| 168 | levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image") |
---|
| 169 | levelDescription:setText(level:getDescription()) |
---|
| 170 | -- only enable config button for "gametype" levels |
---|
| 171 | if level:hasTag("gametype") then |
---|
| 172 | configButton:setProperty("Disabled", "False") |
---|
| 173 | else |
---|
| 174 | configButton:setProperty("Disabled", "True") |
---|
| 175 | end |
---|
| 176 | else |
---|
| 177 | -- also take care of "no level selected" |
---|
| 178 | levelImage:setProperty("Image", "") |
---|
| 179 | levelDescription:setText("") |
---|
| 180 | configButton:setProperty("Disabled", "True") |
---|
| 181 | end --]] |
---|
| 182 | end |
---|
| 183 | |
---|
| 184 | |
---|
[11235] | 185 | function P.HighscoreBackButton_clicked(e) |
---|
| 186 | hideMenuSheet(P.name) |
---|
| 187 | end |
---|
| 188 | |
---|
| 189 | return P |
---|
| 190 | |
---|