Nameplates.lua 24.7 KB
Newer Older
Azilroka's avatar
Azilroka committed
1
local E, L, V, P, G = unpack(ElvUI); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
2
local NP = E:GetModule('NamePlates')
Simpy's avatar
Simpy committed
3
local oUF = E.oUF
Azilroka's avatar
Azilroka committed
4 5

--Lua functions
6
local _G = _G
7
local format = format
Azilroka's avatar
Azilroka committed
8
local pairs = pairs
9 10
local select = select
local strsplit = strsplit
Azilroka's avatar
Azilroka committed
11
local type = type
12
local wipe = wipe
Azilroka's avatar
Azilroka committed
13 14 15
--WoW API / Variables
local hooksecurefunc = hooksecurefunc
local CreateFrame = CreateFrame
16 17
local GetNumGroupMembers = GetNumGroupMembers
local GetNumSubgroupMembers = GetNumSubgroupMembers
Azilroka's avatar
Azilroka committed
18
local IsInGroup, IsInRaid = IsInGroup, IsInRaid
Azilroka's avatar
Azilroka committed
19
local GetInstanceInfo = GetInstanceInfo
20
local SetCVar, GetCVarDefault = SetCVar, GetCVarDefault
21
local UnitClass = UnitClass
22 23
local UnitClassification = UnitClassification
local UnitCreatureType = UnitCreatureType
24 25 26 27 28 29 30 31
local UnitExists = UnitExists
local UnitFactionGroup = UnitFactionGroup
local UnitGroupRolesAssigned = UnitGroupRolesAssigned
local UnitGUID = UnitGUID
local UnitIsFriend = UnitIsFriend
local UnitIsPlayer = UnitIsPlayer
local UnitIsPVPSanctuary = UnitIsPVPSanctuary
local UnitIsUnit = UnitIsUnit
32
local UnitName = UnitName
33
local UnitReaction = UnitReaction
Azilroka's avatar
Azilroka committed
34 35
local C_NamePlate_SetNamePlateSelfSize = C_NamePlate.SetNamePlateSelfSize
local C_NamePlate_SetNamePlateEnemySize = C_NamePlate.SetNamePlateEnemySize
36
local C_NamePlate_SetNamePlateFriendlySize = C_NamePlate.SetNamePlateFriendlySize
37 38 39
local C_NamePlate_SetNamePlateEnemyClickThrough = C_NamePlate.SetNamePlateEnemyClickThrough
local C_NamePlate_SetNamePlateFriendlyClickThrough = C_NamePlate.SetNamePlateFriendlyClickThrough
local C_NamePlate_SetNamePlateSelfClickThrough = C_NamePlate.SetNamePlateSelfClickThrough
Azilroka's avatar
Azilroka committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

local function CopySettings(from, to)
	for setting, value in pairs(from) do
		if(type(value) == 'table' and to[setting] ~= nil) then
			CopySettings(from[setting], to[setting])
		else
			if(to[setting] ~= nil) then
				to[setting] = from[setting]
			end
		end
	end
end

function NP:ResetSettings(unit)
	CopySettings(P.nameplates.units[unit], self.db.units[unit])
end

function NP:CopySettings(from, to)
	if (from == to) then return end

	CopySettings(self.db.units[from], self.db.units[to])
end

Azilroka's avatar
Azilroka committed
63
function NP:CVarReset()
Simpy's avatar
Simpy committed
64
	SetCVar('nameplateMinAlpha', 1)
65
	SetCVar('nameplateMaxAlpha', 1)
Azilroka's avatar
Azilroka committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
	SetCVar('nameplateClassResourceTopInset', GetCVarDefault('nameplateClassResourceTopInset'))
	SetCVar('nameplateGlobalScale', 1)
	SetCVar('NamePlateHorizontalScale', 1)
	SetCVar('nameplateLargeBottomInset', GetCVarDefault('nameplateLargeBottomInset'))
	SetCVar('nameplateLargerScale', 1)
	SetCVar('nameplateLargeTopInset', GetCVarDefault('nameplateLargeTopInset'))
	SetCVar('nameplateMaxAlphaDistance', GetCVarDefault('nameplateMaxAlphaDistance'))
	SetCVar('nameplateMaxScale', 1)
	SetCVar('nameplateMaxScaleDistance', 40)
	SetCVar('nameplateMinAlphaDistance', GetCVarDefault('nameplateMinAlphaDistance'))
	SetCVar('nameplateMinScale', 1)
	SetCVar('nameplateMinScaleDistance', 0)
	SetCVar('nameplateMotionSpeed', GetCVarDefault('nameplateMotionSpeed'))
	SetCVar('nameplateOccludedAlphaMult', GetCVarDefault('nameplateOccludedAlphaMult'))
	SetCVar('nameplateOtherAtBase', GetCVarDefault('nameplateOtherAtBase'))
	SetCVar('nameplateOverlapH', GetCVarDefault('nameplateOverlapH'))
Azilroka's avatar
Azilroka committed
82
	SetCVar('nameplateOverlapV', .5)
Azilroka's avatar
Azilroka committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96
	SetCVar('nameplateResourceOnTarget', GetCVarDefault('nameplateResourceOnTarget'))
	SetCVar('nameplateSelectedAlpha', 1)
	SetCVar('nameplateSelectedScale', 1)
	SetCVar('nameplateSelfAlpha', 1)
	SetCVar('nameplateSelfBottomInset', GetCVarDefault('nameplateSelfBottomInset'))
	SetCVar('nameplateSelfScale', 1)
	SetCVar('nameplateSelfTopInset', GetCVarDefault('nameplateSelfTopInset'))
	SetCVar('nameplateTargetBehindMaxDistance', 40)
