[11235] | 1 | -- HighscoreMenu.lua |
---|
| 2 | |
---|
| 3 | local P = createMenuSheet("HighscoreMenu") |
---|
| 4 | |
---|
[11333] | 5 | P.highscoreList = {} |
---|
[11324] | 6 | P.tabList = {} |
---|
[11235] | 7 | P.linesList = {} |
---|
[11265] | 8 | P.levelList = {} |
---|
[11235] | 9 | |
---|
| 10 | |
---|
[11254] | 11 | P.imageHeight = 50 |
---|
[11235] | 12 | |
---|
| 13 | function P.onLoad() |
---|
[11718] | 14 | P.createLevelList() |
---|
[11235] | 15 | end |
---|
| 16 | |
---|
| 17 | function P.onShow() |
---|
[11718] | 18 | |
---|
| 19 | -- reset tables |
---|
| 20 | P.highscoreList = {} |
---|
| 21 | P.tabList = {} |
---|
| 22 | P.linesList = {} |
---|
[11313] | 23 | |
---|
[11718] | 24 | -- fetch save scores and write it into the list |
---|
| 25 | for i=orxonox.Highscore:getInstance():getNumberOfHighscores()-1,0,-1 do |
---|
| 26 | table.insert(P.highscoreList, orxonox.Highscore:getInstance():getHighscore(i)) |
---|
| 27 | |
---|
| 28 | end |
---|
| 29 | |
---|
| 30 | -- read minigames out of the levelList |
---|
[11324] | 31 | for k,v in pairs(P.levelList) do |
---|
[11333] | 32 | if(v:getName() ~= "Hover level" and v:getName() ~= "Pong") then -- hover and pong dont contain relevant scores |
---|
[11324] | 33 | P.createFilterTab(v:getName(), v:getName()) |
---|
| 34 | end |
---|
| 35 | end |
---|
[11333] | 36 | |
---|
[11235] | 37 | end |
---|
[11324] | 38 | function P.onHide() |
---|
[11333] | 39 | |
---|
[11718] | 40 | -- delete old windows to reload them on show |
---|
[11805] | 41 | local tabControl = P.window:getChild("HighscoreWindow/HighscoreTabControl") |
---|
[11718] | 42 | for k,v in pairs(P.tabList) do |
---|
[11805] | 43 | local default = tabControl:getChild(v) |
---|
| 44 | tabControl:removeChild(default) |
---|
[11718] | 45 | winMgr:destroyWindow(default) |
---|
[11324] | 46 | end |
---|
| 47 | end |
---|
[11265] | 48 | function P.createLevelList() |
---|
| 49 | P.levelList = {} |
---|
| 50 | local size = orxonox.LevelManager:getInstance():getNumberOfLevels() |
---|
| 51 | local index = 0 |
---|
| 52 | local level = nil |
---|
| 53 | while index < size do |
---|
| 54 | level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index) |
---|
| 55 | if (level ~= nil and level:getXMLFilename() ~= "_temp.oxw" and level:hasTag("minigame")) then |
---|
| 56 | table.insert(P.levelList, level) |
---|
| 57 | end |
---|
| 58 | index = index + 1 |
---|
| 59 | end |
---|
| 60 | end |
---|
[11245] | 61 | function P.createFilterTab(name, tag) |
---|
| 62 | -- create unique tab window name |
---|
[11805] | 63 | local tabName = "HighscoreLevelTab" |
---|
[11245] | 64 | if tag ~= nil then |
---|
| 65 | tabName = tabName..tag |
---|
| 66 | end |
---|
| 67 | |
---|
[11324] | 68 | table.insert(P.tabList, tabName) |
---|
[11245] | 69 | -- create new tab window with desired name |
---|
[11718] | 70 | local default = (winMgr:createWindow("DefaultWindow", tabName)) |
---|
[11245] | 71 | default:setText(name) |
---|
[11805] | 72 | default:setProperty("MaxSize", "{{1,0},{1,0}}") |
---|
| 73 | default:setProperty("Area", "{{0,0},{0,0},{1,0},{1,0}}") |
---|
[11254] | 74 | local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", tabName .. "pane") |
---|
[11805] | 75 | pane:setSize(CEGUI.USize(CEGUI.UDim(1,0),CEGUI.UDim(1,0))) |
---|
| 76 | default:addChild(pane) |
---|
[11254] | 77 | |
---|
| 78 | |
---|
| 79 | local offset = 2 |
---|
[11333] | 80 | for k,v in pairs(P.highscoreList) do |
---|
[11718] | 81 | -- split the score ("Playername./.game./.score") |
---|
| 82 | local splitlist = P.Split(v,"./.") |
---|
| 83 | if(splitlist[2] == name)then |
---|
| 84 | local line = P.createPickupEntry(tabName .. k,k,tag) |
---|
| 85 | table.insert(P.linesList, line) |
---|
| 86 | line:setYPosition(CEGUI.UDim(0,offset)) |
---|
[11805] | 87 | offset = offset + P.imageHeight +2 |
---|
| 88 | pane:addChild(line) |
---|
[11718] | 89 | end |
---|
[11315] | 90 | |
---|
[11254] | 91 | end |
---|
| 92 | |
---|
[11805] | 93 | local tabControl = P.window:getChild("HighscoreWindow/HighscoreTabControl") |
---|
| 94 | tabControl:addChild(default) |
---|
[11245] | 95 | |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | end |
---|
[11254] | 99 | function P.createPickupEntry(parent,k,tag) |
---|
| 100 | |
---|
[11805] | 101 | local name = "HiscoreEntry" .. parent |
---|
[11333] | 102 | local splitlist = P.Split(P.highscoreList[k],"./.") |
---|
[11254] | 103 | local item = winMgr:createWindow("DefaultWindow", name) |
---|
[11805] | 104 | item:setSize(CEGUI.USize(CEGUI.UDim(1, 0), CEGUI.UDim(0, P.imageHeight))) |
---|
[11254] | 105 | item:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) |
---|
| 106 | |
---|
| 107 | local player = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Player") |
---|
[11324] | 108 | player:setText(splitlist[1]) |
---|
[11254] | 109 | player:setPosition(CEGUI.UVector2(CEGUI.UDim(0.005,0), CEGUI.UDim(0,0))) |
---|
[11805] | 110 | player:setSize(CEGUI.USize(CEGUI.UDim(0.49, 0), CEGUI.UDim(0, P.imageHeight))) |
---|
[11254] | 111 | |
---|
[11805] | 112 | item:addChild(player) |
---|
[11718] | 113 | |
---|
[11254] | 114 | local score = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Score") |
---|
[11324] | 115 | score:setText(splitlist[3]) |
---|
[11254] | 116 | score:setPosition(CEGUI.UVector2(CEGUI.UDim(0.5,0), CEGUI.UDim(0,0))) |
---|
[11805] | 117 | score:setSize(CEGUI.USize(CEGUI.UDim(0.495, 0), CEGUI.UDim(0, P.imageHeight))) |
---|
[11254] | 118 | |
---|
[11805] | 119 | item:addChild(score) |
---|
[11254] | 120 | |
---|
| 121 | return item |
---|
| 122 | end |
---|
[11245] | 123 | function P.HighscoreGetSelectedLevel() |
---|
| 124 | -- choose the active listbox |
---|
[11805] | 125 | local tabControl = CEGUI.toTabControl(P.window:getChild("HighscoreWindow/HighscoreTabControl")) |
---|
[11245] | 126 | local listbox = CEGUI.toListbox(tabControl:getTabContentsAtIndex(tabControl:getSelectedTabIndex())) |
---|
| 127 | local choice = listbox:getFirstSelectedItem() |
---|
| 128 | if choice ~= nil then |
---|
| 129 | -- get the right tab and the right index |
---|
| 130 | local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1] |
---|
| 131 | local index = tabIndexes[listbox:getItemIndex(choice)+1] |
---|
| 132 | return P.levelList[index] |
---|
| 133 | else |
---|
| 134 | return nil |
---|
| 135 | end |
---|
| 136 | end |
---|
[11315] | 137 | function P.Split(str, delim, maxNb) |
---|
| 138 | -- Eliminate bad cases... |
---|
| 139 | if string.find(str, delim) == nil then |
---|
| 140 | return { str } |
---|
| 141 | end |
---|
| 142 | if maxNb == nil or maxNb < 1 then |
---|
| 143 | maxNb = 0 -- No limit |
---|
| 144 | end |
---|
| 145 | local result = {} |
---|
| 146 | local pat = "(.-)" .. delim .. "()" |
---|
| 147 | local nb = 0 |
---|
| 148 | local lastPos |
---|
| 149 | for part, pos in string.gfind(str, pat) do |
---|
| 150 | nb = nb + 1 |
---|
| 151 | result[nb] = part |
---|
| 152 | lastPos = pos |
---|
| 153 | if nb == maxNb then break end |
---|
| 154 | end |
---|
| 155 | -- Handle the last field |
---|
| 156 | if nb ~= maxNb then |
---|
| 157 | result[nb + 1] = string.sub(str, lastPos) |
---|
| 158 | end |
---|
| 159 | return result |
---|
| 160 | end |
---|
[11245] | 161 | |
---|
| 162 | |
---|
[11333] | 163 | |
---|
[11235] | 164 | function P.HighscoreBackButton_clicked(e) |
---|
| 165 | hideMenuSheet(P.name) |
---|
| 166 | end |
---|
| 167 | |
---|
| 168 | return P |
---|
| 169 | |
---|