ESO Lua File v100010

ingame/leaderboards/campaignleaderboards.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
-----------------
-- Leaderboard Campaign Selector
-----------------
local ZO_LeaderboardCampaignSelector = CampaignSelector:Subclass()
function ZO_LeaderboardCampaignSelector:New(control)
    local selector = ZO_Object.New(self)
    selector.tabs = GetControl(control, "Tabs")
    selector.activeTab = GetControl(control, "TabsActive")
    local function CreateNewTabData(queryType, normal, pressed, highlight)
        local tabData =
        {
            -- Custom data
            queryType = queryType,
            tooltipText = GetString("SI_BATTLEGROUNDQUERYCONTEXTTYPE", queryType),
            -- Menu bar data
            descriptor = queryType,
            normal = normal,
            pressed = pressed,
            highlight = highlight,
            callback = function(tabData) selector:OnQueryTypeChanged(tabData) end,
        }
        return tabData
    end
    selector.homeTabData = CreateNewTabData(BGQUERY_ASSIGNED_CAMPAIGN, "EsoUI/Art/Journal/leaderboard_tabIcon_home_up.dds", "EsoUI/Art/Journal/leaderboard_tabIcon_home_down.dds", "EsoUI/Art/Journal/leaderboard_tabIcon_home_over.dds")
    selector.guestTabData = CreateNewTabData(BGQUERY_LOCAL, "EsoUI/Art/Journal/leaderboard_tabIcon_guest_up.dds", "EsoUI/Art/Journal/leaderboard_tabIcon_guest_down.dds", "EsoUI/Art/Journal/leaderboard_tabIcon_guest_over.dds")
    selector.campaignWindows =
    {
        CAMPAIGN_LEADERBOARDS,
    }
    local menuBarData =
    {
        initialButtonAnchorPoint = LEFT,
        buttonTemplate = "ZO_CampaignLeaderboardSelectorTab",
        normalSize = 51,
        downSize = 64,
        buttonPadding = 15,
        animationDuration = 180,
    }
    ZO_MenuBar_SetData(selector.tabs, menuBarData)
    EVENT_MANAGER:RegisterForEvent("CampaignLeaderboardSelector", EVENT_CURRENT_CAMPAIGN_CHANGED, function() selector:OnCurrentCampaignChanged() end)
    EVENT_MANAGER:RegisterForEvent("CampaignLeaderboardSelector", EVENT_ASSIGNED_CAMPAIGN_CHANGED, function() selector:OnAssignedCampaignChanged() end)
    selector.dataRegistration = ZO_CampaignDataRegistration:New("CampaignLeaderboardSelectorData", function() return selector:NeedsData() end)
    selector:RefreshQueryTypes()
    return selector
end
function ZO_LeaderboardCampaignSelector:OnQueryTypeChanged(tabData)
    local selectedQueryType = tabData.queryType
    if(selectedQueryType ~= self.selectedQueryType) then
        self.selectedQueryType = selectedQueryType
        self.activeTab:SetText(GetCampaignName(self:GetCampaignId()))
        self:UpdateCampaignWindows()
        self.dataRegistration:Refresh()
    end
end
function ZO_LeaderboardCampaignSelector:NeedsData()
    return (CAMPAIGN_LEADERBOARD_FRAGMENT:IsShowing() and self.selectedQueryType == BGQUERY_ASSIGNED_CAMPAIGN)
end
function ZO_LeaderboardCampaignSelector:RefreshQueryTypes()
    local selectedSomething = false
    ZO_MenuBar_AddButton(self.tabs, self.homeTabData)
    if(self.homeTabData.queryType == self.selectedQueryType) then
        ZO_MenuBar_SelectDescriptor(self.tabs, BGQUERY_ASSIGNED_CAMPAIGN)
        selectedSomething = true
    end
    if(GetCurrentCampaignId() ~= 0) then
        ZO_MenuBar_AddButton(self.tabs, self.guestTabData)
        if(self.guestTabData.queryType == self.selectedQueryType) then
            ZO_MenuBar_SelectDescriptor(self.tabs, BGQUERY_LOCAL)
            selectedSomething = true
        end
    end
    if(not selectedSomething) then
        ZO_MenuBar_SelectDescriptor(self.tabs, BGQUERY_ASSIGNED_CAMPAIGN)
    end