end

function NP:SetCVars()
	SetCVar('nameplateMaxDistance', NP.db.loadDistance)
	SetCVar('nameplateMotion', NP.db.motionType == 'STACKED' and 1 or 0)

Azilroka's avatar
Azilroka committed
97 98
	-- SetCVar('nameplateShowAll', 1) -- NP Show Always

Azilroka's avatar
Azilroka committed
99 100 101 102
	SetCVar('NameplatePersonalShowAlways', NP.db.units.PLAYER.visibility.showAlways and 1 or 0)
	SetCVar('NameplatePersonalShowInCombat', NP.db.units.PLAYER.visibility.showInCombat and 1 or 0)
	SetCVar('NameplatePersonalShowWithTarget', NP.db.units.PLAYER.visibility.showWithTarget and 1 or 0)
	SetCVar('NameplatePersonalHideDelayAlpha', NP.db.units.PLAYER.visibility.hideDelay)
Azilroka's avatar
Azilroka committed
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

	SetCVar('nameplateShowFriendlyMinions', NP.db.units.FRIENDLY_PLAYER.minions and 1 or 0)
	SetCVar('nameplateShowEnemyMinions', (NP.db.units.ENEMY_PLAYER.minions or NP.db.units.ENEMY_NPC.minions) and 1 or 0)
	SetCVar('nameplateShowEnemyMinus', NP.db.units.ENEMY_NPC.minors and 1 or 0)
	SetCVar('nameplateShowSelf', (NP.db.units.PLAYER.useStaticPosition == true or NP.db.units.PLAYER.enable ~= true) and 0 or 1)

	if NP.db.questIcon then
		SetCVar('showQuestTrackingTooltips', 1)
	end

	if NP.db.clampToScreen then
		SetCVar('nameplateOtherTopInset', 0.08)
		SetCVar('nameplateOtherBottomInset', 0.1)
	end
end

function NP:PLAYER_REGEN_DISABLED()
	if (NP.db.showFriendlyCombat == 'TOGGLE_ON') then
		SetCVar('nameplateShowFriends', 1);
	elseif (NP.db.showFriendlyCombat == 'TOGGLE_OFF') then
		SetCVar('nameplateShowFriends', 0);
	end

	if (NP.db.showEnemyCombat == 'TOGGLE_ON') then
		SetCVar('nameplateShowEnemies', 1);
	elseif (NP.db.showEnemyCombat == 'TOGGLE_OFF') then
		SetCVar('nameplateShowEnemies', 0);
	end
end

function NP:PLAYER_REGEN_ENABLED()
	if (NP.db.showFriendlyCombat == 'TOGGLE_ON') then
		SetCVar('nameplateShowFriends', 0);
	elseif (NP.db.showFriendlyCombat == 'TOGGLE_OFF') then
		SetCVar('nameplateShowFriends', 1);
	end

	if (NP.db.showEnemyCombat == 'TOGGLE_ON') then
		SetCVar('nameplateShowEnemies', 0);
	elseif (NP.db.showEnemyCombat == 'TOGGLE_OFF') then
		SetCVar('nameplateShowEnemies', 1);
	end
end

Azilroka's avatar
Azilroka committed
147 148 149 150 151
function NP:Style(frame, unit)
	if (not unit) then
		return
	end

Azilroka's avatar
Azilroka committed
152 153
	frame.isNamePlate = true

154 155 156 157 158
	if frame:GetName() == 'ElvNP_TargetClassPower' then
		NP:StyleTargetPlate(frame, unit)
	else
		NP:StylePlate(frame, unit)
	end
Azilroka's avatar
Azilroka committed
159 160 161 162 163 164 165 166 167

	return frame
end

function NP:Construct_RaisedELement(nameplate)
	local RaisedElement = CreateFrame('Frame', nameplate:GetDebugName()..'RaisedElement', nameplate)
	RaisedElement:SetFrameStrata(nameplate:GetFrameStrata())
	RaisedElement:SetFrameLevel(10)
	RaisedElement:SetAllPoints()
Azilroka's avatar
Azilroka committed
168
	RaisedElement:EnableMouse(false)
Azilroka's avatar
Azilroka committed
169 170 171 172

	return RaisedElement
end

173 174
function NP:StyleTargetPlate(nameplate)
	nameplate:Point('CENTER')
Azilroka's avatar
Azilroka committed
175
	nameplate:Size(NP.db.plateSize.personalWidth, NP.db.plateSize.personalHeight)
176 177 178 179 180 181 182 183 184 185 186 187
	nameplate:SetScale(E.global.general.UIScale)

	nameplate.RaisedElement = NP:Construct_RaisedELement(nameplate)

	--nameplate.Power = NP:Construct_Power(nameplate)

	--nameplate.Power.Text = NP:Construct_TagText(nameplate.RaisedElement)

	nameplate.ClassPower = NP:Construct_ClassPower(nameplate)

	if E.myclass == 'DEATHKNIGHT' then
		nameplate.Runes = NP:Construct_Runes(nameplate)
Azilroka's avatar
Azilroka committed
188 189
	elseif E.myclass == 'MONK' then
		nameplate.Stagger = NP:Construct_Stagger(nameplate)
190 191 192 193 194 195 196 197
	end
end

function NP:UpdateTargetPlate(nameplate)
	NP:Update_ClassPower(nameplate)

	if E.myclass == 'DEATHKNIGHT' then
		NP:Update_Runes(nameplate)
