forked from Monteo/SuperMacro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SM_Tooltip.lua
367 lines (351 loc) · 11.6 KB
/
SM_Tooltip.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
--SM_VARS.macroTip1 = 1; -- for spell, item
--SM_VARS.macroTip2 = 1; -- for macro code
SM_ITEM_PATTERN = "[%w '%-:]+";
SM_SPELL_PATTERN="[%w'%(%) %-:]+";
oldActionButton_SetTooltip=ActionButton_SetTooltip;
function ActionButton_SetTooltip()
oldActionButton_SetTooltip();
SM_ActionButton_SetTooltip();
end
--fix Error: attempt to index a nil value in function 'ActionButton_GetPagedID' [Monteo]
oldBActionButton_SetTooltip=BActionButton_SetTooltip;
function BActionButton_SetTooltip()
oldBActionButton_SetTooltip();
SM_BActionButton_SetTooltip();
end
-- Hooking into tooltip caller of Bongos [Fixed by Threewords]
if (BActionButton ~= nil) then
oldUpdateTooltip=BActionButton.UpdateTooltip;
BActionButton.UpdateTooltip = function(button)
oldUpdateTooltip(button);
SM_BActionButton_SetTooltip();
end
end
function SM_ActionButton_SetTooltip()
local actionid=ActionButton_GetPagedID(this);
local macroname=GetActionText(actionid); --or getglobal(this:GetName().."Name"):GetText();
if ( macroname ) then
local macro, _, body = GetMacroInfo(GetMacroIndexByName(macroname));
-- for supermacros
local superfound = SM_ACTION[actionid];
if ( superfound ) then
macro,_,body=GetSuperMacroInfo(superfound);
GameTooltipTextLeft1:SetText(macro);
GameTooltip:Show();
end
if ( SM_VARS.macroTip1==1 ) then
local actiontype, spell = SM_GetActionSpell(macro, superfound);
if ( actiontype=="spell" ) then
local id, book = SM_FindSpell(spell);
GameTooltip:SetSpell(id, book);
local s, r = GetSpellName(id, book);
if ( r ) then
GameTooltipTextRight1:SetText("|cff00ffff"..r.."|r");
GameTooltipTextRight1:Show();
GameTooltip:Show();
end
return;
elseif ( actiontype=="item" ) then
local id, book = FindItem(spell);
if ( book ) then
GameTooltip:SetBagItem(id, book);
elseif ( id ) then
GameTooltip:SetInventoryItem( 'player', id);
end
return;
end
end
if ( SM_VARS.macroTip2 == 1 ) then
-- show macro code
if ( not GameTooltipTextLeft1:GetText() ) then return; end
body = gsub(body, "\n$", "");
GameTooltipTextLeft1:SetText( "|cff00ffff"..macro.."|r");
GameTooltipTextLeft2:SetText("|cffffffff"..body.."|r");
GameTooltipTextLeft2:Show();
GameTooltipTextLeft1:SetWidth(284);
GameTooltipTextLeft2:SetWidth(284);
GameTooltip:SetWidth(300);
GameTooltip:SetHeight( GameTooltipTextLeft1:GetHeight() + GameTooltipTextLeft2:GetHeight() + 23);
GameTooltipTextLeft2:SetNonSpaceWrap(true);
return;
end
end
-- brighten rank text on all tooltips
if ( GameTooltipTextRight1:GetText() ) then
local t = GameTooltipTextRight1:GetText();
GameTooltipTextRight1:SetText("|cff00ffff"..t.."|r");
end
-- show crit info for Attack
if ( GameTooltipTextLeft1:GetText()=="Attack" ) then
id, book = FindSpell("Attack","");
GameTooltip:SetSpell(id, book);
GameTooltip:Show();
end
end
--fix Error: attempt to index a nil value in function 'ActionButton_GetPagedID' [Monteo]
function SM_BActionButton_SetTooltip()
local actionid=BActionButton.GetPagedID(this:GetID());
local macroname=GetActionText(actionid); --or getglobal(this:GetName().."Name"):GetText();
if ( macroname ) then
local macro, _, body = GetMacroInfo(GetMacroIndexByName(macroname));
-- for supermacros
local superfound = SM_ACTION[actionid];
if ( superfound ) then
macro,_,body=GetSuperMacroInfo(superfound);
GameTooltipTextLeft1:SetText(macro);
GameTooltip:Show();
end
if ( SM_VARS.macroTip1==1 ) then
local actiontype, spell = SM_GetActionSpell(macro, superfound);
if ( actiontype=="spell" ) then
local id, book = SM_FindSpell(spell);
GameTooltip:SetSpell(id, book);
local s, r = GetSpellName(id, book);
if ( r ) then
GameTooltipTextRight1:SetText("|cff00ffff"..r.."|r");
GameTooltipTextRight1:Show();
GameTooltip:Show();
end
return;
elseif ( actiontype=="item" ) then
local id, book = FindItem(spell);
if ( book ) then
GameTooltip:SetBagItem(id, book);
elseif ( id ) then
GameTooltip:SetInventoryItem( 'player', id);
end
return;
end
end
if ( SM_VARS.macroTip2 == 1 ) then
-- show macro code
if ( not GameTooltipTextLeft1:GetText() ) then return; end
body = gsub(body, "\n$", "");
GameTooltipTextLeft1:SetText( "|cff00ffff"..macro.."|r");
GameTooltipTextLeft2:SetText("|cffffffff"..body.."|r");
GameTooltipTextLeft2:Show();
GameTooltipTextLeft1:SetWidth(284);
GameTooltipTextLeft2:SetWidth(284);
GameTooltip:SetWidth(300);
GameTooltip:SetHeight( GameTooltipTextLeft1:GetHeight() + GameTooltipTextLeft2:GetHeight() + 23);
GameTooltipTextLeft2:SetNonSpaceWrap(true);
return;
end
end
-- brighten rank text on all tooltips
if ( GameTooltipTextRight1:GetText() ) then
local t = GameTooltipTextRight1:GetText();
GameTooltipTextRight1:SetText("|cff00ffff"..t.."|r");
end
-- show crit info for Attack
if ( GameTooltipTextLeft1:GetText()=="Attack" ) then
id, book = FindSpell("Attack","");
GameTooltip:SetSpell(id, book);
GameTooltip:Show();
end
end
function SM_ActionButton_OnLeave()
this.updateTooltip=nil;
GameTooltipTextLeft2:SetWidth(100);
GameTooltipTextLeft2:SetText("");
GameTooltip:Hide();
end
local oldGetActionCooldown = GetActionCooldown;
function GetActionCooldown( actionid )
-- start, duration, enable
local macro=GetActionText(actionid);
if ( macro and SM_VARS.checkCooldown==1 ) then
local name, icon, body = GetMacroInfo(GetMacroIndexByName(macro));
-- for supermacros
local superfound = SM_ACTION[actionid];
if ( superfound ) then
name,icon,body=GetSuperMacroInfo(superfound);
end
local buttonName = this:GetName() or ("BActionButton"..actionid); -- The part after 'or' is to support Bongos [Fixed by Threewords]
local macroname, pic;
if ( this ) then
macroname=getglobal(buttonName.."Name");
if ( macroname ) then
macroname:SetText(name);
end
pic = getglobal(buttonName.."Icon");
if ( pic ) then
pic:SetTexture(icon);
end
end
local actiontype, spell, texture = SM_GetActionSpell(name, superfound);
if ( actiontype=="spell") then
if ( SM_VARS.replaceIcon==1 and texture and pic) then
pic:SetTexture(texture);
end
local id, book = SM_FindSpell(spell);
return GetSpellCooldown( id, book);
elseif ( actiontype=="item") then
if ( SM_VARS.replaceIcon==1 and texture and pic) then
pic:SetTexture(texture);
end
local id, book, texture, count = FindItem(spell);
if ( count and count>1 and macroname ) then
macroname:Hide();
getglobal(buttonName.."Count"):SetText(count);
elseif ( macroname ) then
macroname:Show();
getglobal(buttonName.."Count"):SetText("");
end
if ( book ) then
return GetContainerItemCooldown(id, book);
elseif ( id ) then
return GetInventoryItemCooldown('player', id);
end
end
end
return oldGetActionCooldown( actionid );
end
function FindFirstSpell( text )
if not text then return nil end;
local body = text;
if (ReplaceAlias and ASFOptions.aliasOn) then
-- correct aliases
body = ReplaceAlias(body);
end
local id, book, texture, spell;
while ( string.find(body, "CastSpellByName") ) do
spell = gsub(body,'^.-CastSpellByName.-%(.-(["\'])(.-)%1.*$','%2');
id, book = SM_FindSpell(spell);
if ( id ) then
texture = GetSpellTexture(id, book);
break;
end
body = gsub(body, "CastSpellByName","",1);
end
if ( not id and string.find(body,"/cast") ) then
spell = gsub(body,'^.-/cast *('..SM_SPELL_PATTERN..')[\n]?.*$','%1');
id, book = SM_FindSpell(spell);
if ( id and book ) then
texture = GetSpellTexture(id, book);
end
end
if ( not id ) then
while ( string.find(body, "[%p%s]cast%(") ) do
spell = gsub(body,'^.-[%p%s]-cast%(.-(["\'])(.-)%1.*$','%2');
id, book = SM_FindSpell(spell);
if ( id ) then
texture = GetSpellTexture(id, book);
break;
end
body = gsub(body, "[%p%s]cast%(","", 1);
end
end
if ( not id ) then
while ( string.find(body, "CastSpell")) do
spell = gsub(body,'^.-CastSpell.-%(%s*(.-)%s*)%s*%).*$','%1');
local _,_,spellid = strfind(spell,"^(%d+).*");
if ( spellid ) then
local _,_,spellbook=strfind(spell,"^.-"..spellid..",%s*'(%a+)'%s*");
id=spellid;
book=spellbook or 'spell';
texture = GetSpellTexture(id, book);
break;
end
body = gsub(body, "CastSpell","", 1);
end
end
return id, book, texture, spell;
end
function FindFirstItem( text )
if not text then return nil end;
local body = text;
if (ReplaceAlias and ASFOptions.aliasOn) then
-- correct aliases
body = ReplaceAlias(body);
end
local bag, slot, texture, count, item;
if ( strfind(body,"UseItemByName") ) then
while ( string.find(body, "UseItemByName") ) do
item = gsub(body,'^.-UseItemByName.-%(.-(["\'])(.-)%1.*$','%2');
bag, slot, texture, count = FindItem(item);
if ( bag ) then
return bag, slot, texture, count, item;
end
body = gsub(body, "UseItemByName","", 1);
end
end
if ( strfind(body,"/use") ) then
while ( string.find(body, "/use") ) do
if ( strfind(body, '^.-/use *%d') ) then
-- number means container or inventory slot
bag, slot = nil, nil;
gsub(body,'^.-/use -(%d+)[,%s]*(%d*)', function(b,s)
bag=tonumber(b);
slot=tonumber(s);
end );
if ( bag and slot ) then
texture, count = GetContainerItemInfo(bag, slot);
item = ItemLinkToName(GetContainerItemLink(bag, slot));
elseif ( bag and bag>0 and bag<=23) then
texture, count = GetInventoryItemTexture('player', bag), GetInventoryItemCount('player', bag);
item = ItemLinkToName(GetInventoryItemLink('player', bag));
end
else
-- not a number
item = gsub(body,'^.-/use *('..SM_ITEM_PATTERN..')\n?.*$', '%1');
bag, slot, texture, count = FindItem(item);
end
if ( bag ) then
return bag, slot, texture, count, item;
end
body = gsub(body, "/use","", 1);
end
end
if ( strfind(body,"use") ) then
while ( string.find(body, "use") ) do
if ( strfind(body, '^.-use.-%(%s*%d') ) then
-- number means container or inventory slot
bag, slot = nil, nil;
gsub(body,'^.-use.-%(.-(%d+)[,%s]*(%d*)', function(b,s)
bag=tonumber(b);
slot=tonumber(s);
end );
if ( bag and slot ) then
texture, count = GetContainerItemInfo(bag, slot);
item = ItemLinkToName(GetContainerItemLink(bag, slot));
elseif ( bag and bag>0 and bag<=23) then
texture, count = GetInventoryItemTexture('player', bag), GetInventoryItemCount('player', bag);
item = ItemLinkToName(GetInventoryItemLink('player', bag));
end
else
-- not a number
item = gsub(body,'^.-use.-%(.-(["\'])('..SM_ITEM_PATTERN..')%1.*$','%2');
bag, slot, texture, count = FindItem(item);
end
if ( bag ) then
return bag, slot, texture, count, item;
end
body = gsub(body, "use","", 1);
end
end
while ( strfind(body, "UseInventoryItem") ) do
bag = gsub(body,'^.-UseInventoryItem.-(%d+)%s-%).*$','%1');
if ( bag~=body) then
texture = GetInventoryItemTexture('player', bag);
count = GetInventoryItemCount('player', bag);
end
if ( texture ) then
item=ItemLinkToName( GetInventoryItemLink('player', bag) );
return bag, slot, texture, count, item;
end
body = gsub(body, "UseInventoryItem","", 1);
end
while ( strfind(body, "UseContainerItem") ) do
bag = gsub(body,'^.-UseContainerItem.-(%d+)%s-,%s-(%d+)%s-%).*$','%1');
slot = gsub(body,'^.-UseContainerItem.-(%d+)%s-,%s-(%d+)%s-%).*$','%2');
if ( bag~=body and slot~=body) then
texture, count = GetContainerItemInfo(bag, slot);
end
if ( bag~=body and slot~=body and texture ) then
item=ItemLinkToName( GetContainerItemLink(bag, slot) );
return bag, slot, texture, count, item;
end
body = gsub(body, "UseContainerItem","", 1);
end
end