Quantcast

stable

Eric Nickell [01-23-11 - 09:50]
stable
Filename
SageGearLevelTooltip.lua
diff --git a/SageGearLevelTooltip.lua b/SageGearLevelTooltip.lua
index fe06b1f..7d252dc 100644
--- a/SageGearLevelTooltip.lua
+++ b/SageGearLevelTooltip.lua
@@ -23,6 +23,10 @@ local CachingEvaluator do
 		instance.cacheHitCount = 0
 		instance.cacheMissCount = 0
 	end
+
+	function class:Name()
+		return self.delegate:Name()
+	end

 	function class:Evaluate(itemLink)
 		-- TODO: normalize link first?
@@ -199,8 +203,13 @@ local BestReforgedEvaluator do
 		local reforging = reforgings:Find(itemLink)
 		return Item:New(itemLink):GetItemStats()
 	end
+
+	function class:Name()
+		return self.label and self.label.label or "<Unknown>"
+	end

 	function class:Evaluate(itemLink)
+--		self:Debug("BestReforgedEvaluator:Evaluate")
 		if not itemLink then return end
 		itemLink = Item:New(itemLink):WithoutMods():ItemString()
 		local stats = GetItemStats(itemLink)	-- baseline w/o reforging
@@ -213,7 +222,9 @@ local BestReforgedEvaluator do
 		end

 		local evaluation = self:_EvalStats(stats)
-		return evaluation, self.label, rightValue, rightLabel
+		if evaluation and (evaluation > 0) then
+			return evaluation, self.label, rightValue, rightLabel
+		end
 	end

 	function class:_FindOptimalReforging(stats)
@@ -262,13 +273,23 @@ local EvaluatorToLineAdderAdaptor do
 	--        NOTE: tooltip is not guaranteed to be an actual tooltip, or support other methods
 	function class:Comment(itemLink, tooltip)
 		local left, leftLabel, right, rightLabel = self.evaluator:Evaluate(itemLink)
