-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUnit.lua
128 lines (116 loc) · 4.74 KB
/
Unit.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
local LibEvent = LibStub:GetLibrary("LibEvent.7000")
local AFK = AFK
local DND = DND
local PVP = PVP
local LEVEL = LEVEL
local OFFLINE = FRIENDS_LIST_OFFLINE
local FACTION_HORDE = FACTION_HORDE
local FACTION_ALLIANCE = FACTION_ALLIANCE
local addon = TinyTooltip
local function strip(text)
return (text:gsub("%s+([|%x%s]+)<trim>", "%1"))
end
local function ColorBorder(tip, config, raw)
if (config.coloredBorder and addon.colorfunc[config.coloredBorder]) then
local r, g, b = addon.colorfunc[config.coloredBorder](raw)
LibEvent:trigger("tooltip.style.border.color", tip, r, g, b)
elseif (type(config.coloredBorder) == "string" and config.coloredBorder ~= "default") then
local r, g, b = addon:GetRGBColor(config.coloredBorder)
if (r and g and b) then
LibEvent:trigger("tooltip.style.border.color", tip, r, g, b)
end
else
LibEvent:trigger("tooltip.style.border.color", tip, unpack(addon.db.general.borderColor))
end
end
local function ColorBackground(tip, config, raw)
local bg = config.background
if not bg then return end
if (bg.colorfunc == "default" or bg.colorfunc == "" or bg.colorfunc == "inherit") then
local r, g, b, a = unpack(addon.db.general.background)
a = bg.alpha or a
LibEvent:trigger("tooltip.style.background", tip, r, g, b, a)
return
end
if (addon.colorfunc[bg.colorfunc]) then
local r, g, b = addon.colorfunc[bg.colorfunc](raw)
local a = bg.alpha or 0.8
LibEvent:trigger("tooltip.style.background", tip, r, g, b, a)
end
end
local function GrayForDead(tip, config, unit)
if (config.grayForDead and UnitIsDeadOrGhost(unit)) then
local line, text
LibEvent:trigger("tooltip.style.border.color", tip, 0.6, 0.6, 0.6)
LibEvent:trigger("tooltip.style.background", tip, 0.1, 0.1, 0.1)
for i = 1, tip:NumLines() do
line = _G[tip:GetName() .. "TextLeft" .. i]
text = (line:GetText() or ""):gsub("|cff%x%x%x%x%x%x", "|cffaaaaaa")
line:SetTextColor(0.7, 0.7, 0.7)
line:SetText(text)
end
end
end
local function ShowBigFactionIcon(tip, config, raw)
if (config.elements.factionBig and config.elements.factionBig.enable and tip.BigFactionIcon and (raw.factionGroup=="Alliance" or raw.factionGroup == "Horde")) then
tip.BigFactionIcon:Show()
tip.BigFactionIcon:SetTexture("Interface\\Timer\\".. raw.factionGroup .."-Logo")
tip:Show()
tip:SetMinimumWidth(tip:GetWidth() + 20)
end
end
local function PlayerCharacter(tip, unit, config, raw)
local data = addon:GetUnitData(unit, config.elements, raw)
addon:HideLines(tip, 2, 3)
addon:HideLine(tip, "^"..LEVEL)
addon:HideLine(tip, "^"..FACTION_ALLIANCE)
addon:HideLine(tip, "^"..FACTION_HORDE)
addon:HideLine(tip, "^"..PVP)
for i, v in ipairs(data) do
addon:GetLine(tip,i):SetText(strip(table.concat(v, " ")))
end
ColorBorder(tip, config, raw)
ColorBackground(tip, config, raw)
GrayForDead(tip, config, unit)
ShowBigFactionIcon(tip, config, raw)
end
local function NonPlayerCharacter(tip, unit, config, raw)
local levelLine = addon:FindLine(tip, "^"..LEVEL)
if (levelLine or tip:NumLines() > 1) then
local data = addon:GetUnitData(unit, config.elements, raw)
local titleLine = addon:GetNpcTitle(tip)
local increase = 0
for i, v in ipairs(data) do
if (i == 1) then
addon:GetLine(tip,i):SetText(table.concat(v, " "))
end
if (i == 2) then
if (config.elements.npcTitle.enable and titleLine) then
titleLine:SetText(addon:FormatData(titleLine:GetText(), config.elements.npcTitle, raw))
increase = 1
end
i = i + increase
addon:GetLine(tip,i):SetText(table.concat(v, " "))
elseif ( i > 2) then
i = i + increase
addon:GetLine(tip,i):SetText(table.concat(v, " "))
end
end
end
addon:HideLine(tip, "^"..LEVEL)
addon:HideLine(tip, "^"..PVP)
ColorBorder(tip, config, raw)
ColorBackground(tip, config, raw)
GrayForDead(tip, config, unit)
ShowBigFactionIcon(tip, config, raw)
end
LibEvent:attachTrigger("tooltip:unit", function(self, tip, unit)
local raw = addon:GetUnitInfo(unit)
if (UnitIsPlayer(unit)) then
PlayerCharacter(tip, unit, addon.db.unit.player, raw)
else
NonPlayerCharacter(tip, unit, addon.db.unit.npc, raw)
end
end)
addon.ColorUnitBorder = ColorBorder
addon.ColorUnitBackground = ColorBackground