end
    InitializeTooltip(InformationTooltip, self, BOTTOMRIGHT, 0, 32)
    SetTooltipText(InformationTooltip, ZO_MenuBarButtonTemplate_GetData(self).tooltipText)
end
    ClearTooltip(InformationTooltip)
end
-----------------
-- Campaign Leaderboards
-----------------
local ZO_CampaignLeaderboardsManager = ZO_LeaderboardBase:Subclass()
function ZO_CampaignLeaderboardsManager:New(control)
    CAMPAIGN_LEADERBOARD_FRAGMENT = ZO_FadeSceneFragment:New(control)
    CAMPAIGN_LEADERBOARD_FRAGMENT:RegisterCallback("StateChange",   function(oldState, state)
                                                                        if state == SCENE_FRAGMENT_SHOWING then
                                                                            QueryCampaignLeaderboardData()
                                                                            CAMPAIGN_LEADERBOARD_SELECTOR.dataRegistration:Refresh()
                                                                        elseif state == SCENE_FRAGMENT_HIDDEN then
                                                                            CAMPAIGN_LEADERBOARD_SELECTOR.dataRegistration:Refresh()
                                                                        end
                                                                    end)
    local manager = ZO_LeaderboardBase.New(self, control, CAMPAIGN_LEADERBOARD_FRAGMENT)
    local UPDATE_INTERVAL_SECS = 1
    manager.lastUpdateSecs = 0
    local function TimerLabelOnUpdate(control, currentTime)
        if currentTime - manager.lastUpdateSecs >= UPDATE_INTERVAL_SECS then
            local secsUntilStart = GetSecondsUntilCampaignStart(manager.campaignId)
            local secsUntilEnd = GetSecondsUntilCampaignEnd(manager.campaignId)
            if secsUntilStart > 0 then
                manager.timerLabel:SetText(zo_strformat(SI_CAMPAIGN_LEADERBOARDS_REOPENS_IN_TIMER, ZO_FormatTime(secsUntilStart, TIME_FORMAT_STYLE_COLONS, TIME_FORMAT_PRECISION_TWELVE_HOUR)))
                manager.scoringInfoLabel:SetText(GetString(SI_CAMPAIGN_LEADERBOARDS_SCORING_CLOSED))
            elseif secsUntilEnd > 0 then
                manager.timerLabel:SetText(zo_strformat(SI_CAMPAIGN_LEADERBOARDS_CLOSES_IN_TIMER, ZO_FormatTime(secsUntilEnd, TIME_FORMAT_STYLE_COLONS, TIME_FORMAT_PRECISION_TWELVE_HOUR)))
                manager.scoringInfoLabel:SetText(GetString(SI_CAMPAIGN_LEADERBOARDS_SCORING_OPEN))
            else
                manager.timerLabel:SetText("")
                manager.scoringInfoLabel:SetText(GetString(SI_CAMPAIGN_LEADERBOARDS_SCORING_NOT_AVAILABLE))
            end
            manager.lastUpdateSecs = currentTime
        end
    end
    manager.timerLabel:SetHandler("OnUpdate", TimerLabelOnUpdate)
    manager:InitializeCategories()
    EVENT_MANAGER:RegisterForEvent("CampaignLeaderboards_DataChanged", EVENT_CAMPAIGN_LEADERBOARD_DATA_CHANGED, function() manager:OnDataChanged() end)
    return manager
end
function ZO_CampaignLeaderboardsManager:UpdatePlayerInfo(points, rank)
    if points then
        self.currentScoreLabel:SetText(zo_strformat(SI_CAMPAIGN_LEADERBOARDS_CURRENT_POINTS, points))
    else
        self.currentScoreLabel:SetText(GetString(SI_CAMPAIGN_LEADERBOARDS_CURRENT_POINTS_NOT_AVAILABLE))
    end
    if rank then
        self.currentRankLabel:SetText(zo_strformat(SI_CAMPAIGN_LEADERBOARDS_CURRENT_RANK, rank))
    else
        self.currentRankLabel:SetText(GetString(SI_CAMPAIGN_LEADERBOARDS_CURRENT_RANK_NOT_AVAILABLE))
    end
