Thread Tools Display Modes
09-24-12, 03:12 AM   #21
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Tested and working with a few minor changes. If there are specific parts you don't understand, feel free to ask.

Edit: Guess I should refresh the page before replying. Leaving this here anyway, but feel free to disregard.

Code:
-- Disable ClamHolyPower if player is not a paladin.
if select(2, UnitClass("player")) ~= "PALADIN" then
    return DisableAddOn("ClamHolyPower")
end

-------------------
-- CONFIGURATION --
-------------------

-- Background Configuration --
local bkr = 0 -- Background color: Red
local bkg = 0 -- Background color: Green
local bkb = 0 -- Background color: Blue
local bka = 0.60 -- Background alpha: 0 = Transparent    1 = Opaque
local hwe = false -- Hide the background when holy power is empty.

-- Indicator Configuration --
local itex = "Interface\\AddOns\\ClamHolyPower\\flatsmooth"  -- Path pointing to the texture used for the indicator.
local ir = 1 -- Indicator color: Red
local ig = 0.8 -- Indicator color: Green
local ib = 0 -- Indicator color: Blue

-- Frame Configuration --
local fposx = -193.25 -- Frame position: X
local fposy = -243 -- Frame position: Y
local fwidth = 231 -- Frame width.
local fheight = 11 -- Frame height.

-----------------------
-- END CONFIGURATION --
-----------------------

-- Create ClamHolyPowerFrame
local f = CreateFrame("Frame", "ClamHolyPowerFrame", UIParent)

-- When the frame recieves an event, run the method on the frame whose
-- name matches the event name:
f:SetScript("OnEvent", function(self, event, ...) return self[event](self, event, ...) end)

-- Register for the event that fires once the initial loading process
-- has finished:
f:RegisterEvent("PLAYER_LOGIN")

function f:PLAYER_LOGIN()
	-- These variables aren't needed outside of this initialization,
	-- so keep them local to this function:
	local maxhp = IsPlayerSpell(115675) and 5 or 3

	self:SetFrameStrata("BACKGROUND")
	self:SetPoint("CENTER", fposx, fposy)
	self:SetWidth(fwidth)
	self:SetHeight(fheight)

	-- Create the background:
	local bk = self:CreateTexture(nil, "BACKGROUND")
	bk:SetTexture(bkr, bkg, bkb, bka)
	bk:SetAllPoints(true)
	self.background = bk

	-- Create the indicators:
	local iwidth = (fwidth - maxhp - 1) / maxhp
	local iheight = fheight - 2

	self.indicators = {}
	for i = 1, maxhp do
		local ind = self:CreateTexture(nil, "HIGH")
		ind:SetTexture(itex)
		-- Just anchor each indicator relative to the previous one:
		if i == 1 then
			ind:SetPoint("LEFT", f, 1, 0)
		else
			ind:SetPoint("LEFT", self.indicators[i-1], "RIGHT", 1, 0)
		end
		ind:SetWidth(iwidth)
		ind:SetHeight(iheight)
		ind:SetVertexColor(ir, ig, ib)
		self.indicators[i] = ind
	end

	-- Don't need this anymore:
	self:UnregisterEvent("PLAYER_LOGIN")

	-- Only register UNIT_POWER for the player unit:
	self:RegisterUnitEvent("UNIT_POWER", "player")

	-- Update the power now:
	self:UNIT_POWER("PLAYER_LOGIN", "player", "HOLY_POWER")
end

function f:UNIT_POWER(event, unit, powerType)
	if powerType ~= "HOLY_POWER" then
		-- Don't waste time updating if holy power didn't change.
		return
	end

	local p = UnitPower("player", 9)
	if hwe and p == 0 then
		self:Hide()
	else
		self:Show()
		for i = 1, #self.indicators do
			if i > p then
				self.indicators[i]:Hide()
			else
				self.indicators[i]:Show()
			end
		end
	end
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-24-12, 08:37 AM   #22
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Woah Phanx, outta left field!

I read through the code, I love that you commented so thoroughly, and that your code follows the structure of what I originally came up with.

You and Dridzt came up with some pretty different approaches (I know yours just sort of expands on mine), but is there any major difference between how you two approached it? Performance or memory wise?

Thank you tons for helping me!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help with my addon


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