Back to Home

ESO Lua File v100030

ingame/dailyloginrewards/dailyloginrewards_base.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
ZO_DailyLoginRewards_Base = ZO_Object:Subclass()
function ZO_DailyLoginRewards_Base:New(...)
    local loginRewards = ZO_Object.New(self)
    loginRewards:Initialize(...)
    return loginRewards
end
function ZO_DailyLoginRewards_Base:Initialize(control)
    self.control = control
    self.hasMultipleRewardPreviews = false
    self.currentRewardAnimationPool = ZO_MetaPool:New(ZO_Pending_Outfit_LoopAnimation_Pool)
    self.isDirty = true
    self.highlightPool = ZO_ControlPool:New("ZO_DailyLoginRewards_Highlight", control, "NextLoginRewardHighlight")
    local particleR, particleG, particleB = ZO_OFF_WHITE:UnpackRGB()
    local FULL_CIRCLE_RADIANS = math.rad(360)
    local blastParticleSystem = ZO_ControlParticleSystem:New(ZO_NumericalPhysicsParticle_Control)
    blastParticleSystem:SetParticlesPerSecond(600)
    blastParticleSystem:SetDuration(.1)
    blastParticleSystem:SetParticleParameter("Texture", "EsoUI/Art/PregameAnimatedBackground/ember.dds")
    blastParticleSystem:SetParticleParameter("BlendMode", TEX_BLEND_MODE_ADD)
    blastParticleSystem:SetParticleParameter("StartAlpha", 1)
    blastParticleSystem:SetParticleParameter("EndAlpha", 0)
    blastParticleSystem:SetParticleParameter("DurationS", ZO_UniformRangeGenerator:New(0.7, 1))
    blastParticleSystem:SetParticleParameter("PhysicsInitialVelocityElevationRadians", ZO_UniformRangeGenerator:New(0, FULL_CIRCLE_RADIANS))
    blastParticleSystem:SetParticleParameter("PhysicsAccelerationElevationRadians1", math.rad(270)) --Down; Right is 0
    blastParticleSystem:SetParticleParameter("PhysicsAccelerationMagnitude1", 250)
    blastParticleSystem:SetParticleParameter("StartColorR", particleR)
    blastParticleSystem:SetParticleParameter("StartColorG", particleG)
    blastParticleSystem:SetParticleParameter("StartColorB", particleB)
    blastParticleSystem:SetParticleParameter("PhysicsInitialVelocityMagnitude", ZO_UniformRangeGenerator:New(400, 600))
    blastParticleSystem:SetParticleParameter("Size", ZO_UniformRangeGenerator:New(6, 12))
    blastParticleSystem:SetParticleParameter("PhysicsDragMultiplier", 4)
    blastParticleSystem:SetSound(SOUNDS.DAILY_LOGIN_REWARDS_CLAIM_FANFARE)
    self.blastParticleSystem = blastParticleSystem
    local USE_LOWERCASE_NUMBER_SUFFIXES = false
    self.dailyLoginRewardsGridEntrySetup = function(control, data, selected)
        control.data = data
        if control.highlightKey then
            self.highlightPool:ReleaseObject(control.highlightKey)
            control.highlightKey = nil
        end
        local isMilestone = false
        if not data.isEmptyCell then
            local isRewardClaimed = IsDailyLoginRewardInCurrentMonthClaimed(data.day)
            if data.quantity > 1 then
                control.quantityLabel:SetText(zo_strformat(SI_NUMBER_FORMAT, ZO_CommaDelimitNumber(data.quantity)))
                control.quantityLabel:SetHidden(isRewardClaimed)
            else
                control.quantityLabel:SetHidden(true)
            end
            local completeMarkControl = control.completeMark
            local statusIconTexture = control.statusIcon
            local iconTexture = control.icon
            local milestoneTexture = control.isMilestoneTag
            local currentRewardIndex = ZO_DAILYLOGINREWARDS_MANAGER:GetDailyLoginRewardIndex()
            local iconFile = data.iconFile or data.icon
            if iconFile then
                iconTexture:SetTexture(iconFile)
                if data.day > GetNumClaimableDailyLoginRewardsInCurrentMonth() then
                    iconTexture:SetDesaturation(1)
                    milestoneTexture:SetDesaturation(1)
                else
                    iconTexture:SetDesaturation(0)
                    milestoneTexture:SetDesaturation(0)
                end
                iconTexture:SetHidden(false)
            else
                iconTexture:SetHidden(true)
            end
            if isRewardClaimed then
                completeMarkControl:SetHidden(false)
                iconTexture:SetHidden(true)
            else
                statusIconTexture:SetTexture("EsoUI/Art/Miscellaneous/status_locked.dds")
                statusIconTexture:SetHidden(data.day <= GetNumClaimableDailyLoginRewardsInCurrentMonth())
            end
            control.timerLabel:SetHidden(true)
             if data.day == currentRewardIndex then
                self.defaultSelectionData = data
                -- there is a next daily reward, but it is not claimable yet, so we want to show the timer
                if GetDailyLoginClaimableRewardIndex() == nil and GetTimeUntilNextDailyLoginMonthS() > ZO_ONE_DAY_IN_SECONDS then
                    if self:ShouldShowNextClaimableRewardBorder()  then
                        local highlightControl, highlightKey = self.highlightPool:AcquireObject()
                        highlightControl:ClearAnchors()
                        highlightControl:SetAnchor(TOPLEFT, control, TOPLEFT)
                        highlightControl:SetAnchor(BOTTOMRIGHT, control, BOTTOMRIGHT)
                        highlightControl:SetParent(control)
                        control.highlightKey = highlightKey
                    end
                    control.timerLabel:SetHidden(false)
                    statusIconTexture:SetHidden(true)
                    self.nextRewardControl = control
                    self:UpdateTimeToNextRewardClaim()
                end
            end
            isMilestone = data.isMilestone
        else
            control.icon:SetHidden(true)
        end
        if data.isEmptyCell then
            control:SetAlpha(0.4)
        else
            if IsDailyLoginRewardInCurrentMonthClaimed(data.day) then
                control.container:SetAlpha(0.4)
            else
                control.container:SetAlpha(1)
            end
        end
        self:SetupGridEntryBorderAndMilestone(control, data, self.currentRewardAnimationPool)
    end
    local function MarkViewDirty()
        self:MarkDirty()
    end
    local function OnMonthChanged()
        if self:IsShowing() then
            PlaySound(SOUNDS.DAILY_LOGIN_REWARDS_MONTH_CHANGE)
        end
        self:MarkDirty()
    end
    control:SetHandler("OnUpdate", function() 
        self:UpdateTimers()
    end)
    control:RegisterForEvent(EVENT_DAILY_LOGIN_REWARDS_UPDATED, MarkViewDirty)
    control:RegisterForEvent(EVENT_NEW_DAILY_LOGIN_REWARD_AVAILABLE, MarkViewDirty)
    control:RegisterForEvent(EVENT_DAILY_LOGIN_REWARDS_CLAIMED, function(...) self:OnRewardClaimed(...) end)
    control:RegisterForEvent(EVENT_DAILY_LOGIN_MONTH_CHANGED, OnMonthChanged)
