-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionless.lua
More file actions
174 lines (143 loc) · 5.41 KB
/
Questionless.lua
File metadata and controls
174 lines (143 loc) · 5.41 KB
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
Questionless = LibStub("AceAddon-3.0"):NewAddon("Questionless", "AceBucket-3.0", "AceEvent-3.0")
function Questionless:EditShadow(button, macroID)
local _, icon, text = GetMacroInfo(macroID)
-- Check if the macro has text and its icon is not a question mark
if text and icon ~= 134400 then
local statement = text:match("/use ([^\n]+)") or text:match("/cast ([^\n]+)")
-- Get the current color
local r, g, b = button.icon:GetVertexColor()
-- Evaluates macro options to check if the macro is not usable
-- IMPORTANT! Requires a "known" condition for every Talent involved
if statement and not SecureCmdOptionParse(statement) then
-- Check if the icon hasn't been altered by other addons
if r == 1 and g == 1 and b == 1 then
button.icon:SetVertexColor(0.5, 0.5, 0.5)
end
else
-- Check if the icon hasn't been altered by other addons
if r == 0.5 and g == 0.5 and b == 0.5 then
button.icon:SetVertexColor(1, 1, 1)
end
end
end
end
-- To avoid analyzing everything again, just check the category
-- IMPORTANT! In case of issues, add a check for the text of the macro
function Questionless:GetMacroID(button)
local slot = button:GetPagedID(button) or button:CalculateAction(button) or button:GetAttribute("action") or 0
if HasAction(slot) then
local category, macroID = GetActionInfo(slot)
if category == "macro" then
return macroID
end
end
end
function Questionless:FixButton(button)
local macroID = self:GetMacroID(button)
if macroID then
self:EditShadow(button, macroID)
-- Check if this button has been already hooked here
if not button.isEditShadowHooked then
-- Do stuff when mouseover starts
button:HookScript("OnEnter", function()
self:FixButton(button)
end)
-- Do stuff when mousover ends, for drag-and-drop
button:HookScript("OnLeave", function()
self:FixButton(button)
end)
-- Note that this button has just been hooked here
button.isEditShadowHooked = true
end
end
end
function Questionless:FixMacro(macroID)
local _, old_icon, text = GetMacroInfo(macroID)
-- Check if the macro has text
if text then
local statement = text:match("/use ([^\n]+)") or text:match("/cast ([^\n]+)")
-- Set the icon to be a question mark
local new_icon = 134400
-- Evaluates macro options to check if the macro is not usable
-- IMPORTANT! Requires a "known" condition for every Talent involved
if statement and not SecureCmdOptionParse(statement) then
local spellID = statement:match("known:(%d+)")
if spellID then
-- Set the icon to match the Spell used in the "known" condition
local spell_info = C_Spell.GetSpellInfo(spellID)
if spell_info then
new_icon = spell_info.iconID
end
end
end
-- Check if not in combat, if the macro contains "known:", and if the new icon is different from the old icon
if not UnitAffectingCombat("player") and string.match(text, "known:") and old_icon ~= new_icon then
EditMacro(macroID, nil, new_icon)
end
end
end
function Questionless:FixButtons()
-- Action Bars 1-8 (in order)
local bars = {
"Action",
"MultiBarBottomLeft",
"MultiBarBottomRight",
"MultiBarRight",
"MultiBarLeft",
"MultiBar5",
"MultiBar6",
"MultiBar7",
}
for _, bar in pairs(bars) do
for slot = 1, 12 do
local button = _G[bar .. "Button" .. slot]
self:FixButton(button)
end
end
end
function Questionless:FixMacros()
-- Loop through account macros (1-120) and character macros (121-150)
for macroID = 1, 150 do
self:FixMacro(macroID)
end
end
function Questionless:OnEnable()
-- Do stuff when the Macros window is being closed
C_AddOns.LoadAddOn("Blizzard_MacroUI")
MacroFrame:HookScript("OnHide", function()
self:FixMacros()
self:FixButtons()
end)
-- Nature's Swiftness
self:RegisterEvent("ACTIONBAR_UPDATE_USABLE", function()
self:FixButtons()
end)
self:RegisterEvent("PLAYER_ENTERING_WORLD", function()
self:FixMacros()
self:FixButtons()
end)
-- Traveler's Tundra Mammoth
self:RegisterEvent("PLAYER_MOUNT_DISPLAY_CHANGED", function()
self:FixButtons()
end)
self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED", function()
self:FixMacros()
self:FixButtons()
end)
-- Cloudburst Totem
self:RegisterEvent("SPELL_UPDATE_ICON", function()
self:FixButtons()
end)
-- Talent changes within the same Specialization
self:RegisterEvent("TRAIT_CONFIG_UPDATED", function()
self:FixMacros()
self:FixButtons()
end)
-- Dragonriding
self:RegisterEvent("UPDATE_BONUS_ACTIONBAR", function()
self:FixButtons()
end)
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT", function()
self:FixButtons()
end)
end