-
Notifications
You must be signed in to change notification settings - Fork 2
/
IndicatorTalentOption.lua
173 lines (151 loc) · 6.01 KB
/
IndicatorTalentOption.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
-- Show or hide indicators based on talent option
---------------------------------------------------------------------------
-- SET YOUR OPTIONS HERE
--
-- "talentID" The ID of the talent that controls the indicator
-- "spec" The spec to run the check on - can use both name and ID
-- "indicator" The name of the indicator you want to control
-- If the indicator doesn't exist in the layout, it will be ignored
-- "enabled" The state of the indicator you want when the talent is active
-- The inverse state will be used when the talent is not active
-- "layout" Name of the layout you want this to apply to
-- If no layout is provided, it will apply to all layouts
---------------------------------------------------------------------------
---@type table<number, IndicatorTalentOption>
local IndicatorTalentOptions = {
-- Example, Only show Prescience indicator when:
-- 1. The talent Prescience is active
-- 2. Playing Augmentation
-- 3. Using the the default layout
{ talentID = 409311, spec = "Augmentation", indicator = "Prescience", enabled = true, layout = "default" },
}
---------------------------------------------------------------------------
-- END OF OPTIONS
---------------------------------------------------------------------------
-- functions
local F = Cell.funcs
local isValidOption, updateCurrentLayoutOptions, updateIndicators, maybeOption, Print, DevAdd
-- vars
local curLayout = Cell.vars.currentLayout
local ValidTalentOptions = {}
local layoutChanged, init
local debug = false
---@param opt IndicatorTalentOption
---@param idx number
---@return boolean
isValidOption = function(opt, idx)
if not opt then return false end
if not opt["talentID"] or type(opt["talentID"]) ~= "number" then
Print("Missing talentID for indicator #" .. idx, true)
return false
end
if not opt["spec"] or (type(opt["spec"]) ~= "string" and type(opt["spec"]) ~= "number") then
Print("Missing spec for indicator #" .. idx, true)
return false
end
if not opt["indicator"] or type(opt["indicator"]) ~= "string" then
Print("Missing indicator for indicator #" .. idx, true)
return false
end
if opt["enabled"] == nil or type(opt["enabled"]) ~= "boolean" then
Print("Missing enabled for indicator #" .. idx, true)
return false
end
if type(opt["layout"]) ~= "string" then
Print("Invalid layout for indicator #" .. idx, true)
end
return true
end
---@param opt IndicatorTalentOption
---@param curSpecID number
---@param curSpecName string
---@param idx number
---@return IndicatorTalentOption|false
maybeOption = function(opt, curSpecID, curSpecName, idx)
if not isValidOption(opt, idx) or (opt.spec ~= curSpecID and opt.spec ~= curSpecName) then
return false
end
if opt["layout"] and opt["layout"] ~= curLayout then
return false
end
for _, indicator in pairs(Cell.vars.currentLayoutTable.indicators) do
if opt.indicator == indicator.name or opt.indicator == indicator.indicatorName then
return {
talentID = opt.talentID,
spec = opt.spec,
indicatorName = indicator.indicatorName,
enabled = opt.enabled,
}
end
end
Print("No indicator matching \"" .. opt.indicator .. "\" found #" .. idx)
return false
end
updateCurrentLayoutOptions = function()
Print("updateCurrentLayoutOptions")
ValidTalentOptions = {}
curLayout = Cell.vars.currentLayout
local curSpecID, curSpecName = GetSpecializationInfo(GetSpecialization())
for idx, opt in pairs(IndicatorTalentOptions) do
local option = maybeOption(opt, curSpecID, curSpecName, idx)
if option then
local layout = opt["layout"] or curLayout
if not ValidTalentOptions[layout] then ValidTalentOptions[layout] = {} end
table.insert(ValidTalentOptions[layout], option)
end
end
DevAdd(ValidTalentOptions, "ValidTalentOptions")
end
updateIndicators = function()
Print("updateIndicators - " .. "layout:" .. curLayout .. " valid:" .. (ValidTalentOptions[curLayout] and #ValidTalentOptions[curLayout] or 0))
if not ValidTalentOptions[curLayout] then return end
for _, opt in pairs(ValidTalentOptions[curLayout]) do
local state
if IsPlayerSpell(opt.talentID) then
state = opt.enabled
else
state = not opt.enabled
end
Cell:Fire("UpdateIndicators", curLayout, opt.indicatorName, "enabled", state)
end
end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:SetScript("OnEvent", function(self, event)
if event == "PLAYER_ENTERING_WORLD" then
updateCurrentLayoutOptions()
-- Init callbacks event listeners
if not init then
init = true
Cell:RegisterCallback("UpdateLayout", "IndicatorTalentOption_UpdateLayout", function()
layoutChanged = true
updateCurrentLayoutOptions()
end)
-- Talent update
eventFrame:RegisterEvent("TRAIT_CONFIG_UPDATED")
-- Easy way to revert current changes
eventFrame:RegisterEvent("ACTIVE_PLAYER_SPECIALIZATION_CHANGED")
end
end
updateIndicators()
end)
-- Use this to properly delay updates on various changes to layout
CellLoadingBar:HookScript("OnHide", function()
if layoutChanged then
layoutChanged = false
updateIndicators()
end
end)
Cell.frames.optionsFrame:HookScript("OnHide", updateIndicators)
-- Debug
Print = function(msg, isErr)
if isErr then F:Print("IndicatorTalentOption: |cFFFF3030" .. msg .. "|r")
elseif debug then F:Print("IndicatorTalentOption: " .. msg) end
end
DevAdd = function(data, name) if debug and DevTool then DevTool:AddData(data, name) end end
---@class IndicatorTalentOption
---@field talentID number
---@field spec string|number
---@field indicator string
---@field enabled boolean
---@field layout string|nil