Thread Tools Display Modes
05-05-11, 01:03 PM   #1
Golle
A Kobold Labourer
Join Date: Jul 2010
Posts: 1
Threat vs Border.

I want to start off by thanking the creators of oUF, thanks to you guys I get to have a really good time enjoying the thrill of "making" my own addon.

Doing the above I just ran into a problem. Working on my layout, which I use the oUF_Lily code, I've set my player frame to contain one big frame with a black color and I call it my Border. On top of it I have a Healthbar, Healthbackground, a Powerbar and a Powerbackground. The way the bars and backgrounds are positioned makes my background-frame, the Border, look like thin borders.

Lately I figured it would be cool to make that border switch to a red color whenever I'm close to taking aggro to alert me of this. Doing so I thought I'd use threat.lua to trigger a function to change the frames color, but apparently threat.lua requires me to have a frame called Threat so I figured I could just rename my Border frame to Threat.
But I can't.

If I rename the frame and its variables from Border to Threat the frame just doesn't seem to load, but the threat-function is called properly. If I reset everything to use the name Border instead the frame now appears but the function is never called. Here's the snippet's of code I'm configuring:

Code:
local PostUpdateThreat = function(status, unit)
	print("threat: ", status, unit)
end

local Player = function(self, unit, isSingle)

        -- Threat/Border frame
        local Threat = CreateFrame("Frame", "PlayerBorder", self)
        Threat:SetPoint("TOPLEFT",0,0)
	Threat:SetFrameStrata("BACKGROUND")
	Threat:SetHeight(50)
	Threat:SetWidth(360)
	local Threattexture = Threat:CreateTexture("THREATLOL")
	Threattexture:SetAllPoints(Threat)
	Threattexture:SetTexture(.0, .0, .0, 1)
	Threat.texture = Threattexture
	self.Threat = Threat

        Threat.PostUpdate = PostUpdateThreat
end
I found that commenting out the "self.Threat = Threat" line is what breaks the code. If I comment it the frame appears, but PostUpdateThreat is never called. If I uncomment it the frame disappears but PostUpdateThreat is called.

I'm confused.
  Reply With Quote
05-05-11, 02:55 PM   #2
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
You're on the right way!

Create a Threat-element to use the oUF-module and then use a PostUpdate-function to alter your border color:

lua Code:
  1. self.Threat = CreateFrame('Frame', nil, self)
  2. self.Threat.PostUpdate = function(self)
  3.     self.Border.tex:SetVertexColor(threatStatus)
  4. end)

This is a raw, drycoded skeleton. You may want to look at my oUF_PredatorSimple, I use the exact same technique. Should be in layout.lua for the frame stuff and the actual function is in core.lua.

https://github.com/Mischback/oUF_Pre...layout.lua#L42 is where Threat is applied (function is here) and here is the ThreatUpdate-function: https://github.com/Mischback/oUF_Pre.../core.lua#L532
__________________
  Reply With Quote
05-06-11, 03:53 AM   #3
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
An easier solution would be to create your frame border as you do:

lua Code:
  1. local Border = CreateFrame("Frame", "PlayerBorder", self)
  2. Border:SetPoint("TOPLEFT",0,0)
  3. Border:SetFrameStrata("BACKGROUND")
  4. Border:SetHeight(50)
  5. Border:SetWidth(360)
  6. self.Border = Border
(btw you'll need to set a backdrop in order to see something)

Then create the the threat texture with it:
lua Code:
  1. Threat = self.Border:CreateTexture(nil, "OVERLAY")
  2. Threat:SetAllPoints()
  3. Threat:SetTexture(yourTexture)
  4. self.Threat = Threat

You don't need Pre/PostUpdate. oUF will hide the texture when you don't have a threat status and show and color it accordingly when you have.
  Reply With Quote
05-06-11, 04:11 AM   #4
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
And another tip (not topic related) if you allow

Don't use fixed sizes for the border as you might wish to add it to other frames too, which have different sizes. Just anchor it better:

lua Code:
  1. Border:SetPoint("TOPLEFT", self, -2, 2)
  2. Border:SetPoint("BOTTOMLEFT", self, 2, -2)

That way you just set the frame size per unit (self) and border and threat grow or shrink accordingly.
  Reply With Quote
05-06-11, 07:44 AM   #5
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Rainrider might have meant it already, but the easiest way is

Code:
      Border:SetPoint("TOPLEFT", self, -2, 2)
      Border:SetPoint("BOTTOMRIGHT", self, 2, -2)
Which will span the border around self. No width/height needed at all.

On a sidenote SetSize(width, height) is a little less code than SetWidth(x), SetHeight(y). Unless you only want to address just width or height on it's own, ofc.
__________________
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
05-06-11, 07:54 AM   #6
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Ah, shame on me, of course I meant BOTTOMRIGHT ^^ Thank you Dawn
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Threat vs Border.


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