-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NameplateColors.lua
322 lines (289 loc) · 8.57 KB
/
NameplateColors.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
local NAME, S = ...
local ACR = LibStub("AceConfigRegistry-3.0")
local ACD = LibStub("AceConfigDialog-3.0")
local db
local isRetail = (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE)
local GetAddOnMetadata = GetAddOnMetadata or C_AddOns.GetAddOnMetadata
local defaults = {
db_version = 1.3,
nameplatesize = 1,
namesize = 10,
pvpicon = true,
friendlynameplate = 1,
friendlynameplatecolor = {r=.34, g=.64, b=1},
friendlyname = 2,
friendlynamecolor = {r=1, g=1, b=1},
enemynameplate = 2,
enemynameplatecolor = {r=.75, g=.05, b=.05},
enemyname = 1,
enemynamecolor = {r=1, g=0, b=0},
}
-- 7.2: protected friendly nameplates dungeons/raids
local instanceType
local restricted = {
party = true,
raid = true,
}
-- only the fixed size fonts seem to be used
-- dont see any blizzard options for controlling useFixedSizeFont
local fonts = {
SystemFont_NamePlate,
SystemFont_LargeNamePlate,
SystemFont_NamePlateFixed,
SystemFont_LargeNamePlateFixed,
}
local function UpdateNamePlates()
for i, frame in ipairs(C_NamePlate.GetNamePlates()) do
NamePlateDriverFrame:ApplyFrameOptions(frame, frame.namePlateUnitToken)
CompactUnitFrame_UpdateAll(frame.UnitFrame)
end
end
local function GetValue(i)
return db[i[#i]]
end
local function SetValue(i, v)
db[i[#i]] = v
UpdateNamePlates()
end
local function GetValueColor(i)
local c = db[i[#i]]
return c.r, c.g, c.b
end
local function SetValueColor(i, r, g, b)
local c = db[i[#i]]
c.r, c.g, c.b = r, g, b
UpdateNamePlates()
end
local function ColorHidden(i)
return db[i[#i]:gsub("color", "")] ~= 2
end
local function SetFontSize(v)
for _, fontobject in pairs(fonts) do
fontobject:SetFont("Fonts/FRIZQT__.TTF", v, "")
end
end
local options = {
type = "group",
name = format("%s |cffADFF2F%s|r", NAME, GetAddOnMetadata(NAME, "Version")),
args = {
friendly = {
type = "group", order = 1,
name = "|cff57A3FF"..FRIENDLY,
inline = true,
args = {
friendlynameplate = {
type = "select", order = 1,
descStyle = "",
name = OPTION_TOOLTIP_UNIT_NAMEPLATES_SHOW_FRIENDS,
values = {
CLASS_COLORS,
FRIENDLY.." "..COLORS,
"|cffFF0000"..ADDON_DISABLED,
},
get = GetValue,
set = SetValue,
},
friendlynameplatecolor = {
type = "color", order = 2,
desc = FRIENDLY.." "..COLORS, width = "half",
name = " ",
get = GetValueColor,
set = SetValueColor,
hidden = ColorHidden,
},
spacing1 = {type = "description", order = 3, name = ""},
friendlyname = {
type = "select", order = 4,
descStyle = "",
name = FRIENDLY.." "..NAMES_LABEL,
values = {
CLASS_COLORS,
FRIENDLY.." "..COLORS,
},
get = GetValue,
set = SetValue,
},
friendlynamecolor = {
type = "color", order = 5,
desc = FRIENDLY.." "..COLORS, width = "half",
name = " ",
get = GetValueColor,
set = SetValueColor,
hidden = ColorHidden,
},
spacing2 = {type = "description", order = 6, name = " "},
},
},
spacing1 = {type = "description", order = 2, name = ""},
enemy = {
type = "group", order = 3,
name = "|cffBF0D0D"..ENEMY,
inline = true,
args = {
enemynameplate = {
type = "select", order = 1,
descStyle = "",
name = OPTION_TOOLTIP_UNIT_NAMEPLATES_SHOW_ENEMIES,
values = {
CLASS_COLORS,
HOSTILE.." "..COLORS,
"|cffFF0000"..ADDON_DISABLED,
},
get = GetValue,
set = SetValue,
},
enemynameplatecolor = {
type = "color", order = 2,
desc = HOSTILE.." "..COLORS, width = "half",
name = " ",
get = GetValueColor,
set = SetValueColor,
hidden = ColorHidden,
},
spacing1 = {type = "description", order = 3, name = ""},
enemyname = {
type = "select", order = 4,
descStyle = "",
name = ENEMY.." "..NAMES_LABEL,
values = {
CLASS_COLORS,
HOSTILE.." "..COLORS,
},
get = GetValue,
set = SetValue,
},
enemynamecolor = {
type = "color", order = 5,
desc = HOSTILE.." "..COLORS, width = "half",
name = " ",
get = GetValueColor,
set = SetValueColor,
hidden = ColorHidden,
},
spacing2 = {type = "description", order = 6, name = " "},
},
},
spacing2 = {type = "description", order = 4, name = ""},
namesize = {
type = "range", order = 7,
width = "double",
name = FONT_SIZE,
get = GetValue,
set = function(i, v)
db.namesize = v
SetFontSize(v)
end,
min = 1, softMin = 8, softMax = 24, max = 32, step = 1,
},
spacing4 = {type = "description", order = 8, name = "\n"},
pvpicon = {
type = "toggle", order = 9,
desc = "|TInterface/PVPFrame/PVP-Currency-Alliance:24|t |TInterface/PVPFrame/PVP-Currency-Horde:24|t",
name = PVP.." "..EMBLEM_SYMBOL,
get = GetValue,
set = SetValue,
},
reset = {
type = "execute", order = 10,
width = "half", descStyle = "",
name = RESET,
confirm = true, confirmText = RESET_TO_DEFAULT.."?",
func = function()
NameplateColorsDB = CopyTable(defaults)
db = NameplateColorsDB
SetFontSize(defaults.namesize)
UpdateNamePlates()
end,
},
},
}
local f = CreateFrame("Frame")
function f:OnEvent(event, ...)
if event == "PLAYER_ENTERING_WORLD" then
instanceType = select(2, IsInInstance())
elseif event == "ZONE_CHANGED_NEW_AREA" then
C_Timer.After(4, function() instanceType = select(2, IsInInstance()) end)
elseif event == "ADDON_LOADED" then
if ... == NAME then
if not NameplateColorsDB or NameplateColorsDB.db_version < defaults.db_version then
NameplateColorsDB = CopyTable(defaults)
end
db = NameplateColorsDB
ACR:RegisterOptionsTable(NAME, options)
ACD:AddToBlizOptions(NAME, NAME)
ACD:SetDefaultSize(NAME, 400, 480)
-- need to be able to toggle bars, dirty hack because lazy af at the moment
C_Timer.After(1, function()
if GetCVar("nameplateShowOnlyNames") == "1" then
SetCVar("nameplateShowOnlyNames", 0)
if not InCombatLockdown() then
NamePlateDriverFrame:UpdateNamePlateOptions() -- taints
end
end
end)
self:SetupNameplates()
self:UnregisterEvent(event)
end
end
end
function f:SetupNameplates()
local CLASS_COLORS = CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS
local pvp = {
Alliance = "|TInterface/PVPFrame/PVP-Currency-Alliance:16|t",
Horde = "|TInterface/PVPFrame/PVP-Currency-Horde:16|t",
}
-- names
hooksecurefunc("CompactUnitFrame_UpdateName", function(frame)
if restricted[instanceType] then return end
if not strfind(frame.unit, "nameplate") then return end
if ShouldShowName(frame) then
-- not sure anymore what colorNameBySelection is for in retail and why its disabled in classic
if not isRetail or frame.optionTable.colorNameBySelection then
if UnitIsPlayer(frame.unit) then
local name = GetUnitName(frame.unit)
local faction = UnitFactionGroup(frame.unit)
local icon = UnitIsPVP(frame.unit) and db.pvpicon and faction and pvp[faction] or ""
frame.name:SetText(icon..name)
local _, class = UnitClass(frame.unit)
local reaction = (UnitIsEnemy("player", frame.unit) and "enemy" or "friendly").."name"
local color = db[reaction] == 1 and CLASS_COLORS[class] or db[reaction.."color"]
frame.name:SetVertexColor(color.r, color.g, color.b)
end
end
end
end)
local playerName = UnitName("player")
-- nameplates
hooksecurefunc("CompactUnitFrame_UpdateHealthColor", function(frame)
if restricted[instanceType] then return end
-- dont color raid frames or Personal Resource Display
if not strfind(frame.unit, "nameplate") or UnitName(frame.unit) == playerName then return end
local flag = UnitIsFriend("player", frame.unit) and "friendly" or "enemy"
if UnitIsPlayer(frame.unit) then
local _, class = UnitClass(frame.unit)
local reaction = flag.."nameplate"
local color = db[reaction] == 1 and CLASS_COLORS[class] or db[reaction.."color"]
local r, g, b = color.r, color.g, color.b
frame.healthBar:SetStatusBarColor(r, g, b)
end
-- can use nameplateShowOnlyNames but it controls both enemy and friendly
local alpha = db[flag.."nameplate"] == 3 and 0 or 1
frame.healthBar:SetAlpha(alpha) -- name-only option
if isRetail then
frame.ClassificationFrame:SetAlpha(alpha) -- also hide that elite dragon icon
end
end)
SetFontSize(db.namesize)
end
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:RegisterEvent("ZONE_CHANGED_NEW_AREA")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", f.OnEvent)
for i, v in pairs({"nc", "namecolors", "nameplatecolors"}) do
_G["SLASH_NAMEPLATECOLORS"..i] = "/"..v
end
function SlashCmdList.NAMEPLATECOLORS()
if not ACD.OpenFrames.NamePlateColors then
ACD:Open(NAME)
end
end