Back to Home

ESO Lua File v101050

ingame/stats/keyboard/zo_statentry_keyboard.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
ZO_StatEntry_Keyboard = ZO_InitializingObject:Subclass()
function ZO_StatEntry_Keyboard:Initialize(control, statType, statObject)
    self.control = control
    self.control.statEntry = self
    self.statType = statType
    self.statObject = statObject
    self.tooltipAnchorSide = RIGHT
    self.currentStatDelta = 0
    self.control.name:SetText(zo_strformat(SI_STAT_NAME_FORMAT, GetString("SI_DERIVEDSTATS", statType)))
    
    local function UpdateStatValue()
        self:UpdateStatValue()
    end
    self.control:RegisterForEvent(EVENT_STATS_UPDATED, UpdateStatValue)
    self.control:AddFilterForEvent(EVENT_STATS_UPDATED, REGISTER_FILTER_UNIT_TAG, "player")
    self.control:SetHandler("OnEffectivelyShown", UpdateStatValue)
    self.nextStatsRefreshSeconds = 0
    local function OnUpdate(_, currentFrameTimeSeconds)
        if self.nextStatsRefreshSeconds < currentFrameTimeSeconds then
            self:UpdateStatValue()
        end
    end
    self.control:SetHandler("OnUpdate", OnUpdate)
end
function ZO_StatEntry_Keyboard:GetPendingStatBonuses()
    if self.statObject then
        return self.statObject:GetPendingStatBonuses(self.statType)
    end
end
function ZO_StatEntry_Keyboard:GetValue()
    return GetPlayerStat(self.statType, STAT_BONUS_OPTION_APPLY_BONUS)
end
function ZO_StatEntry_Keyboard:GetDisplayValue(targetValue)
    local value = targetValue or self:GetValue()
    local statType = self.statType
    if statType == STAT_CRITICAL_STRIKE or statType == STAT_SPELL_CRITICAL then
        return zo_strformat(SI_STAT_VALUE_PERCENT, GetCriticalStrikeChance(value))
    else
        return tostring(value)
    end
end
function ZO_StatEntry_Keyboard:SetHasMundusEffect(hasMundusEffect)
    self.hasMundusEffect = hasMundusEffect
end
function ZO_StatEntry_Keyboard:UpdateMundusIcon()
    if self.hasMundusEffect then
        if not self.mundusIcon then
            local prefix = ""
            if self.statObject and self.statObject.virtualControlPrefix then
                prefix = self.statObject.virtualControlPrefix
            end
            self.mundusIcon = CreateControlFromVirtual(prefix .. "MundusIcon" .. self.statType, self.control, "ZO_StatMundusIcon")
            self.mundusIcon:SetAnchor(RIGHT)
        end
        self.mundusIcon:SetHidden(false)
    elseif self.mundusIcon then
        self.mundusIcon:SetHidden(true)
    end
end
function ZO_StatEntry_Keyboard:UpdateStatValue()
    if not self.control:IsHidden() then
        self.nextStatsRefreshSeconds = GetFrameTimeSeconds() + ZO_STATS_REFRESH_TIME_SECONDS
        local displayValue = self:GetDisplayValue()
        local pendingBonusAmount = self:GetPendingStatBonuses()
        if pendingBonusAmount and pendingBonusAmount > 0 then
            self.control.pendingBonus:SetHidden(false)
            self.control.pendingBonus:SetText(zo_strformat(SI_STAT_PENDING_BONUS_FORMAT, pendingBonusAmount))
        else
            self.control.pendingBonus:SetHidden(true)
        end
        local valueLabel = self.control.value
        local statChanged = displayValue ~= valueLabel:GetText()
        if statChanged then
            valueLabel:SetText(displayValue)
        end
        self.control.name:SetColor(ZO_NORMAL_TEXT:UnpackRGBA())
        self:UpdateMundusIcon()
    end
