-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nameplates.lua
200 lines (167 loc) · 6.54 KB
/
Nameplates.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
--[[
Nameplates, Shadow (Horde) from Mal'Ganis (US)
]]
local Nameplates = select(2, ...)
Nameplates = LibStub("AceAddon-3.0"):NewAddon(Nameplates, "Nameplates", "AceEvent-3.0", "AceHook-3.0")
local frames = {}
local SML
function Nameplates:OnInitialize()
self.defaults = {
profile = {
textureName = "Nameplates Default",
bindings = false,
hideHealth = false,
hideCast = false,
hideElite = false,
hideUninterruptible = false,
name = { name = "Friz Quadrata TT", size = 12, border = "", shadowEnabled = false, shadowColor = { r = 0, g = 0, b = 0, a = 1 }, x = 0, y = 0 },
level = { name = "Friz Quadrata TT", size = 11, border = "", shadowEnabled = false, shadowColor = { r = 0, g = 0, b = 0, a = 1 }, x = 0, y = 0 },
text = { healthType = "percent", castType = "crtmax", name = "Friz Quadrata TT", size = 8, border = "OUTLINE", shadowEnabled = false, shadowColor = { r = 0, g = 0, b = 0, a = 1 }, x = 0, y = 0 },
},
}
self.db = LibStub:GetLibrary("AceDB-3.0"):New("NameplatesDB", self.defaults)
self.revision = tonumber(string.match("$Revision$", "(%d+)") or 1)
SML = LibStub:GetLibrary("LibSharedMedia-3.0")
end
function Nameplates:SetupFontString(text, type)
-- No idea why this is needed
if( not text.SetFont ) then
return
end
local config = self.db.profile[type]
text:SetFont(SML:Fetch(SML.MediaType.FONT, config.name), config.size, config.border)
-- Set shadow
if( config.shadowEnabled ) then
if( not text.NPOriginalShadow ) then
local x, y = text:GetShadowOffset()
local r, g, b, a = text:GetShadowColor()
text.NPOriginalShadow = { r = r, g = g, b = b, a = a, y = y, x = x }
end
text:SetShadowColor(config.shadowColor.r, config.shadowColor.g, config.shadowColor.b, config.shadowColor.a)
text:SetShadowOffset(config.x, config.y)
-- Restore original
elseif( text.NPOriginalShadow ) then
text:SetShadowColor(text.NPOriginalShadow.r, text.NPOriginalShadow.g, text.NPOriginalShadow.b, text.NPOriginalShadow.a)
text:SetShadowOffset(text.NPOriginalShadow.x, text.NPOriginalShadow.y)
text.NPOriginalShadow = nil
end
end
function Nameplates:SetupHiding(texture, type)
if( self.db.profile[type] ) then
texture:Hide()
if( type == "hideUninterruptible" ) then
texture:SetHeight(0.5)
texture:SetWidth(0.5)
texture:SetTexture("")
end
end
end
function Nameplates:OnShow(frame)
local threatGlow, healthBorder, castBorder, castUninterruptible, spellIcon, highlightTexture, nameText, levelText, bossIcon, raidIcon, mobIcon = frame:GetParent():GetRegions()
-- Health bar
frame:SetStatusBarTexture(SML:Fetch(SML.MediaType.STATUSBAR, self.db.profile.textureName))
-- Font string config
self:SetupFontString(frame.NPText, "text")
self:SetupFontString(nameText, "name")
self:SetupFontString(levelText, "level")
-- Hide things
self:SetupHiding(healthBorder, "hideHealth")
self:SetupHiding(castBorder, "hideCast")
self:SetupHiding(mobIcon, "hideElite")
self:SetupHiding(castUninterruptible, "hideUninterruptible")
end
function Nameplates:HealthOnValueChanged(frame, value)
local maxValue = select(2, frame:GetMinMaxValues())
if( self.db.profile.text.healthType == "minmax" ) then
frame.NPText:SetFormattedText("%d / %d", value, maxValue)
elseif( self.db.profile.text.healthType == "deff" ) then
value = maxValue - value
if( value > 0 ) then
frame.NPText:SetFormattedText("-%d", value)
else
frame.NPText:SetText("")
end
elseif( self.db.profile.text.healthType == "percent" ) then
frame.NPText:SetFormattedText("%d%%", value / maxValue * 100)
else
frame.NPText:SetText("")
end
end
function Nameplates:CastOnValueChanged(frame, value)
local minValue, maxValue = frame:GetMinMaxValues()
if( value >= maxValue or value == 0 ) then
frame.NPText:SetText("")
return
end
-- Quick hack stolen from old NP, I need to fix this up
maxValue = maxValue - value + ( value - minValue )
value = math.floor(((value - minValue) * 100) + 0.5) / 100
if( self.db.profile.text.castType == "crtmax" ) then
frame.NPText:SetFormattedText("%.2f / %.2f", value, maxValue)
elseif( self.db.profile.text.castType == "crt" ) then
frame.NPText:SetFormattedText("%.2f", value)
elseif( self.db.profile.text.castType == "percent" ) then
frame.NPText:SetFormattedText("%d%%", value / maxValue)
elseif( self.db.profile.text.castType == "timeleft" ) then
frame.NPText:SetFormattedText("%.2f", maxValue - value)
else
frame.NPText:SetText("")
end
end
function Nameplates:CreateText(frame)
frame.NPText = frame:CreateFontString(nil, "ARTWORK")
frame.NPText:SetFont(SML:Fetch(SML.MediaType.FONT, self.db.profile.text.name), self.db.profile.text.size, self.db.profile.text.border)
frame.NPText:SetPoint("CENTER", frame, "CENTER", 5, 0)
end
-- REGIONS
-- 1 = Threat glow, is the mob attacking you, or almost not etc
-- 2 = Health bar/level border
-- 3 = Border for the casting bar
-- 4 = Spell icon for the casting bar
-- 5 = Glow around the health bar when hovering over
-- 6 = Name text
-- 7 = Level text
-- 8 = Skull icon if the mob/player is 10 or more levels higher then you
-- 9 = Raid icon when you're close enough to the mob/player to see the name plate
-- 10 = Elite icon
local function hookFrames(...)
local self = Nameplates
for i=1, select("#", ...) do
local frame = select(i, ...)
local region = frame:GetRegions()
if( not frames[frame] and not frame:GetName() and region and region:GetObjectType() == "Texture" and region:GetTexture() == "Interface\\TargetingFrame\\UI-TargetingFrame-Flash" ) then
frames[frame] = true
local health, cast = frame:GetChildren()
self:CreateText(health)
self:HookScript(health, "OnValueChanged", "HealthOnValueChanged")
self:HookScript(health, "OnShow", "OnShow")
self:HealthOnValueChanged(health, health:GetValue())
self:OnShow(health)
self:CreateText(cast)
self:HookScript(cast, "OnValueChanged", "CastOnValueChanged")
self:HookScript(cast, "OnShow", "OnShow")
self:CastOnValueChanged(cast, cast:GetValue())
self:OnShow(health)
end
end
end
local numChildren = -1
local frame = CreateFrame("Frame")
frame:SetScript("OnUpdate", function(self, elapsed)
if( WorldFrame:GetNumChildren() ~= numChildren ) then
numChildren = WorldFrame:GetNumChildren()
hookFrames(WorldFrame:GetChildren())
end
end)
function Nameplates:Reload()
for frame in pairs(frames) do
local health, cast = frame:GetChildren()
self:OnShow(health)
self:HealthOnValueChanged(health, health:GetValue())
self:OnShow(cast)
self:CastOnValueChanged(cast, cast:GetValue())
end
end
function Nameplates:Print(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cff33ff99Nameplates|r: " .. msg)
end