Thread Tools Display Modes
08-18-10, 10:35 AM   #21
yj589794
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 314
The standard cpoints element does not support pre and post update routines.

You would need to override the standard update routine to add them in.

Code:
local comboUpdate = function(self, event, unit)
	-- copied from standard update routine
	if(unit == 'pet') then return end

	local cp
	if(UnitExists'vehicle') then
		cp = GetComboPoints('vehicle', 'target')
	else
		cp = GetComboPoints('player', 'target')
	end

	local cpoints = self.CPoints
	for i=1, MAX_COMBO_POINTS do
		if(i <= cp) then
			cpoints[i]:Show()
		else
			cpoints[i]:Hide()
		end
	end

	-- add postupdate support
	if cpoints.PostUpdate then cpoints.PostUpdate(self) end
end

local comboPostUpdate = function(self)
	-- add code to check if combo elements are shown and move aura buttons
end

local style = function(self, unit)
	-- define your combo points element
	local cpoints = ...
	...

	cpoints.Update = comboUpdate
	cpoints.PostUpdate = comboPostUpdate

	self.CPoints = cpoints
end
disclaimer: this is all dry coded and guaranteed to contain bugs
  Reply With Quote
08-18-10, 12:15 PM   #22
Toran
A Nerdscale Dorkin
 
Toran's Avatar
Premium Member
Join Date: May 2006
Posts: 143
Originally Posted by yj589794 View Post
The standard cpoints element does not support pre and post update routines.

You would need to override the standard update routine to add them in.

Code:
local comboUpdate = function(self, event, unit)
	-- copied from standard update routine
	if(unit == 'pet') then return end

	local cp
	if(UnitExists'vehicle') then
		cp = GetComboPoints('vehicle', 'target')
	else
		cp = GetComboPoints('player', 'target')
	end

	local cpoints = self.CPoints
	for i=1, MAX_COMBO_POINTS do
		if(i <= cp) then
			cpoints[i]:Show()
		else
			cpoints[i]:Hide()
		end
	end

	-- add postupdate support
	if cpoints.PostUpdate then cpoints.PostUpdate(self) end
end

local comboPostUpdate = function(self)
	-- add code to check if combo elements are shown and move aura buttons
end

local style = function(self, unit)
	-- define your combo points element
	local cpoints = ...
	...

	cpoints.Update = comboUpdate
	cpoints.PostUpdate = comboPostUpdate

	self.CPoints = cpoints
end
disclaimer: this is all dry coded and guaranteed to contain bugs
Sweet. Dry code is better than no code.

Should I not use my combo points update function in my earlier post? Does yours replace it?

Code:
		local function updateCPoints(self, event, unit)
			if unit == PlayerFrame.unit and unit ~= self.CPoints.unit then
				self.CPoints.unit = unit
			end
		end
  Reply With Quote
08-18-10, 01:12 PM   #23
yj589794
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 314
the one I posted is a copy of the default cpoints element update function, with the addition of a PostUpdate check.

If you are using a custom update function then add the post update check to that rather than using the update function I posted.
  Reply With Quote
08-18-10, 01:51 PM   #24
Toran
A Nerdscale Dorkin
 
Toran's Avatar
Premium Member
Join Date: May 2006
Posts: 143
Thanks. I wonder if I should switch it to the one you posted. I don't see anything in mine about vehicle detection. Hmm.

Will give it all a shot later after work / kids in bed.
  Reply With Quote
08-18-10, 09:04 PM   #25
Toran
A Nerdscale Dorkin
 
Toran's Avatar
Premium Member
Join Date: May 2006
Posts: 143
I've been working on this for a while now and the debuffs just aren't moving if there are combo points. I know I have something not right, so here is the code. Any further hints / kicks in the right direction would be helpful.

Code:
local comboUpdate = function(self, event, unit)
	-- copied from standard update routine
	if(unit == 'pet') then return end

	local cp
	if(UnitExists'vehicle') then
		cp = GetComboPoints('vehicle', 'target')
	else
		cp = GetComboPoints('player', 'target')
	end

	local cpoints = self.CPoints
	for i=1, MAX_COMBO_POINTS do
		if(i <= cp) then
			cpoints[i]:Show()
		else
			cpoints[i]:Hide()
		end
	end

	-- add postupdate support
	if cpoints.PostUpdate then cpoints.PostUpdate(self) end
