Quantcast

Alpha Version 0.0.4

XrystalBelle [02-15-14 - 19:45]
Alpha Version 0.0.4
Filename
XDataTables.lua
XShieldMonitor.lua
XShieldMonitor.toc
diff --git a/XDataTables.lua b/XDataTables.lua
new file mode 100644
index 0000000..ca0e8ca
--- /dev/null
+++ b/XDataTables.lua
@@ -0,0 +1,36 @@
+
+local addonName, addonData = ...
+
+addonData.Backdrop = {}
+
+addonData.Backdrop["Tooltip4"] = {
+	bgFile="Interface\\Tooltips\\UI-Tooltip-Background",
+	edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",
+	tile = true,
+	edgeSize = 4,
+	tileSize = 4,
+	insets = { left = 0, right = 0, top = 0, bottom = 0 },
+}
+
+addonData.Backdrop["Tooltip16"] = {
+	bgFile="Interface\\Tooltips\\UI-Tooltip-Background",
+	edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",
+	tile = true,
+	edgeSize = 16,
+	tileSize = 16,
+	insets = { left = 5, right = 5, top = 5, bottom = 5 },
+}
+
+addonData.BackdropColor = {}
+
+addonData.BackdropColor["Tooltip4"] = {
+	r = 0.75,
+	g = 0.75,
+	b = 0.75,
+}
+
+addonData.BackdropColor["Tooltip16"] = {
+	r = 0.75,
+	g = 0.75,
+	b = 0.75,
+}
diff --git a/XShieldMonitor.lua b/XShieldMonitor.lua
index a1276c3..e3e7ca3 100644
--- a/XShieldMonitor.lua
+++ b/XShieldMonitor.lua
@@ -2,244 +2,305 @@
 local addonName, XSM = ...

 local BarWidth = 200
-local BarHeight = 10
-local ShieldSpell = 17
-
-local FontSize = 8
+local BarHeight = 15
+local FontSize = 10

 XSM = XSM or {}

 XSM.ShieldSpells = {
+
 	17, 	-- Power Word: Shield 	-- Regular Ability
 	123258, -- Power Word: Shield 	-- Modified by Angelic Bulwhark (108946), Divine Insight (123266)
+	47753, 	-- Divine Aegis (1) 	-- Modified by Angelic Bulwhark (108946)
+	114908,	-- Spirit Shell
+	77613,	-- Grace
+	59889,	-- Borrowed Time
+}

+XSM.PlayerSpells = {
+	17, 	-- Power Word: Shield 	-- Regular Ability
+	123258, -- Power Word: Shield 	-- Modified by Angelic Bulwhark (108946), Divine Insight (123266)
 	47753, 	-- Divine Aegis (1) 	-- Modified by Angelic Bulwhark (108946)
+	114908,	-- Spirit Shell
+	--	47517,	-- Grace				-- Modifies Flash Heal, Greater Heal, Penance
+	77613,	-- Grace
+	59889,	-- Borrowed Time

---	108946, -- Angelic Bulwhark 	-- Modifies Power Word: Shield (17), Spirit Shell (109964)
+	109175, -- Divine Insight (75) 	-- Applies Aura Divine Insight (124430/123266/123267)
+	123266, -- Divine Insight 		-- Modifies Power Word Shield (17)
+	123267,	-- Divine Insight
+	124430,	-- Divine Insight
+
+	108946, -- Angelic Bulwhark 	-- Modifies Power Word: Shield (17), Spirit Shell (109964)
 	114214, -- Angelic Bulwhark (1)	-- Regular Ability ?

---	109175, -- Divine Insight (75) 	-- Applies Aura Divine Insight (124430/123266/123267)
---	123266, -- Divine Insight 		-- Modifies Power Word Shield (17)
+}

+XSM.PlayerCooldowns = {
 	109964, -- Spirit Shell (28) 	-- Modifies Heals to absorb - Modified By Angelic Bulwhark (108946)
+	47750,	-- Penance
+	47540,	-- Penance (Discipline)
+	52798,	-- Borrowed Time ( Discipline )		-- Applies Aura 59889
 }