end
function ZO_DailyLoginRewards_Base:GridEntryCleanup(control)
    control.quantityLabel:SetHidden(true)
    control.completeMark:SetHidden(true)
    control.container:SetAlpha(1)
end
function ZO_DailyLoginRewards_Base:UpdateCurrentMonthName()
    local shouldHideMonth = not ZO_DAILYLOGINREWARDS_MANAGER:HasClaimableRewardInMonth() or ZO_DAILYLOGINREWARDS_MANAGER:IsDailyRewardsLocked()
    self.currentMonthLabel:SetHidden(shouldHideMonth)
    local currentMonth = GetCurrentDailyLoginMonth()
    local currentMonthName = GetString("SI_GREGORIANCALENDARMONTHS", currentMonth)
    local currentESOMonthName = GetString("SI_GREGORIANCALENDARMONTHS_LORENAME", currentMonth)
    self.currentMonthLabel:SetText(zo_strformat(SI_DAILY_LOGIN_REWARDS_MONTH_FORMATTER, currentESOMonthName, currentMonthName))
end
function ZO_DailyLoginRewards_Base:UpdateGridList()
    local gridListPanelList = self.gridListPanelList
    gridListPanelList:ClearGridList()
    self.defaultSelectionData = nil
    local numPreviewableRewards = 0
    
    if ZO_DAILYLOGINREWARDS_MANAGER:IsDailyRewardsLocked() then
        self.lockedLabel:SetText(GetString(SI_DAILY_LOGIN_REWARDS_LOCKED))
        self.lockedLabel:SetHidden(false)
    elseif ZO_DAILYLOGINREWARDS_MANAGER:HasClaimableRewardInMonth() then
        local numRewardsInMonth = GetNumRewardsInCurrentDailyLoginMonth()
        for i = 1, numRewardsInMonth do
            local rewardId, quantity, isMilestone = GetDailyLoginRewardInfoForCurrentMonth(i)
            local rewardData = REWARDS_MANAGER:GetInfoForDailyLoginReward(rewardId, quantity)
            if rewardData then
                local dailyLoginRewardData = ZO_GridSquareEntryData_Shared:New(rewardData)
                dailyLoginRewardData.day = i
                dailyLoginRewardData.isMilestone = isMilestone
                dailyLoginRewardData.quantity = quantity
                if CanPreviewReward(dailyLoginRewardData:GetRewardId()) then
                    numPreviewableRewards = numPreviewableRewards + 1
                end
                self.gridListPanelList:AddEntry(dailyLoginRewardData)
            end
        end
        self.lockedLabel:SetHidden(true)
    else
        self.lockedLabel:SetHidden(false)
        -- text for the lock label will be set in UpdateTimeToNextMonthText
    end
    self.hasMultipleRewardPreviews = numPreviewableRewards > 1
    gridListPanelList:CommitGridList()
