View Single Post
11-11-10, 06:01 AM   #3
kawe
A Cyclonian
 
kawe's Avatar
Join Date: Sep 2009
Posts: 40
adding castbar

Originally Posted by haste View Post
https://github.com/haste/oUF/wiki/element---casting-bar has a example of how to add a casting bar to "your" layout.

(sent from my phone)

i tried to insert the code into this oUF layout; not working

Code:
local FONT = [=[Interface\AddOns\oUF_Senomar\calibri.ttf]=]
local FONTSIZE = 13
local HEIGHT = 26
local HEALTHHEIGHT = 21
local TEXTURE = [=[Interface\AddOns\oUF_Senomar\minimalist]=]
local BACKDROP = {
	bgFile = TEXTURE, insets = {top = -1, bottom = -1, left = -1, right = -1}
}
local _, playerclass = UnitClass("player")

local function ShortenValue(value)
	if(value >= 1e6) then
		return ('%.2fm'):format(value / 1e6):gsub('%.?0+([km])$', '%1')
	elseif(value >= 1e4) then
		return ('%.1fk'):format(value / 1e3):gsub('%.?0+([km])$', '%1')
	else
		return value
	end
end

oUF.Tags['seno:health'] = function(u)
	local min, max = UnitHealth(u), UnitHealthMax(u)
	local status = not UnitIsConnected(u) and 'Offline' or UnitIsGhost(u) and 'Ghost' or UnitIsDead(u) and 'Dead'

	if(status) then
		return status
	elseif(u == 'target' and UnitCanAttack('player', u)) then
		return ('%s || %d|cff0090ff%%|r'):format(ShortenValue(min), min / max * 100)
	elseif(u == 'target') then
		local power = UnitPower(u)
		local pmin = ""
		if(power > 0 and not UnitIsDeadOrGhost(u)) then
			local _, type = UnitPowerType(u)
			local colors = _COLORS.power
			pmin = ('%s%s|r'):format(Hex(colors[type] or colors['RUNES']), ShortenValue(power)) .. ' | '
		end
		return pmin .. ('%s'):format(ShortenValue(min), ShortenValue(min))
	elseif(u == 'player' and min ~= max) then
		return ('|cffff8080-%s|r || %s'):format(ShortenValue((min - max)*-1), ShortenValue(min))
	elseif(u == 'player') then
		return max
	elseif(min ~= max) then
		return ShortenValue(min)
	else
		return ShortenValue(max)
	end
end

oUF.Tags['seno:power'] = function(u)
	local power = UnitPower(u)
	if(power > 0 and not UnitIsDeadOrGhost(u)) then
		local _, type = UnitPowerType(u)
		local colors = _COLORS.power
		return ('%s%d|r'):format(Hex(colors[type] or colors['RUNES']), power)
	end
end

oUF.Tags['seno:druid'] = function(u)
	local min, max = UnitPower(u, 0), UnitPowerMax(u, 0)
	if(UnitPowerType(u) ~= 0 and min ~= max) then
		return ('|cff0090ff%d%%|r'):format(min / max * 100)
	end
end

oUF.TagEvents['seno:shards'] = 'UNIT_POWER'
oUF.Tags['seno:shards'] = function(u) return UnitPower(u, SPELL_POWER_SOUL_SHARDS) end

oUF.Tags['pvp'] = function(u)
local running = IsPVPTimerRunning()
	if(UnitIsPVP(u) and not running) then
		return '|cffff0000+|r'
	elseif(running) then
		local timer = GetPVPTimer() / 1e3
		return ('|cffff0000%d:%02d|r'):format(timer / 60, timer % 60)
	end	
end

oUF.TagEvents['seno:name'] = 'UNIT_NAME_UPDATE UNIT_REACTION UNIT_FACTION'
oUF.Tags['seno:name'] = function(u)
	local reaction = UnitReaction(u, 'player')

	local r, g, b = 1, 1, 1
	if((UnitIsTapped(u) and not UnitIsTappedByPlayer(u)) or not UnitIsConnected(u)) then
		r, g, b = 3/5, 3/5, 3/5
	elseif(not UnitIsPlayer(u) and reaction) then
		r, g, b = unpack(_COLORS.reaction[reaction])
	elseif(UnitFactionGroup(u) and UnitIsEnemy(u, 'player') and UnitIsPVP(u)) then
		r, g, b = 1, 0, 0
	end

	return ('%s%s|r'):format(Hex(r, g, b), UnitName(u))
