Quantcast

The bulk of this code is untested due to my unreliable interenet connection, but there are no errors when logging in :P

James Whitehead II [01-22-08 - 22:41]
The bulk of this code is untested due to my unreliable interenet connection, but there are no errors when logging in :P
* Added a strictness checkmark to the buff filtering.  This is on a per-buff basis.
* Moved the entire highlight module out to another file, and added an option to show tooltip on mouseover.
* The highlight code now uses fired messages to update the highlighted state, and should be more reliable, if it works.

Please email me if you run into any issues, my internet is so unreliable at the moment, its the best way to reach me.
Filename
Localization.enUS.lua
PerfectRaid.lua
PerfectRaid.toc
PerfectRaid_Buffs.lua
diff --git a/Localization.enUS.lua b/Localization.enUS.lua
index a58a2de..26fa223 100644
--- a/Localization.enUS.lua
+++ b/Localization.enUS.lua
@@ -135,6 +135,7 @@ PerfectRaidLocals = {
 	["Show HP deficit"] = "Show HP deficit",
 	["Show group number"] = "Show group number",
 	["Show options GUI"] = "Show options GUI",
+	["Show unit tooltip on mouseover"] = "Show unit tooltip on mouseover",
 	["Sort Frames By:"] = "Sort Frames By:",
 	["Soulstone Resurrection"] = "Soulstone Resurrection",
 	["Spacing between columns:"] = "Spacing between columns:",
diff --git a/PerfectRaid.lua b/PerfectRaid.lua
index 61af0e5..7581bb0 100644
--- a/PerfectRaid.lua
+++ b/PerfectRaid.lua
@@ -61,6 +61,7 @@ function PerfectRaid:Initialize()
 			showmanaonly = true,
 			highlight = {
 				mouseover = true,
+				tooltip = false,
 				curse = (class == "DRUID" or class == "MAGE"),
 				disease = (class == "PRIEST" or class == "PALADIN" or class == "SHAMAN"),
 				magic = (class == "PRIEST" or class == "PALADIN"),
diff --git a/PerfectRaid.toc b/PerfectRaid.toc
index fecc948..b231359 100644
--- a/PerfectRaid.toc
+++ b/PerfectRaid.toc
@@ -23,3 +23,4 @@ PerfectRaid_Aggro.lua
 PerfectRaid_Buffs.lua
 PerfectRaid_Frames.lua
 PerfectRaid_Range.lua
+PerfectRaid_Highlight.lua
diff --git a/PerfectRaid_Buffs.lua b/PerfectRaid_Buffs.lua
index b2d0c25..f174a5c 100644
--- a/PerfectRaid_Buffs.lua
+++ b/PerfectRaid_Buffs.lua
@@ -93,43 +93,6 @@ function Buffs:ConfigureButton(button)
 	button.aura = font
 end

-local backdrop = {
-	bgFile = "Interface\\AddOns\\PerfectRaid\\images\\bgFile",
-	tile = true, tileSize = 32,
---	edgeFile = "Interface\\AddOns\\PerfectRaid\\images\\edgeFile",
---	edgeSize = 16,
-	insets = {
-		left = 6,
-		right = 6,
---		top = 1,
---		bottom = 1
-	},
-}
-
-local r,g,b,a
-local function OnEnter(frame)
-	if not PerfectRaid.db.profile.highlight.mouseover then return end
-
-	if frame.backdropset then
-		r,g,b,a = frame:GetBackdropColor()
-	end
-
---	frame:SetBackdropColor(1, 0.84, 0, 0.3)
-	frame:SetBackdropColor(0.9, 0.9, 0.9, 0.3)
-	frame.backdropset = true
-end
-
-local function OnLeave(frame)
-	if r then
-		frame:SetBackdropColor(r,g,b,a)
-	else
-		frame:SetBackdropColor(0,0,0,0)
-	end
-
-	frame.backdropset = false
-	r,g,b,a = nil,nil,nil,nil
-end
-
 function Buffs:UpdateButtonLayout(button, options)
 	button.aura:ClearAllPoints()

@@ -138,12 +101,6 @@ function Buffs:UpdateButtonLayout(button, options)
 	else
 		button.aura:SetPoint("LEFT", button.rightbox, "LEFT", 2, 0)
 	end
-
-	button:SetBackdrop(backdrop)
-	button:SetBackdropColor(0,0,0,0)
-
-	button:SetScript("OnEnter", OnEnter)
-	button:SetScript("OnLeave", OnLeave)
 end

 function Buffs:ShowButton(button)
@@ -153,30 +110,84 @@ end

 local buffs = {}
 local buffcache = {}
+local mybuffs = {}
+
+local BIT_CURSE = 1
+local BIT_MAGIC = 2
+local BIT_POISON = 4
+local BIT_DISEASE = 8
+
+local debuffstatus = setmetatable({}, {__index=function(t,k) rawset(t, k, 0); return 0 end})

 local work = {}
 function Buffs:UNIT_AURA(event, unit)
 	if not frames[unit] then return end

 	for k,v in pairs(buffcache) do buffcache[k] = nil end
+	for k,v in pairs(mybuffs) do mybuffs[k] = nil end

 	for i=1,40 do
-		local name,rank,texture,count = UnitBuff(unit, i)
+		local name,rank,texture,count,duration,timeleft = UnitBuff(unit, i)
 		if not name then break end
 		buffcache[name] = (buffcache[name] or 0) + 1
+		-- Flag this, if this is our buff
+		if timeleft then
+			mybuffs[name] = true
+		end
 	end

 	local debuffType
 	for i=1,40 do
-		local name,rank,texture,count,type = UnitDebuff(unit, i)
+		local name,rank,texture,count,type,durating,timeleft = UnitDebuff(unit, i)
 		if not name and not type then break end
 		buffcache[name] = (buffcache[name] or 0) + 1
+		-- Flag this, if this is our debuff
+		if timeleft then
+			mybuffs[name] = true
+		end
+
 		if type and name ~= type then
 			buffcache[type] = (buffcache[type] or 0) + 1
 			debuffType = type
 		end
 	end

+	-- Raise any relevant debuff gained/lost messages
+	local status = debuffstatus[unit]
+
+	-- Disease
+	if buffcache.Disease and status < BIT_DISEASE then
+		debuffstatus[unit] = debuffstatus[unit] + BIT_DISEASE
+		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Disease")
+	elseif status >= BIT_DISEASE then
+		debuffstatus[unit] = debuffstatus[unit] - BIT_DISEASE
+		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Disease")
+	end
+
+	if buffcache.Poison and status < BIT_POISON then
+		debuffstatus[unit] = debuffstatus[unit] + BIT_POISON
+		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Poison")
+	elseif status >= BIT_POISON then
+		debuffstatus[unit] = debuffstatus[unit] - BIT_POISON
+		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Poison")
+	end
+
+	if buffcache.Magic and status < BIT_MAGIC then
+		debuffstatus[unit] = debuffstatus[unit] + BIT_MAGIC
+		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Magic")
+	elseif status >= BIT_MAGIC then
+		debuffstatus[unit] = debuffstatus[unit] - BIT_MAGIC
+		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Magic")
+	end
+
+	if buffcache.Curse and status < BIT_CURSE then
+		debuffstatus[unit] = debuffstatus[unit] + BIT_CURSE
+		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_GAINED", unit, "Curse")
+	elseif status >= BIT_CURSE then
+		debuffstatus[unit] = debuffstatus[unit] - BIT_CURSE
+		self:TriggerMessage("PERFECTRAID_DEBUFFTYPE_LOST", unit, "Curse")
+	end
+
 	for k,v in pairs(work) do work[k] = nil end

 	for i,entry in ipairs(buffs) do
@@ -196,11 +207,13 @@ function Buffs:UNIT_AURA(event, unit)
 		local conds = self.conditions
 		local group = raidLookup[unit]

-		if checkcond then
+		-- Handle the condition checking for the buff, taking strictness into account
+		if entry.strict then
+			-- Set up a boolean value so we can trip it if a filter fails
 			local pass = true

 			for i,name in pairs(entry.cond) do
-				if conds[name] and not conds[name](unit,class,group) then
+				if conds[name] and not conds[name](unit, class, group) then
 					pass = false
 				end
 			end
@@ -212,39 +225,29 @@ function Buffs:UNIT_AURA(event, unit)
 					table.insert(work, entry.colortext)
 				end
 			end
+		else
+			-- Simply iterate each of the conditions, and break when we match
+			for i,name in pairs(entry.cond) do
+				if conds[name] and conds[name](unit, class, group) then
+					if num and num > 1 then
+						table.insert(work, entry.colortext .. "(" .. num .. ")")
+					else
+						table.insert(work, entry.colortext)
+					end
+
+					break
+				end
+			end
 		end
 	end

-	-- Check to see if we need to change the backdrop
-	local opt = PerfectRaid.db.profile.highlight
-	local bdset = true
-	local r,g,b,a
-	if buffcache.Curse and opt.curse then
-		r,g,b,a = 0.6,0,1,0.7
-	elseif buffcache.Poison and opt.poison then
-		r,g,b,a = 0,0.6,0,0.7
-	elseif buffcache.Disease and opt.disease then
-		r,g,b,a = 0.6,0.4,0,0.7
-	elseif buffcache.Magic and opt.magic then
-		r,g,b,a = 0.2,0.6,1,0.7
-	else
-		r,g,b,a = 0,0,0,0
-		bdset = false
-	end
-
 	local status = strjoin(" ", unpack(work))
 	for frame in pairs(frames[unit]) do
 		frame.aura:SetFormattedText(status)
-		frame:SetBackdropColor(r,g,b,a)
-		frame.backdropset = bdset
 	end
 end

 function Buffs:CreateOptions(opt)
-
-	-- Call the highlight options frame creation script
-	self:CreateOptions_Highlight(opt)
-
 	self.options = opt
 	local options = CreateFrame("Frame", "PROptions_Buffs", PROptions)
 	opt:AddOptionsTab(L["Buffs/Debuffs"], options)
@@ -522,6 +525,12 @@ function Buffs:CreateEditFrame(parent)
 	disabled:Show()
 	frame.disabled = disabled

+	local strict = CreateFrame("CheckButton", "PRBuffs_Strict", PROptions_Buffs_Edit, "PRCheckTemplate")
+	strict.Label:SetText(L["Make filters strict"])
+	strict:SetPoint("TOPLEFT", disabled, "TOPRIGHT", 200, 0)
+	strict:Show()
+	frame.strict = strict
+
 	local dropdown = CreateFrame("Frame", "PRBuffs_Dropdown", PROptions_Buffs_Edit, "UIDropDownMenuTemplate")
 	dropdown:SetID(1)
 	dropdown:SetPoint("BOTTOMRIGHT", -115, 30)
@@ -553,6 +562,7 @@ function Buffs:FillEntry(entry)

 	options.missing:SetChecked(entry.missing)
 	options.disabled:SetChecked(entry.disabled)
+	options.strict:SetChecked(entry.strict)
 end

 function Buffs:EditEntry()
@@ -583,6 +593,7 @@ function Buffs:AddEntry()
 	end
 	options.missing:SetChecked(false)
 	options.disabled:SetChecked(false)
+	optinos.strict:SetChecked(false)
 	options.buffname:SetFocus()
 end

@@ -608,6 +619,7 @@ function Buffs:UpdateBuffTable()
 			tbl.groupname = entry.groupname
 			tbl.colortext = "|cFF"..entry.color..entry.disptext.."|r"
 			tbl.missing = entry.missing
+			tbl.strict = entry.strict
 			tbl.cond = {string.split(",", entry.conds)}
 			table.insert(buffs, tbl)
 		end
@@ -660,6 +672,7 @@ function Buffs:SaveEntry()
 	entry.conds = conds
 	entry.missing = frame.missing:GetChecked()
 	entry.disabled = frame.disabled:GetChecked()
+	entry.strict = frame.strict:GetChecked()

 	local color = utils.RGBPercToHex(frame.disptext:GetTextColor())
 	entry.color = color
@@ -767,93 +780,6 @@ function Buffs:AddDefaultBuff(profile, entry)
 	table.insert(profile, tbl)
 end

-local options
-function Buffs:CreateOptions_Highlight(opt)
-	options = CreateFrame("Frame", "PROptions_Highlight", PROptions)
-
-	opt:AddOptionsTab("Highlight", options)
-
-	options.widgets = {}
-
-	local check = CreateFrame("CheckButton", "PRHighlight_Mouseover", options, "PRCheckTemplate")
-	check.Label:SetText(L["Highlight on mouseover"])
-	table.insert(options.widgets, check)
-
-	local check = CreateFrame("CheckButton", "PRHighlight_Disease", options, "PRCheckTemplate")
-	check.Label:SetText(L["Highlight when diseased"])
-	table.insert(options.widgets, check)
-
-	local check = CreateFrame("CheckButton", "PRHighlight_Curse", options, "PRCheckTemplate")
-	check.Label:SetText(L["Highlight when cursed"])
-	table.insert(options.widgets, check)
-
-	local check = CreateFrame("CheckButton", "PRHighlight_Magic", options, "PRCheckTemplate")
-	check.Label:SetText(L["Highlight when magic debuffed"])
-	table.insert(options.widgets, check)
-
-	local check = CreateFrame("CheckButton", "PRHighlight_Poison", options, "PRCheckTemplate")
-	check.Label:SetText(L["Highlight when poisoned"])
-	table.insert(options.widgets, check)
-
-	local cancel = CreateFrame("Button", "PRHighlight_Cancel", options, "PRButtonTemplate")
-	cancel:SetText(L["Cancel"])
-	cancel:SetPoint("BOTTOMRIGHT", 0, 5)
-	cancel:SetScript("OnClick", function() options:CancelOptions() end)
-	cancel:Show()
-
-	local save = CreateFrame("Button", "PRHighlight_Save", options, "PRButtonTemplate")
-	save:SetText(L["Save"])
-	save:SetPoint("BOTTOMRIGHT", cancel, "BOTTOMLEFT", -10, 0)
-	save:SetScript("OnClick", function() options:SaveOptions() end)
-	save:Show()
-
-	function options:SaveOptions()
-		local mouseover = PRHighlight_Mouseover:GetChecked() and true or false
-		local disease = PRHighlight_Disease:GetChecked() and true or false
-		local curse = PRHighlight_Curse:GetChecked() and true or false
-		local magic = PRHighlight_Magic:GetChecked() and true or false
-		local poison = PRHighlight_Poison:GetChecked() and true or false
-
-		PerfectRaid.db.profile.highlight.mouseover = mouseover
-		PerfectRaid.db.profile.highlight.disease = disease
-		PerfectRaid.db.profile.highlight.curse = curse
-		PerfectRaid.db.profile.highlight.magic = magic
-		PerfectRaid.db.profile.highlight.poison = poison
-
-		-- Trigger update here
-		for unit in pairs(frames) do
-			Buffs:UNIT_AURA(nil, unit)
-		end
-	end
-
-	function options:CancelOptions()
-		local opt = PerfectRaid.db.profile.highlight
-
-		PRHighlight_Mouseover:SetChecked(opt.mouseover)
-		PRHighlight_Disease:SetChecked(opt.disease)
-		PRHighlight_Curse:SetChecked(opt.curse)
-		PRHighlight_Magic:SetChecked(opt.magic)
-		PRHighlight_Poison:SetChecked(opt.poison)
-
-		-- Trigger update here
-		for unit in pairs(frames) do
-			Buffs:UNIT_AURA(nil, unit)
-		end
-	end
-
-	-- Force an update when tab is clicked
-	options:SetScript("OnShow", options.CancelOptions)
-
-	for idx,widget in ipairs(options.widgets) do
-		widget:Show()
-		if idx == 1 then
-			widget:SetPoint("TOPLEFT", 0, 0)
-		else
-			widget:SetPoint("TOPLEFT", options.widgets[idx - 1], "BOTTOMLEFT", 0, -15)
-		end
-	end
-end
-
 local class = select(2, UnitClass("player"))
 local race = select(2, UnitRace("player"))