ESO Lua File v100010

ingame/leaderboards/leaderboards.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
-----------------
--Leaderboards
-----------------
local LEADERBOARD_PLAYER_DATA = 1
local ZO_LeaderboardsManager = ZO_SortFilterList:Subclass()
function ZO_LeaderboardsManager:New(control)
    local manager = ZO_SortFilterList.New(self, control)
    manager.activeLeaderboardLabel = GetControl(control, "ActiveLeaderboard")
    manager.pointsHeaderLabel = GetControl(control, "HeadersPoints")
    manager.noRankingsRow = GetControl(control, "NoRankingsRow")
    ZO_ScrollList_AddDataType(manager.list, LEADERBOARD_PLAYER_DATA, "ZO_LeaderboardsPlayerRow", 30, function(control, data) manager:SetupLeaderboardPlayerEntry(control, data) end)
    LEADERBOARDS_SCENE = ZO_Scene:New("leaderboards", SCENE_MANAGER)
    LEADERBOARDS_SCENE:RegisterCallback("StateChange", function(oldState, newState)
                                                                    if(newState == SCENE_SHOWING) then
                                                                        manager:RefreshData()
                                                                        if manager.leaderboardObject then
                                                                            manager.leaderboardObject:OnSelected()
                                                                        end
                                                                    end
                                                                end)
    return manager
end
function ZO_LeaderboardsManager:UpdateCategories()
    self.navigationTree:Commit()
end
function ZO_LeaderboardsManager:InitializeCategoryList(control)
    self.navigationTree = ZO_Tree:New(control:GetNamedChild("NavigationContainerScrollChild"), 60, -10, 259)
    local function TreeHeaderSetup(node, control, data, open)
        control.text:SetModifyTextType(MODIFY_TEXT_TYPE_UPPERCASE)
        control.text:SetText(data.name)
        local iconTexture = (open and data.pressedIcon or data.normalIcon) or "EsoUI/Art/Icons/icon_missing.dds"
        local mouseoverTexture = data.mouseoverIcon or "EsoUI/Art/Icons/icon_missing.dds"
        
        control.icon:SetTexture(iconTexture)
        control.iconHighlight:SetTexture(mouseoverTexture)
        ZO_IconHeader_Setup(control, open)
    end
    local function TreeEntrySetup(node, control, data, open)
        control:SetText(data.name)
    end
    local function TreeEntryOnSelected(control, data, selected, reselectingDuringRebuild)
        control:SetSelected(selected)
        if selected and not reselectingDuringRebuild then
            self:OnLeaderboardSelected(data)
        end
    end
    local function TreeEntryEquality(left, right)
        return left.name == right.name
    end
    self.navigationTree:AddTemplate("ZO_IconHeader", TreeHeaderSetup, nil, nil, nil, 0)
    self.navigationTree:AddTemplate("ZO_LeaderboardsNavigationEntry", TreeEntrySetup, TreeEntryOnSelected, TreeEntryEquality)
    self.navigationTree:SetExclusive(true)
    self.navigationTree:SetOpenAnimation("ZO_TreeOpenAnimation")
end
function ZO_LeaderboardsManager:AddTreeCategory(name, normalIcon, pressedIcon, mouseoverIcon)
    local entryData = 
    {
        name = name,
        normalIcon = normalIcon, 
        pressedIcon = pressedIcon, 
        mouseoverIcon = mouseoverIcon,
    }
    return self.navigationTree:AddNode("ZO_IconHeader", entryData, nil, SOUNDS.LEADERBOARD_CATEGORY_SELECTED)
end
-- NOTE: Adding a maxRankFunction will require that all data is loaded up right away, instead of as-needed. Use a maxRankFunction ONLY when you want/need that behavior.
function ZO_LeaderboardsManager:AddTreeEntry(leaderboardObject, name, titleName, parent, subType, countFunction, maxRankFunction, infoFunction, pointsFormatFunction, pointsHeaderString)
    local entryData = 
    {
        leaderboardObject = leaderboardObject,
        name = name,
        titleName = titleName or name,
        subType = subType,
        countFunction = countFunction,
        maxRankFunction = maxRankFunction,
        infoFunction = infoFunction,
        pointsHeaderString = pointsHeaderString,
    }
    return self.navigationTree:AddNode("ZO_LeaderboardsNavigationEntry", entryData, parent, SOUNDS.LEADERBOARD_SUBCATEGORY_SELECTED)
end
function ZO_LeaderboardsManager:SetSelectedLeaderboardObject(leaderboardObject, subType)
    if self.leaderboardObject ~= leaderboardObject then
        if self.leaderboardObject then
            self.leaderboardObject:OnUnSelected()
        end
        if leaderboardObject then
            leaderboardObject:OnSelected()
        end
        self.leaderboardObject = leaderboardObject
    end
    if self.leaderboardObject then
        self.leaderboardObject:OnSubtypeSelected(subType)
    end
