Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/HighscoreMenu.lua @ 11820

Last change on this file since 11820 was 11783, checked in by landauf, 7 years ago

merged Presentation_HS17_merge back to trunk

  • Property svn:eol-style set to native
File size: 5.1 KB
RevLine 
[11235]1-- HighscoreMenu.lua
2
3local P = createMenuSheet("HighscoreMenu")
4
[11333]5P.highscoreList = {}
[11324]6P.tabList = {}
[11235]7P.linesList = {}
[11265]8P.levelList = {}
[11235]9
10
[11254]11P.imageHeight = 50
[11235]12
13function P.onLoad()
[11718]14    P.createLevelList()   
[11235]15end
16
17function 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]37end
[11324]38function P.onHide()
[11333]39
[11718]40    -- delete old windows to reload them on show
41    local tabControl = winMgr:getWindow("orxonox/HighscoreTabControl")
42    for k,v in pairs(P.tabList) do
43            local default = winMgr:getWindow(v)
[11324]44            tabControl:removeChildWindow(default)
[11718]45            winMgr:destroyWindow(default)
[11324]46    end
47end
[11265]48function 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
60end
[11245]61function P.createFilterTab(name, tag)
62    -- create unique tab window name
63    local tabName = "orxonox/HighscoreLevelTab"
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)
[11254]72    default:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}")
73    default:setProperty("UnifiedAreaRect", "{{0,0},{0,0},{1,0},{1,0}}")
74    local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", tabName .. "pane") 
75    pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,0),CEGUI.UDim(1,0)))
76    default:addChildWindow(pane)
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))
87            offset = offset + line:getHeight():asAbsolute(1)+2
88            pane:addChildWindow(line)
89        end
[11315]90       
[11254]91    end
92
[11718]93    local tabControl = winMgr:getWindow("orxonox/HighscoreTabControl")
94    tabControl:addChildWindow(default)
[11245]95 
96
97   
98end
[11254]99function P.createPickupEntry(parent,k,tag)
100   
101    local name = "orxonox/HiscoreEntry" .. parent
[11333]102    local splitlist = P.Split(P.highscoreList[k],"./.")
[11254]103    local item = winMgr:createWindow("DefaultWindow", name)
104    item:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0, P.imageHeight)))
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)))
110    player:setSize(CEGUI.UVector2(CEGUI.UDim(0.49, 0), CEGUI.UDim(0, P.imageHeight)))
111   
112    item:addChildWindow(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)))
117    score:setSize(CEGUI.UVector2(CEGUI.UDim(0.495, 0), CEGUI.UDim(0, P.imageHeight)))
118   
119    item:addChildWindow(score)
120
121    return item
122end
[11245]123function P.HighscoreGetSelectedLevel()
124    -- choose the active listbox
125    local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/HighscoreTabControl"))
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
136end
[11315]137function 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
160end
[11245]161
162
[11333]163
[11235]164function P.HighscoreBackButton_clicked(e)
165    hideMenuSheet(P.name)
166end
167
168return P
169
Note: See TracBrowser for help on using the repository browser.