Back to Home

ESO Lua File v101050

ingame/spectacleevents/spectacleevents_manager.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
ZO_SpectacleEvents_Manager = ZO_InitializingCallbackObject:Subclass()
function ZO_SpectacleEvents_Manager:Initialize()
end
function ZO_SpectacleEvents_Manager:InitializeEvents()
    local function OnSpectacleEventUpdated(_, spectacleEventId)
    end
    EVENT_MANAGER:RegisterForEvent("ZO_SpectacleEvents_Manager", EVENT_SPECTACLE_EVENT_UPDATED, OnSpectacleEventUpdated)
    local function OnSpectacleEventPhaseUpdated(_, spectacleEventId, oldActivePhaseId, newActivePhaseId, isInitialUpdate)
        self:UpdateActiveSpectacleEventPhaseId(spectacleEventId, oldActivePhaseId, newActivePhaseId, isInitialUpdate)
    end
    EVENT_MANAGER:RegisterForEvent("ZO_SpectacleEvents_Manager", EVENT_SPECTACLE_EVENT_PHASE_UPDATED, OnSpectacleEventPhaseUpdated)
end
function ZO_SpectacleEvents_Manager:GetActiveSpectacleEventId()
    return self.activeSpectacleEventId
end
function ZO_SpectacleEvents_Manager:IsAnySpectacleEventActive()
    return self.activeSpectacleEventId ~= nil and self.activeSpectacleEventId ~= 0
end
function ZO_SpectacleEvents_Manager:UpdateActiveSpectacleEventId()
    local previousActiveSpectacleEventId = self.activeSpectacleEventId
    if GetNumActiveSpectacleEvents() > 0 then
        self.activeSpectacleEventId = GetActiveSpectacleEventId(1)
    else
        self.activeSpectacleEventId = 0
    end
    if previousActiveSpectacleEventId ~= self.activeSpectacleEventId then
        self:FireCallbacks("ActiveSpectacleEventUpdated", self.activeSpectacleEventId)
    end
end
function ZO_SpectacleEvents_Manager:UpdateActiveSpectacleEventPhaseId(spectacleEventId, oldActivePhaseId, newActivePhaseId, isInitialUpdate)
    if oldActivePhaseId ~= newActivePhaseId then
        if oldActivePhaseId ~= 0 then
            self:FireCallbacks("ActiveSpectacleEventPhaseComplete", spectacleEventId, oldActivePhaseId, isInitialUpdate)
        end
        if newActivePhaseId ~= 0 then
            self:FireCallbacks("ActiveSpectacleEventPhaseStarted", spectacleEventId, newActivePhaseId, isInitialUpdate)
        end
    end
end
function ZO_SpectacleEvents_Manager:GetActiveSpectacleEventNextPhaseBeginsString(spectacleEventId)
    local secondsRemainingUntilStart = GetSecondsRemainingUntilNextActiveSpectacleEventPhase(spectacleEventId)
    local timeRemainingString
    if secondsRemainingUntilStart < ZO_ONE_MINUTE_IN_SECONDS then
        timeRemainingString = GetString(SI_STR_TIME_LESS_THAN_MINUTE_SHORT)
    else
        timeRemainingString = ZO_FormatTimeLargestTwo(secondsRemainingUntilStart, TIME_FORMAT_STYLE_DESCRIPTIVE_MINIMAL_HIDE_ZEROES)
    end
    local currentPhase, numPhases = GetActiveSpectacleEventPhaseInfo(spectacleEventId)
    if currentPhase >= numPhases then
        -- There can be a phantom phase at the end of the event to allow for a more graceful ending
        -- In that case currentPhase == numPhases, but the server will have sent us a transition time
        if secondsRemainingUntilStart > 0 then
            return zo_strformat(SI_SPECTACLE_EVENTS_EVENT_ENDS_IN_FORMATTER, ZO_SELECTED_TEXT:Colorize(timeRemainingString))
        end
        return nil
    end
    local nextPhase = currentPhase + 1
    if not IsActiveSpectacleEventPhaseTransitionEnabled(spectacleEventId) then
        return zo_strformat(SI_SPECTACLE_EVENTS_PHASE_BEGINS_NEXT_UPDATE_FORMATTER, nextPhase)
    end
    if secondsRemainingUntilStart <= 0 then
        return zo_strformat(SI_SPECTACLE_EVENTS_PHASE_BEGINS_SOON_FORMATTER, nextPhase)
    end
    return zo_strformat(SI_SPECTACLE_EVENTS_PHASE_BEGINS_IN_FORMATTER, nextPhase, ZO_SELECTED_TEXT:Colorize(timeRemainingString))
end
SPECTACLE_EVENTS_MANAGER = ZO_SpectacleEvents_Manager:New()