Azilroka's avatar
Azilroka committed
198 199
	elseif E.myclass == 'MONK' then
		NP:Update_Stagger(nameplate)
200 201
	end

202
	nameplate:UpdateAllElements('OnShow')
203 204
end

Azilroka's avatar
Azilroka committed
205
function NP:ScalePlate(nameplate, scale, targetPlate)
206
	local mult = (nameplate == _G.ElvNP_Player and E.mult) or E.global.general.UIScale
207
	if targetPlate and NP.targetPlate then
208
		NP.targetPlate:SetScale(mult)
209
		NP.targetPlate = nil
Azilroka's avatar
Azilroka committed
210 211
	end

212
	if not nameplate then return end
Azilroka's avatar
Azilroka committed
213

214
	local targetScale = format('%.2f', mult * scale)
Azilroka's avatar
Azilroka committed
215
	nameplate:SetScale(targetScale)
Azilroka's avatar
Azilroka committed
216 217 218 219

	if targetPlate then
		NP.targetPlate = nameplate
	end
Azilroka's avatar
Azilroka committed
220 221
end

Azilroka's avatar
Azilroka committed
222
function NP:StylePlate(nameplate)
223
	nameplate:Point('CENTER')
224
	nameplate:SetScale(E.global.general.UIScale)
Azilroka's avatar
Azilroka committed
225

Azilroka's avatar
Azilroka committed
226 227
	nameplate.RaisedElement = NP:Construct_RaisedELement(nameplate)
	nameplate.Health = NP:Construct_Health(nameplate)
Azilroka's avatar
Azilroka committed
228
	nameplate.Health.Text = NP:Construct_TagText(nameplate.RaisedElement)
Azilroka's avatar
Azilroka committed
229 230 231 232 233
	nameplate.HealthPrediction = NP:Construct_HealthPrediction(nameplate)
	nameplate.Power = NP:Construct_Power(nameplate)
	nameplate.Power.Text = NP:Construct_TagText(nameplate.RaisedElement)
	nameplate.Name = NP:Construct_TagText(nameplate.RaisedElement)
	nameplate.Level = NP:Construct_TagText(nameplate.RaisedElement)
234
	nameplate.Title = NP:Construct_TagText(nameplate.RaisedElement)
Azilroka's avatar
Azilroka committed
235 236 237 238 239 240 241 242 243
	nameplate.ClassificationIndicator = NP:Construct_ClassificationIndicator(nameplate.RaisedElement)
	nameplate.Castbar = NP:Construct_Castbar(nameplate)
	nameplate.Portrait = NP:Construct_Portrait(nameplate.RaisedElement)
	nameplate.QuestIcons = NP:Construct_QuestIcons(nameplate.RaisedElement)
	nameplate.RaidTargetIndicator = NP:Construct_RaidTargetIndicator(nameplate.RaisedElement)
	nameplate.TargetIndicator = NP:Construct_TargetIndicator(nameplate)
	nameplate.ThreatIndicator = NP:Construct_ThreatIndicator(nameplate.RaisedElement)
	nameplate.Highlight = NP:Construct_Highlight(nameplate)
	nameplate.ClassPower = NP:Construct_ClassPower(nameplate)
244 245
	nameplate.PvPIndicator = NP:Construct_PvPIndicator(nameplate.RaisedElement) -- Horde / Alliance / HonorInfo
	nameplate.PvPClassificationIndicator = NP:Construct_PvPClassificationIndicator(nameplate.RaisedElement) -- Cart / Flag / Orb / Assassin Bounty
Azilroka's avatar
Azilroka committed
246
	nameplate.HealerSpecs = NP:Construct_HealerSpecs(nameplate.RaisedElement)
Azilroka's avatar
Azilroka committed
247
	--nameplate.Cutaway = NP:Construct_Cutaway(nameplate)
248

Azilroka's avatar
Azilroka committed
249 250 251 252
	NP:Construct_Auras(nameplate)

	if E.myclass == 'DEATHKNIGHT' then
		nameplate.Runes = NP:Construct_Runes(nameplate)
Azilroka's avatar
Azilroka committed
253 254
	elseif E.myclass == 'MONK' then
		nameplate.Stagger = NP:Construct_Stagger(nameplate)
Azilroka's avatar
Azilroka committed
255
	end
Azilroka's avatar
Azilroka committed
256

257
	NP.Plates[nameplate] = nameplate:GetName()
258 259

	NP:StyleFilterPlateStyled(nameplate)
Azilroka's avatar
Azilroka committed
260 261 262
end

function NP:UpdatePlate(nameplate)
263 264
	if nameplate == _G.ElvNP_Player and not _G.ElvNP_Player:IsEnabled() then return end

Azilroka's avatar
Azilroka committed
265
	NP:Update_Tags(nameplate)
Azilroka's avatar
Azilroka committed
266
	NP:Update_Highlight(nameplate)
Azilroka's avatar
Azilroka committed
267

268
	if (nameplate.VisibilityChanged or nameplate.NameOnlyChanged) or (not NP.db.units[nameplate.frameType].enable) or NP.db.units[nameplate.frameType].nameOnly then
269
		NP:DisablePlate(nameplate, nameplate.NameOnlyChanged or (NP.db.units[nameplate.frameType].nameOnly and not nameplate.VisibilityChanged))
