-
Notifications
You must be signed in to change notification settings - Fork 0
/
NameplateClassColors.lua
186 lines (151 loc) · 5.98 KB
/
NameplateClassColors.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
-- NAMESPACE: NameplateClassColors
NameplateClassColors = {}
-- STATE VARIABLES
local defaults = {
["playersOnly"] = true,
["enabled"] = true,
}
local loaded = false
local linkKey = "nameplateclasscolors"
-- INTERFACE
local NameplateClassColorsFrame = CreateFrame("Frame") -- Root frame
-- REGISTER EVENTS
NameplateClassColorsFrame:RegisterEvent("ADDON_LOADED")
NameplateClassColorsFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
NameplateClassColorsFrame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
-- REGISTER EVENT LISTENERS
NameplateClassColorsFrame:SetScript("OnEvent", function(self, event, arg1, ...)
if event == "ADDON_LOADED" then
local addonName = arg1
if addonName == "NameplateClassColors" then
-- Initialize Settings
NameplateClassColors_Options = NameplateClassColors_Options or defaults
-- Print Information
NameplateClassColorsFrame:PrintHelp()
print("# ")
NameplateClassColorsFrame:PrintOptions()
-- Flag loaded for Nameplate Recoloring to begin
loaded = true
end
end
if event == "NAME_PLATE_UNIT_ADDED" then
local unitID = arg1
NameplateClassColorsFrame:AddNamePlate(unitID)
end
if event == "NAME_PLATE_UNIT_REMOVED" then
local unitID = arg1
NameplateClassColorsFrame:RemoveNameplate(unitID)
end
end);
-- EVENT HANDLERS
function NameplateClassColorsFrame:AddNamePlate(unitId)
if (not loaded) or (not NameplateClassColors_Options.enabled) then return end
local localizedClass, englishClass, classIndex = UnitClass(unitId)
local playerControlled = UnitPlayerControlled(unitId)
local doRecolor = (not NameplateClassColors_Options.playersOnly) or (NameplateClassColors_Options.playersOnly and playerControlled)
if doRecolor then
local classColor = C_ClassColor.GetClassColor(englishClass)
local nameplate = C_NamePlate.GetNamePlateForUnit(unitId)
local unitframe = nameplate.UnitFrame
local healthBar = unitframe.healthBar
healthBar:SetStatusBarTexture("Interface\\TARGETINGFRAME\\UI-StatusBar")
healthBar:GetStatusBarTexture():SetHorizTile(false)
healthBar:GetStatusBarTexture():SetVertTile(false)
healthBar:SetStatusBarColor(classColor:GetRGB())
end
end
function NameplateClassColorsFrame:RemoveNameplate(unitId)
if (not loaded) or (not NameplateClassColors_Options.enabled) then return end
local nameplate = C_NamePlate.GetNamePlateForUnit(unitId)
local unitframe = nameplate.UnitFrame
local healthBar = unitframe.healthBar
end
-- HELPERS
local function startsWith(text, prefix)
return text:sub(1, #prefix) == prefix
end
function NameplateClassColorsFrame:PrintOptions()
print("# Nameplate Class Colors -- Options")
print("# ")
print("# "..NameplateClassColorsFrame:createChatLink("enabled", NameplateClassColors_Options.enabled))
print("# ")
print("# "..NameplateClassColorsFrame:createChatLink("playersOnly", NameplateClassColors_Options.playersOnly))
print("# ")
print("# ----------------------------------")
end
function NameplateClassColorsFrame:createChatLink(option, value)
local color1 = "f9a825"
local color2 = "f9a825"
local template = "\124cff"..color1.."\124H"..linkKey..":%s\124h%s (%s) - click to toggle\124h"
local stringValue = ""
if type(value) == "boolean" then
if value then stringValue = "true" else stringValue = "false" end
else
stringValue = ""..value
end
return string.format(template, option, option, stringValue)
end
-- Create a local reference to the SetHyperLink function
local SetHyperlink = ItemRefTooltip.SetHyperlink
-- Then override it to intercept our Recount links
function ItemRefTooltip:SetHyperlink(link)
-- If the link doesn't start with "recountlink", pass it on
if not startsWith(link, linkKey) then
SetHyperlink(self, link)
return
end
local option = link:match(linkKey..":%a+.*")
if not (option == nil) then
local key = option:match(":%a+.*"):match("%a+.*")
if not (key == nil) then
NameplateClassColors_Options[key] = not NameplateClassColors_Options[key]
ReloadUI()
end
end
end
-- COMMANDS
SLASH_FSR1 = '/ncc';
function SlashCmdList.FSR(msg, editbox)
local cmd = string.lower(msg)
if cmd == "" or cmd == "help" then
PrintHelp()
end
if cmd == "reset" then
NameplateClassColors_Options.playersOnly = false
ReloadUI();
end
if cmd == "enable" then
NameplateClassColors_Options.enabled = true
ReloadUI();
end
if cmd == "disable" then
NameplateClassColors_Options.enabled = false
ReloadUI();
end
if cmd == "options" then
NameplateClassColorsFrame:PrintOptions()
end
if cmd == "players only" or cmd == "playersonly" then
NameplateClassColors_Options.playersOnly = not NameplateClassColors_Options.playersOnly;
ReloadUI();
if NameplateClassColors_Options.playersOnly then
print("Recolor nameplates for PLAYERS only.")
else
print("Recolor nameplates for PLAYERS and NPCs.")
end
end
end
-- HELP
function NameplateClassColorsFrame:PrintHelp()
print("# Nameplate Class Colors - Commands")
print("# ")
print("# /ncc playersOnly: Toggle option (true/false): either recolor ALL nameplates or only nameplates owned by PLAYERS (hostile and friendly). Reloads UI.")
print("# /ncc reset: Resets options to default. Reloads UI.")
print("# /ncc enable: Enables recolouring. Reloads UI.")
print("# /ncc disable: Disables recolouring. Reloads UI.")
print("# /ncc options: Prints the current options set for the addon.")
print("# /ncc help: Print this help message.")
print("# ")
print("# Thank you for using Nameplate Class colors!")
print("# Source: https://github.com/smp4903/wow-classic-nameplate-class-colors")
end