end
function ZO_LeaderboardsManager:SelectNode(node)
    self.navigationTree:SelectNode(node)
end
function ZO_LeaderboardsManager:OnLeaderboardSelected(data)
    self:SetSelectedLeaderboardObject(data.leaderboardObject, data.subType)
    local titleName = type(data.titleName) == "function" and data.titleName(data.subType) or data.titleName
    self.activeLeaderboardLabel:SetText(titleName)
    self.subType = data.subType
    self.pointsHeaderLabel:SetText(data.pointsHeaderString or GetString(SI_CAMPAIGN_LEADERBOARDS_HEADER_POINTS))
    self:RefreshData()
end
function ZO_LeaderboardsManager:OnLeaderboardDataChanged(leaderboardObject)
    if self.leaderboardObject == leaderboardObject then
        local data = self.navigationTree:GetSelectedData()
        if data then
            self:OnLeaderboardSelected(data)
        else
            self:RefreshData()
        end
    end
end
function ZO_LeaderboardsManager:SetupLeaderboardPlayerEntry(control, data)
    ZO_SortFilterList.SetupRow(self, control, data)
    control.rankLabel:SetHidden(data.rank == 0)
    control.rankLabel:SetText(data.rank)
    control.nameLabel:SetText(data.localizedName)
    control.pointsLabel:SetText(data.points)
    local classTexture = GetClassIcon(data.class)
    if(classTexture) then
        control.classIcon:SetHidden(false)
        control.classIcon:SetTexture(classTexture)
    else
        control.classIcon:SetHidden(true)
    end
    local allianceTexture = GetAllianceSymbolIcon(data.alliance)
    if(allianceTexture) then
        control.allianceIcon:SetHidden(false)
        control.allianceIcon:SetTexture(allianceTexture)
    else
        control.allianceIcon:SetHidden(true)
    end
    local bg = GetControl(control, "BG")
    local hidden = (data.index % 2) == 0
    bg:SetHidden(hidden)
end
function ZO_LeaderboardsManager:SortScrollList()
    -- No sorting...just leave in rank order
end
function ZO_LeaderboardsManager:FilterScrollList()
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    ZO_ClearNumericallyIndexedTable(scrollData)
    for i = 1, #self.masterList do
        local data = self.masterList[i]
        if not self.maxAllowedRank or data.rank <= self.maxAllowedRank then
            table.insert(scrollData, ZO_ScrollList_CreateDataEntry(LEADERBOARD_PLAYER_DATA, data))
        end
    end
    self.noRankingsRow:SetHidden(#scrollData ~= 0)
end
function ZO_LeaderboardsManager:CommitScrollList()
    ZO_SortFilterList.CommitScrollList(self)
end
function ZO_LeaderboardsManager:SetupDataTable(dataTable)
    local rank, name, points, class, alliance = self.infoFunction(dataTable.index, self.subType)
    dataTable.rank = rank
    dataTable.localizedName = zo_strformat(SI_UNIT_NAME, name)
    dataTable.gender = GetGenderFromNameDescriptor(name)
    dataTable.class = class
    dataTable.alliance = alliance
    if points == 0 then
        dataTable.points = ""
    else
        dataTable.points = self.pointsFormatFunction and self.pointsFormatFunction(points) or points
    end
end
function ZO_LeaderboardsManager:BuildMasterList()
    self.masterList = {}
    if not self.countFunction or not self.infoFunction then
        return
    end
    local function IndexFunction(dataTable, key)
        self:SetupDataTable(dataTable)
        return dataTable[key]
    end
    local dataMetatable = {__index = IndexFunction}
    local numEntries = self.countFunction(self.subType)
    for i = 1, numEntries do
        local data = { index = i }
        setmetatable(data, dataMetatable)
        if self.maxAllowedRankFunction then
            self:SetupDataTable(data)
            self.maxAllowedRank = self.maxAllowedRankFunction()
        else
            self.maxAllowedRank = nil
        end
        self.masterList[#self.masterList + 1] = data
    end
end
function ZO_LeaderboardsManager:GetRowColors(data, mouseIsOver)
    local textColor = ZO_SECOND_CONTRAST_TEXT
    local iconColor = ZO_SELECTED_TEXT
    return textColor, iconColor
end
function ZO_LeaderboardsManager:ColorRow(control, data, mouseIsOver)
    local textColor = self:GetRowColors(data, mouseIsOver)
    local name = GetControl(control, "Name")
    name:SetColor(textColor:UnpackRGBA())
end
--Global XML Handlers
-----------------------
    ZO_SocialList.Class_OnMouseEnter(LEADERBOARDS, control)
end
    ZO_SocialList.Class_OnMouseExit(LEADERBOARDS, control)
end
    ZO_SocialList.Alliance_OnMouseEnter(LEADERBOARDS, control)
end
    ZO_SocialList.Alliance_OnMouseExit(LEADERBOARDS, control)
end
    LEADERBOARDS = ZO_LeaderboardsManager:New(self)
end