end
function ZO_StatEntry_Keyboard:UpdateStatComparisonValue()
    if not self.control:IsHidden() and not self.control.comparisonValue:IsHidden() and self.currentStatDelta and self.currentStatDelta ~= 0 then
        local comparisonStatValue = self:GetValue()
        if not self.currentStatExcludeDelta then
            comparisonStatValue = comparisonStatValue + self.currentStatDelta
        end
        local color
        local icon
        if self.currentStatDelta > 0 then
            color = ZO_SUCCEEDED_TEXT
            icon = "EsoUI/Art/Buttons/Gamepad/gp_upArrow.dds"
        else
            color = ZO_ERROR_COLOR
            icon = "EsoUI/Art/Buttons/Gamepad/gp_downArrow.dds"
        end
        local INHERIT_COLOR = true
        local comparisonValueString = zo_iconTextFormatNoSpace(icon, 24, 24, self:GetDisplayValue(comparisonStatValue), INHERIT_COLOR)
        comparisonValueString = color:Colorize(comparisonValueString)
        self.control.comparisonValue:SetText(comparisonValueString)
    end
end
function ZO_StatEntry_Keyboard:ShowComparisonValue(statDelta, excludeDelta)
    if statDelta and statDelta ~= 0 then
        self.currentStatDelta = statDelta
        self.currentStatExcludeDelta = excludeDelta
        self.control.value:SetHidden(true)
        self.control.comparisonValue:SetHidden(false)
    end
end
function ZO_StatEntry_Keyboard:HideComparisonValue()
    self.currentStatDelta = 0
    self.control.comparisonValue:SetText("")
    self.control.comparisonValue:SetHidden(true)
    self.control.value:SetHidden(false)
end
    local statEntry = control.statEntry
    if statEntry then
        local statType = statEntry.statType
        local description = ZO_STAT_TOOLTIP_DESCRIPTIONS[statType]
        if description then
            InitializeTooltip(InformationTooltip, control, statEntry.tooltipAnchorSide, -5)
            local displayValue = statEntry:GetDisplayValue()
            local statName = zo_strformat(SI_STAT_NAME_FORMAT, GetString("SI_DERIVEDSTATS", statType))
            InformationTooltip:AddLine(statName, "", ZO_NORMAL_TEXT:UnpackRGBA())
            InformationTooltip:AddLine(zo_strformat(description, displayValue))
        end
    end
end
    ClearTooltip(InformationTooltip)
end
    InitializeTooltip(InformationTooltip, control, RIGHT, -5)
    InformationTooltip:AddLine(zo_strformat(SI_STAT_NAME_FORMAT, control.statData.displayName), "", ZO_NORMAL_TEXT:UnpackRGBA())
    if control.statData.description then
        InformationTooltip:AddLine(zo_strformat(control.statData.description))
    end
    if control.statData.flatValue then
        local flatValueText = ZO_SELECTED_TEXT:Colorize(control.statData.flatValue)
        InformationTooltip:AddLine(zo_strformat(SI_STAT_RATING_TOOLTIP_FORMAT, control.statData.displayName, flatValueText), "", ZO_NORMAL_TEXT:UnpackRGBA())
    end
end
    ClearTooltip(InformationTooltip)
end
-- Mundus stats
ZO_StatsMundus_ShouldShowHelpKeybind = false
    InitializeTooltip(GameTooltip, control, control.mouseOverAnchor, control.mouseOverOffsetX)
    local buffSlot = control.buffSlot
    if buffSlot then
        GameTooltip:SetBuff(buffSlot, "player")
        ZO_StatsMundus_ShouldShowHelpKeybind = false
    else
        GameTooltip:AddLine(GetString(SI_STATS_MUNDUS_NONE_TOOLTIP_TITLE), "", ZO_SELECTED_TEXT:UnpackRGBA())
        GameTooltip:AddLine(GetString(SI_STATS_MUNDUS_NONE_TOOLTIP_DESCRIPTION), "", ZO_NORMAL_TEXT:UnpackRGBA())
        ZO_StatsMundus_ShouldShowHelpKeybind = true
    end
    local statEffects = control.statEffects
    if statEffects then
        for i, data in ipairs(statEffects) do
            local EXCLUDE_DELTA = true
            STATS:ShowComparisonForDerivedStat(data.statType, data.effect, EXCLUDE_DELTA)
        end
    end
    KEYBIND_STRIP:UpdateKeybindButtonGroup(STATS.keybindButtons)
    ZO_ADVANCED_STATS_WINDOW:SetMundusMouseAbility(control.abilityId)
    ZO_ADVANCED_STATS_WINDOW:UpdateAdvancedStats()
