diff KBF.lua @ 42:d792f986400f

Add in support for custom display of weapon enchants.
author Chris Mellon <arkanes@gmail.com>
date Tue, 18 Jan 2011 22:34:29 -0600
parents 15a0ceebbd83
children 81cade22f2f9
line wrap: on
line diff
--- a/KBF.lua	Sat Jan 15 18:12:29 2011 -0600
+++ b/KBF.lua	Tue Jan 18 22:34:29 2011 -0600
@@ -109,12 +109,16 @@
 	end
 	
     -- temporary enchants
+    -- TODO: So much copy/paste here. I really need to clean this up.
     local tempEnchant = self.secureHeader:GetAttribute("tempEnchant1")
     if tempEnchant and tempEnchant:IsShown() then
 		self:BindBarToWeaponEnchant(tempEnchant, 16)
         self:UpdateBarExpirationTime(tempEnchant)
         buffCount = buffCount + 1
     end
+    if ( tempEnchant and GameTooltip:IsOwned(tempEnchant) ) then
+		self:OnEnter(tempEnchant)
+	end
     tempEnchant = self.secureHeader:GetAttribute("tempEnchant2")
     if tempEnchant and tempEnchant:IsShown() then
 		self:BindBarToWeaponEnchant(tempEnchant, 17)
@@ -127,6 +131,9 @@
         	tempEnchant:SetAttribute('target-slot', 17)
        	end
     end
+    if ( tempEnchant and GameTooltip:IsOwned(tempEnchant) ) then
+		self:OnEnter(tempEnchant)
+	end
     -- make a fake third buff bar. It can't be used to cancel the buff, but
     -- at least you can see it.
     
@@ -152,7 +159,9 @@
         self:UpdateBarExpirationTime(tempEnchant)
         buffCount = buffCount + 1
     end
-    
+	if ( tempEnchant and GameTooltip:IsOwned(tempEnchant) ) then
+		self:OnEnter(tempEnchant)
+	end
     -- debuffs
     -- Since debuffs aren't cancellable, don't need to use the secure header
     -- for them. This could be rewritten to support useful features like
@@ -212,6 +221,8 @@
     end
 end
 
+local gratt = LibStub:GetLibrary("LibGratuity-3.0")
+
 function kbf:BindBarToWeaponEnchant(parentFrame, slotOverride)
     -- allow passing of explicit slot in order to work around aura header bug
     local slot = slotOverride or parentFrame:GetAttribute("target-slot")
@@ -221,14 +232,42 @@
     -- remaining time is in milliseconds
     if not hasEnchant then return end -- this should never happen
     local remaining = remaining / 1000
+    
     local icon = GetInventoryItemTexture("player", slot)
-    -- this is terrible, but I hate myself and everyone else.
-    -- We're going to assume that the duration of the temp enchant
-    -- is either 60 minutes, or however long is left, because poisons are 1 hour
-    local duration = max((60 * 60), remaining)
+    local maxDuration
+    if select(2, UnitClass("player")) == "ROGUE" then
+    	-- Rogues are probably using poisons, which are an hour
+    	maxDuration = 60 * 60
+    else
+    	-- everyone else is probably using something thats a half hour
+    	maxDuration = 30 * 60
+    end
+    local duration = max(maxDuration, remaining)
     local expirationTime = GetTime() + remaining
-    -- TODO
     local name = GetItemInfo(GetInventoryItemID("player", slot))
+    -- try to figure out what the weapon enchant is
+    -- tooltip string -> {spellid, duration}
+    local knownEnchants = {
+    	["Flametongue"] = {8024, 30*60},
+    	["Frostbrand"] = {8033, 30*60},
+    
+    }
+    local spellId = nil
+	if gratt then
+		gratt:SetInventoryItem("player", slot)
+		for tag, info in pairs(knownEnchants) do
+			if gratt:Find(tag) then 
+				spellId, duration = unpack(info)
+				-- TODO: Maybe want to leave it as the weapon icon?
+				-- I don't think theres enough room to add both the name of the weapon & the buff in there
+				-- maybe use the tag?
+				-- Or maybe use the slot name, ie Flametongue / Main Hand
+				name, _, _ = GetSpellInfo(spellId)
+				break
+			end
+		end
+	end
+    parentFrame.spellId = spellId
     if not parentFrame.icon then
         self:ConstructBar(parentFrame, 1, 0, 1)
     end
@@ -301,9 +340,22 @@
         return
     end
     local slot = button:GetAttribute("target-slot") -- temp enchant
-    GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT");
-    GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2);
-    GameTooltip:SetInventoryItem(unit, slot)
+    if slot then
+		GameTooltip:SetOwner(button, "ANCHOR_BOTTOMLEFT");
+		GameTooltip:SetFrameLevel(button:GetFrameLevel() + 2);
+    	if button.spellId then
+    		-- TODO: This might be too big of a tooltip to care about that much.
+    		-- Maybe I should just have a single line with the weapon name
+    		--GameTooltip:SetInventoryItem(unit, slot)
+    		local name = GetItemInfo(GetInventoryItemID("player", slot))
+    		local r, g, b = GetItemQualityColor(GetInventoryItemQuality("player", slot))
+    		GameTooltip:SetText(name, r, g, b)
+    		GameTooltip:AddLine(" ")
+    		GameTooltip:AddSpellByID(button.spellId)
+    	else
+    		GameTooltip:SetInventoryItem(unit, slot)
+    	end
+	end
 end
 
 -- creates a icon + statusbar bar