Azilroka's avatar
Azilroka committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
	else
		NP:Update_Health(nameplate)
		NP:Update_HealthPrediction(nameplate)
		NP:Update_Power(nameplate)
		NP:Update_Castbar(nameplate)
		NP:Update_ClassPower(nameplate)
		NP:Update_Auras(nameplate)
		NP:Update_ClassificationIndicator(nameplate)
		NP:Update_QuestIcons(nameplate)
		NP:Update_Portrait(nameplate)
		NP:Update_PvPIndicator(nameplate) -- Horde / Alliance / HonorInfo
		NP:Update_PvPClassificationIndicator(nameplate) -- Cart / Flag / Orb / Assassin Bounty
		NP:Update_TargetIndicator(nameplate)
		NP:Update_ThreatIndicator(nameplate)
		NP:Update_RaidTargetIndicator(nameplate)
		NP:Update_HealerSpecs(nameplate)
Azilroka's avatar
Azilroka committed
286

Simpy's avatar
Simpy committed
287 288
		if E.myclass == 'DEATHKNIGHT' then
			NP:Update_Runes(nameplate)
Azilroka's avatar
Azilroka committed
289 290
		elseif E.myclass == 'MONK' then
			NP:Update_Stagger(nameplate)
Simpy's avatar
Simpy committed
291
		end
Azilroka's avatar
Azilroka committed
292

293
		if nameplate == _G.ElvNP_Player then
Azilroka's avatar
Azilroka committed
294 295
			NP:Update_Fader(nameplate)
		end
296 297 298 299

		if nameplate.isTarget then
			NP:SetupTarget(nameplate)
		end
Azilroka's avatar
Azilroka committed
300 301
	end

302
	NP:StyleFilterEvents(nameplate)
Azilroka's avatar
Azilroka committed
303 304
end

Azilroka's avatar
Azilroka committed
305
function NP:DisablePlate(nameplate, nameOnly)
Azilroka's avatar
Azilroka committed
306 307 308 309 310 311 312 313 314 315 316 317 318
	if nameplate:IsElementEnabled('Health') then nameplate:DisableElement('Health') end
	if nameplate:IsElementEnabled('HealthPrediction') then nameplate:DisableElement('HealthPrediction') end
	if nameplate:IsElementEnabled('Power') then nameplate:DisableElement('Power') end
	if nameplate:IsElementEnabled('ClassificationIndicator') then nameplate:DisableElement('ClassificationIndicator') end
	if nameplate:IsElementEnabled('Castbar') then nameplate:DisableElement('Castbar') end
	if nameplate:IsElementEnabled('Portrait') then nameplate:DisableElement('Portrait') end
	if nameplate:IsElementEnabled('QuestIcons') then nameplate:DisableElement('QuestIcons') end
	if nameplate:IsElementEnabled('ThreatIndicator') then nameplate:DisableElement('ThreatIndicator') end
	if nameplate:IsElementEnabled('ClassPower') then nameplate:DisableElement('ClassPower') end
	if nameplate:IsElementEnabled('PvPIndicator') then nameplate:DisableElement('PvPIndicator') end
	if nameplate:IsElementEnabled('PvPClassificationIndicator') then nameplate:DisableElement('PvPClassificationIndicator') end
	if nameplate:IsElementEnabled('HealerSpecs') then nameplate:DisableElement('HealerSpecs') end
	if nameplate:IsElementEnabled('Auras') then nameplate:DisableElement('Auras') end
319 320
	if E.myclass == 'DEATHKNIGHT' and nameplate:IsElementEnabled('Runes') then nameplate:DisableElement('Runes') end
	if E.myclass == 'MONK' and nameplate:IsElementEnabled('Stagger') then nameplate:DisableElement('Stagger') end
Azilroka's avatar
Azilroka committed
321 322 323

	nameplate.Health.Text:Hide()
	nameplate.Power.Text:Hide()
Azilroka's avatar
Azilroka committed
324 325 326
	nameplate.Name:Hide()
	nameplate.Level:Hide()
	nameplate.Title:Hide()
Azilroka's avatar
Azilroka committed
327

Azilroka's avatar
Azilroka committed
328
	if nameOnly then
Azilroka's avatar
Azilroka committed
329
		NP:Update_Highlight(nameplate)
330 331 332 333
		nameplate.Name:Show()
		nameplate.Name:ClearAllPoints()
		nameplate.Name:SetPoint('CENTER', nameplate, 'CENTER', 0, 0)
		if NP.db.units[nameplate.frameType].showTitle then
Azilroka's avatar
Azilroka committed
334 335 336
			nameplate.Title:Show()
			nameplate.Title:ClearAllPoints()
			nameplate.Title:SetPoint('TOP', nameplate.Name, 'BOTTOM', 0, -2)
337 338
		end
	end
Azilroka's avatar
Azilroka committed
339 340
end

Simpy's avatar
Simpy committed
341
function NP:SetupTarget(nameplate, removed)
342 343
	local TCP = _G.ElvNP_TargetClassPower
	local nameOnly = nameplate and (nameplate.NameOnlyChanged or NP.db.units[nameplate.frameType].nameOnly)
Simpy's avatar
Simpy committed
344
	TCP.realPlate = (NP.db.units.TARGET.classpower.enable and not (removed or nameOnly) and nameplate) or nil
345 346

	local moveToPlate = TCP.realPlate or TCP
347

348 349 350
	if TCP.ClassPower then
		TCP.ClassPower:SetParent(moveToPlate)
		TCP.ClassPower:ClearAllPoints()
351
		TCP.ClassPower:SetPoint('CENTER', moveToPlate, 'CENTER', NP.db.units.TARGET.classpower.xOffset, NP.db.units.TARGET.classpower.yOffset)
352
	end
