Quantcast
 --[[
##############################################################################
_____/\\\\\\\\\\\____/\\\________/\\\__/\\\________/\\\__/\\\\\\\\\\\_       #
 ___/\\\/////////\\\_\/\\\_______\/\\\_\/\\\_______\/\\\_\/////\\\///__      #
  __\//\\\______\///__\//\\\______/\\\__\/\\\_______\/\\\_____\/\\\_____     #
   ___\////\\\__________\//\\\____/\\\___\/\\\_______\/\\\_____\/\\\_____    #
    ______\////\\\________\//\\\__/\\\____\/\\\_______\/\\\_____\/\\\_____   #
     _________\////\\\______\//\\\/\\\_____\/\\\_______\/\\\_____\/\\\_____  #
      __/\\\______\//\\\______\//\\\\\______\//\\\______/\\\______\/\\\_____ #
       _\///\\\\\\\\\\\/________\//\\\________\///\\\\\\\\\/____/\\\\\\\\\\\_#
        ___\///////////___________\///___________\/////////_____\///////////_#
##############################################################################
S U P E R - V I L L A I N - U I   By: Munglunch                              #
##############################################################################
 --]]
local SuperVillain, L = unpack(select(2, ...));
local MOD = SuperVillain.Registry:Expose('SVUnit');
local _, ns = ...
local oUF_SuperVillain = ns.oUF
--[[ MUNGLUNCH's FASTER ASSERT FUNCTION ]]--
local assert = enforce;
assert(oUF_SuperVillain, "SVUI was unable to locate oUF.")
local ceil,tinsert = math.ceil,table.insert
--[[
##########################################################
BUILD FUNCTION
##########################################################
]]--
function MOD.Construct:player()
	MOD:SetActionPanel(self, "player")
	self.Health = MOD:CreateHealthBar(self, true)
	self.Health.frequentUpdates = true
	self.Power = MOD:CreatePowerBar(self, true)
	self.Power.frequentUpdates = true
	MOD:CreatePortrait(self, false, true)
	self.Buffs = MOD:CreateBuffs(self, "player")
	self.Debuffs = MOD:CreateDebuffs(self, "player")
	self.Castbar = MOD:CreateCastbar(self, false, L["Player Castbar"], true, true)
	MOD:CreateExperienceRepBar(self)
	MOD:GetClassResources(self)
	self.RaidIcon = MOD:CreateRaidIcon(self)
	self.Resting = MOD:CreateRestingIndicator(self)
	self.Combat = MOD:CreateCombatIndicator(self)
	self.PvPText = self.InfoPanel:CreateFontString(nil,'OVERLAY')
	self.PvPText:SetFontTemplate(SuperVillain.Shared:Fetch("font", MOD.db.font), MOD.db.fontSize, MOD.db.fontOutline)
	self.Afflicted = MOD:CreateAfflicted(self)
	self.HealPrediction = MOD:CreateHealPrediction(self, true)
	self.AuraBars = MOD:CreateAuraBarHeader(self, "player")
	self.CombatFade = true;
	self:Point("BOTTOMLEFT", SuperVillain.UIParent, "BOTTOM", -413, 182)
	SuperVillain:SetSVMovable(self, self:GetName().."_MOVE", L["Player Frame"], nil, nil, nil, "ALL, SOLO")
end
--[[
##########################################################
UPDATE
##########################################################
]]--
function MOD.FrameUpdate:player()
	local db = MOD.db["player"]
	local UNIT_WIDTH = db.width;
	local UNIT_HEIGHT = db.height;
	local USE_CLASSBAR = db.classbar.enable;
	local classBarHeight = db.classbar.height;
	local classBarWidth = db.width * 0.4;
	local healthPanel = self.HealthPanel
	local iconDB = db.icons
	self:RegisterForClicks(MOD.db.fastClickTarget and "AnyDown" or "AnyUp")
	self.colors = oUF_SuperVillain.colors;
	self:Size(UNIT_WIDTH, UNIT_HEIGHT)
	_G[self:GetName().."_MOVE"]:Size(self:GetSize())

	MOD:RefreshUnitLayout(self, "player")

	do
		local resting = self.Resting;
		if resting then
			if iconDB and iconDB.restIcon and iconDB.restIcon.enable then
				local size = iconDB.restIcon.size;
				resting:ClearAllPoints()
				resting:Size(size)
				SuperVillain:ReversePoint(resting, iconDB.restIcon.attachTo, healthPanel, iconDB.restIcon.xOffset, iconDB.restIcon.yOffset)
				if not self:IsElementEnabled("Resting")then
					self:EnableElement("Resting")
				end
			elseif self:IsElementEnabled("Resting")then
				self:DisableElement("Resting")
				resting:Hide()
			end
		end
	end
	do
		local combat = self.Combat;
		if combat then
			if iconDB and iconDB.combatIcon and iconDB.combatIcon.enable then
				local size = iconDB.combatIcon.size;
				combat:ClearAllPoints()
				combat:Size(size)
				SuperVillain:ReversePoint(combat, iconDB.combatIcon.attachTo, healthPanel, iconDB.combatIcon.xOffset, iconDB.combatIcon.yOffset)
				if not self:IsElementEnabled("Combat")then
					self:EnableElement("Combat")
				end
			elseif self:IsElementEnabled("Combat")then
				self:DisableElement("Combat")
				combat:Hide()
			end
		end
	end
	do
		local pvp = self.PvPText;
		local point = db.pvp.position;
		pvp:ClearAllPoints()
		pvp:Point(db.pvp.position, healthPanel, db.pvp.position)
		self:Tag(pvp, db.pvp.tags)
	end
	do
		local power = self.Power;
		if SuperVillain.class == "DRUID" and self.DruidAltMana then
			if db.power.druidMana then
				self:EnableElement("DruidAltMana")
			else
				self:DisableElement("DruidAltMana")
				self.DruidAltMana:Hide()
			end
		end
		if SuperVillain.class == "MONK" then
			local stagger = self.DrunkenMaster;
			if db.stagger.enable then
				if not self:IsElementEnabled("DrunkenMaster")then
					self:EnableElement("DrunkenMaster")
				end
			else
				if self:IsElementEnabled("DrunkenMaster")then
					self:DisableElement("DrunkenMaster")
				end
			end
		end
	end
	do
		if(self.DruidAltMana) then
			if db.power.druidMana then
				self:EnableElement("DruidAltMana")
			else
				self:DisableElement("DruidAltMana")
				self.DruidAltMana:Hide()
			end
		end
		if(self.DrunkenMaster) then
			if db.stagger.enable then
				if not self:IsElementEnabled("DrunkenMaster")then
					self:EnableElement("DrunkenMaster")
				end
			else
				if self:IsElementEnabled("DrunkenMaster")then
					self:DisableElement("DrunkenMaster")
				end
			end
		end

		if(self.ClassBar or self.HyperCombo) then
			if self.ClassBarRefresh then
				self.ClassBarRefresh(self)
			end
			if(self.ClassBar) then
				local classBar = self[self.ClassBar];
				if not db.classbar.detachFromFrame then
					if classBar.Avatar then
						classBar.Avatar:SetScale(0.000001)
						classBar.Avatar:SetAlpha(0)
					end
				else
					classBarWidth = db.classbar.detachedWidth;
					if not classBar.Avatar then
						classBar:Point("TOPLEFT", self, "BOTTOMLEFT", 0, -2)
						SuperVillain:SetSVMovable(classBar, "ClassBar_MOVE", L["Classbar"], nil, nil, nil, "ALL, SOLO")
					else
						classBar.Avatar:SetScale(1)
						classBar.Avatar:SetAlpha(1)
					end
				end
				if USE_CLASSBAR then
					if(not self:IsElementEnabled(self.ClassBar)) then
						self:EnableElement(self.ClassBar)
					end
					classBar:Show()
				else
					if(self:IsElementEnabled(self.ClassBar)) then
						self:DisableElement(self.ClassBar)
					end
					classBar:Hide()
				end
			end
			if(self.HyperCombo) then
				if not self:IsElementEnabled("HyperCombo") then
					self:EnableElement("HyperCombo")
				end
			else
				if self:IsElementEnabled("HyperCombo") then
					self:DisableElement("HyperCombo")
				end
			end
		end
	end
	do
		if db.combatfade and not self:IsElementEnabled("CombatFade")then
			self:EnableElement("CombatFade")
		elseif
			not db.combatfade and self:IsElementEnabled("CombatFade")then
			self:DisableElement("CombatFade")
		end
	end
	self:UpdateAllElements()
end