Assist.lua 4.39 KB
Newer Older
Azilroka's avatar
Azilroka committed
1
local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
Simpy's avatar
Simpy committed
2 3
local UF = E:GetModule('UnitFrames')

4 5
local _, ns = ...
local ElvUF = ns.oUF
Simpy's avatar
Simpy committed
6
assert(ElvUF, 'ElvUI was unable to locate oUF.')
7

8
local _G = _G
Simpy's avatar
Simpy committed
9
local max = max
Simpy's avatar
stuff  
Simpy committed
10
local CreateFrame = CreateFrame
11
local IsAddOnLoaded = IsAddOnLoaded
12
local InCombatLockdown = InCombatLockdown
13
local RegisterAttributeDriver = RegisterAttributeDriver
14

15
function UF:Construct_AssistFrames()
16 17
	self:SetScript('OnEnter', _G.UnitFrame_OnEnter)
	self:SetScript('OnLeave', _G.UnitFrame_OnLeave)
18

19 20
	self.RaisedElementParent = CreateFrame('Frame', nil, self)
	self.RaisedElementParent.TextureParent = CreateFrame('Frame', nil, self.RaisedElementParent)
21
	self.RaisedElementParent:SetFrameLevel(self:GetFrameLevel() + 100)
22

23 24
	self.Health = UF:Construct_HealthBar(self, true)
	self.Name = UF:Construct_NameText(self)
25
	self.ThreatIndicator = UF:Construct_Threat(self)
26
	self.RaidTargetIndicator = UF:Construct_RaidIcon(self)
27 28
	self.MouseGlow = UF:Construct_MouseGlow(self)
	self.TargetGlow = UF:Construct_TargetGlow(self)
29
	self.FocusGlow = UF:Construct_FocusGlow(self)
Simpy's avatar
Simpy committed
30
	self.Fader = UF:Construct_Fader()
31
	self.Cutaway = UF:Construct_Cutaway(self)
32 33 34 35 36 37

	if not self.isChild then
		self.Buffs = UF:Construct_Buffs(self)
		self.Debuffs = UF:Construct_Debuffs(self)
		self.AuraWatch = UF:Construct_AuraWatch(self)
		self.RaidDebuffs = UF:Construct_RaidDebuffs(self)
Azilroka's avatar
Azilroka committed
38
		self.AuraHighlight = UF:Construct_AuraHighlight(self)
39

Simpy's avatar
Simpy committed
40
		self.unitframeType = 'assist'
41
	else
Simpy's avatar
Simpy committed
42
		self.unitframeType = 'assisttarget'
43 44 45 46 47 48 49 50 51 52 53 54 55
	end

	self.originalParent = self:GetParent()

	return self
end

function UF:Update_AssistHeader(header, db)
	header:Hide()
	header.db = db

	UF:ClearChildPoints(header:GetChildren())

Azilroka's avatar
Azilroka committed
56
	if not header.isForced and db.enable then
Azilroka's avatar
Azilroka committed
57 58
		RegisterAttributeDriver(header, 'state-visibility', '[@raid1,exists] show;hide')
	end
59 60 61

	header:SetAttribute('point', 'BOTTOM')
	header:SetAttribute('columnAnchorPoint', 'LEFT')
Simpy's avatar
Simpy committed
62
	header:SetAttribute('yOffset', db.verticalSpacing)
Rubgrsch's avatar
Rubgrsch committed
63

64 65
	if not header.positioned then
		header:ClearAllPoints()
Simpy's avatar
Simpy committed
66
		header:Point('TOPLEFT', E.UIParent, 'TOPLEFT', 4, -248)
67

Azilroka's avatar
Azilroka committed
68
		local width, height = header:GetSize()
69
		local minHeight = max(height, 2 * db.height + db.verticalSpacing)
Simpy's avatar
Simpy committed
70 71
		header:SetAttribute('minHeight', minHeight)
		header:SetAttribute('minWidth', width)
Azilroka's avatar
Azilroka committed
72