353 354 355
	if TCP.Runes then
		TCP.Runes:SetParent(moveToPlate)
		TCP.Runes:ClearAllPoints()
356
		TCP.Runes:SetPoint('CENTER', moveToPlate, 'CENTER', NP.db.units.TARGET.classpower.xOffset, NP.db.units.TARGET.classpower.yOffset)
357
	end
Azilroka's avatar
Azilroka committed
358 359 360
	if TCP.Stagger then
		TCP.Stagger:SetParent(moveToPlate)
		TCP.Stagger:ClearAllPoints()
361
		TCP.Stagger:SetPoint('CENTER', moveToPlate, 'CENTER', NP.db.units.TARGET.classpower.xOffset, NP.db.units.TARGET.classpower.yOffset)
Azilroka's avatar
Azilroka committed
362
	end
363 364
end

365
function NP:SetNamePlateClickThrough()
Azilroka's avatar
Azilroka committed
366
	self:SetNamePlateSelfClickThrough()
367 368 369 370 371 372
	self:SetNamePlateFriendlyClickThrough()
	self:SetNamePlateEnemyClickThrough()
end

function NP:SetNamePlateSelfClickThrough()
	C_NamePlate_SetNamePlateSelfClickThrough(NP.db.clickThrough.personal)
Simpy's avatar
Simpy committed
373
	_G.ElvNP_StaticSecure:EnableMouse(not NP.db.clickThrough.personal)
374 375 376 377 378 379 380 381 382 383
end

function NP:SetNamePlateFriendlyClickThrough()
	C_NamePlate_SetNamePlateFriendlyClickThrough(NP.db.clickThrough.friendly)
end

function NP:SetNamePlateEnemyClickThrough()
	C_NamePlate_SetNamePlateEnemyClickThrough(NP.db.clickThrough.enemy)
end

Azilroka's avatar
Azilroka committed
384 385 386 387 388 389
function NP:Update_StatusBars()
	for StatusBar in pairs(NP.StatusBars) do
		StatusBar:SetStatusBarTexture(E.LSM:Fetch('statusbar', NP.db.statusbar))
	end
end

390
function NP:GROUP_ROSTER_UPDATE()
Simpy's avatar
Simpy committed
391 392
	local isInRaid = IsInRaid()
	NP.IsInGroup = isInRaid or IsInGroup()
Azilroka's avatar
Azilroka committed
393 394

	wipe(NP.GroupRoles)
Azilroka's avatar
Azilroka committed
395

Azilroka's avatar
Azilroka committed
396
	if NP.IsInGroup then
Simpy's avatar
Simpy committed
397
		local NumPlayers, Unit = (isInRaid and GetNumGroupMembers()) or GetNumSubgroupMembers(), (isInRaid and 'raid') or 'party'
Azilroka's avatar
Azilroka committed
398
		for i = 1, NumPlayers do
399 400 401
			if UnitExists(Unit..i) then
				NP.GroupRoles[UnitName(Unit..i)] = UnitGroupRolesAssigned(Unit..i)
			end
Azilroka's avatar
Azilroka committed
402 403 404 405 406
		end
	end
end

function NP:GROUP_LEFT()
407
	NP.IsInGroup = IsInRaid() or IsInGroup()
Azilroka's avatar
Azilroka committed
408
	wipe(NP.GroupRoles)
Azilroka's avatar
Azilroka committed
409 410 411
end

function NP:PLAYER_ENTERING_WORLD()
Azilroka's avatar
Azilroka committed
412
	NP.InstanceType = select(2, GetInstanceInfo())
Azilroka's avatar
Azilroka committed
413
	NP:UpdatePlate(_G.ElvNP_Player)
Azilroka's avatar
Azilroka committed
414 415
end

Simpy's avatar
Simpy committed
416
function NP:ConfigureAll()
417
	NP:StyleFilterConfigure() -- keep this at the top
Azilroka's avatar
Azilroka committed
418

Azilroka's avatar
Azilroka committed
419
	local Scale = E.global.general.UIScale
420

Azilroka's avatar
Azilroka committed
421 422 423
	C_NamePlate_SetNamePlateSelfSize(NP.db.plateSize.personalWidth * Scale, NP.db.plateSize.personalHeight * Scale)
	C_NamePlate_SetNamePlateEnemySize(NP.db.plateSize.enemyWidth * Scale, NP.db.plateSize.enemyHeight * Scale)
	C_NamePlate_SetNamePlateFriendlySize(NP.db.plateSize.friendlyWidth * Scale, NP.db.plateSize.friendlyHeight * Scale)
Azilroka's avatar
Azilroka committed
424 425 426

	NP:PLAYER_REGEN_ENABLED()

Azilroka's avatar
Azilroka committed
427 428
	if NP.db.units.PLAYER.enable and NP.db.units.PLAYER.useStaticPosition then
		_G.ElvNP_Player:Enable()
Simpy's avatar
Simpy committed
429
		_G.ElvNP_StaticSecure:Show()
Azilroka's avatar
Azilroka committed
430 431
	else
		_G.ElvNP_Player:Disable()
Simpy's avatar
Simpy committed
432
		_G.ElvNP_StaticSecure:Hide()
Azilroka's avatar
Azilroka committed
433 434
	end

435
	NP:UpdateTargetPlate(_G.ElvNP_TargetClassPower)
Azilroka's avatar
Azilroka committed
436 437

	for nameplate in pairs(NP.Plates) do
438
		NP:StyleFilterClear(nameplate) -- keep this at the top of the loop