-		if left and leftLabel and right and rightLabel then
-			tooltip:AddDoubleLine(
-					leftLabel.label .. ": " .. left,
-					rightLabel.label .. ": " .. right,
+		local leftText = left and leftLabel and (leftLabel.label .. ": " .. left)
+		local rightText = right and rightLabel and (rightLabel.label .. ": " .. right)
+		if leftText and rightText then
+--			self:Debug("left [" .. tostring(leftText) .. "]  right [" .. tostring(rightText) .. "] tooltip " .. tostring(tooltip))
+--			ChatFrame1:AddMessage("left [" .. tostring(leftText) .. "]  right [" .. tostring(rightText) .. "] tooltip " .. tostring(tooltip))
+--			self:Debug("r=" .. leftLabel.r .. " g=" .. leftLabel.g .. " b=" .. leftLabel.b)
+--			print(tooltip == GameTooltip, "L <", leftText, ">", leftLabel.r, leftLabel.g, leftLabel.b)
+--			print(tooltip == GameTooltip, "R <", rightText, ">", rightLabel.r, rightLabel.g, rightLabel.b)
+			tooltip:AddDoubleLine(leftText, rightText,
 					leftLabel.r, leftLabel.g, leftLabel.b,
 					rightLabel.r, rightLabel.g, rightLabel.b)
-		elseif left and leftLabel then
+--			tooltip:Show()
+		elseif leftText then
+--			self:Debug("left [" .. tostring(leftText) .. "]  right [" .. tostring(rightText) .. "] tooltip " .. tostring(tooltip))
+--			ChatFrame1:AddMessage("left [" .. tostring(leftText) .. "]  right [" .. tostring(rightText) .. "] tooltip " .. tostring(tooltip))
+--			self:Debug("r=" .. leftLabel.r .. " g=" .. leftLabel.g .. " b=" .. leftLabel.b)
+--			print(tooltip == GameTooltip, "L <", leftText, ">", leftLabel.r, leftLabel.g, leftLabel.b)
 			tooltip:AddLine(leftLabel.label .. ": " .. left, leftLabel.r, leftLabel.g, leftLabel.b)
 		end
 	end
@@ -276,6 +297,9 @@ local EvaluatorToLineAdderAdaptor do
 	EvaluatorToLineAdderAdaptor = class
 end

+--[[
+/run function qz(...) local t,i,v={...}; if (#t)==0 then return end i=math.random(#t); v=table.remove(t, i); return v, qz(unpack(t)) end
+  ]]
 ----------------------------------------------------------------------------------------------------
 local SageGearLevelTooltipUpdater do
 	local class = newClass{name="TooltipUpdater"}
@@ -291,9 +315,19 @@ local SageGearLevelTooltipUpdater do
 	-- Updates the tooltip with all the comments from the item commenters
 	-- @param tooltip A "tooltip" support :AddLine and :AddDoubleLine *only*
 	function class:UpdateTooltip(tooltip)
+--		self:Debug("Updating tooltip " .. tostring(tooltip))
 		local _,itemLink = tooltip:GetItem()
+		local tooltipAdapter = {
+			mustShow = false,
+--			Show = function(adapter, ...) tooltip:Show(...) end,
+			AddLine = function(adapter, ...) adapter.mustShow = true; tooltip:AddLine(...) end,
+			AddDoubleLine = function(adapter, ...) adapter.mustShow = true; tooltip:AddDoubleLine(...) end
+		}
 		for _,commenter in ipairs(self.commenters) do
-			commenter:Comment(itemLink, tooltip)
+			commenter:Comment(itemLink, tooltipAdapter)
+		end
+		if tooltipAdapter.mustShow then
+			tooltip:Show()
 		end
 	end

@@ -311,17 +345,28 @@ local SageGearLevelTooltipUpdater do
 				function(tooltip, ...)
 						self:UpdateTooltip(tooltip)
 				end
+		local methodCount = 0
 		for _, method in ipairs(methods) do
 --			self:Debug((tooltip and tooltipName or "whoops") .. "/" .. type(tooltip) .. "+" .. method .. "/" .. type(method))
-			hooksecurefunc(tooltip, method, update)
+			local hasMethodToHook = tooltip[method]
+			if hasMethodToHook then
+				hooksecurefunc(tooltip, method, update)
+				methodCount = methodCount + 1
+			else
+				self:Debug("Tooltip " .. tostring(tooltipName) .. " is missing method " .. method)
+			end
 		end
+		self:Debug("Tooltip " .. tostring(tooltipName) .. "(" .. tostring(tooltip) .. ") has " .. methodCount .. " methods hooked.")
 		return self;
 	end

 	function class:AddSelfEvaluator(className, e)
-		return (className == select(2, UnitClass('player')))
-				and self:AddEvaluator(e)
-				or self
+		local playerClassLocal, playerClass = UnitClass('player')
+		if className == playerClass then
+			self:Debug("Installing evaluator for " .. playerClassLocal .. ": " .. (e:Name()))
+			return self:AddEvaluator(e)
+		end
+		return self
 	end

 	function class:AddEvaluator(e)
@@ -348,14 +393,17 @@ end
 --	ShoppingTooltip2 = {"SetHyperlinkCompareItem"}}

 SageGearLevelTooltipUpdater:New(methodsToHook)
-		:HookTooltip("GameTooltip", {"SetBagItem", "SetInventoryItem", "SetHyperlink", "SetAuctionItem",
-					"SetQuestItem", "SetQuestLogItem"})
+		:HookTooltip("GameTooltip", {"SetAuctionItem", "SetAuctionSellItem", "SetBagItem", "SetBuybackItem",
+				"SetExistingSocketGem", "SetGuildBankItem", "SetInboxItem", "SetInventoryItem", "SetHyperlink",
+				"SetLootItem", "SetLootRollItem", "SetMerchantItem", "SetQuestItem", "SetQuestLogItem",
+				"SetSendMailItem", "SetSocketGem", "SetTradePlayerItem", "SetTradeSkillItem",
+				"SetTradeTargetItem", "SetTrainerService" })
 		:HookTooltip("ItemRefTooltip", {"SetHyperlink", "Show", "Hide"})
 		:HookTooltip("ShoppingTooltip1", {"SetHyperlinkCompareItem"})
 		:HookTooltip("ShoppingTooltip2", {"SetHyperlinkCompareItem"})


-		:AddItemCommenter(ItemLevelIdCommenter:New())
+--		:AddItemCommenter(ItemLevelIdCommenter:New())

 		--DK
 		:AddSelfEvaluator("DEATHKNIGHT", BestReforgedEvaluator:New({label = "Blood DK", r=1.0, g=0.2, b=0.4},
@@ -368,7 +416,7 @@ SageGearLevelTooltipUpdater:New(methodsToHook)
 		:AddSelfEvaluator("DEATHKNIGHT", BestReforgedEvaluator:New({label = "Unholy DK", r=0.6, g=0.6, b=0.6},
 						{Strength=100, MeleeDPS=100, Hit=43, Expertise=41, Haste=37, Mastery=35, AP=32, Crit=26})
 						:Cache())
-
+
 		--Druid
 		:AddSelfEvaluator("DRUID", BestReforgedEvaluator:New({label = "Moonkin", r=0.3, g=0.3, b=1.0},
 						{Hit=100, Master=100, SP=66, Haste=54, Crit=43, Intellect=22, Spirit=22})
@@ -413,10 +461,44 @@ SageGearLevelTooltipUpdater:New(methodsToHook)
 		:AddSelfEvaluator("PALADIN", BestReforgedEvaluator:New({label = "Prot Paladin", r=1.0, g=0.4, b=0.4},
 				{Mastery=100, Stamina=100, Agility=60, Expertise=59, Dodge=55, Parry=30, Strength=16, Armor=8})
 				:Cache())
-		:AddSelfEvaluator("PALADIN", BestReforgedEvaluator:New({label = "Ret Paladin", r=0.3, g=0.3, b=1.0},
+		:AddSelfEvaluator("PALADIN", BestReforgedEvaluator:New({label = "Ret Paladin", r=1.0, g=1.0, b=0.5},
 				{MeleeDPS=470, Mastery=100, Hit=100, Strength=80, Expertise=66, Crit=40, Agility=32, Haste=30, SP=9})
 				:Cache())

+		--Priest
+		:AddSelfEvaluator("PRIEST", BestReforgedEvaluator:New({label = "Disc Priest", r=0.3, g=0.3, b=1.0},
+						{SP=100, Mastery=100, Intellect=65, Haste=59, Crit=48, Spirit=22})
+						:Cache())
+		:AddSelfEvaluator("PRIEST", BestReforgedEvaluator:New({label = "Holy Priest", r=0.3, g=1.0, b=0.3},
+						{Mastery=100, Intellect=69, SP=60, Spirit=52, Crit=38, Haste=31})
+						:Cache())
+		:AddSelfEvaluator("PRIEST", BestReforgedEvaluator:New({label = "Shadow Priest", r=0.5, g=0.5, b=0.5},
+						{Hit=100, Mastery=100, SP=76, Crit=54, Haste=50, Intellect=16, Spirit=16})
+						:Cache())
+
+		--Rogue
+		:AddSelfEvaluator("ROGUE", BestReforgedEvaluator:New({label = "Assassin", r=0.8, g=1.0, b=0.5},
+						{MeleeDPS=100, Agility=100, Hit=67, Mastery=50, Haste=46, Expertise=42, Crit=35})
+						:Cache())
+		:AddSelfEvaluator("ROGUE", BestReforgedEvaluator:New({label = "Combat Rogue", r=1.0, g=0.8, b=0.5},
+						{MeleeDPS=100, Agility=100, Hit=70, Expertise=59, Haste=56, Crit=35, Mastery=33})
+						:Cache())
+		:AddSelfEvaluator("ROGUE", BestReforgedEvaluator:New({label = "Subtlety", r=1.0, g=1.0, b=0.3},
+						{MeleeDPS=100, Agility=100, Hit=40, Haste=37, Expertise=33, Crit=31, Mastery=20})
+						:Cache())
+
+		--Shaman
+		:AddSelfEvaluator("SHAMAN", BestReforgedEvaluator:New({label = "Ele Shaman", r=0.5, g=0.5, b=1.0},
+						{Mastery=100, Hit=100, SP=60, Haste=56, Crit=40, Intellect=11})
+						:Cache())
+		:AddSelfEvaluator("SHAMAN", BestReforgedEvaluator:New({label = "Enh Shaman", r=1.0, g=1.0, b=0.5},
+						{MeleeDPS=124, Agility=100, Hit=60, Expertise=48, Mastery=44, Strength=42, AP=40,
+								Intellect=36, SP=36, Crit=28, Haste=16})
+						:Cache())
+		:AddSelfEvaluator("SHAMAN", BestReforgedEvaluator:New({label = "Resto Shaman", r=0.3, g=1.0, b=0.3},
+						{Intellect=100, SP=83, Spriti=75, Haste=67, Crit=58, Mastery=42, Stamina=8})
+						:Cache())
+
 		--Warlock
 		:AddSelfEvaluator("WARLOCK", BestReforgedEvaluator:New({label = "Aff Warlock", r=1.0, g=0.2, b=1.0},
 				{Hit=100, Master=100, SP=72, Haste=61, Crit=38, Spirit=34, Intellect=15})
@@ -424,10 +506,19 @@ SageGearLevelTooltipUpdater:New(methodsToHook)
 		:AddSelfEvaluator("WARLOCK", BestReforgedEvaluator:New({label = "Dem Warlock", r=0.8, g=0.2, b=1.0},
 				{Hit=100, Master=100, Haste=50, SP=45, Crit=31, Spirit=29, Intellect=13})
 				:Cache())
+		:AddSelfEvaluator("WARLOCK", BestReforgedEvaluator:New({label = "Destro Warlock", r=1.0, g=0.6, b=0.0},
+				{Mastery=100, Hit=100, SP=47, Haste=46, Spirit=26, Crit=16, Intellect=13})
+				:Cache())

 		-- Warrior
-		:AddSelfEvaluator("WARRIOR", BestReforgedEvaluator:New({label = "Prot Warrior", r=0.8, g=0.8, b=1.0},
-				{Strength=48, Agility=67, Stamina=100, Hit=10, Crit=7, Haste=1, AP=1, Expertise=19, Armor=6, Dodge=90, Parry=67})
+		:AddSelfEvaluator("WARRIOR", BestReforgedEvaluator:New({label = "Arms Warrior", r=0.8, g=0.8, b=1.0},
+				{Mastery=100, Strength=100, Hit=90, Expertise=85, Crit=80, Agility=65, Haste=50, Armor=1})
+				:Cache())
+		:AddSelfEvaluator("WARRIOR", BestReforgedEvaluator:New({label = "Fury Warrior", r=0.8, g=0.8, b=0.2},
+				{Mastery=100, Expertise=100, Strength=82, Crit=66, Agility=53, Hit=48, Haste=36, Armor=5})
+				:Cache())
+		:AddSelfEvaluator("WARRIOR", BestReforgedEvaluator:New({label = "Prot Warrior", r=1.0, g=0.4, b=0.4},
+				{Stamina=100, Mastery=100, Dodge=90, Parry=67, Agility=67, Strength=48, Expertise=19, Hit=10, Crit=7, Armor=6, Haste=1})
 				:Cache())

 --		:AddEvaluator(SimplePawnEvaluator:New({label = "W.Simple", r=0.8, g=0.8, b=1.0},