end
function ZO_DailyLoginRewards_Base:UpdateTimeToNextMonth()
    local timeUntilNextDailyLoginMonthS = GetTimeUntilNextDailyLoginMonthS()
    if timeUntilNextDailyLoginMonthS ~= self.lastCalculatedTimeUntilNextMonthS then
        local formattedTime = ZO_FormatTimeLargestTwo(timeUntilNextDailyLoginMonthS, TIME_FORMAT_STYLE_DESCRIPTIVE_MINIMAL)
        self.lastCalculatedTimeUntilNextMonthS = timeUntilNextDailyLoginMonthS
        self:UpdateTimeToNextMonthText(formattedTime)
    end
end
function ZO_DailyLoginRewards_Base:UpdateTimeToNextRewardClaim()
    if self.nextRewardControl then
        local timeUntilNextDailyLoginRewardClaimS = GetTimeUntilNextDailyLoginRewardClaimS()
        if timeUntilNextDailyLoginRewardClaimS ~= self.lastCalcualtedTimeUntilNextRewardClaimS then
            local formattedTime = ZO_FormatCountdownTimer(timeUntilNextDailyLoginRewardClaimS, TIME_FORMAT_STYLE_DESCRIPTIVE_MINIMAL)
            self.lastCalcualtedTimeUntilNextRewardClaimS = timeUntilNextDailyLoginRewardClaimS
            self:UpdateTimeToNextRewardClaimText(formattedTime)
        end
    end
end
function ZO_DailyLoginRewards_Base:UpdateTimeToNextRewardClaimText(formattedTime)
    if self.nextRewardControl then
        self.nextRewardControl.timerLabel:SetText(formattedTime)
    end
end
function ZO_DailyLoginRewards_Base:UpdateTimers()
end
function ZO_DailyLoginRewards_Base:OnShowing()
    self:CleanDirty()
    TriggerTutorial(TUTORIAL_TRIGGER_DAILY_LOGIN_REWARDS_OPENED)
end 
function ZO_DailyLoginRewards_Base:OnHiding()
     self.blastParticleSystem:Stop()
end 
function ZO_DailyLoginRewards_Base:HasMultiplePreviews()
    return self.hasMultipleRewardPreviews
end
function ZO_DailyLoginRewards_Base:OnRewardClaimed()
    if self:IsShowing() then
        if ZO_DAILYLOGINREWARDS_MANAGER:HasClaimableRewardInMonth() then
            self.gridListPanelList:RefreshGridList()
            self:ShowClaimedRewardFlair()
        else
            -- this will hide all the controls and show the "nothing left to claim" message
            self:MarkDirty()
        end
    else
        self:MarkDirty()
    end
end
function ZO_DailyLoginRewards_Base:ShowClaimedRewardFlair()
    if self.targetedClaimData then
        local claimedControl = self.gridListPanelList:GetControlFromData(self.targetedClaimData)
        self.particleGeneratorPosition:ClearAnchors()
        self.particleGeneratorPosition:SetAnchor(CENTER, claimedControl, CENTER, 0, -10)
        self.blastParticleSystem:Start()
        ZO_CraftingResults_Base_PlayPulse(claimedControl)
        self:SetTargetedClaimData(nil)
    end
end
function ZO_DailyLoginRewards_Base:MarkDirty()
    self.isDirty = true
    if self:IsShowing() then
        self:CleanDirty()
    end
end
function ZO_DailyLoginRewards_Base:CleanDirty()
    if self.isDirty then
        self:UpdateGridList()
        self:UpdateCurrentMonthName()
        self:UpdateTimers()
        self.isDirty = false
    end
end
function ZO_DailyLoginRewards_Base:SetTargetedClaimData(claimData)
    self.targetedClaimData = claimData
end
function ZO_DailyLoginRewards_Base:UpdateTimeToNextMonthText(formattedTime)
    if not ZO_DAILYLOGINREWARDS_MANAGER:IsDailyRewardsLocked() then
        self.lockedLabel:SetText(zo_strformat(SI_DAILY_LOGIN_REWARDS_LOCKED_UNTIL_NEW_MONTH, ZO_WHITE:Colorize(formattedTime)))
    end
end
function ZO_DailyLoginRewards_Base:ShouldChangeTimerBeHidden()
    return self.lastCalculatedTimeUntilNextMonthS == 0 or ZO_DAILYLOGINREWARDS_MANAGER:IsDailyRewardsLocked() or not ZO_DAILYLOGINREWARDS_MANAGER:HasClaimableRewardInMonth()
end
function ZO_DailyLoginRewards_Base:UpdateTimeToNextMonthVisibility()
    assert(false) -- must be overridden in derived classes
end
function ZO_DailyLoginRewards_Base:IsShowing()
    assert(false) -- must be overridden in derived classes
end
function ZO_DailyLoginRewards_Base:ShouldShowNextClaimableRewardBorder()
    assert(false) -- must be overridden in derived classes
end