Azilroka's avatar
Azilroka committed
439 440 441 442 443 444 445 446

		if nameplate.frameType == 'PLAYER' then
			nameplate:Size(NP.db.plateSize.personalWidth, NP.db.plateSize.personalHeight)
		elseif nameplate.frameType == 'FRIENDLY_PLAYER' or nameplate.frameType == 'FRIENDLY_NPC' then
			nameplate:Size(NP.db.plateSize.friendlyWidth, NP.db.plateSize.friendlyHeight)
		else
			nameplate:Size(NP.db.plateSize.enemyWidth, NP.db.plateSize.enemyHeight)
		end
447

448
		NP:UpdatePlate(nameplate)
449 450 451 452 453

		if nameplate.isTarget then
			NP:SetupTarget(nameplate)
		end

Azilroka's avatar
Azilroka committed
454
		nameplate:UpdateAllElements('ForceUpdate')
455

Azilroka's avatar
Azilroka committed
456 457 458 459 460 461
		if nameplate.frameType == 'PLAYER' then
			NP.PlayerNamePlateAnchor:ClearAllPoints()
			NP.PlayerNamePlateAnchor:SetParent(NP.db.units.PLAYER.useStaticPosition and _G.ElvNP_Player or nameplate)
			NP.PlayerNamePlateAnchor:SetAllPoints(NP.db.units.PLAYER.useStaticPosition and _G.ElvNP_Player or nameplate)
			NP.PlayerNamePlateAnchor:Show()
		end
Simpy's avatar
Simpy committed
462

463
		NP:StyleFilterUpdate(nameplate, 'NAME_PLATE_UNIT_ADDED') -- keep this at the end of the loop
Azilroka's avatar
Azilroka committed
464 465 466
	end

	NP:Update_StatusBars()
467
	NP:SetNamePlateClickThrough()
Azilroka's avatar
Azilroka committed
468 469
end

470 471 472 473
function NP:PlateFadeFinish()
	self.FadePlate.Fading = nil
end

474 475
function NP:PlateFade(nameplate, timeToFade, startAlpha, endAlpha)
	if not nameplate.FadePlate then
476
		nameplate.FadePlate = {}
477 478 479 480 481 482 483
	else
		nameplate.FadePlate.fadeTimer = nil
	end

	nameplate.FadePlate.timeToFade = timeToFade
	nameplate.FadePlate.startAlpha = startAlpha
	nameplate.FadePlate.endAlpha = endAlpha
484 485
	nameplate.FadePlate.finishedFunc = NP.PlateFadeFinish
	nameplate.FadePlate.finishedArg1 = nameplate
486

487 488 489 490
	if not nameplate.FadePlate.Fading then
		E:UIFrameFade(nameplate, nameplate.FadePlate)
		nameplate.FadePlate.Fading = true
	end
491 492
end

Azilroka's avatar
Azilroka committed
493
function NP:NamePlateCallBack(nameplate, event, unit)
Simpy's avatar
Simpy committed
494
	if event == 'NAME_PLATE_UNIT_ADDED' then
Simpy's avatar
Simpy committed
495
		NP:StyleFilterClear(nameplate) -- keep this at the top
496

Azilroka's avatar
Azilroka committed
497 498
		unit = unit or nameplate.unit

499
		nameplate.blizzPlate = nameplate:GetParent().UnitFrame
500
		nameplate.className, nameplate.classFile, nameplate.classID = UnitClass(unit)
501
		nameplate.repReaction = UnitReaction(unit, 'player')
502
		nameplate.reaction = UnitReaction('player', unit)
503 504
		nameplate.classification = UnitClassification(unit)
		nameplate.creatureType = UnitCreatureType(unit)
505
		nameplate.isPlayer = UnitIsPlayer(unit)
506
		nameplate.unitGUID = UnitGUID(unit)
Simpy's avatar
Simpy committed
507 508
		nameplate.unitName = UnitName(unit)
		nameplate.npcID = nameplate.unitGUID and select(6,strsplit('-',nameplate.unitGUID))
509 510

		if nameplate.unitGUID then
511
			NP.PlateGUID[nameplate.unitGUID] = nameplate
512
		end
513

514 515
		NP:StyleFilterSetVariables(nameplate) -- sets: isTarget, isTargetingMe, isFocused

Azilroka's avatar
Azilroka committed
516
		if UnitIsUnit(unit, 'player') and NP.db.units.PLAYER.enable then
Azilroka's avatar
Azilroka committed
517
			nameplate.frameType = 'PLAYER'
Azilroka's avatar
Azilroka committed
518
			NP.PlayerNamePlateAnchor:ClearAllPoints()
519 520 521
			NP.PlayerNamePlateAnchor:SetParent(NP.db.units.PLAYER.useStaticPosition and _G.ElvNP_Player or nameplate)
			NP.PlayerNamePlateAnchor:SetAllPoints(NP.db.units.PLAYER.useStaticPosition and _G.ElvNP_Player or nameplate)
			NP.PlayerNamePlateAnchor:Show()
522
		elseif UnitIsPVPSanctuary(unit) or (nameplate.isPlayer and UnitIsFriend('player', unit) and nameplate.reaction and nameplate.reaction >= 5) then
Azilroka's avatar
Azilroka committed
523
			nameplate.frameType = 'FRIENDLY_PLAYER'
524
		elseif not nameplate.isPlayer and (nameplate.reaction and nameplate.reaction >= 5) or UnitFactionGroup(unit) == 'Neutral' then
Azilroka's avatar
Azilroka committed
525
			nameplate.frameType = 'FRIENDLY_NPC'
