Quantcast

* Changed usage from RGBPercToHex instead of RGBToHex

James Whitehead II [12-28-06 - 03:49]
* Changed usage from RGBPercToHex instead of RGBToHex
* Added a slash command which shows the options, using the new system
* Removed an old reference to header.count
* Fixed an issue with CreatePartyFrame() which didn't properly initialize the drag parent
* Added an aggro check, which turns the deficit text red, or displays "Aggro" as red
* Removed an old range check which caused flickers when we didn't update every frame
* Added buff counting, for when a buff appears multiple times on a single unit (i.e. Rejuvenation)
* Worked on another visual representation for aggro display, with a flashing red bar.  Needs to be adjusted before its released
Filename
PerfectRaid.lua
PerfectRaidOptions.lua
diff --git a/PerfectRaid.lua b/PerfectRaid.lua
index 4086789..a84af93 100644
--- a/PerfectRaid.lua
+++ b/PerfectRaid.lua
@@ -31,6 +31,7 @@

 local frames = {}
 local unavail = {}
+local aggro = {}

 local L
 local utils = DongleStub("DongleUtils")
@@ -87,6 +88,7 @@ function PerfectRaid:Enable()

 	-- Register slash command
 	self.cmd = self:InitializeSlashCommand("PerfectRaid Options", "PERFECTRAID", "praid", "perfectraid")
+	self.cmd:RegisterSlashHandler("Show Options", "", "ShowOptions")

 	-- Force a roster update
 	self:RAID_ROSTER_UPDATE()
@@ -274,7 +276,6 @@ function PerfectRaid:CreateRaidFrame(name, title, filter, strict, dragparent)
 	frame.title = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
 	frame.title:SetPoint("BOTTOM", frame, "TOP", 0, 3)
 	frame.title:SetText(title or "")
-	frame.count = 0
 	frame:SetAttribute("point", "TOP")
 	frame:SetAttribute("groupFilter", filter)
 	frame:SetAttribute("template", "SecureUnitButtonTemplate")
@@ -298,6 +299,7 @@ function PerfectRaid:CreatePartyFrame()
 	frame:SetAttribute("template", "SecureUnitButtonTemplate")
 	frame:SetAttribute("templateType", "Button")
 	frame:SetAttribute("nameList", UnitName("player"))
+	frame:SetAttribute("dragparent", frame)
 	frame:SetAttribute("yOffset", -2)

 	frame.initialConfigFunction = PerfectRaid.ConfigureButton
@@ -308,8 +310,8 @@ function PerfectRaid:CreatePartyFrame()
 	local frame = CreateFrame("Button", "PRaidPlayerFrame", PRaidPartyHeader, "SecureUnitButtonTemplate")
 	PerfectRaid.ConfigureButton(frame)
 	frame:SetAttribute("unit", "player")
+	frame:SetAttribute("dragparent", PRaidPartyHeader)
 	frame:SetPoint("BOTTOM", PRaidPartyHeader, "TOP", 0, 2)
-	frame:SetScript("OnUpdate", PerfectRaid.OnUpdate)

 	PRaidPartyHeader:Show()
 end
@@ -330,13 +332,25 @@ function PerfectRaid:UNIT_HEALTH(event, unit)
 	local perc = UnitHealthMax(unit) / health
 	local class = select(2, UnitClass(unit))
 	local perc = (health/max) or 0
+	local aggro = aggro[unit] >= 15

-	if deficit > 999 then
-		deficit = string.format("%.1fk", deficit / 1000)
-	elseif deficit == 0 then
-		deficit = ""
+	if aggro then
+		if deficit > 999 then
+			deficit = string.format("|cFFFF1111%.1fk|r", deficit / 1000)
+		elseif deficit == 0 then
+			deficit = "|cFFFF1111Aggro|r"
+		else
+			deficit = string.format("|cFFFF1111%d|r", deficit)
+		end
+	else
+		if deficit > 999 then
+			deficit = string.format("%.1fk", deficit / 1000)
+		elseif deficit == 0 then
+			deficit = ""
+		end
 	end

+
 	if UnitIsDead(unit) or UnitIsGhost(unit) or not UnitIsConnected(unit) then
 		local status

@@ -379,7 +393,6 @@ function PerfectRaid:UNIT_HEALTH(event, unit)
 		end

 		for frame in pairs(frames[unit]) do
