Quantcast

Merge remote-tracking branch 'origin/incoming-heals' into panoramix

F. Dekker [03-28-13 - 16:49]
Merge remote-tracking branch 'origin/incoming-heals' into panoramix
Filename
PerfectRaid.toc
PerfectRaid_Config.lua
PerfectRaid_IncomingHeals.lua
diff --git a/PerfectRaid.toc b/PerfectRaid.toc
index 33a2238..d7046d8 100644
--- a/PerfectRaid.toc
+++ b/PerfectRaid.toc
@@ -28,3 +28,4 @@ PerfectRaid_Range.lua
 PerfectRaid_Highlight.lua
 PerfectRaid_Config.lua
 PerfectRaid_RaidIcons.lua
+PerfectRaid_IncomingHeals.lua
diff --git a/PerfectRaid_Config.lua b/PerfectRaid_Config.lua
index 5abaf80..2e1a422 100644
--- a/PerfectRaid_Config.lua
+++ b/PerfectRaid_Config.lua
@@ -86,6 +86,10 @@ function Config:CreateOptions(opt)
 	iconPositionDropDown:SetWidth(200);
 	iconPositionDropDown:SetPoint("LEFT", check, "RIGHT", 100, 0)
 	options.iconposition = iconPositionDropDown;
+
+	local check = CreateFrame("CheckButton", "PRConfig_IncomingHeals", options, "PRCheckTemplate")
+	check.Label:SetText(L["Show incoming heals"])
+	table.insert(options.widgets, check)

 	local cancel = CreateFrame("Button", "PRConfig_Cancel", options, "PRButtonTemplate")
 	cancel:SetText(L["Cancel"])
@@ -105,14 +109,16 @@ function Config:CreateOptions(opt)
 		local clickCast = PRConfig_ClickCast:GetChecked() and true or false
 		local locked = PRConfig_Lock:GetChecked() and true or false
 		local showRaidIcons = PRConfig_RaidIcons:GetChecked() and true or false
+		local showIncomingHeals = PRConfig_IncomingHeals:GetChecked() and true or false
 		local raidIconPosition = UIDropDownMenu_GetSelectedValue(PRConfig_IconPositionDropDown)
-
+
 		PerfectRaid.db.profile.hideparty = hideParty
 		PerfectRaid.db.profile.showmanaonly = showMana
 		PerfectRaid.db.profile.clickcast = clickCast
 		PerfectRaid.db.profile.locked = locked
 		PerfectRaid.db.profile.showraidicons = showRaidIcons
 		PerfectRaid.db.profile.raidiconposition = raidIconPosition
+		PerfectRaid.db.profile.showincomingheals = showIncomingHeals

 		PerfectRaid:TriggerMessage("PERFECTRAID_CONFIG_CHANGED")
 		Config:PartyVisibility()
@@ -124,6 +130,7 @@ function Config:CreateOptions(opt)
 		PRConfig_ClickCast:SetChecked(PerfectRaid.db.profile.clickcast)
 		PRConfig_Lock:SetChecked(PerfectRaid.db.profile.locked)
 		PRConfig_RaidIcons:SetChecked(PerfectRaid.db.profile.showraidicons)
+		PRConfig_IncomingHeals:SetChecked(PerfectRaid.db.profile.showincomingheals)
 		UIDropDownMenu_SetSelectedValue(PRConfig_IconPositionDropDown,PerfectRaid.db.profile.raidiconposition)
 	end