526
		elseif not nameplate.isPlayer and (nameplate.reaction and nameplate.reaction <= 4) then
Azilroka's avatar
Azilroka committed
527 528 529 530 531
			nameplate.frameType = 'ENEMY_NPC'
		else
			nameplate.frameType = 'ENEMY_PLAYER'
		end

Azilroka's avatar
Azilroka committed
532 533 534 535 536 537 538 539 540 541
		if nameplate.frameType == 'PLAYER' then
			nameplate.width, nameplate.height = NP.db.plateSize.personalWidth, NP.db.plateSize.personalHeight
		elseif nameplate.frameType == 'FRIENDLY_PLAYER' or nameplate.frameType == 'FRIENDLY_NPC' then
			nameplate.width, nameplate.height = NP.db.plateSize.friendlyWidth, NP.db.plateSize.friendlyHeight
		else
			nameplate.width, nameplate.height = NP.db.plateSize.enemyWidth, NP.db.plateSize.enemyHeight
		end

		nameplate:Size(nameplate.width, nameplate.height)

Azilroka's avatar
Azilroka committed
542 543
		NP:UpdatePlate(nameplate)

544 545
		if nameplate.isTarget then
			NP:SetupTarget(nameplate)
546 547
		end

Simpy's avatar
Simpy committed
548 549
		-- Fade In when the option is ON and it's not the Disabled Static Player Nameplate
		if NP.db.fadeIn and not (nameplate == _G.ElvNP_Player and not _G.ElvNP_Player:IsEnabled()) then
550
			NP:PlateFade(nameplate, 1, 0, 1)
Azilroka's avatar
Azilroka committed
551
		end
Simpy's avatar
Simpy committed
552

553 554
		NP:StyleFilterUpdate(nameplate, event) -- keep this at the end
	elseif event == 'NAME_PLATE_UNIT_REMOVED' then
Simpy's avatar
Simpy committed
555
		NP:StyleFilterClear(nameplate) -- keep this at the top
556

557
		if nameplate.frameType == 'PLAYER' and nameplate ~= _G.ElvNP_Test then
Azilroka's avatar
Azilroka committed
558 559 560
			NP.PlayerNamePlateAnchor:Hide()
		end

Simpy's avatar
Simpy committed
561
		if nameplate.isTarget then
Simpy's avatar
Simpy committed
562
			NP:SetupTarget(nameplate, true)
Azilroka's avatar
Azilroka committed
563
			NP:ScalePlate(nameplate, 1, true)
Simpy's avatar
Simpy committed
564 565
		end

566 567 568 569
		if nameplate.unitGUID then
			NP.PlateGUID[nameplate.unitGUID] = nil
		end

570
		NP:StyleFilterClearVariables(nameplate)
Simpy's avatar
Simpy committed
571 572
	elseif event == 'PLAYER_TARGET_CHANGED' then -- we need to check if nameplate exists in here
		NP:SetupTarget(nameplate) -- pass it, even as nil here
Azilroka's avatar
Azilroka committed
573 574 575
	end
end

Azilroka's avatar
Azilroka committed
576
local optionsTable = {'EnemyMinus','EnemyMinions','FriendlyMinions','PersonalResource','PersonalResourceOnEnemy','MotionDropDown'}
577 578 579 580 581 582 583 584 585
function NP:HideInterfaceOptions()
	for _, x in pairs(optionsTable) do
		local o = _G['InterfaceOptionsNamesPanelUnitNameplates'..x]
		o:SetSize(0.0001, 0.0001)
		o:SetAlpha(0)
		o:Hide()
	end
end

Azilroka's avatar
Azilroka committed
586 587 588 589
function NP:Initialize()
	NP.db = E.db.nameplates

	if E.private.nameplates.enable ~= true then return end
590
	NP.Initialized = true
Azilroka's avatar
Azilroka committed
591

Simpy's avatar
Simpy committed
592 593
	oUF:RegisterStyle('ElvNP', function(frame, unit) NP:Style(frame, unit) end)
	oUF:SetActiveStyle('ElvNP')
Azilroka's avatar
Azilroka committed
594 595

	NP.Plates = {}
596
	NP.PlateGUID = {}
Azilroka's avatar
Azilroka committed
597
	NP.StatusBars = {}
598
	NP.GroupRoles = {}
Simpy's avatar
Simpy committed
599
	NP.multiplier = 0.35
600

Azilroka's avatar
Azilroka committed
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
	local BlizzPlateManaBar = _G.NamePlateDriverFrame.classNamePlatePowerBar
	if BlizzPlateManaBar then
		BlizzPlateManaBar:Hide()
		BlizzPlateManaBar:UnregisterAllEvents()
	end

	hooksecurefunc(_G.NamePlateDriverFrame, 'SetupClassNameplateBars', function(frame)
		if frame.classNamePlateMechanicFrame then
			frame.classNamePlateMechanicFrame:Hide()
		end
		if frame.classNamePlatePowerBar then
			frame.classNamePlatePowerBar:Hide()
			frame.classNamePlatePowerBar:UnregisterAllEvents()
		end
	end)

Simpy's avatar
Simpy committed
617
	oUF:Spawn('player', 'ElvNP_Player', '')
Azilroka's avatar
Azilroka committed
618
	_G.ElvNP_Player:Point('TOP', _G.UIParent, 'CENTER', 0, -150)
Azilroka's avatar
Azilroka committed
619
	_G.ElvNP_Player:Size(NP.db.plateSize.personalWidth, NP.db.plateSize.personalHeight)
620
	_G.ElvNP_Player:SetScale(E.mult)