end

			
--move the debuffs if combo points are detected
local comboPostUpdate = function(self)
	if CPoints then
		self.Debuffs:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 45)
	else
		self.Debuffs:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 10)
	end			
end	

local UnitSpecific = {
...
     target = function(self)
     ...
         if auras then
         ...
			local debuffs = CreateFrame("Frame", nil, self)
			debuffs:SetHeight(height+2)
			debuffs:SetWidth(width)
			--debuffs:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 10)
			debuffs.spacing = 4
			debuffs.size = height+2
			debuffs.initialAnchor = "BOTTOMLEFT"
			
			debuffs.PostCreateIcon = auraIcon
			debuffs.PostUpdateIcon = PostUpdateIcon
		
			self.Debuffs = debuffs
			self.Debuffs.num = 32
          end

          local CPoints = {}
			for index = 1, MAX_COMBO_POINTS do
				local CPoint = CreateFrame("Frame", nil, self.Health)
				CPoint:SetHeight(6)
				CPoint:SetWidth(width * .96 / MAX_COMBO_POINTS)
				CPoint:SetFrameStrata("BACKGROUND")
				kiss_set_me_a_backdrop(CPoint)
				CPoint.bg = CPoint:CreateTexture(nil, "LOW")
				CPoint.bg:SetTexture(texture)
				CPoint.bg:SetAllPoints(CPoint)
				--CPoint:SetPoint('LEFT', index == 1 and self.Health or CPoints[index - 1], 'LEFT', 20, 10)
				if(index == 1) then
					CPoint:SetPoint("LEFT", self.Health, "LEFT", 0, 15)
				else
					CPoint:SetPoint("LEFT", CPoints[index-1], "RIGHT", 2, 0)
				end

				if(index == 1) then CPoint.bg:SetVertexColor(1,1,0) end
				if(index == 2) then CPoint.bg:SetVertexColor(1,0.75,0) end
				if(index == 3) then CPoint.bg:SetVertexColor(1,0.5,0) end
				if(index == 4) then CPoint.bg:SetVertexColor(1,0.25,0) end
				if(index == 5) then CPoint.bg:SetVertexColor(1,0,0) end
				CPoints[index] = CPoint
			end
			CPoints.Update = comboUpdate
			CPoints.PostUpdate = comboPostUpdate
			self.CPoints = CPoints
     end

Last edited by Toran : 08-20-10 at 11:10 AM.
  Reply With Quote
08-18-10, 09:54 PM   #26
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
That works, but there's not really any point in "adding PostUpdate support". Just write what you want to do into the Update function:

Code:
local comboUpdate = function(self, event, unit)
	-- copied from standard update routine
	if unit == "pet" then return end

	local cp = UnitExists("vehicle") and GetComboPoints("vehicle", "target") or GetComboPoints("player", "target")

	local cpoints = self.CPoints
	for i = 1, MAX_COMBO_POINTS do
		if i <= cp then
			cpoints[i]:Show()
		else
			cpoints[i]:Hide()
		end
	end

	-- move the debuffs up if there are combo points
	if self.Debuffs then
		self.Debuffs:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, cp > 0 and 45 or 10)
	end
end

-- inside your spawn function:
self.CPoints.Update = comboUpdate
Note that the if CPoints then check in your original comboPostUpdate function would always evaluate to false since there is no variable CPoints defined in that scope, and in any case, you want to adjust the Debuffs position based on the number of combo points currently active, not whether or not the frame has a CPoints element.
  Reply With Quote
08-19-10, 02:07 AM   #27
yj589794
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 314
Originally Posted by Phanx View Post
That works, but there's not really any point in "adding PostUpdate support". Just write what you want to do into the Update function:
This is more of a stylistic choice of how to implement the functionality required.

Personally, I would go with the PostUpdate as it provides a degree of separation between the Update routine (which updates the combo points) and the PostUpdate routine (which moves other elements dependant upon combo points being shown).

Also, this has the benefit of meaning less code would need to be changed if the default cpoints element adds support for PostUpdate functions.
*** Hint: Toran, you should send Haste a message to add this as a feature request ***
  Reply With Quote
08-19-10, 06:38 AM   #28
Toran
A Nerdscale Dorkin
 
Toran's Avatar
Premium Member
Join Date: May 2006
Posts: 143
Originally Posted by Phanx View Post
That works, but there's not really any point in "adding PostUpdate support". Just write what you want to do into the Update function:

Code:
local comboUpdate = function(self, event, unit)
	-- copied from standard update routine
	if unit == "pet" then return end

	local cp = UnitExists("vehicle") and GetComboPoints("vehicle", "target") or GetComboPoints("player", "target")

	local cpoints = self.CPoints
	for i = 1, MAX_COMBO_POINTS do
		if i <= cp then
			cpoints[i]:Show()
		else
			cpoints[i]:Hide()
		end
	end

	-- move the debuffs up if there are combo points
	if self.Debuffs then
		self.Debuffs:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, cp > 0 and 45 or 10)
	end
end

-- inside your spawn function:
self.CPoints.Update = comboUpdate
Note that the if CPoints then check in your original comboPostUpdate function would always evaluate to false since there is no variable CPoints defined in that scope, and in any case, you want to adjust the Debuffs position based on the number of combo points currently active, not whether or not the frame has a CPoints element.
Neat. Love how the debuffs appear in one place when there are combo points, then pop over to another place when the combo points go away.

Worked perfectly - just tested on my rogue. Will keep testing to make sure there aren't any situations where it bugs out (shouldn't be).

Thanks to all of you for your help and patience.
  Reply With Quote
08-20-10, 06:26 PM   #29
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by yj589794 View Post
This is more of a stylistic choice of how to implement the functionality required.
To some extent, yes, but why add more function closures than necessary? If code will only ever be called from inside one function, that code should just be written into that function, not factored out into a separate function.
  Reply With Quote
08-20-10, 07:08 PM   #30
yj589794
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 314
Originally Posted by Phanx View Post
To some extent, yes, but why add more function closures than necessary? If code will only ever be called from inside one function, that code should just be written into that function, not factored out into a separate function.
The rest of the quoted text covers my argument quite well...

Originally Posted by yj589794 View Post
Personally, I would go with the PostUpdate as it provides a degree of separation between the Update routine (which updates the combo points) and the PostUpdate routine (which moves other elements dependant upon combo points being shown).

Also, this has the benefit of meaning less code would need to be changed if the default cpoints element adds support for PostUpdate functions.
*** Hint: Toran, you should send Haste a message to add this as a feature request ***
Having one function do all updates will give some negligible performance benefit, I believe in this case that maintainable code is a better trade off.
  Reply With Quote
08-21-10, 02:55 AM   #31
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
I guess it's a part of the personal programming-style. I go with Phanx: "If code is only executed once, don't put it in a seperate function".

Don't get me wrong, if we were talking about 100 lines or so, your argument may fit, but since we need to create a custom Update-function, we could aswell put the debuff-code in it.
__________________
  Reply With Quote
08-21-10, 03:26 AM   #32
Broes
A Deviate Faerie Dragon
Join Date: Jul 2010
Posts: 11
Any chance you could post the complete finished source somewhere? Really like this implementation.

Thanks in advance!
  Reply With Quote
08-21-10, 06:26 AM   #33
yj589794
A Rage Talon Dragon Guard
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 314
Originally Posted by Mischback View Post
I guess it's a part of the personal programming-style. I go with Phanx: "If code is only executed once, don't put it in a seperate function".

Don't get me wrong, if we were talking about 100 lines or so, your argument may fit, but since we need to create a custom Update-function, we could aswell put the debuff-code in it.
In some ways yes, in others no. Overwriting an element Update routine with your own custom functionality means that you need to check for any changes in your code whenever the element gets updated. This is not a good situation, which is why I suggested...

Originally Posted by yj589794 View Post
*** Hint: Toran, you should send Haste a message to add this as a feature request ***
By getting PreUpdate and PostUpdate function checks added to the element now, means that you do not need to overwrite the Update routine. This improves code maintainability as any changes to the element in the future would have less impact on your code.

Anyway, I'm going to stop banging on about this now as people seem to not see things in the same way as me. Fighting losing battles only leads to frustration.
  Reply With Quote
08-21-10, 09:22 AM   #34
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
It would be something different, if there actually were a PostUpdate-hook in the oUF-CP-element. But there is no, so you have to implement the Update- and the PostUpdate... So why not just implementing one function.

It would be awesome, if haste would include the hook, though! *hint*
__________________

Last edited by Mischback : 08-21-10 at 09:49 AM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Runebar and combobar


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