-XSM.Events = CreateFrame("Frame")
+XSM.SetMovable = function(self,frame)
+	if not frame then return end
+	frame:EnableMouse(true)
+	frame:SetMovable(true)
+	frame:RegisterForDrag("LeftButton")
+	frame:SetScript("OnDragStart",function(self)
+		self:StartMoving()
+	end)

-XSM.CreateFrames = function(self)
-
-	XSM.MaxAbsorb = 0
-	XSM.CurrAbsorb = 0
-	XSM.PercAbsorb = 0
-	XSM.LastAbsorb = 0
-
-	-- Create the Main Bar
-	XSM.Bar = CreateFrame("Frame","XShieldMonitor_Bar",UIParent)
-	XSM.Bar:SetWidth(BarWidth)
-	XSM.Bar:SetHeight(BarHeight * 3)
-	XSM.Bar:EnableMouse(true)
-	XSM.Bar:SetMovable(true)
-	if ( not XSM.Bar:IsUserPlaced() ) then
-		XSM.Bar:SetPoint("CENTER")
-	end
-	XSM.Bar:SetUserPlaced(true)
-	XSM.Bar:RegisterForDrag("LeftButton")
-	XSM.Bar:SetScript("OnDragStart",function(self) self:StartMoving() end)
-	XSM.Bar:SetScript("OnDragStop",function(self) self:StopMovingOrSizing() end)
-	XSM.Bar:Show()
-
-
-	-- create the Spell Icon for the Cooldown Animation
-	XSM.Icon = CreateFrame("Frame","XShieldMonitor_Icon",XSM.Bar)
-	XSM.Icon:SetWidth(BarHeight * 3)
-	XSM.Icon:SetHeight(BarHeight * 3)
-	XSM.Icon:SetPoint("TOPLEFT")
-	XSM.Icon.Texture = XSM.Icon:CreateTexture(nil,"ARTWORK")
-	XSM.Icon.Texture:SetTexture(GetSpellTexture(ShieldSpell))
-	XSM.Icon.Texture:SetAllPoints()
-	XSM.Icon.Texture:Show()
-	XSM.Icon.Caption = XSM.Icon:CreateFontString(nil,"OVERLAY","GameFontNormal")
-	XSM.Icon.Caption:SetFont("Fonts\\FRIZQT__.TTF",FontSize,"OUTLINE")
-	XSM.Icon.Caption:SetJustifyV("CENTER")
-	XSM.Icon.Caption:SetJustifyH("MIDDLE")
-	XSM.Icon.Caption:SetAllPoints()
-	XSM.Icon.Caption:Show()
-	XSM.Icon.Cooldown = CreateFrame("Cooldown","XShieldMonitor_Icon_Cooldown",XSM.Icon,"CooldownFrameTemplate")
-	XSM.Icon.Duration = CreateFrame("Cooldown","XShieldMonitor_Icon_Duration",XSM.Icon,"CooldownFrameTemplate")
-	XSM.Icon:Show()
-
-
-	-- the Cooldown Bar
-	XSM.Cooldown = CreateFrame("StatusBar","XShieldMonitor_Cooldown",XSM.Bar)
-	XSM.Cooldown.Background = XSM.Cooldown:CreateTexture(nil,"BACKGROUND")
-	XSM.Cooldown.Background:SetTexture(0,0,0)
-	XSM.Cooldown.Background:SetAllPoints()
-	XSM.Cooldown.Background:Show()
-	XSM.Cooldown.Caption = XSM.Cooldown:CreateFontString(nil,"OVERLAY","GameFontNormal")
-	XSM.Cooldown.Caption:SetFont("Fonts\\FRIZQT__.TTF",FontSize,"OUTLINE")
-	XSM.Cooldown.Caption:SetJustifyV("CENTER")
-	XSM.Cooldown.Caption:SetJustifyH("MIDDLE")
-	XSM.Cooldown.Caption:SetAllPoints()
-	XSM.Cooldown.Caption:Show()
-	XSM.Cooldown:SetWidth(BarWidth - (BarHeight * 3))
-	XSM.Cooldown:SetHeight(BarHeight)
-	XSM.Cooldown:SetOrientation("HORIZONTAL")
-	XSM.Cooldown:SetMinMaxValues(0,100)
-	XSM.Cooldown:SetStatusBarColor(0,0,1,1)
-	XSM.Cooldown:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
-	XSM.Cooldown:SetValue(0)
-	XSM.Cooldown:SetPoint("TOPLEFT",XSM.Icon,"TOPRIGHT",0,0)
-	XSM.Cooldown:SetPoint("RIGHT")
-	XSM.Cooldown:SetScript("OnUpdate",function(self,elapsed)
-		if not XSM.CDActivated then return end
-		XSM.CDCounter = XSM.CDCounter + elapsed
-		XSM.CDLeft = XSM.CDDuration - XSM.CDCounter
-		XSM.Cooldown.Caption:SetText(string.format("%0.2d",XSM.CDLeft))
-		local percLeft = (( XSM.CDLeft / XSM.CDDuration ) * 100 )
-		XSM.Cooldown:SetValue(percLeft)
-		HealthBar_OnValueChanged(XSM.Cooldown,percLeft,true)
-		if ( XSM.CDCounter and XSM.CDCounter >= XSM.CDDuration ) then
-			XSM.CDActivated = false
-		end
+	frame:SetScript("OnDragStop",function(self)
+		self:StopMovingOrSizing()
+		self:SetUserPlaced(true)
+		self:SetClampedToScreen(true)
 	end)
-	XSM.Cooldown:Show()
-
-	-- The Shield Status Bar
-	XSM.Status = CreateFrame("StatusBar","XShieldMonitor_Status",XSM.Bar)
-	XSM.Status.Background  = XSM.Status:CreateTexture(nil,"BACKGROUND")
-	XSM.Status.Background:SetTexture(0,0,0)
-	XSM.Status.Background:SetAllPoints()
-	XSM.Status.Background:Show()
-	XSM.Status.Caption = XSM.Status:CreateFontString(nil,"OVERLAY","GameFontNormal")
-	XSM.Status.Caption:SetFont("Fonts\\FRIZQT__.TTF",FontSize,"OUTLINE")
-	XSM.Status.Caption:SetJustifyV("CENTER")
-	XSM.Status.Caption:SetJustifyH("MIDDLE")
-	XSM.Status.Caption:SetAllPoints()
-	XSM.Status.Caption:Show()
-	XSM.Status:SetWidth(BarWidth - (BarHeight * 3))
-	XSM.Status:SetHeight(BarHeight)
-	XSM.Status:SetOrientation("HORIZONTAL")
-	XSM.Status:SetMinMaxValues(0,100)
-	XSM.Status:SetStatusBarColor(0,1,0,1)
-	XSM.Status:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
-	XSM.Status:SetValue(0)
-	XSM.Status:SetPoint("TOPLEFT",XSM.Cooldown,"BOTTOMLEFT",0,0)
-	XSM.Status:SetPoint("RIGHT")
-	XSM.Status:Show()
-
-	-- The Aura duration Bar
-	XSM.Timer = CreateFrame("StatusBar","XShieldMonitor_Timer",XSM.Bar)
-	XSM.Timer.Background = XSM.Timer:CreateTexture(nil,"BACKGROUND")
-	XSM.Timer.Background:SetTexture(0,0,0)
-	XSM.Timer.Background:SetAllPoints()
-	XSM.Timer.Background:Show()
-	XSM.Timer.Caption = XSM.Timer:CreateFontString(nil,"OVERLAY","GameFontNormal")
-	XSM.Timer.Caption:SetFont("Fonts\\FRIZQT__.TTF",FontSize,"OUTLINE")
-	XSM.Timer.Caption:SetJustifyV("CENTER")
-	XSM.Timer.Caption:SetJustifyH("MIDDLE")
-	XSM.Timer.Caption:SetAllPoints()
-	XSM.Timer.Caption:Show()
-	XSM.Timer:SetWidth(BarWidth - (BarHeight * 3))
-	XSM.Timer:SetHeight(BarHeight)
-	XSM.Timer:SetOrientation("HORIZONTAL")
-	XSM.Timer:SetMinMaxValues(0,100)
-	XSM.Timer:SetStatusBarColor(1.0,0.0,0.0,1.0)
-	XSM.Timer:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
-	XSM.Timer:SetValue(0)
-	XSM.Timer:SetPoint("TOPLEFT",XSM.Status,"BOTTOMLEFT",0,0)
-	XSM.Timer:SetPoint("RIGHT")
-	XSM.Timer:SetScript("OnUpdate",function(self,elapsed)
-		if not XSM.AuraActivated then return end
-		XSM.AuraCounter = XSM.AuraCounter + elapsed
-		XSM.AuraLeft = XSM.AuraDuration - XSM.AuraCounter
-		XSM.Timer.Caption:SetText(string.format("%0.2d",XSM.AuraLeft))
-		local percLeft = (( XSM.AuraLeft / XSM.AuraDuration ) * 100 )
-		XSM.Timer:SetValue(percLeft)
-		HealthBar_OnValueChanged(XSM.Timer,percLeft,true)
-		if ( XSM.AuraCounter and XSM.AuraCounter >= XSM.AuraDuration ) then
-			XSM.AuraActivated = false
-			XSM:CheckAura("player")
-		end
+
+	frame:SetScript("OnHide",function(self)
+		self:StopMovingOrSizing()
+		self:SetUserPlaced(true)
+		self:SetClampedToScreen(true)
 	end)
-	XSM.Timer:Show()
+
 end

--- Check the Aura Duration for the Shield Spell and update the timers accordingly
-XSM.CheckAura = function(self,...)
-	if ( XSM.AuraActivated ) then return end
-	XSM.AuraStart, XSM.AuraDuration, XSM.AuraCounter, XSM.AuraEnabled,XSM.AuraActivated = 0,0,0,0,false
-	XSM.AuraActivated = false
-	for i = 1,40 do
-		local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, shouldConsolidate, spellId, canApplyAura, isBossDebuff, isCastByPlayer, auraData1,auraData2,auraData3 = UnitAura("player",i,"PLAYER HELPFUL")
-		if ( not name ) then break end
-		if tContains(XSM.ShieldSpells,spellId) then
---			print(i,spellId,name)
-			if ( XSM.AuraActivated == false ) then
-				XSM.AuraStart = GetTime()
-				XSM.AuraDuration = expirationTime - GetTime()
-				XSM.AuraEnabled = true
-				XSM.AuraCounter = 0
-				XSM.AuraActivated = true
-				XSM.Spell = spellId
-				XSM.Icon.Texture:SetTexture(GetSpellTexture(spellId))
+XSM.CreateShieldFrame = function(self,unit)
+	local f = CreateFrame("Frame","XSM_"..unit.."ShieldMonitor",UIParent,"SecureHandlerStateTemplate")
+	f.unit = unit
+	f:SetWidth(BarWidth)
+	f:SetHeight(BarHeight * 3)
+
+	self:SetMovable(f)
+	if ( not f:IsUserPlaced() ) then
+		f:SetPoint("CENTER")
+	end
+
+	f:SetBackdrop(self.Backdrop["Tooltip4"])
+	f:SetBackdropColor(self.BackdropColor["Tooltip4"])
+
+	f.Name = f:CreateFontString(nil,"OVERLAY")
+	f.Name:SetFont("Fonts\\FRIZQT__.TTF",FontSize,"THICKOUTLINE")
+	f.Name:SetPoint("TOP",f,"TOP",0,-5)
+	f.Name:SetJustifyV("CENTER")
+	f.Name:SetJustifyH("MIDDLE")
+	f.Name:SetText(unit)
+	f.Name:SetHeight(BarHeight)
+
+	f.Shield = CreateFrame("StatusBar","$parentShield",f)
+	f.Shield:SetWidth(BarWidth - 10)
+	f.Shield:SetHeight(BarHeight)
+	f.Shield:SetOrientation("HORIZONTAL")
+	f.Shield:SetMinMaxValues(0,100)
+	f.Shield:SetStatusBarColor(0,1,0,1)
+	f.Shield:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
+	f.Shield:SetValue(0)
+	f.Shield:SetPoint("BOTTOMLEFT",f,"BOTTOMLEFT",5,5)
+
+	f.Shield.Background  = f.Shield:CreateTexture(nil,"BACKGROUND")
+	f.Shield.Background:SetAllPoints()
+	f.Shield.Background:Show()
+
+	f.Shield.Text = f.Shield:CreateFontString(nil,"OVERLAY")
+	f.Shield.Text:SetFont("Fonts\\FRIZQT__.TTF",FontSize,"THICKOUTLINE")
+	f.Shield.Text:SetHeight(BarHeight - 5)
+	f.Shield.Text:SetWidth(BarWidth - 5)
+	f.Shield.Text:SetJustifyV("CENTER")
+	f.Shield.Text:SetJustifyH("MIDDLE")
+	f.Shield.Text:SetAllPoints()
+	f.Shield.Text:SetText("Test")
+	f.Shield.Text:Show()
+
+	f.Shield:Show()
+
+	f.Icons = {}
+	local firstIcon,lastIcon = nil,nil
+	for i,v in pairs(f.unit == "player" and XSM.PlayerSpells or XSM.ShieldSpells) do
+		f.Icons[v] = CreateFrame("Frame","$parent_Icon_"..v,f)
+		f.Icons[v]:SetWidth(32)
+		f.Icons[v]:SetHeight(32)
+		if i == 1 then
+			f.Icons[v]:SetPoint("TOPLEFT",f,"BOTTOMLEFT",5,-5)
+			lastLineIcon = v
+		elseif math.fmod(i,6) == 1 then
+			f.Icons[v]:SetPoint("TOPLEFT",f.Icons[lastLineIcon],"BOTTOMLEFT",0,0)
+			lastLineIcon = v
+		else
+			f.Icons[v]:SetPoint("TOPLEFT",f.Icons[lastIcon],"TOPRIGHT",0,0)
+		end
+
+		f.Icons[v]:SetScript("OnEnter",function(self)
+			GameTooltip:SetOwner(self,"ANCHOR_CURSOR")
+			GameTooltip:SetSpellByID(v)
+			GameTooltip:AddLine(string.format("Spell ID: %d",v),1.0,1.0,1.0,1.0)
+			GameTooltip:Show()
+		end)
+
+		f.Icons[v]:SetScript("OnLeave",function(self)
+			GameTooltip:Hide()
+		end)
+
+		f.Icons[v].Texture = f.Icons[v]:CreateTexture(nil,"ARTWORK")
+		f.Icons[v].Texture:SetTexture(GetSpellTexture(v))
+		f.Icons[v].Texture:SetAllPoints()
+		f.Icons[v].Texture:Show()
+
+		f.Icons[v].Caption = f.Icons[v]:CreateFontString(nil,"OVERLAY","GameFontNormal")
+		f.Icons[v].Caption:SetFont("Fonts\\FRIZQT__.TTF",FontSize,"OUTLINE")
+		f.Icons[v].Caption:SetJustifyV("CENTER")
+		f.Icons[v].Caption:SetJustifyH("MIDDLE")
+		f.Icons[v].Caption:SetAllPoints()
+		f.Icons[v].Caption:Show()
+
+		f.Icons[v].Cooldown = CreateFrame("Cooldown","$parent_Cooldown",f.Icons[v],"CooldownFrameTemplate")
+
+		f.Icons[v].Duration = CreateFrame("Cooldown","$parent_Duration",f.Icons[v],"CooldownFrameTemplate")
+		f.Icons[v].Duration:SetScript("OnUpdate",function(self,elapsed)
+			local spellName = GetSpellInfo(v)
+			if not f.Icons[v].AuraActivated then return end
+			f.Icons[v].AuraCounter = f.Icons[v].AuraCounter + elapsed
+			f.Icons[v].AuraLeft = f.Icons[v].AuraDuration - f.Icons[v].AuraCounter
+			if f.Icons[v].LastAuraLeft and f.Icons[v].AuraLeft > f.Icons[v].LastAuraLeft then
+				CooldownFrame_SetTimer(self,f.Icons[v].AuraStart,f.Icons[v].AuraDuration,true)
+				f.Icons[v].DurationStarted = true
 			end
+			f.Icons[v].Caption:SetText(string.format("%0.2d",f.Icons[v].AuraLeft))
+			local percLeft = (( f.Icons[v].AuraLeft / f.Icons[v].AuraDuration ) * 100 )
+			local auraName = UnitAura(f.unit or unit,spellName,"PLAYER HELPFUL")
+			if ( not auraName and spellId == v or f.Icons[v].AuraLeft < 0 ) then
+				f.Icons[v].AuraActivated = false
+				f.Icons[v].Caption:SetText("")
+				f.Icons[v].DurationStarted = false
+				f.Icons[v]:SetAlpha(0.25)
+			end
+			f.Icons[v].LastAuraLeft = f.Icons[v].AuraLeft
+		end)
+
+		f.Icons[v]:SetAlpha(0.25)
+
+		f.Icons[v]:Show()
+
+		lastIcon = v
+	end
+
+	f.RefreshAbsorb = function(self)
+		if f.Shield then
+			f.MaxAbsorb = f.MaxAbsorb or UnitGetTotalAbsorbs(f.unit) or 0
+			f.CurrAbsorb = UnitGetTotalAbsorbs(f.unit) or 0
+			if ( f.CurrAbsorb > f.MaxAbsorb ) then f.MaxAbsorb = f.CurrAbsorb end
+			f.PercAbsorb = f.MaxAbsorb > 0 and ((f.CurrAbsorb / f.MaxAbsorb) * 100) or 0
+			if f.PercAbsorb < 0 then f.MaxAbsorb = 0 f.CurrAbsorb = 0 f.PercAbsorb = 0 end
+			f.Shield:SetValue( f.PercAbsorb )
+			HealthBar_OnValueChanged(f.Shield,f.PercAbsorb,true)
+			f.Shield.Text:SetText(AbbreviateLargeNumbers(f.CurrAbsorb) .. " / " .. AbbreviateLargeNumbers(f.MaxAbsorb) .. " (" .. string.format("%0.2d",f.PercAbsorb) .. "% )")
+			f.Shield.TextString = f.Shield.Text:GetText()
+			f.LastAbsorb = f.CurrAbsorb
 		end
 	end
-	CooldownFrame_SetTimer(XSM.Icon.Duration,XSM.AuraStart,XSM.AuraDuration,XSM.AuraEnabled)
-end

--- Check the Absorb Value as this will affect the shield status
-XSM.CheckAbsorbs = function(self,...)
-	local args = { ... }
-	XSM.MaxAbsorb = XSM.MaxAbsorb or UnitGetTotalAbsorbs(args[1]) or 0
-	XSM.CurrAbsorb = UnitGetTotalAbsorbs(args[1]) or 0
-	if ( XSM.CurrAbsorb > XSM.MaxAbsorb ) then XSM.MaxAbsorb = XSM.CurrAbsorb end
-	XSM.PercAbsorb = ((XSM.CurrAbsorb / XSM.MaxAbsorb) * 100) or 0
-	if XSM.PercAbsorb < 0 then XSM.MaxAbsorb = 0 end
-	XSM.Status:SetValue( XSM.PercAbsorb )
-	HealthBar_OnValueChanged(XSM.Status,XSM.PercAbsorb,true)
-	XSM.Status.Caption:SetText(XSM.CurrAbsorb .. "/" .. XSM.MaxAbsorb .. " (" .. string.format("%0.2d",XSM.PercAbsorb) .. "% )")
-	XSM.LastAbsorb = XSM.CurrAbsorb
-end
+	f.RefreshName = function(self)
+		local name = GetUnitName(f.unit) or ""
+		local unitText = "(" .. f.unit ..")"
+		f.Name:SetText(name .. unitText)
+	end

--- Check the shield spell cooldown
-XSM.CheckCooldowns = function(self,...)
-	for i,v in pairs(XSM.ShieldSpells) do
-		local start, duration, enabled = GetSpellCooldown(v)
-		local name = GetSpellInfo(v)
-		print(i,v,name,start,duration,enabled, start > 0 and GetTime() - start or 0)
+	f.RefreshAuras = function(self)
+		for i = 1,40 do
+			local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, shouldConsolidate, spellId, canApplyAura, isBossDebuff, isCastByPlayer, auraData1,auraData2,auraData3 = UnitAura(f.unit,i,"PLAYER HELPFUL")
+			if name and name == "Divine Insight" then
+				print(name,spellId)
+			end
+			if tContains(XSM.ShieldSpells,spellId) and name then
+				f.Icons[tonumber(spellId)].AuraStart = GetTime()
+				f.Icons[tonumber(spellId)].AuraDuration = expirationTime - f.Icons[tonumber(spellId)].AuraStart
+				f.Icons[tonumber(spellId)].AuraCounter = 0
+				f.Icons[tonumber(spellId)].AuraEnabled = true
+				f.Icons[tonumber(spellId)].AuraActivated = true
+				if ( not f.Icons[tonumber(spellId)].DurationStarted ) then
+					CooldownFrame_SetTimer(f.Icons[tonumber(spellId)].Duration,f.Icons[tonumber(spellId)].AuraStart,f.Icons[tonumber(spellId)].AuraDuration,true)
+					f.Icons[tonumber(spellId)].DurationStarted = true
+				end
+				f.Icons[tonumber(spellId)]:SetAlpha(1)
+			end
+		end
 	end
-	if XSM.CDActivated then return end
-	XSM.CDStart, XSM.CDDuration, XSM.CDEnabled, XSM.CDActivated = nil,nil,nil,false
-	XSM.CDStart, XSM.CDDuration, XSM.CDEnabled = GetSpellCooldown(GetSpellInfo(ShieldSpell))
-	if not XSM.CDEnabled then return end
-	if ( XSM.CDDuration ~= nil and XSM.CDDuration > 2 ) then
-		XSM.CDCounter = 0
-		XSM.CDActivated = true
+
+	f.RefreshUnit = function(self)
+		f.RefreshName()
+		f.RefreshAbsorb()
+		f.RefreshAuras()
 	end
-	if XSM.CDActivated then CooldownFrame_SetTimer(XSM.Icon.Cooldown,XSM.CDStart,XSM.CDDuration,XSM.CDEnabled) end
+
+	RegisterStateDriver(f,"visibility","[@"..unit..",exists] show;hide")
+	f:SetShown(UnitExists(unit))
+
+	f:RegisterUnitEvent("UNIT_AURA",unit)
+	f:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED",unit)
+	f:RegisterUnitEvent("UNIT_TARGET",unit)
+	f:RegisterEvent("PLAYER_ENTERING_WORLD")
+
+	f:SetScript("OnEvent",function(self,event,...)
+		if event == "UNIT_TARGET" and f.unit == "player" then
+			if UnitExists("target") then
+				f.TargetFrame:RefreshUnit()
+			end
+
+		elseif event == "UNIT_TARGET" and f.unit == "target" then
+			if UnitExists("targettarget") then
+				f.TargetFrame:RefreshUnit()
+			end
+
+		elseif event == "UNIT_TARGET" and f.unit == "focus" then
+			if UnitExists("focustarget") then
+				f.TargetFrame:RefreshUnit()
+			end
+
+		elseif event == "UNIT_FOCUS" and  f.unit == "player" then
+			if UnitExists("focus") then
+				f.FocusFrame:RefreshUnit()
+			end
+
+		elseif event == "UNIT_ABSORB_AMOUNT_CHANGED" and f.unit == ... then
+			f:RefreshAbsorb()
+
+		elseif event == "UNIT_AURA" and ... == f.unit then
+			f:RefreshAuras()
+
+		elseif event == "PLAYER_ENTERING_WORLD" then
+			f.MaxAbsorb = 0
+			f.CurrAbsorb = 0
+			f.PercAbsorb = 0
+			f.LastAbsorb = 0
+			f:RefreshUnit()
+			if f.TargetFrame and UnitExists(f.TargetFrame.unit) then
+				f.TargetFrame:RefreshUnit()
+				f.TargetFrame.TargetFrame:RefreshUnit()
+			end
+			if f.FocusFrame and UnitExists(f.FocusFrame.unit) then
+				f.FocusFrame:RefreshUnit()
+				f.FocusFrame.TargetFrame:RefreshUnit()
+			end
+
+		end
+	end)
+
+	return f
 end

+XSM.Events = CreateFrame("Frame")
+
 -- check any events and deal with accordingly
 XSM.Events:SetScript("OnEvent",function(self,event,...)
 	local args = { ... }
 	if ( event == "ADDON_LOADED" and args[1] == addonName ) then
-		XSM:CreateFrames()
-	elseif ( event == "UNIT_AURA" ) then
-		print(event,...)
-		XSM:CheckAura(...)
-		XSM:CheckCooldowns(...)
-	elseif ( event == "UNIT_ABSORB_AMOUNT_CHANGED" ) then
-		print(event,...)
-		XSM:CheckAbsorbs(...)
-	elseif ( event == "SPELL_UPDATE_COOLDOWN" ) then
-		print(event,...)
-		XSM:CheckAura(...)
-		XSM:CheckCooldowns(...)
+		--XSM:CreateFrames()
+		XSM.PlayerFrame = XSM:CreateShieldFrame("player")
+		XSM.TargetFrame = XSM:CreateShieldFrame("target")
+		XSM.PlayerFrame.TargetFrame = XSM.TargetFrame
+		XSM.FocusFrame = XSM:CreateShieldFrame("focus")
+		XSM.PlayerFrame.FocusFrame = XSM.FocusFrame
 	end
 end)

 XSM.Events:RegisterEvent("ADDON_LOADED")
-XSM.Events:RegisterUnitEvent("UNIT_AURA","player")
-XSM.Events:RegisterUnitEvent("UNIT_ABSORB_AMOUNT_CHANGED","player")
-XSM.Events:RegisterEvent("SPELL_UPDATE_COOLDOWN")
diff --git a/XShieldMonitor.toc b/XShieldMonitor.toc
index 3a76bd6..62920c3 100644
--- a/XShieldMonitor.toc
+++ b/XShieldMonitor.toc
@@ -1,7 +1,7 @@
 ## Interface: 50400
 ## Title: Xrystal Shield Monitor
 ## Author: Tina Kirby / Gwynedda / Sen'Jin
-## Version: 5.4.0.17399 ( 0.0.3 alpha )
+## Version: 5.4.0.17399 ( 0.0.4 alpha )
 ## eMail: xrystal@swangen.co.uk
 ## Notes: Monitors Absorption Shields. -- Copyright (c) 2013 by Tina Kirby -- All Rights Reserved
 ## OptionalDeps:
@@ -10,5 +10,6 @@
 ## SavedVariables:
 ## SavedVariablesPerCharacter:

+XDataTables.lua
 XShieldMonitor.lua