end

local f = CreateFrame"Frame"
f.peticon = nil
f:RegisterEvent('PET_ATTACK_START')
f:RegisterEvent('PET_ATTACK_STOP')
f:SetScript('OnEvent', function(self, e) if e == 'PET_ATTACK_START' then self.peticon:Show() else self.peticon:Hide() end end)

local function SpawnMenu(self)
	ToggleDropDownMenu(1, nil, _G[string.gsub(self.unit, '^.', string.upper)..'FrameDropDown'], 'cursor')
end

local function PostUpdatePower(element, unit, min, max)
	element:GetParent().Health:SetHeight(max ~= 0 and HEALTHHEIGHT or HEIGHT)
end

local function PostCreateAura(element, button)
	button:SetBackdrop(BACKDROP)
	button:SetBackdropColor(0, 0, 0)
	button.cd:SetReverse()
	button.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
	button.icon:SetDrawLayer('ARTWORK')
end

local function PostUpdateDebuff(element, unit, button, index)
	if(UnitIsFriend('player', unit) or button.isPlayer) then
		local _, _, _, _, type = UnitAura(unit, index, button.filter)
		local color = DebuffTypeColor[type] or DebuffTypeColor.none

		button:SetBackdropColor(color.r * 3/5, color.g * 3/5, color.b * 3/5)
		button.icon:SetDesaturated(false)
	else
		button:SetBackdropColor(0, 0, 0)
		button.icon:SetDesaturated(true)
	end
end

local buffFilter = {
	[GetSpellInfo(47236)] = true, -- Demonic Pact
	[GetSpellInfo(77746)] = true, -- Totemic Wrath
	[GetSpellInfo(8227)] = true, -- Flametongue Totem
}

local function customFilter(icons, unit, icon, name)
	if(buffFilter[name] and (playerclass == 'WARLOCK' or playerclass == 'PRIEST' or playerclass == 'MAGE')) then return true end
end

Castbar.CustomTimeText = function(self, duration)
	if self.casting then
		self.Time:SetFormattedText("%.1f", self.max - duration)
	elseif self.channeling then
		self.Time:SetFormattedText("%.1f", duration)
	end
end

local Castbar = CreateFrame("StatusBar", nil, self)
Castbar:SetSize(20, 20)
Castbar:SetPoint('TOP')
Castbar:SetPoint('LEFT')
Castbar:SetPoint('RIGHT')

-- Add a background
local Background = Castbar:CreateTexture(nil, 'BACKGROUND')
Background:SetAllPoints(Castbar)
Background:SetTexture(1, 1, 1, .5)

-- Add a spark
local Spark = Castbar:CreateTexture(nil, "OVERLAY")
Spark:SetSize(20, 20)
Spark:SetBlendMode("ADD")

-- Add a timer
local Time = Castbar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
Time:SetPoint("RIGHT", Castbar)

-- Add spell text
local Text = Castbar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
Text:SetPoint("LEFT", Castbar)

-- Add spell icon
local Icon = Castbar:CreateTexture(nil, "OVERLAY")
Icon:SetSize(20, 20)
Icon:SetPoint("TOPLEFT", Castbar, "TOPLEFT")

-- Register it with oUF
self.Castbar = Castbar
self.Castbar.bg = Background
self.Castbar.Spark = Spark
self.Castbar.Time = Time
self.Castbar.Text = Text
self.Castbar.Icon = Icon
self.Castbar.SafeZone = SafeZone

end

