-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArcanistJobGauge.lua
182 lines (155 loc) · 7.29 KB
/
ArcanistJobGauge.lua
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
ArcanistJobGauge = {
name = "ArcanistJobGauge",
version = "1.0",
author = "@ViciousTomato",
color = "92e721",
menuName = "Arcanist Job Gauge",
playerName = GetRawUnitName("player"),
isPlayerArcanist = GetUnitClassId("player") == 117,
fragment = nil,
}
local CRUX_BUFF_ID = 184220
local TEXTURES = {
ACTIVE = "ArcanistJobGauge/assets/crux_active.dds",
INACTIVE = "ArcanistJobGauge/assets/crux_inactive.dds",
}
local COLORS = {
ACTIVE = { 0.57, 0.9, 0.12 },
INACTIVE = { 1, 1, 1 }
}
function ArcanistJobGauge.Colorize(text, color)
if not color then color = ArcanistJobGauge.color end
text = string.format('|c%s%s|r', color, text)
return text
end
function ArcanistJobGauge.OnAddOnLoaded(event, addonName)
if addonName ~= ArcanistJobGauge.name then return end
EVENT_MANAGER:UnregisterForEvent(ArcanistJobGauge.name, EVENT_ADD_ON_LOADED)
ArcanistJobGauge.characterSavedVars = ZO_SavedVars:New("ArcanistJobGaugeSavedVariables", 1, nil,
ArcanistJobGauge.savedVars)
ArcanistJobGauge.accountSavedVars = ZO_SavedVars:NewAccountWide("ArcanistJobGaugeSavedVariables", 1, nil,
ArcanistJobGauge.savedVars)
if not ArcanistJobGauge.characterSavedVars.accountWide then
ArcanistJobGauge.savedVars = ArcanistJobGauge.characterSavedVars
else
ArcanistJobGauge.savedVars = ArcanistJobGauge.accountSavedVars
end
ArcanistJobGauge.LoadSettings()
ArcanistJobGauge:Initialize()
end
function ArcanistJobGauge:Initialize()
ArcanistJobGaugeWindowLabelBG:SetMouseEnabled(not ArcanistJobGauge.savedVars.isLocked)
EVENT_MANAGER:RegisterForEvent(ArcanistJobGauge.name, EVENT_COMBAT_EVENT, ArcanistJobGauge.updateCounter)
EVENT_MANAGER:AddFilterForEvent(ArcanistJobGauge.name, EVENT_COMBAT_EVENT, REGISTER_FILTER_SOURCE_COMBAT_UNIT_TYPE,
COMBAT_UNIT_TYPE_PLAYER)
EVENT_MANAGER:AddFilterForEvent(ArcanistJobGauge.name, EVENT_COMBAT_EVENT, REGISTER_FILTER_IS_ERROR, false)
EVENT_MANAGER:RegisterForEvent(ArcanistJobGauge.name, EVENT_PLAYER_COMBAT_STATE, ArcanistJobGauge.updateCombat)
ArcanistJobGauge.updateVisibility()
ArcanistJobGauge.setPosition()
ArcanistJobGauge.updateCounter()
ArcanistJobGauge.updateCombat()
end
function ArcanistJobGauge.AddSceneFragments()
if ArcanistJobGauge.fragment ~= nil or not ArcanistJobGauge.savedVars.enabled then return end
ArcanistJobGauge.fragment = ZO_HUDFadeSceneFragment:New(ArcanistJobGaugeWindow, nil, 0)
HUD_SCENE:AddFragment(ArcanistJobGauge.fragment)
HUD_UI_SCENE:AddFragment(ArcanistJobGauge.fragment)
end
function ArcanistJobGauge.RemoveSceneFragments()
if ArcanistJobGauge.fragment == nil then return end
HUD_SCENE:RemoveFragment(ArcanistJobGauge.fragment)
HUD_UI_SCENE:RemoveFragment(ArcanistJobGauge.fragment)
ArcanistJobGauge.fragment = nil
end
function ArcanistJobGauge.savePosition()
ArcanistJobGauge.savedVars.left = ArcanistJobGaugeWindowLabelBG:GetLeft()
ArcanistJobGauge.savedVars.top = ArcanistJobGaugeWindowLabelBG:GetTop()
end
function ArcanistJobGauge.updateCombat()
ArcanistJobGauge.AddSceneFragments()
if ArcanistJobGauge.savedVars.hideCombat then
if IsUnitInCombat("player") then
ArcanistJobGaugeWindow:SetHidden(false)
else
ArcanistJobGaugeWindow:SetHidden(true)
ArcanistJobGauge.RemoveSceneFragments()
end
end
end
function ArcanistJobGauge.updateSimplified()
if ArcanistJobGauge.savedVars.simplified then
ArcanistJobGaugeWindowComplex:SetHidden(true)
ArcanistJobGaugeWindowSimplified:SetHidden(false)
else
ArcanistJobGaugeWindowComplex:SetHidden(false)
ArcanistJobGaugeWindowSimplified:SetHidden(true)
end
end
function ArcanistJobGauge.updateVisibility()
if not ArcanistJobGauge.savedVars.enabled then
ArcanistJobGaugeWindow:SetHidden(true)
return
end
if ArcanistJobGauge.isPlayerArcanist then
ArcanistJobGaugeWindow:SetHidden(false)
ArcanistJobGauge.updateSimplified()
else
ArcanistJobGaugeWindow:SetHidden(true)
end
end
function ArcanistJobGauge.setPosition(left, top)
if left == nil or top == nil then
left = ArcanistJobGauge.savedVars.left
top = ArcanistJobGauge.savedVars.top
end
ArcanistJobGaugeWindowLabelBG:ClearAnchors()
ArcanistJobGaugeWindowLabelBG:SetAnchor(TOPLEFT, ArcanistJobGaugeWindow, CENTER, left, top)
end
function ArcanistJobGauge.updateCounter()
local hasCrux = false
for i = 1, GetNumBuffs("player") do
local _, _, _, _, stackCount, _, _, _, _, _, abilityId, _, _ = GetUnitBuffInfo("player", i)
if abilityId == CRUX_BUFF_ID then
hasCrux = true
-- putting previous crux into higher one just in case there is situation where number goes up or down more than 1
if stackCount == 1 then
ArcanistJobGaugeWindowComplexCrux1:SetTexture(TEXTURES.ACTIVE)
ArcanistJobGaugeWindowSimplifiedCrux1:SetColor(unpack(COLORS.ACTIVE))
ArcanistJobGaugeWindowComplexCrux2:SetTexture(TEXTURES.INACTIVE)
ArcanistJobGaugeWindowComplexCrux3:SetTexture(TEXTURES.INACTIVE)
ArcanistJobGaugeWindowSimplifiedCrux2:SetColor(unpack(COLORS.INACTIVE))
ArcanistJobGaugeWindowSimplifiedCrux3:SetColor(unpack(COLORS.INACTIVE))
return
else
if stackCount == 2 then
ArcanistJobGaugeWindowComplexCrux1:SetTexture(TEXTURES.ACTIVE)
ArcanistJobGaugeWindowSimplifiedCrux1:SetColor(unpack(COLORS.ACTIVE))
ArcanistJobGaugeWindowComplexCrux2:SetTexture(TEXTURES.ACTIVE)
ArcanistJobGaugeWindowSimplifiedCrux2:SetColor(unpack(COLORS.ACTIVE))
ArcanistJobGaugeWindowComplexCrux3:SetTexture(TEXTURES.INACTIVE)
ArcanistJobGaugeWindowSimplifiedCrux3:SetColor(unpack(COLORS.INACTIVE))
return
else
if stackCount == 3 then
ArcanistJobGaugeWindowComplexCrux1:SetTexture(TEXTURES.ACTIVE)
ArcanistJobGaugeWindowSimplifiedCrux1:SetColor(unpack(COLORS.ACTIVE))
ArcanistJobGaugeWindowComplexCrux2:SetTexture(TEXTURES.ACTIVE)
ArcanistJobGaugeWindowSimplifiedCrux2:SetColor(unpack(COLORS.ACTIVE))
ArcanistJobGaugeWindowComplexCrux3:SetTexture(TEXTURES.ACTIVE)
ArcanistJobGaugeWindowSimplifiedCrux3:SetColor(unpack(COLORS.ACTIVE))
return
end
end
end
end
end
if not hasCrux then
ArcanistJobGaugeWindowComplexCrux1:SetTexture(TEXTURES.INACTIVE)
ArcanistJobGaugeWindowComplexCrux2:SetTexture(TEXTURES.INACTIVE)
ArcanistJobGaugeWindowComplexCrux3:SetTexture(TEXTURES.INACTIVE)
ArcanistJobGaugeWindowSimplifiedCrux1:SetColor(unpack(COLORS.INACTIVE))
ArcanistJobGaugeWindowSimplifiedCrux2:SetColor(unpack(COLORS.INACTIVE))
ArcanistJobGaugeWindowSimplifiedCrux3:SetColor(unpack(COLORS.INACTIVE))
end
end
EVENT_MANAGER:RegisterForEvent(ArcanistJobGauge.name, EVENT_ADD_ON_LOADED, ArcanistJobGauge.OnAddOnLoaded)