end
    ZO_StatsMundus_ShouldShowHelpKeybind = false
    local statEffects = control.statEffects
    if statEffects then
        for i, data in ipairs(statEffects) do
            STATS:HideComparisonForDerivedStat(data.statType)
        end
    end
    KEYBIND_STRIP:UpdateKeybindButtonGroup(STATS.keybindButtons)
    ClearTooltip(GameTooltip)
    ZO_ADVANCED_STATS_WINDOW:SetMundusMouseAbility()
    ZO_ADVANCED_STATS_WINDOW:UpdateAdvancedStats()
end
-- Shared logic functions
-- Populates mundusIconControls passed in and returns table of shown mundus names
function ZO_SharedStats_SetupMundusIconControls(mundusIconControls, mouseOverAnchor, mouseOverOffsetX, GetDerivedStatByTypeFunction)
    local mundusStoneNameList = {}
    local activeMundusStoneBuffIndices = { GetUnitActiveMundusStoneBuffIndices("player") }
    local numActiveMundusStoneBuffs = #activeMundusStoneBuffIndices
    local numMundusSlots = GetNumAvailableMundusStoneSlots()
    local isPlayerAtMundusWarningLevel = GetUnitLevel("player") >= GetMundusWarningLevel()
    local mundusStoneNameListContainsBuff = false
    for i, control in ipairs(mundusIconControls) do
        control.statEffects = {}
        control.mouseOverAnchor = mouseOverAnchor
        control.mouseOverOffsetX = mouseOverOffsetX
        if i <= numMundusSlots - numActiveMundusStoneBuffs then
            local nameText = GetString("SI_MUNDUSSTONE", MUNDUS_STONE_INVALID)
            control.buffSlot = nil
            control.icon:SetTexture(ZO_STAT_MUNDUS_ICONS[MUNDUS_STONE_INVALID])
            if isPlayerAtMundusWarningLevel then
                control.icon:SetColor(ZO_ERROR_COLOR:UnpackRGBA())
                nameText = ZO_ERROR_COLOR:Colorize(nameText)
            else
                control.icon:SetColor(ZO_DISABLED_TEXT:UnpackRGBA())
            end
            control:SetHidden(false)
            if mundusStoneNameListContainsBuff or #mundusStoneNameList == 0 then
                table.insert(mundusStoneNameList, zo_strformat(SI_STATS_MUNDUS_FORMATTER, nameText))
            end
        elseif i <= numMundusSlots then
            local buffName, _, _, buffSlot, _, _, _, _, _, _, abilityId = GetUnitBuffInfo("player", activeMundusStoneBuffIndices[i - (numMundusSlots - numActiveMundusStoneBuffs)])
            local mundusStoneIndex = GetAbilityMundusStoneType(abilityId)
            control.buffSlot = buffSlot
            control.abilityId = abilityId
            control.icon:SetTexture(ZO_STAT_MUNDUS_ICONS[mundusStoneIndex])
            control.icon:SetColor(ZO_SELECTED_TEXT:UnpackRGBA())
            control:SetHidden(false)
            table.insert(mundusStoneNameList, zo_strformat(SI_STATS_MUNDUS_FORMATTER, buffName))
            mundusStoneNameListContainsBuff = true
            local numStatsForAbility = GetAbilityNumDerivedStats(abilityId)
            for statIndex = 1, numStatsForAbility do
                local statType, effectValue = GetAbilityDerivedStatAndEffectByIndex(abilityId, statIndex)
                local statControl = GetDerivedStatByTypeFunction(statType)
                if statControl then
                    statControl.statEntry:SetHasMundusEffect(true)
                    statControl.statEntry:UpdateStatValue()
                end
                local statEffect =
                {
                    statType = statType,
                    effect = effectValue,
                }
                table.insert(control.statEffects, statEffect)
            end
        else
            control.buffSlot = nil
            control:SetHidden(true)
        end
    end
    return mundusStoneNameList
end