From 843129c900b3ccfb52716eb416398bd9c366afe9 Mon Sep 17 00:00:00 2001 From: Parnic Date: Mon, 18 Oct 2010 12:32:12 +0000 Subject: [PATCH] - initial rev of 'vengeance' module submitted by user Rokiyo --- IceHUD.toc | 1 + modules/Vengeance.lua | 113 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 modules/Vengeance.lua diff --git a/IceHUD.toc b/IceHUD.toc index 7f68cea..7827b1a 100644 --- a/IceHUD.toc +++ b/IceHUD.toc @@ -79,3 +79,4 @@ modules\ClassPowerCounter.lua modules\HolyPower.lua modules\Shards.lua modules\EclipseBar.lua +modules\Vengeance.lua diff --git a/modules/Vengeance.lua b/modules/Vengeance.lua new file mode 100644 index 0000000..9d697fb --- /dev/null +++ b/modules/Vengeance.lua @@ -0,0 +1,113 @@ +local L = LibStub("AceLocale-3.0"):GetLocale("IceHUD", false) +local Vengeance = IceCore_CreateClass(IceUnitBar) + +local VENGEANCE_SPELL_ID = 93098 + +Vengeance.prototype.current = nil +Vengeance.prototype.max = nil +Vengeance.prototype.tooltipBuffer = nil + +-- constructor +function Vengeance.prototype:init() + Vengeance.super.prototype.init(self, "Vengeance", "player") + + self.current = 0 + self.max = floor(0.1*UnitHealthMax(self.unit)) + self.tooltipBuffer = CreateFrame("GameTooltip","tooltipBuffer",nil,"GameTooltipTemplate") + self.tooltipBuffer:SetOwner(WorldFrame, "ANCHOR_NONE") + + self:SetDefaultColor("Vengeance", 200, 45, 45) +end + +-- default settings +function Vengeance.prototype:GetDefaultSettings() + local defaults = Vengeance.super.prototype.GetDefaultSettings(self) + defaults.enabled = false + defaults.usesDogTagStrings = false + defaults.lockUpperTextAlpha = false + defaults.shouldAnimate = false + defaults.hideAnimationSettings = true + defaults.offset = 5 + defaults.side = IceCore.Side.Left + return defaults +end + +-- enable plugin +function Vengeance.prototype:Enable(core) + Vengeance.super.prototype.Enable(self, core) + + -- Avoiding iteration where I can + self:RegisterEvent("UNIT_AURA", "UpdateCurrent") + self:RegisterEvent("UNIT_MAXHEALTH", "UpdateMax") +end + +-- disable plugin +function Vengeance.prototype:Disable(core) + Vengeance.super.prototype.Disable(self, core) + + self:UnregisterAllEvents() +end + +-- OVERRIDE +function Vengeance.prototype:UseTargetAlpha(scale) + return (scale and (scale > 0)) +end + +function Vengeance.prototype:UpdateCurrent(event, unit) + if (unit and (unit ~= self.unit)) then + return + end + + local name, _, _, _, _, _, _, _, _, _, auraID = UnitAura(unit, GetSpellInfo(VENGEANCE_SPELL_ID)) + if (name) then + -- Buff found, copy it into the buffer for scanning + self.tooltipBuffer:ClearLines() + self.tooltipBuffer:SetUnitBuff(unit, name) + + -- Grab all regions + local regions = {self.tooltipBuffer:GetRegions()} + + -- Convert FontStrings to strings, replace anything else with "" + for i=1, #regions do + local region = regions[i] + regions[i] = region:GetObjectType() == "FontString" and region:GetText() or "" + end + + -- Find the number, save it + self.current = tonumber(string.match(table.concat(regions),"%d+")) or 0 + else + self.current = 0 + end + + self:Update(unit) +end + +function Vengeance.prototype:UpdateMax(event, unit) + if (unit and (unit ~= self.unit)) then + return + end + + self.max = floor(0.1*UnitHealthMax(unit)) + self:Update(unit) +end + +function Vengeance.prototype:Update(unit) + Vengeance.super.prototype.Update(self) + + if self.current == 0 then + self:Show(false) + return + else + self:Show(true) + end + + self:UpdateBar(self.current / self.max, "Vengeance") + self:SetBottomText1(floor(self.current / self.max * 100) .. "%") + self:SetBottomText2(self.current) +end + +-- Load for tanks only +local _, unitClass = UnitClass("player") +if (unitClass == "DEATHKNIGHT" or unitClass == "DRUID" or unitClass == "PALADIN" or unitClass == "WARRIOR" and IceHUD.WowVer >= 40000) then + IceHUD.Vengeance = Vengeance:new() +end \ No newline at end of file