Thread Tools Display Modes
07-21-10, 08:55 PM   #1
Unkn
Premium Member
 
Unkn's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 258
Question about coloring background...

I am trying to set class color to the backdrop of my hp. Trying to match my oUF layout to my grid. Which is set grey until there is a deficit hp then goes class colored. Right now everyone has bright blue background to their hp. Which is well an improvement over the white or black I was getting, but obviously not right.

Code is as follows. Pulled set points out because its just set points...

Code:
   local hp = CreateFrame("StatusBar", nil, self)
   hp:SetStatusBarTexture(statusbartexture)
   hp:SetHeight(hp_height)
   hp:SetStatusBarColor(0.15, 0.15, 0.15) 
     if unit == "player" then
      ....
    elseif unit == "target" then
      .... 
    else
       .....
    end
        hp:SetBackdrop({bgFile="Interface\\AddOns\\oUF_GearedRedux\\StatusBar\\Minimalistv"})
   hp.colorDisconnected = true
   hp.colorClass = false
   hp.colorClassPet = false
   hp.frequentUpdates = true
   self.Health = hp
   
   
-- set health background color
	local color = RAID_CLASS_COLORS[select(2,  UnitClass("unit"))]	
	if UnitIsPlayer("player") and color then
		hp:SetBackdropColor(color.r, color.g, color.b, 1)
	else
		local r, g, b = UnitSelectionColor("unit")
		hp:SetBackdropColor(r, g, b, 1)	
	end
Thats what I've got. Bright blue backdrop..... Any suggestions? ( blue is friendly? reaction type I believe. So guess thats working. But I want that for npcs and the like. For any player I want class colored.)
Attached Thumbnails
Click image for larger version

Name:	bluebgofdoom.jpeg
Views:	722
Size:	70.9 KB
ID:	4635  
__________________
"I'm very feminine. And I'll beat the crap out of ANYONE who disagrees!"

Last edited by Unkn : 07-21-10 at 09:02 PM. Reason: edited for typo
  Reply With Quote
07-21-10, 09:26 PM   #2
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
A PostUpdateHealth function would do it. I'm using one to create class and reaction (for npcs) coloured backgrounds for oUF_Nivea.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
07-21-10, 09:45 PM   #3
Unkn
Premium Member
 
Unkn's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 258
Originally Posted by Dawn
A PostUpdateHealth function would do it.
Now its back to the white/grey. Still not working


Code:
	local PostUpdateHealth = function(unit, min, max)
-- set health background color
		local color = RAID_CLASS_COLORS[select(2,  UnitClass("unit"))]	
		if UnitIsPlayer("player") and color then
			hp:SetBackdropColor(color.r, color.g, color.b, .5)
		else
			local r, g, b = UnitSelectionColor("unit")
			hp:SetBackdropColor(r, g, b, .5)	
		end
	end
__________________
"I'm very feminine. And I'll beat the crap out of ANYONE who disagrees!"

Last edited by Unkn : 07-21-10 at 11:47 PM.
  Reply With Quote
07-21-10, 11:51 PM   #4
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
Originally Posted by Unkn View Post
Code:
	local PostUpdateHealth = function(unit, min, max)
-- set health background color
		local color = RAID_CLASS_COLORS[select(2,  UnitClass("unit"))]	
		if UnitIsPlayer("player") and color then
			hp:SetBackdropColor(color.r, color.g, color.b, .5)
		else
			local r, g, b = UnitSelectionColor("unit")
			hp:SetBackdropColor(r, g, b, .5)	
		end
	end