diff --git a/PerfectRaid_IncomingHeals.lua b/PerfectRaid_IncomingHeals.lua
new file mode 100644
index 0000000..885185f
--- /dev/null
+++ b/PerfectRaid_IncomingHeals.lua
@@ -0,0 +1,130 @@
+--[[-------------------------------------------------------------------------
+  *
+  * IncomingHeals module for PerfectRaid addon.
+  *
+  * Written by: Panoramix
+  * Version: 1.0
+  *
+---------------------------------------------------------------------------]]
+
+
+local IncomingHeals = PerfectRaid:NewModule("PerfectRaid-IncomingHeals")
+
+local L = PerfectRaidLocals
+local utils, frames
+
+function IncomingHeals:Initialize()
+
+	frames = PerfectRaid.frames
+	utils = PerfectRaid.utils
+
+	self:RegisterMessage("DONGLE_PROFILE_CHANGED")
+	self:RegisterMessage("PERFECTRAID_CONFIG_CHANGED")
+end
+
+
+function IncomingHeals:DONGLE_PROFILE_CHANGED(event, addon, svname, name)
+	if svname == "PerfectRaidDB" then
+		IncomingHeals:EnableIncomingHeals(PerfectRaid.db.profile.showincomingheals)
+	end
+end
+
+function IncomingHeals:PERFECTRAID_CONFIG_CHANGED(event, addon, svname, name)
+	IncomingHeals:EnableIncomingHeals(PerfectRaid.db.profile.showincomingheals)
+end
+
+function IncomingHeals:Enable()
+	IncomingHeals:EnableIncomingHeals(PerfectRaid.db.profile.showincomingheals)
+end
+
+function IncomingHeals:EnableIncomingHeals(value)
+	if value then
+		self:RegisterEvent("UNIT_HEAL_PREDICTION", "UpdateIncomingHeals")
+		self:RegisterEvent("UNIT_ABSORB_AMOUNT_CHANGED", "UpdateIncomingHeals")
+	else
+		self:UnregisterEvent("UNIT_HEAL_PREDICTION", "UpdateIncomingHeals")
+		self:UnregisterEvent("UNIT_ABSORB_AMOUNT_CHANGED", "UpdateIncomingHeals")
+	end
+end
+
+
+function IncomingHeals:ConfigureButton( button )
+
+	local inchealbar = CreateFrame("StatusBar", nil, button)
+	button.incominghealsbar = inchealbar
+
+	local absorbbar = CreateFrame("StatusBar", nil, button)
+	button.absorbbar = absorbbar
+end
+
+function IncomingHeals:UpdateButtonLayout( button )
+
+	button.incominghealsbar:ClearAllPoints()
+	button.incominghealsbar:SetPoint("TOPLEFT", button.leftbox, "TOPRIGHT", 0, -1)
+	button.incominghealsbar:SetPoint("BOTTOMRIGHT", button.rightbox, "BOTTOMLEFT", 0, 1)
+	button.incominghealsbar:SetStatusBarTexture("Interface\\AddOns\\PerfectRaid\\images\\smooth")
+	button.incominghealsbar:SetFrameLevel( button.healthbar:GetFrameLevel()-1 )
+	button.incominghealsbar:SetStatusBarColor( 0.3, 0.5, 0.3 )
+	button.incominghealsbar:Hide()
+
+	button.absorbbar:ClearAllPoints()
+	button.absorbbar:SetPoint("TOPLEFT", button.leftbox, "TOPRIGHT", 0, -1)
+	button.absorbbar:SetPoint("BOTTOMRIGHT", button.rightbox, "BOTTOMLEFT", 0, 1)
+	button.absorbbar:SetStatusBarTexture("Interface\\AddOns\\PerfectRaid\\images\\smooth")
+	button.absorbbar:SetFrameLevel( button.healthbar:GetFrameLevel()-2 )
+	button.absorbbar:SetStatusBarColor( 0.83, 0.45, 0.09 )
+	button.absorbbar:Hide()
+
+end
+
+function IncomingHeals:UpdateIncomingHeals( event, target )
+
+	-- not the right unit
+	if target == "target" then return end
+
+	local health = UnitHealth(target)
+	local maxhealth = UnitHealthMax(target)
+	local healinc = UnitGetIncomingHeals(target)
+	local absorbinc = UnitGetTotalAbsorbs(target)
+
+	-- not correct healinc or health
+	if health == null or healinc == null then return end
+
+	local healthincsum = health + healinc
+	local healthabsorbsum = health + healinc + absorbinc
+
+	-- adjust healthsum to maxhealth
+	if healthincsum > maxhealth then healthincsum = maxhealth end
+	if healthabsorbsum > maxhealth then healthabsorbsum = maxhealth end
+
+	for unit, tbl in pairs(frames) do
+
+		if UnitIsUnit( target, unit ) then
+
+			for frame in pairs(frames[unit]) do
+
+				-- heal inc
+				if healinc == 0 or health == maxhealth then
+					frame.incominghealsbar:Hide()
+				else
+					frame.incominghealsbar:SetMinMaxValues(0, maxhealth)
+					frame.incominghealsbar:SetValue(healthincsum)
+					frame.incominghealsbar:Show()
+				end
+
+				-- absorb inc
+				if absorbinc == 0 or health == maxhealth then
+					frame.absorbbar:Hide()
+				else
+					frame.absorbbar:SetMinMaxValues(0, maxhealth)
+					frame.absorbbar:SetValue(healthabsorbsum)
+					frame.absorbbar:Show()
+				end
+
+			end
+
+		end
+	end
+
+
+end
\ No newline at end of file