local UnitSpecific = {
	player = function(self)
		local buffs = CreateFrame('Frame', nil, self)
		buffs:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -4)
		buffs:SetSize(110, 44)
		buffs.num = 10
		buffs.size = 18
		buffs.spacing = 3
		buffs.initialAnchor = 'TOPLEFT'
		buffs['growth-y'] = 'DOWN'
		buffs.PostCreateIcon = PostCreateAura
		buffs.CustomFilter = customFilter
		self.Buffs = buffs

		local leader = self.Health:CreateTexture(nil, 'OVERLAY')
		leader:SetPoint('TOPLEFT', self, 0, 8)
		leader:SetSize(16, 16)
		self.Leader = leader

		local assistant = self.Health:CreateTexture(nil, 'OVERLAY')
		assistant:SetPoint('TOPLEFT', self, 0, 8)
		assistant:SetSize(16, 16)
		self.Assistant = assistant

		local info = self.Health:CreateFontString(nil, 'OVERLAY')
		info:SetFont(FONT, FONTSIZE)
		info:SetShadowColor(0, 0, 0)
		info:SetShadowOffset(1, -1)
		info:SetPoint('CENTER')
		self:Tag(info, '[pvp]')
		
		--[[
		local debuffs = CreateFrame('Frame', nil, self)
		debuffs.spacing = 10
		debuffs:SetSize(180, 200)
		debuffs.initialAnchor = 'BOTTOMLEFT'
		debuffs.PostCreateIcon = PostCreateAura
		debuffs:SetPoint('BOTTOMLEFT', self, 'TOPLEFT', 10, 10)
		debuffs.num = 18
		debuffs.size = 28
		debuffs['growth-y'] = 'UP'
		debuffs['growth-x'] = 'RIGHT'
		debuffs.PostUpdateIcon = PostUpdateDebuff
		self.Debuffs = debuffs
		]]--
		
		--self:SetAttribute('initial-width', 170)
		self:SetWidth(170)
	end,
	target = function(self)
		local buffs = CreateFrame('Frame', nil, self)
		buffs:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -4)
		buffs:SetSize(110, 44)
		buffs.num = 10
		buffs.size = 18
		buffs.spacing = 3
		buffs.initialAnchor = 'TOPLEFT'
		buffs['growth-y'] = 'DOWN'
		buffs.PostCreateIcon = PostCreateAura
		self.Buffs = buffs

		local cpoints = self:CreateFontString(nil, 'OVERLAY', 'SubZoneTextFont')
		cpoints:SetPoint('RIGHT', self, 'LEFT', -9, 0)
		cpoints:SetJustifyH('RIGHT')
		self:Tag(cpoints, '|cffffffff[cpoints]|r')

		self.Power.PostUpdate = PostUpdatePower
		self:SetWidth(210)
	end,
	pet = function(self)
		self:SetWidth(90)

		f.peticon = CreateFrame("Frame",nil,self)
		f.peticon:SetBackdrop(BACKDROP)
		f.peticon:SetBackdropColor(0, 0, 0)
		f.peticon:SetFrameStrata("BACKGROUND")
		f.peticon:SetSize(18, 18)
		local t = f.peticon:CreateTexture(nil,"BACKGROUND")
		t:SetTexture('Interface\\Icons\\Ability_GhoulFrenzy')
		t:SetTexCoord(0.08, 0.92, 0.08, 0.92)
		t:SetDrawLayer('ARTWORK')
		t:SetAllPoints(f.peticon)
		f.peticon.texture = t
		f.peticon:SetPoint("TOPLEFT",-22, 0)
		f.peticon:Hide()
	end,
	targettarget = function(self)
		self:SetWidth(170)
	end,
	focus = function(self)
		self:SetWidth(170)
	end,
}