I think you have a little problem in you if-clause, cause you're only checking, if the player is a player-controlled character... Here's the function in the API.
But I think some other function calls are false, aswell, since you're passing strings to functions several times, but you want to pass the unit-variable. And I don't really understand your call to UnitSelectionColor (not in the API-documentation, so I don't know what it should do).

Code:
	local PostUpdateHealth = function(unit, min, max)
-- set health background color
		local color = RAID_CLASS_COLORS[select(2,  UnitClass(unit))]	
		if (UnitIsPlayer(unit) and color) then
			hp:SetBackdropColor(color.r, color.g, color.b, .5)
		else
			local r, g, b = UnitSelectionColor(unit)
			hp:SetBackdropColor(r, g, b, .5)	
		end
	end
You can try this one, but I'm at work, so it's untested.
  Reply With Quote
07-22-10, 12:31 AM   #5
Unkn
Premium Member
 
Unkn's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 258
I've got to be doing something wrong elsewhere because none of it is working. I'm not getting any errors, just showing no color at all now. Its just the base color of the bg file.
__________________
"I'm very feminine. And I'll beat the crap out of ANYONE who disagrees!"
  Reply With Quote
07-22-10, 01:28 AM   #6
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
Ahh, missed the scoping...
Code:
	local PostUpdateHealth = function(unit, min, max)
-- set health background color
		local color = RAID_CLASS_COLORS[select(2,  UnitClass(unit))]	
		if (UnitIsPlayer(unit) and color) then
			self.Health:SetBackdropColor(color.r, color.g, color.b, .5)
		else
			local r, g, b = UnitSelectionColor(unit)
			self.Health:SetBackdropColor(r, g, b, .5)	
		end
	end
Still untested
  Reply With Quote
07-22-10, 01:46 AM   #7
Unkn
Premium Member
 
Unkn's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 258
Okay so i went and got frustrated.

Code:
 	-- hp bg
	hpbg = hp:CreateTexture(nil, "BACKGROUND")
	hpbg:SetAllPoints(hp)
	hpbg:SetTexture("Interface\\AddOns\\oUF_GearedRedux\\StatusBar\\Minimalistv")
	hp.bg = hpbg
	local _, class = UnitClass("player");
	if class == "WARRIOR" then
		self.Health.bg:SetVertexColor(0.95, 0.23, 0.23, .75)
	elseif class == "PRIEST" then
		self.Health.bg:SetVertexColor(1, 0.96, 0.98, .75)
	elseif class == "MAGE" then
		self.Health.bg:SetVertexColor(0.00, 1, 1, .75)
	elseif class == "DRUID" then
		self.Health.bg:SetVertexColor(1, 0.49, 0.04, .75)
	elseif class == "PALADIN" then
		self.Health.bg:SetVertexColor(0.92, 0.22, 0.46, .75)
	elseif class == "HUNTER" then
		self.Health.bg:SetVertexColor(0.33, 0.86, 0.00, .75)
	elseif class == "ROGUE" then
		self.Health.bg:SetVertexColor(1, 0.94, 0.16, .75)
	elseif class == "SHAMAN" then
		self.Health.bg:SetVertexColor(0.13, 0.42, 1, .75)
	elseif class == "WARLOCK" then
		self.Health.bg:SetVertexColor(0.36, 0.18, 1, .75)
	end
Haha... It colors the background, my toons color. Its a step in the right direction? maybe... but now everything has the background color of the class im playing. whatever atm I can deal with that. I need to figure out how to fix that now.

Took a new screenshot so you could see what I mean. **note, im not trying to get ouf to change the hp status bar to class colored, just the background to be colored the units class type**
Attached Thumbnails
Click image for larger version

Name:	hahaplayerclasscoloredbg.jpg
Views:	702
Size:	35.2 KB
ID:	4636  
__________________
"I'm very feminine. And I'll beat the crap out of ANYONE who disagrees!"

Last edited by Unkn : 07-22-10 at 01:51 AM.
  Reply With Quote
07-22-10, 01:55 AM   #8
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
Originally Posted by Unkn View Post
Okay so i went and got frustrated.

Code:
 	--- snip
	local _, class = UnitClass("player");
	-- snap
You should read the API carefully, regarding the usage of UnitIDs.

Your code works perfeectly, since you're applying YOUR class everytime. You will have to use the class of the unit, not the class of "player".

Go with something like local _, class = UnitClass(unit) (of course you must make sure, that the variable unit is set) and it should work just fine.
  Reply With Quote
07-22-10, 02:12 AM   #9
Unkn
Premium Member
 
Unkn's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 258
Yeah I know I'm calling the player's class, and setting that color as my background. I know thats why everyone has an orange background atm. Working on fixing it.

But I'm happy with the improvement.
__________________
"I'm very feminine. And I'll beat the crap out of ANYONE who disagrees!"
  Reply With Quote
07-22-10, 03:39 AM   #10
Unkn
Premium Member
 
Unkn's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 258
I'm to tired to even think about this anymore, maybe that was the problem to start with.

Tomorrow fresh eyes!
__________________
"I'm very feminine. And I'll beat the crap out of ANYONE who disagrees!"
  Reply With Quote
07-24-10, 03:18 PM   #11
Unkn
Premium Member
 
Unkn's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 258
Nope wasn't me being tired, was me just failing at knowing what to do. Any ideas?
__________________
"I'm very feminine. And I'll beat the crap out of ANYONE who disagrees!"
  Reply With Quote
07-25-10, 03:08 AM   #12
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
I thought you got the trick already...

Code:
 	-- hp bg
	hpbg = hp:CreateTexture(nil, "BACKGROUND")
	hpbg:SetAllPoints(hp)
	hpbg:SetTexture("Interface\\AddOns\\oUF_GearedRedux\\StatusBar\\Minimalistv")
	hp.bg = hpbg
	local _, class = UnitClass("player");
	if class == "WARRIOR" then
		self.Health.bg:SetVertexColor(0.95, 0.23, 0.23, .75)
        -- snipsnap
Just replace local _, class = UnitClass("player"); with local _, class = UnitClass(unit);.

This is untested, but I think, you can access unit inside of the styling-functions, so take and use it!
  Reply With Quote
07-29-10, 11:36 PM   #13
Taroven
A Cyclonian
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 49
If you're still having issues, my layout (oUF_Taroven, check the author link) does this. Here's the postupdate.

Code:
local updateHealth = function(self,unit,min,max)
    if not unit then return end
    local frame = oUF.units[unit]
    if not frame or frame.unit ~= unit then return end    
    
    local r,g,b,t
    local isdead = UnitIsDeadOrGhost(unit)
    
    if isdead or not UnitIsConnected(unit) then
        r,g,b = .6,.6,.6
    elseif(UnitIsPlayer(unit)) then
        local _,class = UnitClass(unit)
        t = oUF.colors.class[class]
    else
        r,g,b = .2,.5,.5
    end

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

    self.bg:SetVertexColor(r,g,b,0.5)
end
Change the static numbers as you please, of course.

EDIT: Unit checking is good, mkay?
__________________
Former author of EventHorizon Continued and Other Releases.

Last edited by Taroven : 08-01-10 at 12:16 AM.
  Reply With Quote
07-30-10, 09:38 PM   #14
Dender
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jul 2010
Posts: 3
Castbars by classcolor

Help please with classcolor CastBar.
Function:
Code:
local PostCastStart = function(self, event, unit)
    local r,g,b,t
    
    if UnitIsPlayer(unit) then
        local _,class = UnitClass(unit)
        t = oUF.colors.class[class]
    else
        r,g,b = 0,1,0
    end

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

    self:SetStatusBarColor(r,g,b)

end
Style:
Code:
local castbar = CreateFrame("StatusBar", self:GetName().."_Castbar", self)
castbar:SetStatusBarColor(r,g,b)
But the color of all castbars(target,focus,focustarget,tot,etc) by my classcolor.
And I need that would castbars was the color whose castbar.

Prompt please where I was wrong.

P.S.: Sorry for my english.
  Reply With Quote
08-01-10, 12:15 AM   #15
Taroven
A Cyclonian
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 49
Update on my BG color method:
Code:
local updateHealth = function(self,unit,min,max)
	if not unit then return end
	local frame = oUF.units[unit]
	if not frame or frame.unit ~= unit then return end	
	
	local r,g,b,t
	local isdead = UnitIsDeadOrGhost(unit)
	
	if isdead or not UnitIsConnected(unit) then
		r,g,b = .6,.6,.6
	elseif(UnitIsPlayer(unit)) then
		local _,class = UnitClass(unit)
		t = oUF.colors.class[class]
	else
		r,g,b = .2,.5,.5
	end

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

	self.bg:SetVertexColor(r,g,b,0.5)
end
Let's just say that not firing that 25 times per UNIT_HEALTH event is a good thing.

Dender: Place this outside of your style function.
Code:
local PostCastStart = function(self,event,unit)
	if not unit then return end
	local frame = oUF.units[unit]
	if not frame or frame.unit ~= unit then return end	
	
	local r,g,b,t
	local isdead = UnitIsDeadOrGhost(unit)
	
	if(UnitIsPlayer(unit)) then
		local _,class = UnitClass(unit)
		t = oUF.colors.class[class]
	else
		r,g,b = 0, 1, 0
	end

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

	self:SetStatusBarColor(r,g,b)
end
Style:
Code:
local castbar = CreateFrame("StatusBar", self:GetName().."_Castbar", self)
castbar.PostCastStart = PostCastStart
castbar:SetStatusBarColor(0,1,0)
self.Castbar = castbar
My only guess is that you weren't setting castbar.PostCastStart, or you didn't set it properly.
__________________
Former author of EventHorizon Continued and Other Releases.
  Reply With Quote
08-01-10, 07:48 AM   #16
Dender
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jul 2010
Posts: 3
Taroven, now my update function is:
Code:
local PostCastStart = function(self,event,unit)
	if not unit then return end
	local frame = oUF.units[unit]
	if not frame or frame.unit ~= unit then return end	
	
	local r, g, b, t
	local isdead = UnitIsDeadOrGhost(unit)
	
	if(UnitIsPlayer(unit)) then
		local _, class = UnitClass(unit)
		t = oUF.colors.class[class]
	else
		r, g, b = 0, 1, 0
	end

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

	self:SetStatusBarColor(r, g, b)
end
As you said.

And style:
Code:
local castbar = CreateFrame("StatusBar", self:GetName().."_Castbar", self)
castbar:SetStatusBarTexture(texture)
castbar:SetHeight(10)
castbar:SetWidth(150)
castbar:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
castbar:SetStatusBarColor(r, g, b)
castbar.PostCastStart = PostCastStart
castbar.PostChannelStart = PostCastStart
self.Castbar = castbar
All castbars is white. If i set in style function castbar:SetStatusBarColor(0, 1, 0) as you said - all castbars is green.

And not classcolor (not my classcolor, need selected unit classcolor(if my focus warlock, focus castbar is warlock classcolor/etc))

Thanks for your help.
  Reply With Quote
08-01-10, 11:33 PM   #17
Rostok
A Flamescale Wyrmkin
Join Date: Jul 2008
Posts: 127
You don't need to do a castbar:SetStatusBarColor(r, g, b) to color your castbar when you declare it in your layout, delete that line and let the coloring come with the postcaststart.
You really should learn a bit of lua before asking such questions...
  Reply With Quote
08-03-10, 07:29 AM   #18
Dender
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jul 2010
Posts: 3
Originally Posted by Rostok View Post
You don't need to do a castbar:SetStatusBarColor(r, g, b) to color your castbar when you declare it in your layout, delete that line and let the coloring come with the postcaststart.
You really should learn a bit of lua before asking such questions...
If i delete castbar:SetStatusBarColor(r, g, b) from my style func, all castbars is white.
Have you tried to do this? Do you have castbar in classcolor?
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Question about coloring background...


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