Azilroka's avatar
Azilroka committed
621
	_G.ElvNP_Player.frameType = 'PLAYER'
Rubgrsch's avatar
Rubgrsch committed
622
	E:CreateMover(_G.ElvNP_Player, 'ElvNP_PlayerMover', L["Player NamePlate"], nil, nil, nil, 'ALL,SOLO', nil, 'nameplate,playerGroup')
Azilroka's avatar
Azilroka committed
623

Simpy's avatar
Simpy committed
624
	local StaticSecure = CreateFrame('Button', 'ElvNP_StaticSecure', _G.UIParent, 'SecureUnitButtonTemplate')
625
	StaticSecure:SetAttribute('unit', 'player')
Simpy's avatar
Simpy committed
626 627
	StaticSecure:SetAttribute('*type1', 'target')
	StaticSecure:SetAttribute('*type2', 'togglemenu')
628
	StaticSecure:SetAttribute('toggleForVehicle', true)
629
	StaticSecure:RegisterForClicks('LeftButtonDown', 'RightButtonDown')
630 631 632 633 634
	StaticSecure:SetScript('OnEnter', _G.UnitFrame_OnEnter)
	StaticSecure:SetScript('OnLeave', _G.UnitFrame_OnLeave)
	StaticSecure:Point('BOTTOMRIGHT', _G.ElvNP_PlayerMover)
	StaticSecure:Point('TOPLEFT', _G.ElvNP_PlayerMover)
	StaticSecure.unit = 'player' -- Needed for OnEnter, OnLeave
Simpy's avatar
Simpy committed
635
	StaticSecure:Hide()
636

Simpy's avatar
Simpy committed
637
	oUF:Spawn('player', 'ElvNP_Test')
Azilroka's avatar
Azilroka committed
638
	_G.ElvNP_Test:Point('BOTTOM', _G.UIParent, 'BOTTOM', 0, 250)
Azilroka's avatar
Azilroka committed
639
	_G.ElvNP_Test:Size(NP.db.plateSize.personalWidth, NP.db.plateSize.personalHeight)
640
	_G.ElvNP_Test:SetScale(1)
Azilroka's avatar
Azilroka committed
641 642
	_G.ElvNP_Test:SetMovable(true)
	_G.ElvNP_Test:RegisterForDrag("LeftButton", "RightButton")
Azilroka's avatar
Azilroka committed
643
	_G.ElvNP_Test:SetScript("OnDragStart", function() _G.ElvNP_Test:StartMoving() end)
Azilroka's avatar
Azilroka committed
644 645 646
	_G.ElvNP_Test:SetScript("OnDragStop", function() _G.ElvNP_Test:StopMovingOrSizing() end)
	_G.ElvNP_Test.frameType = 'PLAYER'
	_G.ElvNP_Test:Disable()
647
	NP:DisablePlate(_G.ElvNP_Test)
Azilroka's avatar
Azilroka committed
648

Simpy's avatar
Simpy committed
649
	oUF:Spawn('player', 'ElvNP_TargetClassPower')
Azilroka's avatar
Azilroka committed
650
	_G.ElvNP_TargetClassPower:SetScale(1)
Azilroka's avatar
Azilroka committed
651
	_G.ElvNP_TargetClassPower:Size(NP.db.plateSize.personalWidth, NP.db.plateSize.personalHeight)
652 653
	_G.ElvNP_TargetClassPower.frameType = 'TARGET'
	_G.ElvNP_TargetClassPower:SetAttribute('toggleForVehicle', true)
Simpy's avatar
Simpy committed
654
	_G.ElvNP_TargetClassPower:Point('TOP', E.UIParent, 'BOTTOM', 0, -500)
Azilroka's avatar
Azilroka committed
655 656

	NP.PlayerNamePlateAnchor = CreateFrame("Frame", "ElvUIPlayerNamePlateAnchor", E.UIParent)
Azilroka's avatar
Azilroka committed
657
	NP.PlayerNamePlateAnchor:EnableMouse(false)
Azilroka's avatar
Azilroka committed
658
	NP.PlayerNamePlateAnchor:Hide()
659

Simpy's avatar
Simpy committed
660
	oUF:SpawnNamePlates('ElvNP_', function(nameplate, event, unit) NP:NamePlateCallBack(nameplate, event, unit) end)
Azilroka's avatar
Azilroka committed
661 662 663 664

	NP:RegisterEvent('PLAYER_REGEN_ENABLED')
	NP:RegisterEvent('PLAYER_REGEN_DISABLED')
	NP:RegisterEvent('PLAYER_ENTERING_WORLD')
Azilroka's avatar
Azilroka committed
665
	NP:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
666
	NP:RegisterEvent('GROUP_ROSTER_UPDATE')
Azilroka's avatar
Azilroka committed
667
	NP:RegisterEvent('GROUP_LEFT')
668
	NP:RegisterEvent('PLAYER_LOGOUT', NP.StyleFilterClearDefaults)
Azilroka's avatar
Azilroka committed
669

670
	NP:StyleFilterInitialize()
Azilroka's avatar
Azilroka committed
671
	NP:HideInterfaceOptions()
Merathilis's avatar
Merathilis committed
672
	NP:GROUP_ROSTER_UPDATE()
673
	NP:SetCVars()
Azilroka's avatar
Azilroka committed
674
	NP:ConfigureAll()
Azilroka's avatar
Azilroka committed
675 676 677 678 679 680 681
end

local function InitializeCallback()
	NP:Initialize()
end

E:RegisterModule(NP:GetName(), InitializeCallback)