-			if not range then frame:SetAlpha(0.3) else frame:SetAlpha(1.0) end
 			local class = select(2, UnitClass(unit))
 			frame.healthbar:SetValue(health)
 			frame.healthbar:SetStatusBarColor(utils.GetHPSeverity(perc))
@@ -450,6 +463,7 @@ local function OnShow(frame)

 	frames[unit] = frames[unit] or {}
 	frames[unit][frame] = true
+	aggro[unit] = 0

 	self:UNIT_HEALTH(nil, unit)
 	self:UNIT_MANA(nil, unit)
@@ -600,33 +614,6 @@ function PerfectRaid:RAID_ROSTER_UPDATE()
 	end
 end

-local class = select(2, UnitClass("player"))
-local spells = {
-	DRUID = "Healing Touch",
-	SHAMAN = "Healing Wave",
-	PRIEST = "Lesser Heal",
-	PALADIN = "Holy Light",
-}
-
-local rangespell = spells[class]
-
-if rangespell then
-	local elapsed = 0
-	function PerfectRaid.OnUpdate(frame, arg1)
-		for unit,tbl in pairs(frames) do
-			local range = IsSpellInRange(rangespell, unit) == 1
-			local alpha = range and 1.0 or 0.3
-			for frame in pairs(tbl) do
-				frame:SetAlpha(alpha)
-			end
-		end
-		elapsed = 0
-	end
-
-	local frame = CreateFrame("Frame", "PRUpdateFrame")
-	frame:SetScript("OnUpdate", PerfectRaid.OnUpdate)
-end
-
 local buffcache = {}
 local work = {}
 function PerfectRaid:UNIT_AURA(event, unit)
@@ -650,6 +637,7 @@ function PerfectRaid:UNIT_AURA(event, unit)
 	local buffs = self.db.profile.buffs
 	for i,entry in ipairs(buffs) do
 		local checkcond = false
+		local num = buffcache[entry.buffname]
 		if entry.missing then
 			if not buffcache[entry.buffname] and not buffcache[entry.groupbuff or "nil"] then
 				checkcond = true
@@ -664,7 +652,11 @@ function PerfectRaid:UNIT_AURA(event, unit)
 		if checkcond then
 			for i,name in pairs(entry.cond) do
 				if conds[name] and conds[name](unit) then
-					table.insert(work, entry.colortext)
+					if num and num > 1 then
+						table.insert(work, entry.colortext .. "(" .. num .. ")")
+					else
+						table.insert(work, entry.colortext)
+					end
 				end
 			end
 		end
@@ -690,3 +682,157 @@ function PerfectRaid:RAID_TARGET_UPDATE(event, unit)
 		end
 	end
 end