local function Shared(self, unit)
	self.colors.power.MANA = {0, 144/255, 1}

	self:RegisterForClicks('AnyDown')
	self:SetScript('OnEnter', UnitFrame_OnEnter)
	self:SetScript('OnLeave', UnitFrame_OnLeave)

	self:SetBackdrop(BACKDROP)
	self:SetBackdropColor(0, 0, 0)

	self:SetHeight(HEIGHT)

	local health = CreateFrame('StatusBar', nil, self)
	health:SetStatusBarTexture(TEXTURE)
	health:SetStatusBarColor(0.1, 0.1, 0.1)
	health.frequentUpdates = true
	self.Health = health

	local healthBG = health:CreateTexture(nil, 'BORDER')
	healthBG:SetAllPoints()
	
	if(unit == 'player' or unit == 'pet') then
		healthBG:SetTexture(0.75, 0.1, 0.1)
	else
		healthBG:SetTexture(1/3, 1/3, 1/3)
	end

	local healthValue = health:CreateFontString(nil, 'OVERLAY')
	healthValue:SetFont(FONT, FONTSIZE)
	healthValue:SetShadowColor(0, 0, 0)
	healthValue:SetShadowOffset(1, -1)
	healthValue:SetPoint('RIGHT', health, -2, 0)
	healthValue:SetJustifyH('RIGHT')
	healthValue.frequentUpdates = 1/4
	self:Tag(healthValue, '[seno:health]')

	if(unit == 'player' or unit == 'target' or unit == 'pet') then
		local power = CreateFrame('StatusBar', nil, self)
		power:SetPoint('BOTTOMRIGHT')
		power:SetPoint('BOTTOMLEFT')
		power:SetPoint('TOP', health, 'BOTTOM', 0, -1)
		power:SetStatusBarTexture(TEXTURE)
		power.frequentUpdates = true
		self.Power = power

		power.colorClass = true
		power.colorTapping = true
		power.colorDisconnected = true
		power.colorReaction = unit ~= 'pet'
		power.colorHappiness = unit == 'pet'
		power.colorPower = unit == 'pet'

		local powerBG = power:CreateTexture(nil, 'BORDER')
		powerBG:SetAllPoints()
		powerBG:SetTexture(TEXTURE)
		powerBG.multiplier = 1/3
		power.bg = powerBG

		if(unit ~= 'target') then
			local powerValue = health:CreateFontString(nil, 'OVERLAY')
			powerValue:SetFont(FONT, FONTSIZE)
			powerValue:SetShadowColor(0, 0, 0)
			powerValue:SetShadowOffset(1, -1)
			powerValue:SetPoint('LEFT', health, 2, 0)
			powerValue:SetJustifyH('LEFT')
			powerValue.frequentUpdates = 0.1
			if (unit == 'player' and playerclass == 'WARLOCK') then
				self:Tag(powerValue, '[seno:power< ][seno:shards][seno:druid]')
			else
				self:Tag(powerValue, '[seno:power< ][seno:druid]')
			end
		end

		local raidicon = health:CreateTexture(nil, 'OVERLAY')
		raidicon:SetPoint('TOP', self, 0, 8)
		raidicon:SetSize(16, 16)
		self.RaidIcon = raidicon

		health:SetHeight(HEALTHHEIGHT)
		health:SetPoint('TOPRIGHT')
		health:SetPoint('TOPLEFT')

		self.menu = SpawnMenu
	end

	if(unit == 'focus' or unit:find('target')) then
		local name = health:CreateFontString(nil, 'OVERLAY')
		name:SetFont(FONT, FONTSIZE)
		name:SetShadowColor(0, 0, 0)
		name:SetShadowOffset(1, -1)
		name:SetPoint('LEFT', health, 2, 0)
		name:SetPoint('RIGHT', healthValue, 'LEFT')
		name:SetJustifyH('LEFT')
		if unit == 'target' then
			self:Tag(name, '[difficulty][plus][level] [seno:name< ][|cff0090ff>rare<|r]')
		else
			self:Tag(name, '[seno:name< ][|cff0090ff>rare<|r]')
		end

		local debuffs = CreateFrame('Frame', nil, self)
		debuffs.spacing = 3
		debuffs:SetSize(110, 44)
		debuffs.initialAnchor = 'TOPRIGHT'
		debuffs.PostCreateIcon = PostCreateAura
		debuffs:SetPoint('TOPRIGHT', self, 'BOTTOMRIGHT', 0, -4)
		debuffs.num = 10
		debuffs.size = 18
		debuffs['growth-y'] = 'DOWN'
		debuffs['growth-x'] = 'LEFT'
		debuffs.PostUpdateIcon = PostUpdateDebuff
		self.Debuffs = debuffs

		if(unit ~= 'target') then
			debuffs.num = 5
			health:SetAllPoints()
		end

		if(unit == 'focus') then
			debuffs.onlyShowPlayer = true
			debuffs.size = 24
		end

	end

	if(UnitSpecific[unit]) then
		return UnitSpecific[unit](self)
	end
end

oUF.colors.power.MANA = {0, 144/255, 1}

oUF:RegisterStyle('seno', Shared)

oUF:Factory(function(self)
	self:SetActiveStyle('seno')
	self:Spawn('player'):SetPoint('CENTER', -220, -300)
	self:Spawn('pet'):SetPoint('CENTER', -370, -300)
	self:Spawn('focus'):SetPoint('CENTER', 500, -300)
	self:Spawn('target'):SetPoint('CENTER', 0, -300)
	self:Spawn('targettarget'):SetPoint('CENTER', 220, -300)
end)
  Reply With Quote