This repository has been archived by the owner on Jun 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
FocusFrame.lua
659 lines (565 loc) · 20.2 KB
/
FocusFrame.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
local _G = getfenv(0)
local Focus = assert(_G.FocusCore, "FocusCore not loaded.")
local AurasUpdate
FocusFrameDB = FocusFrameDB or { unlock = true, scale = 1 }
-- Most local functions here can be post-hooked using Focus:OnEvent() if needed.
-- @see UpdatePortrait() in mods/classPortraits.lua for examples.
-- @see Focus:RemoveEvent() for completely overwriting functions
local function OnFocusTargetUpdated(event, name, isDead, unitID)
if not name then
FocusFrameTargetofTargetFrame:Hide()
return
end
if name == "target" then return end
FocusFrameTargetofTargetFrame:Show()
local health, maxHealth = Focus:GetTargetHealth()
local mana, maxMana = Focus:GetTargetPower()
FocusFrameTargetofTargetHealthBar:SetMinMaxValues(0, maxHealth)
FocusFrameTargetofTargetHealthBar:SetValue(health)
FocusFrameTargetofTargetManaBar:SetMinMaxValues(0, maxMana)
FocusFrameTargetofTargetManaBar:SetValue(mana)
if isDead then
FocusFrameTargetofTargetDeadText:Show()
else
FocusFrameTargetofTargetDeadText:Hide()
end
FocusFrameTargetofTargetName:SetText(name)
SetPortraitTexture(FocusFrameTargetofTargetPortrait, unitID)
end
local function OnFocusSat(event, unit)
FocusName:SetText(UnitName(unit))
FocusFrame:SetScale(FocusFrameDB.scale or 1)
--[[if Focus:GetTargetName() then
OnFocusTargetChanged(event, Focus:GetTargetName(), Focus:TargetIsDead())
end]]
FocusFrame:SetScript("OnUpdate", FocusFrame_CastingBarOnUpdate)
FocusFrame:Show()
end
local function OnFocusIdle()
if FocusFrameDB.fadeOnIdle then
FocusFrame:SetAlpha(0.6)
end
end
local function OnFocusActive()
FocusFrame:SetAlpha(1)
end
local function HealthUpdate()
local health, maxHealth = Focus:GetHealth()
local mana, maxMana = Focus:GetPower()
FocusFrameHealthBar:SetMinMaxValues(0, maxHealth)
FocusFrameHealthBar:SetValue(health)
FocusFrameManaBar:SetMinMaxValues(0, maxMana)
FocusFrameManaBar:SetValue(mana)
if FocusFrameManaBar:IsShown() then
local color = Focus:GetPowerColor()
FocusFrameManaBar:SetStatusBarColor(color.r, color.g, color.b)
else
FocusFrameManaBarText:SetText(nil)
end
if Focus:IsDead() then
FocusDeadText:Show()
else
FocusDeadText:Hide()
end
end
local function RaidTargetIconUpdate()
local index = Focus:GetData("raidIcon")
if index then
SetRaidTargetIconTexture(FocusRaidTargetIcon, index)
FocusRaidTargetIcon:Show()
else
FocusRaidTargetIcon:Hide()
end
end
function FocusFrame_CastingBarOnUpdate() -- ran every fps
local cast, value, maxValue, sparkPosition, timer = Focus:GetCast()
if cast then
local castbar = FocusCastingBar
castbar:SetMinMaxValues(0, maxValue)
castbar:SetValue(value)
castbar.spark:SetPoint("CENTER", castbar, "LEFT", sparkPosition * castbar:GetWidth(), 0)
castbar.timer:SetText(timer)
if cast.immune then
castbar.shield:Show()
else
castbar.shield:Hide()
end
if not castbar:IsVisible() or castbar.text:GetText() ~= cast.spell then
castbar.text:SetText(cast.spell)
castbar.icon:SetTexture(cast.icon)
castbar:SetAlpha(castbar:GetAlpha())
castbar:Show()
end
else
FocusCastingBar:Hide()
end
end
function FocusFrame_OnShow()
-- Ran on FOCUS_SET. "target" = focus here
if UnitIsEnemy("target", "player") then
PlaySound("igCreatureAggroSelect")
elseif UnitIsFriend("player", "target") then
PlaySound("igCharacterNPCSelect")
else
PlaySound("igCreatureNeutralSelect")
end
end
function FocusFrame_OnHide() -- can't be hooked, global due to xml
if FocusFrame:IsVisible() then -- called by FOCUS_CLEAR instead of OnHide
FocusFrame:SetScript("OnUpdate", nil)
FocusFrame:Hide()
else
PlaySound("INTERFACESOUND_LOSTTARGETUNIT")
CloseDropDownMenus()
end
end
function FocusFrame_OnClick(button)
if button == "RightButton" and SpellIsTargeting() then
return SpellStopTargeting()
end
if button == "LeftButton" then
if SpellIsTargeting() then
Focus:Call(SpellTargetUnit)
elseif CursorHasItem() then
Focus:Call(DropItemOnUnit)
else
Focus:TargetFocus()
end
else
ToggleDropDownMenu(1, nil, FocusFrameDropDown, "FocusFrame", 120, 10)
end
end
function FocusFrameTarget_OnClick(button)
if button == "LeftButton" then
Focus:TargetFocusTarget()
end
end
local function CheckPortrait(event, unit)
SetPortraitTexture(FocusPortrait, unit)
FocusPortrait:SetAlpha(1)
end
local function CheckLevel()
local level, isCorpse = Focus:GetData("unitLevel", "unitIsCorpse")
if isCorpse == 1 then
FocusLevelText:Hide()
FocusHighLevelTexture:Show()
elseif level > 0 then
-- Normal level target
FocusLevelText:SetText(level)
-- Color level number
if Focus:GetData("playerCanAttack") == 1 then
local color = GetDifficultyColor(level)
FocusLevelText:SetVertexColor(color.r, color.g, color.b)
else
FocusLevelText:SetVertexColor(1.0, 0.82, 0.0)
end
FocusLevelText:Show()
FocusHighLevelTexture:Hide()
else
-- Target is too high level to tell
FocusLevelText:Hide()
FocusHighLevelTexture:Show()
end
end
local function CheckFaction()
if Focus:GetData("unitPlayerControlled") == 1 then
local r, g, b = Focus:GetReactionColors()
FocusFrameNameBackground:SetVertexColor(r, g, b)
FocusPortrait:SetVertexColor(1.0, 1.0, 1.0)
elseif Focus:GetData("unitIsTapped") == 1 and Focus:GetData("unitIsTappedByPlayer") ~= 1 then
FocusFrameNameBackground:SetVertexColor(0.5, 0.5, 0.5)
FocusPortrait:SetVertexColor(0.5, 0.5, 0.5)
elseif Focus:GetData("unitIsCivilian") == 1 then
FocusFrameNameBackground:SetVertexColor(1.0, 1.0, 1.0)
FocusPortrait:SetVertexColor(1.0, 1.0, 1.0)
else
local reaction = Focus:GetData("unitReaction")
if reaction then
local color = UnitReactionColor[reaction]
FocusFrameNameBackground:SetVertexColor(color.r, color.g, color.b)
else
FocusFrameNameBackground:SetVertexColor(0, 0, 1.0)
end
FocusPortrait:SetVertexColor(1.0, 1.0, 1.0)
end
-- PvP Icon
local factionGroup = Focus:GetData("unitFactionGroup")
if Focus:GetData("unitIsPVPFreeForAll") == 1 then
FocusPVPIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-FFA")
FocusPVPIcon:Show()
elseif factionGroup and Focus:GetData("unitIsPVP") == 1 then
FocusPVPIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-" .. factionGroup)
FocusPVPIcon:Show()
else
FocusPVPIcon:Hide()
end
end
local function CheckClassification()
local classification = Focus:GetData("unitClassification")
if classification == "worldboss" or classification == "rareelite" or classification == "elite" then
FocusFrameTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Elite")
elseif classification == "rare" then
FocusFrameTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Rare")
else
FocusFrameTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame")
end
end
local function CheckLeader()
if Focus:GetData("unitIsPartyLeader") == 1 then
FocusLeaderIcon:Show()
else
FocusLeaderIcon:Hide()
end
end
do
-- Aura handling
-- Works the same as in blizz TargetFrame.lua
local function AdjustAuras(numDebuffs, numBuffs)
local unitIsFriend = Focus:GetData("unitIsFriend")
local targetofTarget = FocusFrameTargetofTargetFrame:IsShown()
local debuffSize, debuffFrameSize
local debuffWrap = 6
if numDebuffs >= debuffWrap then
debuffSize = 17
debuffFrameSize = 19
else
debuffSize = 21
debuffFrameSize = 23
end
if unitIsFriend == 1 then
FocusFrameBuff1:SetPoint("TOPLEFT", "FocusFrame", "BOTTOMLEFT", 5, 32)
FocusFrameDebuff1:SetPoint("TOPLEFT", "FocusFrameBuff1", "BOTTOMLEFT", 0, -2)
else
FocusFrameDebuff1:SetPoint("TOPLEFT", "FocusFrame", "BOTTOMLEFT", 5, 32)
if targetofTarget then
if numDebuffs < 5 then
FocusFrameBuff1:SetPoint("TOPLEFT", "FocusFrameDebuff6", "BOTTOMLEFT", 0, -2)
elseif numDebuffs >= 5 and numDebuffs < 10 then
FocusFrameBuff1:SetPoint("TOPLEFT", "FocusFrameDebuff6", "BOTTOMLEFT", 0, -2)
elseif numDebuffs >= 10 then
FocusFrameBuff1:SetPoint("TOPLEFT", "FocusFrameDebuff11", "BOTTOMLEFT", 0, -2)
end
else
FocusFrameBuff1:SetPoint("TOPLEFT", "FocusFrameDebuff7", "BOTTOMLEFT", 0, -2)
end
end
-- set the wrap point for the rows of de/buffs.
debuffWrap = targetofTarget and 5 or 6
-- and shrinks the debuffs if they begin to overlap the TargetFrame
if ((targetofTarget and (numBuffs == 5)) or (numDebuffs >= debuffWrap)) then
debuffSize = 17
debuffFrameSize = 19
else
debuffSize = 21
debuffFrameSize = 23
end
-- resize Buffs
for i = 1, 5 do
local button = _G["FocusFrameBuff" .. i]
if button then
button:SetWidth(debuffSize)
button:SetHeight(debuffSize)
end
end
-- resize Debuffs
for i = 1, 6 do
local button = _G["FocusFrameDebuff" .. i]
local debuffFrame = _G["FocusFrameDebuff" .. i .. "Border"]
if debuffFrame then
debuffFrame:SetWidth(debuffFrameSize)
debuffFrame:SetHeight(debuffFrameSize)
end
button:SetWidth(debuffSize)
button:SetHeight(debuffSize)
end
-- Reset anchors for debuff wrapping
_G["FocusFrameDebuff"..debuffWrap]:ClearAllPoints()
_G["FocusFrameDebuff"..debuffWrap]:SetPoint("LEFT", _G["FocusFrameDebuff"..(debuffWrap - 1)], "RIGHT", 3, 0)
_G["FocusFrameDebuff"..(debuffWrap + 1)]:ClearAllPoints()
_G["FocusFrameDebuff"..(debuffWrap + 1)]:SetPoint("TOPLEFT", "FocusFrameDebuff1", "BOTTOMLEFT", 0, -2)
_G["FocusFrameDebuff"..(debuffWrap + 2)]:ClearAllPoints()
_G["FocusFrameDebuff"..(debuffWrap + 2)]:SetPoint("LEFT", _G["FocusFrameDebuff"..(debuffWrap + 1)], "RIGHT", 3, 0)
FocusFrameDebuff11:ClearAllPoints()
FocusFrameDebuff11:SetPoint("LEFT", "FocusFrameDebuff10", "RIGHT", 3, 0)
-- Set anchor for the last row if debuffWrap is 5
FocusFrameDebuff11:ClearAllPoints()
if debuffWrap == 5 then
FocusFrameDebuff11:SetPoint("TOPLEFT", "FocusFrameDebuff6", "BOTTOMLEFT", 0, -2)
else
FocusFrameDebuff11:SetPoint("LEFT", "FocusFrameDebuff10", "RIGHT", 3, 0)
end
-- Move castbar based on amount of auras shown
local y = (numBuffs + numDebuffs) > 7 and -70 or -35
if unitIsFriend ~= 1 and numBuffs >= 1 then
FocusCastingBar:SetPoint("BOTTOMLEFT", _G["FocusFrameBuff1"], 0, -35)
else
FocusCastingBar:SetPoint("BOTTOMLEFT", FocusFrame, 20, y)
end
end
function AurasUpdate() -- local, ran very frequent
local buffData = Focus:GetBuffs()
if not buffData then return end
local buffs = buffData.buffs
local debuffs = buffData.debuffs
local numBuffs = 0
local numDebuffs = 0
-- Set buffs shown
for i = 1, 5 do
local buff = buffs[i]
local button = _G["FocusFrameBuff" .. i]
if buff then
_G["FocusFrameBuff" .. i .. "Icon"]:SetTexture(buff.icon)
button:Show()
button.id = i
numBuffs = numBuffs + 1
else
button:Hide()
end
end
-- Set debuffs shown
for i = 1, 16 do
local button = _G["FocusFrameDebuff" .. i]
local debuff = debuffs[i]
if debuff then
local debuffCount = _G["FocusFrameDebuff" .. i .. "Count"]
local debuffBorder = _G["FocusFrameDebuff" .. i .. "Border"]
local color = debuff.border
local debuffStack = debuff.stacks
_G["FocusFrameDebuff" .. i .. "Icon"]:SetTexture(debuff.icon)
if debuffStack and debuffStack > 1 then
debuffCount:SetText(debuffStack)
debuffCount:Show()
else
debuffCount:Hide()
end
debuffBorder:SetVertexColor(color[1], color[2], color[3], color[4])
button:Show()
numDebuffs = numDebuffs + 1
else
button:Hide()
end
button.id = i
end
AdjustAuras(numDebuffs, numBuffs)
end
end
-- Dropdown menu
do
local info = {}
local FocusFrameDropDown = CreateFrame("Frame", "FocusFrameDropDown")
FocusFrameDropDown.displayMode = "MENU"
local function SetRaidMark()
local mark = this.value
if mark >= 9 then mark = 0 end
Focus:Call(SetRaidTargetIcon, "target", mark)
end
local function Unlock()
FocusFrameDB.unlock = not FocusFrameDB.unlock
end
local function Rescale()
if FocusFrameDB.scale >= 1 then
FocusFrameDB.scale = 0.9
else
FocusFrameDB.scale = 1
end
FocusFrame:SetScale(FocusFrameDB.scale)
end
local function ClearFocus()
Focus:ClearFocus()
end
function FocusFrameDropDown_Initialize(level) -- ran every time dropdown is shown/updated
if not level then return end
for k, v in pairs(info) do info[k] = nil end
if level == 1 then
info.isTitle = 1
info.text = Focus:GetName()
info.notCheckable = 1
UIDropDownMenu_AddButton(info, level)
-- Reusing same table for mem improvements, so delete old values
info.disabled = nil
info.isTitle = nil
info.notCheckable = nil
local isLeader = UnitIsPartyLeader("player")
info.text = "Target Marker Icon"
info.nested = 1
info.hasArrow = isLeader
info.disabled = not isLeader
UIDropDownMenu_AddButton(info, level)
info.hasArrow = nil
info.nested = nil
info.menuList = nil
info.disabled = nil
info.text = "Clear Focus"
info.func = ClearFocus
UIDropDownMenu_AddButton(info, level)
info.isTitle = 1
info.text = "Other Options"
info.notCheckable = 1
UIDropDownMenu_AddButton(info, level)
info.disabled = nil
info.isTitle = nil
info.notCheckable = nil
info.text = "Larger Focus Frame"
info.checked = FocusFrameDB.scale or 1 >= 1
info.func = Rescale
UIDropDownMenu_AddButton(info, level)
info.checked = nil
info.text = "Unlock"
info.checked = FocusFrameDB.unlock
info.func = Unlock
UIDropDownMenu_AddButton(info, level)
info.checked = nil
-- Close menu item
info.text = "Close"
info.func = CloseDropDownMenus
info.checked = nil
info.notCheckable = 1
UIDropDownMenu_AddButton(info, level)
else
-- Build nested dropdown for raid marks
for i, name in ipairs(UnitPopupMenus["RAID_TARGET_ICON"]) do
local item = UnitPopupButtons[name]
info.color = nil
info.icon = nil
info.value = nil
for k, v in pairs(item) do
info[k] = v
info.value = i
end
info.func = SetRaidMark
UIDropDownMenu_AddButton(info, level)
end
end
end
FocusFrameDropDown.initialize = FocusFrameDropDown_Initialize
end
-- Create castbar
-- @TODO add to xml
-- lua table names are deprecated. Please use global frame names if you're gonna modify these
FocusFrame.cast = CreateFrame("StatusBar", "FocusCastingBar", FocusFrame)
FocusFrame.cast:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
FocusFrame.cast:SetStatusBarColor(0.4, 1, 0)
FocusFrame.cast:SetHeight(13)
FocusFrame.cast:SetWidth(151)
FocusFrame.cast:SetPoint("BOTTOMLEFT", FocusFrame, 15, -35)
FocusFrame.cast:SetValue(0)
FocusFrame.cast:Hide()
FocusFrame.cast.spark = FocusFrame.cast:CreateTexture("FocusCastingBarSpark", "OVERLAY")
FocusFrame.cast.spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
FocusFrame.cast.spark:SetHeight(26)
FocusFrame.cast.spark:SetWidth(26)
FocusFrame.cast.spark:SetBlendMode("ADD")
FocusFrame.cast.border = FocusFrame.cast:CreateTexture("FocusCastingBarBorder", "OVERLAY")
FocusFrame.cast.border:SetPoint("TOPLEFT", -23, 20)
FocusFrame.cast.border:SetPoint("TOPRIGHT", 23, 20)
FocusFrame.cast.border:SetHeight(50)
FocusFrame.cast.border:SetTexture("Interface\\AddOns\\FocusFrame\\Media\\UI-CastingBar-Border-Small.blp")
FocusFrame.cast.text = FocusFrame.cast:CreateFontString("FocusCastingBarText", "OVERLAY")
FocusFrame.cast.text:SetTextColor(1, 1, 1)
FocusFrame.cast.text:SetFont(STANDARD_TEXT_FONT, 10)
FocusFrame.cast.text:SetShadowColor(0, 0, 0)
FocusFrame.cast.text:SetPoint("CENTER", FocusFrame.cast, 0, 2)
FocusFrame.cast.text:SetText("Drain Life")
FocusFrame.cast.timer = FocusFrame.cast:CreateFontString("FocusCastingBarTimer", "OVERLAY")
FocusFrame.cast.timer:SetTextColor(1, 1, 1)
FocusFrame.cast.timer:SetFont(STANDARD_TEXT_FONT, 9)
FocusFrame.cast.timer:SetShadowColor(0, 0, 0)
FocusFrame.cast.timer:SetPoint("RIGHT", FocusFrame.cast, 28, 2)
FocusFrame.cast.timer:SetText("2.0")
FocusFrame.cast.icon = FocusFrame.cast:CreateTexture("FocusCastingBarIcon", "OVERLAY", nil, 7)
FocusFrame.cast.icon:SetWidth(20)
FocusFrame.cast.icon:SetHeight(20)
FocusFrame.cast.icon:SetPoint("LEFT", FocusFrame.cast, -23, 1)
FocusFrame.cast.icon:SetTexture("Interface\\Icons\\Spell_shadow_lifedrain02")
FocusFrame.cast.shield = FocusFrame.cast:CreateTexture("FocusCastingBarShield", "OVERLAY")
FocusFrame.cast.shield:SetPoint("TOPLEFT", -28, 20)
FocusFrame.cast.shield:SetPoint("TOPRIGHT", 18, 20)
FocusFrame.cast.shield:SetHeight(50)
FocusFrame.cast.shield:SetTexture("Interface\\AddOns\\FocusFrame\\Media\\UI-CastingBar-Small-Shield.blp")
FocusFrame.cast.shield:Hide()
-- Register events
Focus:OnEvent("FOCUS_SET", OnFocusSat)
Focus:OnEvent("FOCUS_CLEAR", FocusFrame_OnHide)
Focus:OnEvent("RAID_TARGET_UPDATE", RaidTargetIconUpdate)
Focus:OnEvent("PLAYER_FLAGS_CHANGED", CheckLeader)
Focus:OnEvent("PARTY_LEADER_CHANGED", CheckLeader)
Focus:OnEvent("UNIT_HEALTH_OR_POWER", HealthUpdate)
Focus:OnEvent("UNIT_AURA", AurasUpdate)
Focus:OnEvent("UNIT_LEVEL", CheckLevel)
Focus:OnEvent("UNIT_FACTION", CheckFaction)
Focus:OnEvent("UNIT_CLASSIFICATION_CHANGED", CheckClassification)
Focus:OnEvent("UNIT_PORTRAIT_UPDATE", CheckPortrait)
Focus:OnEvent("FOCUS_UNITID_EXISTS", CheckPortrait) -- update on retarget/mouseover aswell
Focus:OnEvent("FOCUS_ACTIVE", OnFocusActive)
Focus:OnEvent("FOCUS_INACTIVE", OnFocusIdle)
Focus:OnEvent("FOCUS_TARGET_UPDATED", OnFocusTargetUpdated)
-- Chat options
SLASH_FOCUSOPTIONS1 = "/foption"
SlashCmdList.FOCUSOPTIONS = function(msg)
local space = strfind(msg or "", " ")
local cmd = strsub(msg, 1, space and (space-1))
local value = tonumber(strsub(msg, space or -1))
local print = function(a, b)
if type(b) == "boolean" then b = tostring(b) end
DEFAULT_CHAT_FRAME:AddMessage(string.format(a, b))
end
if cmd == "scale" and value then
local x = value > 0.1 and value <= 2 and value or 1
FocusFrame:SetScale(x)
FocusFrameDB.scale = x
print("Scale set to %f", x)
elseif cmd == "lock" then
FocusFrameDB.unlock = not FocusFrameDB.unlock
print("Frame is now %slocked.", FocusFrameDB.unlock and "un" or "")
elseif cmd == "nohide" then
local x = FocusFrameDB.alwaysShow
FocusFrameDB.alwaysShow = not x
print("Frame auto hide set to %s", not x)
elseif cmd == "fade" then
FocusFrameDB.fadeOnIdle = not FocusFrameDB.fadeOnIdle
print("Fade on inactive set to %s (requires retarget on focus)", FocusFrameDB.fadeOnIdle)
elseif cmd == "strictaura" then
FocusFrameDB.strictAuras = not FocusFrameDB.strictAuras
FSPELLCASTINGCOREstrictAuras = FocusFrameDB.strictAuras
print("Strict aura/cast set to %s.", FocusFrameDB.strictAuras)
elseif cmd == "noplates" then
local x = FocusFrameDB.disableNameplateScan
FocusFrameDB.disableNameplateScan = not x
print("Nameplate scanning set to %s.", x)
elseif cmd == "target" then
FocusFrameDB.tot = not FocusFrameDB.tot
OnFocusTargetUpdated(nil, nil) -- force hide tot frame
print("Target of Target set to %s", FocusFrameDB.tot)
elseif cmd == "statustext" then
FocusFrameDB.statusText = not FocusFrameDB.statusText
FocusFrameHealthBar.TextString:SetAlpha(FocusFrameDB.statusText and 0 or 1) -- kinda hacky with alpha but easiest solution
FocusFrameManaBar.TextString:SetAlpha(FocusFrameDB.statusText and 0 or 1)
print("Status text set to %s.", not FocusFrameDB.statusText)
elseif cmd == "tarcycles" and value then
local x = value > 0 and value < 50 and value or 15
FocusFrameDB.targetCycles = x
print("Target cycles set to %d.", x)
elseif cmd == "reset" then
FocusFrameDB = { scale = 1, unlock = true }
FocusFrame:SetScale(1)
FocusFrame:SetAlpha(1)
FocusFrame:SetPoint("TOPLEFT", 250, -300)
FocusFrame:StopMovingOrSizing() -- trigger save
FSPELLCASTINGCOREstrictAuras = false
FocusFrameHealthBar.TextString:SetAlpha(1)
FocusFrameManaBar.TextString:SetAlpha(1)
print("FocusFrame has been reset.")
else
print("FocusFrame v%s:", GetAddOnMetadata("FocusFrame", "version"))
print(" scale 1.0 -|cff00FF7F Change frame size (0.2 - 2.0)")
print(" lock -|cff00FF7F Toggle dragging of frame")
print(" nohide -|cff00FF7F Toggle auto hide of frame on loading screens/release spirit.")
print(" fade -|cff00FF7F Toggle fading of frame when focus hasn't been updated for ~10s.")
print(" strictaura -|cff00FF7F Toggle aura/cast optimization. See github wiki for more info.")
print(" noplates -|cff00FF7F Toggle nameplate scanning. Disable if you don't use nameplates.")
print(" target -|cff00FF7F Toggle focus target's target frame.")
print(" statustext -|cff00FF7F Toggle mana/hp status text.")
print(" tarcycles -|cff00FF7F Set how many targets to cycle through for /fmcast.")
print(" reset -|cff00FF7F Reset to default settings.")
end
end