-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodules.lua
175 lines (154 loc) · 5.47 KB
/
modules.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
local a, c, v = select(2, ...):unpack()
--===================================================
-- Range & Mana Display
-- A good bit borrowed from TullaCC, who makes this cpu-efficient
--===================================================
local _G, next, pairs, ATTACK_BUTTON_FLASH_TIME, IsActionInRange, IsUsableAction, HasAction = _G, next, pairs, ATTACK_BUTTON_FLASH_TIME, IsActionInRange, IsUsableAction, HasAction
local total = 0
local throttle = 0.15
local buttons = {}
local buttonColors = {}
local colors = {}
colors['normal'] = {1, 1, 1}
colors['outmana'] = {0.3, 0.3, 0.8}
colors['outrange'] = {0.8, 0.1, 0.1}
colors['unusable'] = {0.3, 0.3, 0.3}
local updater = CreateFrame("frame")
updater:Hide()
--=========================================
-- BUTTON FUNCTIONS
--=========================================
-- This actually colors the button, main function
local function UpdateButtonUsable(self, force)
if force then
buttonColors[self] = nil
end
local action = self.action
local isUsable, notEnoughMana = IsUsableAction(action)
local colorkey = "normal"
if (isUsable) then
if (ActionHasRange(action) and IsActionInRange(action) == false) then
colorkey = "outrange"
elseif (notEnoughMana) then
colorkey = "outmana"
end
else
colorkey = "unusable"
end
-- cache results, because SetVertexColor is expensive, we don't want to recall it if unecessary
if buttonColors[self] == colorkey then return end
buttonColors[self] = colorkey
local r, g, b = unpack(colors[colorkey])
self.icon:SetVertexColor(r, g, b)
end
-- since we stripped the OnUpdate from the button, we gotta reimplement this blizzard code
local function UpdateButtonFlash(self, elapsed)
if self.flashing ~= 1 then return end
self.flashtime = self.flashtime + elapsed
if (flashtime >= ATTACK_BUTTON_FLASH_TIME) then
local flashTexture = self.Flash;
if ( flashTexture:IsShown() ) then
flashTexture:Hide();
else
flashTexture:Show();
end
self.flashtime = 0;
end
end
--=========================================
-- UPDATER FUNCTIONS
-- Loop through / enable OnUpdater as necessary
--=========================================
local function UpdateButtons(elapsed)
if next(buttons) then
for button in pairs(buttons) do
UpdateButtonUsable(button)
UpdateButtonFlash(button, elapsed)
end
return true
end
return false
end
local function RequestUpdate()
if next(buttons) then
updater:Show()
end
end
-- add button to the queue if it's visible and actionable
-- then run the onupdate if we're passed the throttle time
local function UpdateButtonStatus(self)
local action = self.action
if action and self:IsVisible() and HasAction(action) then
buttons[self] = true
else
buttons[self] = nil
end
RequestUpdate()
end
-- Throttled Updater
-- Automatically hides when not in use, reducing onupdate calls
updater:SetScript("OnUpdate", function(self, elapsed)
total = total + elapsed
if (total >= throttle) then
total = 0
if not UpdateButtons(elapsed) then
self:Hide()
end
end
end)
--===================================================
-- Hotkey Improvements
--===================================================
function a:UpdateHotkeys(frame)
if (not self and frame) then self = frame end
local hotkey = _G[self:GetName() .. "HotKey"]
local text = hotkey:GetText()
if (not text) then return end
text = string.gsub(text, "(s%-)", "S-")
text = string.gsub(text, "(a%-)", "A-")
text = string.gsub(text, "(c%-)", "C-")
text = string.gsub(text, KEY_MOUSEWHEELDOWN , "MDn")
text = string.gsub(text, KEY_MOUSEWHEELUP , "MUp")
text = string.gsub(text, KEY_BUTTON3, "M3")
text = string.gsub(text, KEY_BUTTON4, "M4")
text = string.gsub(text, KEY_BUTTON5, "M5")
text = string.gsub(text, KEY_MOUSEWHEELUP, "MU")
text = string.gsub(text, KEY_MOUSEWHEELDOWN, "MD")
text = string.gsub(text, KEY_NUMPAD0, "N0")
text = string.gsub(text, KEY_NUMPAD1, "N1")
text = string.gsub(text, KEY_NUMPAD2, "N2")
text = string.gsub(text, KEY_NUMPAD3, "N3")
text = string.gsub(text, KEY_NUMPAD4, "N4")
text = string.gsub(text, KEY_NUMPAD5, "N5")
text = string.gsub(text, KEY_NUMPAD6, "N6")
text = string.gsub(text, KEY_NUMPAD7, "N7")
text = string.gsub(text, KEY_NUMPAD8, "N8")
text = string.gsub(text, KEY_NUMPAD9, "N9")
text = string.gsub(text, KEY_NUMPADDECIMAL, "N.")
text = string.gsub(text, KEY_NUMPADDIVIDE, "N/")
text = string.gsub(text, KEY_NUMPADMINUS, "N-")
text = string.gsub(text, KEY_NUMPADMULTIPLY, "N*")
text = string.gsub(text, KEY_NUMPADPLUS, "N+")
text = string.gsub(text, KEY_PAGEUP, "PU")
text = string.gsub(text, KEY_PAGEDOWN, "PD")
text = string.gsub(text, KEY_SPACE, "Spc")
text = string.gsub(text, KEY_INSERT, "Ins")
text = string.gsub(text, KEY_HOME, "Hm")
text = string.gsub(text, KEY_DELETE, "Del")
text = string.gsub(text, KEY_INSERT_MAC, "Hlp") -- mac
hotkey:SetText(text)
end
--=====================================================
-- Main Hooks
-- Dequeue this button's updater, and use our own queue
--=====================================================
hooksecurefunc('ActionButton_OnUpdate', function(button)
button:HookScript('OnShow', UpdateButtonStatus)
button:HookScript('OnHide', UpdateButtonStatus)
button:SetScript('OnUpdate', nil)
UpdateButtonStatus(button)
end)
hooksecurefunc('ActionButton_Update', UpdateButtonStatus)
hooksecurefunc('ActionButton_UpdateUsable', function(button) UpdateButtonUsable(button, true) end)
hooksecurefunc("ActionButton_UpdateHotkeys", a.UpdateHotkeys)
hooksecurefunc("PetActionButton_SetHotkeys", a.UpdateHotkeys)