Quantcast

Blizzards incoming heals notification

F. Dekker [01-26-13 - 19:47]
Blizzards incoming heals notification
- A darker bar below the healthbar as indication for the incoming heal
- A checkbox under config to enable/disable incoming heals display
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..2729dde
--- /dev/null
+++ b/PerfectRaid_IncomingHeals.lua
@@ -0,0 +1,105 @@
+--[[-------------------------------------------------------------------------
+  *
+  * 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")
+	else
+		self:UnregisterEvent("UNIT_HEAL_PREDICTION", "UpdateIncomingHeals")
+	end
+end
+
+
+function IncomingHeals:ConfigureButton( button )
+
+	local bar = CreateFrame("StatusBar", nil, button)
+	button.incominghealsbar = bar
+
+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()
+
+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)
+
+	-- not correct healinc or health
+	if health == null or healinc == null then return end
+
+	local healthsum = health + healinc
+
+	-- adjust healthsum to maxhealth
+	if healthsum > maxhealth then healthsum = maxhealth end
+
+	for unit, tbl in pairs(frames) do
+
+		if UnitIsUnit( target, unit ) then
+
+			for frame in pairs(frames[unit]) do
+
+				if healinc == 0 or health == maxhealth then
+					frame.incominghealsbar:Hide()
+				else
+					frame.incominghealsbar:SetMinMaxValues(0, maxhealth)
+					frame.incominghealsbar:SetValue(healthsum)
+					frame.incominghealsbar:Show()
+				end
+			end
+
+			break
+		end
+	end
+
+
+end
\ No newline at end of file