Thread Tools Display Modes
07-27-10, 12:11 PM   #1
Barcode
A Murloc Raider
Join Date: Jul 2010
Posts: 4
Problem w/ coloring power by class

I have my power bars colored by the units class and it working fine whenever I'm targeting another player controlled unit. However if I target a player then an npc its power bar will be the same color as the player's class. For example I target a Paladin then an NPC that has mana. The NPC's mana bar will be pink.

I just use
Code:
self.Power.colorClass = true
I can't figure out a way to fix this either. I've tried to use the change target event to reevaluate the target but nothing I do seems to works.
Any help here would be great.

Last edited by Barcode : 07-27-10 at 01:32 PM.
  Reply With Quote
07-27-10, 12:34 PM   #2
Rostok
A Flamescale Wyrmkin
Join Date: Jul 2008
Posts: 127
try colorReaction and this is self.Power.colorClass
  Reply With Quote
07-27-10, 01:29 PM   #3
Barcode
A Murloc Raider
Join Date: Jul 2010
Posts: 4
Sorry my code segment is wrong it is self.Power.colorClass not : as you pointed out.
Coloring by reaction will fix the copied color problem. However I'd like the have the power bars of npc colored to their power type rather than reaction type.
  Reply With Quote
07-27-10, 01:35 PM   #4
yj589794
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 314
Code:
self.Power.colorClass = true
self.Power.colorClassNPC = true
self.Power.colorClassPet = true
that should color all units (that have a class) by their class.
  Reply With Quote
07-29-10, 12:23 PM   #5
Barcode
A Murloc Raider
Join Date: Jul 2010
Posts: 4
Code:
self.Power.colorClass = true
self.Power.colorClassNPC = true
self.Power.colorClassPet = true
worked to make all units colored by class and fixed the color carry over problem I was having but I wanted NPCs to have their bars colored by ptype not class.


I was able to figure this out. However, the only way I could get it to work is by adding a condition to haste's oUF power element. If someone knows how to get this working from within one's layout only it would probably be better.

Thanks for the help both yj589794 and Rostok.
  Reply With Quote
07-29-10, 01:42 PM   #6
yj589794
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 314
Ahhh, yeah I see what you want to do now.

In the default power bar update colouring by power type has a higher priority than colouring by unit class. So, if you turn on colouring by power type it will occur for all units.

It is possible to use your own power update routine within your layout without modifying oUF directly.

Add a routine like below (default power update routine with order of power and class colouring swapped):
Code:
local MyPowerUpdate = function(self, event, unit)
	if(self.unit ~= unit) then return end
	local power = self.Power

	if(power.PreUpdate) then power:PreUpdate(unit) end

	local min, max = UnitPower(unit), UnitPowerMax(unit)
	local disconnected = not UnitIsConnected(unit)
	power:SetMinMaxValues(0, max)

	if(disconnected) then
		power:SetValue(max)
	else
		power:SetValue(min)
	end

	power.disconnected = disconnected
	power.unit = unit

	local r, g, b, t
	if(power.colorTapping and UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit)) then
		t = self.colors.tapped
	elseif(power.colorDisconnected and not UnitIsConnected(unit)) then
		t = self.colors.disconnected
	elseif(power.colorHappiness and UnitIsUnit(unit, "pet") and GetPetHappiness()) then
		t = self.colors.happiness[GetPetHappiness()]
	elseif(power.colorClass and UnitIsPlayer(unit)) or
		(power.colorClassNPC and not UnitIsPlayer(unit)) or
		(power.colorClassPet and UnitPlayerControlled(unit) and not UnitIsPlayer(unit)) then
		local _, class = UnitClass(unit)
		t = self.colors.class[class]
	elseif(power.colorPower) then
		local ptype, ptoken, altR, altG, altB  = UnitPowerType(unit)

		t = self.colors.power[ptoken]
		if(not t and altR) then
			r, g, b = altR, altG, altB
		end
	elseif(power.colorReaction and UnitReaction(unit, 'player')) then
		t = self.colors.reaction[UnitReaction(unit, "player")]
	elseif(power.colorSmooth) then
		r, g, b = self.ColorGradient(min / max, unpack(power.smoothGradient or self.colors.smooth))
	end

	if(t) then
		r, g, b = t[1], t[2], t[3]
	end

	if(b) then
		power:SetStatusBarColor(r, g, b)

		local bg = power.bg
		if(bg) then
			local mu = bg.multiplier or 1
			bg:SetVertexColor(r * mu, g * mu, b * mu)
		end
	end

	if(power.PostUpdate) then
		return power:PostUpdate(unit, min, max)
	end
end
and in your style function add in:
Code:
self.Power.colorClass = true
self.Power.colorPower = true
self.Power.Update = MyPowerUpdate
This will cause player characters to have the power coloured by class and for all other units it will be coloured by power type.


Hope that helps
  Reply With Quote
08-02-10, 01:02 PM   #7
Barcode
A Murloc Raider
Join Date: Jul 2010
Posts: 4
Yeah, I did something similar. I added the condition colorPowerNPC instead of changing the priorities.

Code:
...
elseif(power.colorPower) or (power.colorClassNPC and not UnitIsPlayer(unit)) then
	local ptype, ptoken, altR, altG, altB  = UnitPowerType(unit)

	t = self.colors.power[ptoken]
	if(not t and altR) then
		r, g, b = altR, altG, altB
	end
...
and in my layout just had

Code:
self.Power.colorClass = true
self.Power.colorPowerNPC = true
Again thanks for the help.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Problem w/ coloring power by class


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off