Back to Home

ESO Lua File v101041

libraries/zo_multiicon/zo_multiicon.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
local MultiIconTimer = ZO_Object:Subclass()
function MultiIconTimer:New()
    local timer = ZO_Object.New(self)
    timer.alpha = 0
    timer.cycle = 0
    timer.multiIcons = {}
    timer.timeline = ANIMATION_MANAGER:CreateTimelineFromVirtual("MultiIconAnimation")
    timer.timeline.object = timer
    timer.timeline:PlayFromStart()
    return timer
end
function MultiIconTimer:SetupMultiIconTexture(multiIcon)
    local index = (self.cycle % #multiIcon.iconData) + 1
    multiIcon:SetTexture(multiIcon.iconData[index].iconTexture)
    if multiIcon.iconData[index].iconTint then
        multiIcon:SetColor(multiIcon.iconData[index].iconTint:UnpackRGBA())
    else
        multiIcon:SetColor(ZO_WHITE:UnpackRGBA())
    end
end
function MultiIconTimer:AddMultiIcon(multiIcon)
    table.insert(self.multiIcons, multiIcon)
    self:SetupMultiIconTexture(multiIcon)
    multiIcon:SetAlpha(self.alpha * (multiIcon.maxAlpha or 1))
end
function MultiIconTimer:RemoveMultiIcon(multiIcon)
    for i = 1, #self.multiIcons do
        if self.multiIcons[i] == multiIcon then
            table.remove(self.multiIcons, i)
            break
        end
    end
end
function MultiIconTimer:SetAlphas(alpha)
    self.alpha = alpha
    for i = 1, #self.multiIcons do
        self.multiIcons[i]:SetAlpha(alpha)
    end
end
function MultiIconTimer:OnAnimationComplete()
    self.cycle = (self.cycle + 1) % 100
    for i = 1, #self.multiIcons do
        self:SetupMultiIconTexture(self.multiIcons[i])
    end
    self.timeline:PlayFromStart()
end
--Global XML
function ZO_MultiIconAnimation_SetAlpha(animation, alpha)
    animation:GetTimeline().object:SetAlphas(alpha)
end
function ZO_MultiIconAnimation_OnStop(timeline)
    if timeline:GetProgress() == 1 then
        timeline.object:OnAnimationComplete()
    end
end
do
    local MULTI_ICON_TIMER
    
    local function Show(self)
        if self:IsHidden() and self.iconData and #self.iconData > 0 then
            self:SetHidden(false)
        end
    end
    local function Hide(self)
        self:SetHidden(true)
    end
    local function ClearIcons(self)
        if self.iconData then
            Hide(self)
            ZO_ClearNumericallyIndexedTable(self.iconData)
        end
    end
    local function HasIcon(self, iconTexture)
        if self.iconData then
            for _, existingIconTexture in ipairs(self.iconData) do
                if existingIconTexture.iconTexture == iconTexture then
                    return true
                end
            end
        end
        return false
    end
    local function AddIcon(self, iconTexture, iconTint, iconNarration)
        if iconTexture then
            if not self.iconData then
                self.iconData = {}
            end
            local iconData =
            {
                iconTexture = iconTexture,
                iconTint = iconTint,
                iconNarration = iconNarration,
            }
            table.insert(self.iconData, iconData)
        end
    end
    local function GetNarrationText(self)
        local narrations = {}
        if self.iconData then
            for _, iconData in ipairs(self.iconData) do
                table.insert(narrations, SCREEN_NARRATION_MANAGER:CreateNarratableObject(iconData.iconNarration))
            end
        end
        return narrations
    end
    local function SetMaxAlpha(self, maxAlpha)
        self.maxAlpha = maxAlpha
    end
    function ZO_MultiIcon_OnShow(self)
        if self.iconData then
            if #self.iconData > 1 then
                MULTI_ICON_TIMER:AddMultiIcon(self)
            else
                self:SetTexture(self.iconData[1].iconTexture)
                if self.iconData[1].iconTint then
                    self:SetColor(self.iconData[1].iconTint:UnpackRGBA())
                else
                    self:SetColor(ZO_WHITE:UnpackRGBA())
                end
                self:SetAlpha(self.maxAlpha or 1)
            end
        end
    end
    function ZO_MultiIcon_OnHide(self)
        if self.iconData then
            if #self.iconData > 1 then
                MULTI_ICON_TIMER:RemoveMultiIcon(self)
            end
        end
    end
    function ZO_MultiIcon_Initialize(self)
        if not MULTI_ICON_TIMER then
            MULTI_ICON_TIMER = MultiIconTimer:New()
        end
        self.ClearIcons = ClearIcons
        self.AddIcon = AddIcon
        self.HasIcon = HasIcon
        self.Show = Show
        self.Hide = Hide
        self.SetMaxAlpha = SetMaxAlpha
    end
end