end
function ZO_CampaignLeaderboardsManager:InitializeCategories()
    local header = LEADERBOARDS:AddTreeCategory(GetString(SI_CAMPAIGN_LEADERBOARDS_ALLIANCE_WAR), "EsoUI/Art/Journal/leaderboard_indexIcon_ava_up.dds", "EsoUI/Art/Journal/leaderboard_indexIcon_ava_down.dds", "EsoUI/Art/Journal/leaderboard_indexIcon_ava_over.dds")
    local function GetMaxRank()
        return GetCampaignLeaderboardMaxRank(self.campaignId)
    end
    local function GetOverallCount()
        self:UpdatePlayerInfo()
        return GetNumCampaignLeaderboardEntries(self.campaignId)
    end
    local function GetOverallInfo(entryIndex)
        local isPlayer, rank, name, points, class, alliance = GetCampaignLeaderboardEntryInfo(self.campaignId, entryIndex)
        if isPlayer then
            self:UpdatePlayerInfo(points, rank)
        end
        return rank, name, points, class, alliance
    end
    LEADERBOARDS:AddTreeEntry(self, GetString(SI_CAMPAIGN_LEADERBOARDS_OVERALL), nil, header, nil, GetOverallCount, GetMaxRank, GetOverallInfo)
    local function GetSingleAllianceCount(alliance)
        self:UpdatePlayerInfo()
        return GetNumCampaignAllianceLeaderboardEntries(self.campaignId, alliance)
    end
    local function GetSingleAllianceInfo(entryIndex, alliance)
        local isPlayer, rank, name, points, class = GetCampaignAllianceLeaderboardEntryInfo(self.campaignId, alliance, entryIndex)
        if isPlayer then
            self:UpdatePlayerInfo(points, rank)
        end
        return rank, name, points, class, alliance
    end
    LEADERBOARDS:AddTreeEntry(self, zo_strformat(SI_ALLIANCE_NAME, GetAllianceName(ALLIANCE_ALDMERI_DOMINION)), nil, header, ALLIANCE_ALDMERI_DOMINION, GetSingleAllianceCount, GetMaxRank, GetSingleAllianceInfo)
    LEADERBOARDS:AddTreeEntry(self, zo_strformat(SI_ALLIANCE_NAME, GetAllianceName(ALLIANCE_DAGGERFALL_COVENANT)), nil, header, ALLIANCE_DAGGERFALL_COVENANT, GetSingleAllianceCount, GetMaxRank, GetSingleAllianceInfo)
    LEADERBOARDS:AddTreeEntry(self, zo_strformat(SI_ALLIANCE_NAME, GetAllianceName(ALLIANCE_EBONHEART_PACT)), nil, header, ALLIANCE_EBONHEART_PACT, GetSingleAllianceCount, GetMaxRank, GetSingleAllianceInfo)
    local function GetSingleClassCount(classId)
        self:UpdatePlayerInfo()
        return GetNumCampaignClassLeaderboardEntries(self.campaignId, classId)
    end
    local function GetSingleClassInfo(entryIndex, classId)
        local isPlayer, rank, name, points, alliance = GetCampaignClassLeaderboardEntryInfo(self.campaignId, classId, entryIndex)
        if isPlayer then
            self:UpdatePlayerInfo(points, rank)
        end
        return rank, name, points, classId, alliance
    end
    for i = 1, GetNumClasses() do
        local classId = GetClassInfo(i)
        LEADERBOARDS:AddTreeEntry(self, zo_strformat(SI_CLASS_NAME, GetClassName(GENDER_MALE, classId)), nil, header, classId, GetSingleClassCount, GetMaxRank, GetSingleClassInfo)
    end
    LEADERBOARDS:UpdateCategories()
end
function ZO_CampaignLeaderboardsManager:SetCampaignAndQueryType(campaignId, queryType)
    self.campaignId = campaignId
    self:OnDataChanged()
end
    CAMPAIGN_LEADERBOARDS = ZO_CampaignLeaderboardsManager:New(self)
    CAMPAIGN_LEADERBOARD_SELECTOR = ZO_LeaderboardCampaignSelector:New(self)
end