Simpy's avatar
Simpy committed
73
		E:CreateMover(header, header:GetName()..'Mover', L["MA Frames"], nil, nil, nil, 'ALL,RAID', nil, 'unitframe,groupUnits,assist,generalGroup')
Simpy's avatar
Simpy committed
74
		header.mover:SetSize(width, minHeight)
Simpy's avatar
Simpy committed
75 76

		header.positioned = true
77 78 79 80 81 82
	end
end

function UF:Update_AssistFrames(frame, db)
	frame.db = db
	frame.colors = ElvUF.colors
83
	frame:RegisterForClicks(UF.db.targetOnMouseDown and 'AnyDown' or 'AnyUp')
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

	do
		frame.ORIENTATION = db.orientation --allow this value to change when unitframes position changes on screen?
		frame.SHADOW_SPACING = 3
		frame.UNIT_WIDTH = db.width
		frame.UNIT_HEIGHT = db.height
		frame.USE_POWERBAR = false
		frame.POWERBAR_DETACHED = false
		frame.USE_INSET_POWERBAR = false
		frame.USE_MINI_POWERBAR = false
		frame.USE_POWERBAR_OFFSET = false
		frame.POWERBAR_OFFSET = 0
		frame.POWERBAR_HEIGHT = 0
		frame.POWERBAR_WIDTH = 0
		frame.USE_PORTRAIT = false
		frame.USE_PORTRAIT_OVERLAY = false
		frame.PORTRAIT_WIDTH = 0
		frame.CLASSBAR_YOFFSET = 0
		frame.BOTTOM_OFFSET = 0
	end

Azilroka's avatar
Azilroka committed
105
	if frame.isChild then
106 107
		local childDB = db.targetsGroup
		frame.db = db.targetsGroup
Azilroka's avatar
Azilroka committed
108

Simpy's avatar
Simpy committed
109
		frame:Size(childDB.width, childDB.height)
110 111 112

		if not InCombatLockdown() then
			if childDB.enable then
Azilroka's avatar
Azilroka committed
113
				frame:Enable()
114
				frame:ClearAllPoints()
Simpy's avatar
Simpy committed
115
				frame:Point(E.InversePoints[childDB.anchorPoint], frame.originalParent, childDB.anchorPoint, childDB.xOffset, childDB.yOffset)
116
			else
Azilroka's avatar
Azilroka committed
117
				frame:Disable()
118 119
			end
		end
120
	else
Simpy's avatar
Simpy committed
121
		frame:Size(frame.UNIT_WIDTH, frame.UNIT_HEIGHT)
122 123 124 125
	end

	UF:Configure_HealthBar(frame)
	UF:Configure_Threat(frame)
126
	UF:UpdateNameSettings(frame)
Simpy's avatar
Simpy committed
127
	UF:Configure_Fader(frame)
128
	UF:Configure_RaidIcon(frame)
129 130
	UF:Configure_Cutaway(frame)

131
	if not frame.isChild then
Simpy's avatar
Simpy committed
132
		if not IsAddOnLoaded('Clique') then
Azilroka's avatar
Azilroka committed
133
			if db.middleClickFocus then
Simpy's avatar
Simpy committed
134 135 136
				frame:SetAttribute('type3', 'focus')
			elseif frame:GetAttribute('type3') == 'focus' then
				frame:SetAttribute('type3', nil)
Azilroka's avatar
Azilroka committed
137 138
			end
		end
Azilroka's avatar
Azilroka committed
139

140
		UF:EnableDisable_Auras(frame)
141
		UF:Configure_AllAuras(frame)
142
		UF:Configure_RaidDebuffs(frame)
Azilroka's avatar
Azilroka committed
143
		UF:Configure_AuraHighlight(frame)
144
		UF:Configure_AuraWatch(frame)
145 146
	end

Simpy's avatar
Simpy committed
147
	frame:UpdateAllElements('ElvUI_UpdateAllElements')
148 149
end

Simpy's avatar
Simpy committed
150
UF.headerstoload.assist = {'MAINASSIST', 'ELVUI_UNITTARGET'}