Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/PresentationFS18/data/gui/scripts/HighscoreMenu.lua @ 12183

Last change on this file since 12183 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
Line 
1-- HighscoreMenu.lua
2
3local P = createMenuSheet("HighscoreMenu")
4
5P.highscoreList = {}
6P.tabList = {}
7P.linesList = {}
8P.levelList = {}
9
10
11P.imageHeight = 50
12
13function P.onLoad()
14    P.createLevelList()   
15end
16
17function P.onShow()
18   
19    -- reset tables
20    P.highscoreList = {}
21    P.tabList = {}
22    P.linesList = {}
23
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
31    for k,v in pairs(P.levelList) do
32        if(v:getName() ~= "Hover level" and v:getName() ~= "Pong") then   -- hover and pong dont contain relevant scores
33            P.createFilterTab(v:getName(), v:getName())
34        end
35    end
36 
37end
38function P.onHide()
39
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)
44            tabControl:removeChildWindow(default)
45            winMgr:destroyWindow(default)
46    end
47end
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
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
68    table.insert(P.tabList, tabName)
69    -- create new tab window with desired name
70    local default = (winMgr:createWindow("DefaultWindow", tabName))
71    default:setText(name)
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
80    for k,v in pairs(P.highscoreList) do
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
90       
91    end
92
93    local tabControl = winMgr:getWindow("orxonox/HighscoreTabControl")
94    tabControl:addChildWindow(default)
95 
96
97   
98end
99function P.createPickupEntry(parent,k,tag)
100   
101    local name = "orxonox/HiscoreEntry" .. parent
102    local splitlist = P.Split(P.highscoreList[k],"./.")
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")
108    player:setText(splitlist[1])
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)
113       
114    local score = winMgr:createWindow("MenuWidgets/StaticText", name .. "/Score")
115    score:setText(splitlist[3])
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
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
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
161
162
163
164function P.HighscoreBackButton_clicked(e)
165    hideMenuSheet(P.name)
166end
167
168return P
169
Note: See TracBrowser for help on using the repository browser.