+
+function PerfectRaid:ShowOptions()
+	if not PROptions then
+		self:CreateOptions()
+	end
+
+	if PROptions:IsVisible() then
+		PROptions:Hide()
+	else
+		PROptions:Show()
+	end
+end
+
+local class = select(2, UnitClass("player"))
+local spells = {
+	DRUID = "Healing Touch",
+	SHAMAN = "Healing Wave",
+	PRIEST = "Lesser Heal",
+	PALADIN = "Holy Light",
+}
+
+local rangespell = spells[class]
+
+local victims = {}
+local targets = {}
+local flashing = {}
+
+if rangespell then
+	local elapsed = 0
+	function PerfectRaid.OnUpdate(frame, arg1)
+		elapsed = elapsed + arg1
+		if elapsed >= 0.5 then
+			if rangespell then
+				for unit,tbl in pairs(frames) do
+					local range = IsSpellInRange(rangespell, unit) == 1
+					local alpha = range and 1.0 or 0.3
+					for frame in pairs(tbl) do
+						if not flashing[frame] then
+							frame:SetAlpha(alpha)
+						end
+					end
+				end
+			end
+
+			-- Aggro check
+			for unit,tbl in pairs(frames) do
+				if not targets[unit] then
+					targets[unit] = unit.."target"
+					victims[unit] = unit.."targettarget"
+					aggro[unit] = 0
+				end
+
+				local target = targets[unit]
+				local victim = victims[unit]
+				if UnitIsUnit(victim, unit) and UnitCanAttack(unit, target) then
+					-- unit is being targeted by a hostile mob
+					if aggro[unit] < 20 then
+						local val = aggro[unit]
+						if val >= 5 and val <= 10 then
+							PerfectRaid:UNIT_HEALTH(nil, unit)
+						end
+						aggro[unit] = val + 10
+					end
+				end
+
+				-- Aggro decay (thanks BanzaiLib)
+				if aggro[unit] >= 5 then
+					aggro[unit] = aggro[unit] - 5
+				end
+
+				if aggro[unit] >= 15 then
+					showaggro(unit)
+				end
+
+				local name = UnitName(unit)
+			end
+
+			elapsed = 0
+		end
+	end
+
+	local frame = CreateFrame("Frame", "PRUpdateFrame")
+	frame:SetScript("OnUpdate", PerfectRaid.OnUpdate)
+end
+
+function showaggro(unit)
+	if true then return end
+	for frame in pairs(frames[unit]) do
+		local name = frame:GetName()
+		local texture = frame.healthbar.aggro
+		if not texture then
+			local bar = frame.healthbar
+			texture = frame.healthbar:CreateTexture(name.."Aggro", "ARTWORK")
+			texture:SetTexture("Interface\\AddOns\\PerfectRaid\\images\\smooth")
+			texture:SetAllPoints(bar)
+			frame.healthbar.aggro = texture
+		end
+		texture:SetVertexColor(1,0,0)
+		UIFrameFlash(texture, 0.4, 0.4, 2, nil, 0.1, 0.1)
+	end
+end
+
+local textures = {}
+local handlers = {}
+function flashbar(frame, length, wait)
+	if not textures[frame] then
+		texture = frame:CreateTexture(nil, "ARTWORK")
+		texture:SetTexture("Interface\\AddOns\\PerfectRaid\\images\\smooth")
+		texture:SetPoint("TOPLEFT", 0, 0)
+		texture:SetPoint("BOTTOMLEFT", 0, 0)
+		textures[frame] = texture
+	end
+
+	frame.fadeLength = length or 0.4
+	frame.fadeTime = 0
+	frame.waitLength = wait or 0.1
+	frame.waitTime = 0
+	frame.waitHalf = true
+
+	if not handlers[frame] then
+		local function handler(frame, arg1)
+			frame.fadeTime = frame.fadeTime + arg1
+			local half = frame.fadeLength / 2
+			if frame.fadeTime < half then
+				-- We're fading out
+				local alpha = 1 - (frame.fadeTime / half)
+				frame:SetAlpha(alpha)
+			elseif frame.fadeTime <= frame.fadeLength then
+				if frame.waitHalf then
+					frame.fadeTime = frame.fadeTime - arg1
+					frame.waitTime = frame.waitTime + arg1
+					if frame.waitTime >= frame.waitLength then
+						frame.waitHalf = false
+					end
+				else
+					local alpha = (frame.fadeTime - half) / half
+					frame:SetAlpha(alpha)
+				end
+			else
+				frame.waitTime = frame.waitTime + arg1
+				if frame.waitTime >= frame.waitLength then
+					frame.fadeTime = 0
+					frame.waitTime = 0
+					frame.waitHalf = true
+				end
+			end
+		end
+		handlers[frame] = handler
+	end
+
+	frame:SetScript("OnUpdate", handlers[frame])
+end
+
+--flashbar(PlayerFrame, 2, 1)
\ No newline at end of file
diff --git a/PerfectRaidOptions.lua b/PerfectRaidOptions.lua
index 07a3587..ad333e6 100644
--- a/PerfectRaidOptions.lua
+++ b/PerfectRaidOptions.lua
@@ -912,8 +912,9 @@ function PerfectRaid:CreateBuffEditWindow()
 		entry.texture = iconbutton.icon:GetTexture()
 		entry.missing = missing:GetChecked()
 		entry.disabled = disabled:GetChecked()
-		entry.color = swatch.color
-		entry.colortext = string.format("|cFF%s%s|r", utils.RGBToHex(unpack(entry.color)), entry.disptext)
+		entry.color = PRColorSelect.color
+		entry.colortext = string.format("|cFF%s%s|r", utils.RGBPercToHex(unpack(PRColorSelect.color)), entry.disptext)
+		self:Print(unpack(PRColorSelect.color))

 		if not self.editSave then
 			table.insert(list, entry)