forked from kakaZzzz/AutoEquip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuff.lua
243 lines (187 loc) · 5.63 KB
/
buff.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
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
local _, SELFAQ = ...
local debug = SELFAQ.debug
local clone = SELFAQ.clone
local diff = SELFAQ.diff
local L = SELFAQ.L
local player = SELFAQ.player
local GetItemTexture = SELFAQ.GetItemTexture
function SELFAQ.createBuffIcon()
if SELFAQ.buff ~= nil then
return
end
-- 注册事件的frame
local timerf = CreateFrame("Frame")
timerf.TimeSinceLastUpdate = 0
-- 函数执行间隔时间
timerf.Interval = 0.2
timerf:SetScript("OnUpdate", SELFAQ.onBuffChanged)
-- 选择BUTTON类似,才能触发鼠标事件
local f = CreateFrame("Button", "AutoEquip_Buff", UIParent, "BackdropTemplate")
SELFAQ.buff = f
f:SetFrameStrata("HIGH")
f:SetWidth(40)
f:SetHeight(40)
f:SetScale(AQSV.buffZoom)
f:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "Interface/Tooltips/UI-Tooltip-Background", edgeSize = 2});
f:SetBackdropBorderColor(0,0,0,0.9);
-- buff时间倒计时
local t1 = f:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
t1:SetFont(STANDARD_TEXT_FONT, 18, "OUTLINE")
-- t1:SetShadowColor(0, 0, 0, 1)
-- t1:SetShadowOffset(1, -1)
t1:SetPoint("BOTTOM", f, 2, -24)
f.buffTime = t1
-- buff层数
local t2 = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
t2:SetFont(STANDARD_TEXT_FONT, 18, "OUTLINE")
-- t2:SetShadowColor(0, 0, 0, 1)
-- t2:SetShadowOffset(1, -1)
t2:SetPoint("CENTER", f, 2, 0)
f.count = t2
local texture = f:CreateTexture(nil, "BACKGROUND")
-- 取消边框
texture:SetTexCoord(0.07, 0.93, 0.07, 0.93)
texture:SetAllPoints(f)
f.texture = texture
local text = f:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
text:SetFont(STANDARD_TEXT_FONT, 12, "OUTLINE")
text:SetText(L["Buff Alert"])
-- text:SetShadowColor(0, 0, 0, 1)
-- text:SetShadowOffset(1, -1)
text:SetPoint("CENTER", f, 2, 0)
f.drag = text
local menuFrame = CreateFrame("Frame", nil, f, "UIDropDownMenuTemplate")
local menu = {}
menu[1] = {}
menu[1]["text"] = L[" Lock frame"]
menu[1]["checked"] = AQSV.buffLocked
menu[1]["func"] = function()
AQSV.buffLocked = not AQSV.buffLocked
SELFAQ.lockBuff()
menu[1]["checked"] = AQSV.locked
end
menu[2] = {}
menu[2]["text"] = L[" Close"]
menu[2]["func"] = function()
menuFrame:Hide()
end
f.menu = menuFrame
f.menuList = menu
f:RegisterForClicks("RightButtonDown");
f:SetScript('OnClick', function(self, button)
if AQSV.buffLocked then
if not UnitAffectingCombat("player") then
CancelUnitBuff("player", f.spellIndex)
end
else
EasyMenu(menu, menuFrame, "cursor", 0 , 0, "MENU")
end
end)
f:SetScript("OnEnter", function(self)
SELFAQ.showBuffTooltip()
end)
f:SetScript("OnLeave", function(self)
SELFAQ.hideTooltip()
end)
-- 定位判断
SELFAQ.lockBuff()
-- 实现拖动
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:SetFrameLevel(2)
-- 初始化位置
f:SetPoint(AQSV.pointBuff, AQSV.xBuff, AQSV.yBuff)
if AQSV.enableBuff then
f:Show()
else
f:Hide()
end
for k,v in pairs(AQSV.usableItems) do
for k1,v1 in pairs(v) do
local spellName = GetItemSpell(v1)
if spellName and not tContains(SELFAQ.buffs, spellName) then
tinsert(SELFAQ.buffs, spellName)
end
end
end
-- debug(SELFAQ.buffs)
end
function SELFAQ.lockBuff()
SELFAQ.buff.menuList[1]["checked"] = AQSV.buffLocked
-- SELFAQ.buff:EnableMouse(not AQSV.buffLocked)
SELFAQ.buff:EnableMouse(true)
SELFAQ.buff:SetMovable(not AQSV.buffLocked)
SELFAQ.buff:RegisterForDrag("LeftButton")
SELFAQ.f.checkbox["buffLocked"]:SetChecked(AQSV.buffLocked)
if AQSV.buffLocked then
SELFAQ.buff.drag:Hide()
SELFAQ.buff:Hide()
-- SELFAQ.buff:SetAlpha(0)
SELFAQ.buff:SetBackdropColor(0,0,0,0)
else
SELFAQ.buff.drag:Show()
SELFAQ.buff:Show()
-- SELFAQ.buff:SetAlpha(1)
SELFAQ.buff:SetBackdropColor(0,0,0,1)
end
end
function SELFAQ.onBuffChanged(self, elapsed)
if not AQSV.enableBuff then
SELFAQ.buff:Hide()
return
end
self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
if (self.TimeSinceLastUpdate > self.Interval) then
-- 重新计时
self.TimeSinceLastUpdate = 0
local index = 1
local find = false
local name, icon, count, debuffType, duration, expire = UnitBuff("player", index)
while name do
if tContains(SELFAQ.buffs, name) then
name = nil
find = true
else
index = index + 1
name, icon, count, debuffType, duration, expire = UnitBuff("player", index)
end
end
if find then
SELFAQ.buff.spellIndex = index
local buffTime = math.floor(expire - GetTime())
if buffTime > 60 then
buffTime = math.ceil(buffTime / 60).."m"
end
SELFAQ.buff.texture:SetTexture(icon)
SELFAQ.buff:Show()
SELFAQ.buff.buffTime:SetText(buffTime)
if count > 0 then
SELFAQ.buff.count:SetText(count)
end
else
SELFAQ.buff.spellIndex = nil
SELFAQ.buff.texture:SetTexture()
SELFAQ.buff.count:SetText()
if AQSV.buffLocked then
SELFAQ.buff:Hide()
end
SELFAQ.buff.buffTime:SetText()
end
end
end
function SELFAQ.showBuffTooltip()
if not AQSV.buffLocked then
local tooltip = _G["GameTooltip"]
tooltip:ClearLines()
tooltip:SetOwner(SELFAQ.buff, "ANCHOR_NONE")
tooltip:SetPoint("BOTTOM", SELFAQ.buff, "TOP" )
-- tooltip:SetPoint("BOTTOMLEFT",button,0,-20)
tooltip:AddLine(SELFAQ.color("00FF00",L["Auto-detect trinket buff"]))
tooltip:AddLine(SELFAQ.color("FFFFFF",L["Unlock:"]))
tooltip:AddLine(L["Right-Click: Lock Position"])
tooltip:AddLine(L["Left-Drag: Move Frame"])
tooltip:AddLine(SELFAQ.color("FFFFFF",L["Locked:"]))
tooltip:AddLine(L["Right-Click: Cancel Aura"])
tooltip:Show()
end
end