Quantcast

Stable

Eric Nickell [01-14-11 - 03:36]
Stable
Filename
SageGearLevelTooltip.lua
todo.txt
diff --git a/SageGearLevelTooltip.lua b/SageGearLevelTooltip.lua
index 9778fe3..3033258 100644
--- a/SageGearLevelTooltip.lua
+++ b/SageGearLevelTooltip.lua
@@ -59,16 +59,25 @@ local CachableEvaluator do
 end

 ----------------------------------------------------------------------------------------------------
-local ItemLevelEvaluator do
-	local class = newClass{name="ItemLevelEvaluator"}
+local ItemLevelIdCommenter do
+	local class = newClass{name="ItemLevelIdCommenter"}

-	function class:Evaluate(itemLink)
+	function class:Comment(itemLink, tooltip)
 		if not itemLink then return end
 		local _,_,_,level = GetItemInfo(itemLink)
-		return level, {label="iLevel", r=class.r, g=class.g, b=class.b}
+		local itemId = itemLink:match("item:(%d+):")
+		itemId = itemId
+		    and tonumber(itemId)
+		    or ">>" .. itemLink:gsub("|", "!")
+		tooltip:AddDoubleLine(
+				"iLevel " .. level,
+				"id " .. itemId,
+				class.r, class.g, class.b,
+				1, 1, 1)
+--		return level, {label="iLevel", r=class.r, g=class.g, b=class.b}
 	end

-	ItemLevelEvaluator = class
+	ItemLevelIdCommenter = class
 end

 ----------------------------------------------------------------------------------------------------
@@ -78,11 +87,11 @@ local ItemIdEvaluator do

 	function class:Evaluate(itemLink)
 		if not itemLink then return end
---		local itemId = itemLink:match("item:(%d+):")
---		itemId = itemId
---		    and tonumber(itemId)
---		    or ">>" .. itemLink:gsub("|", "!")
-		local itemId = Item:New(itemLink):ItemString()
+		local itemId = itemLink:match("item:(%d+):")
+		itemId = itemId
+		    and tonumber(itemId)
+		    or ">>" .. itemLink:gsub("|", "!")
+--		local itemId = Item:New(itemLink):ItemString()
 		return itemId, label
 	end

@@ -90,8 +99,20 @@ local ItemIdEvaluator do
 end

 ----------------------------------------------------------------------------------------------------
-local PairEvaluator do
-	local class = newClass{name="PairEvaluator", super=CachableEvaluator}
+local PairItemCommentor do
+	local class = newClass{name="PairItemCommenter", super=CachableEvaluator}
+
+--		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,
+--					leftLabel.r, leftLabel.g, leftLabel.b,
+--					rightLabel.r, rightLabel.g, rightLabel.b)
+--		elseif left and leftLabel then
+--			tooltip:AddLine(leftLabel.label .. ": " .. left, leftLabel.r, leftLabel.g, leftLabel.b)
+--		end
+

 	function class:_Initialize(instance, left, right)		--self is class
 		self.super:_Initialize(instance)
@@ -109,7 +130,7 @@ local PairEvaluator do
 		end
 	end

-	PairEvaluator = class
+	PairItemCommentor = class
 end

 ----------------------------------------------------------------------------------------------------
@@ -275,7 +296,7 @@ local EvaluatorToLineAdderAdaptor do
 	-- @param itemLink a link for the item
 	-- @param tooltip a callback supporting :AddLine and :AddDoubleLine with same args as a GameTooltip
 	--        NOTE: tooltip is not guaranteed to be an actual tooltip, or support other methods
-	function class:AddLines(itemLink, tooltip)
+	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(
@@ -295,61 +316,76 @@ end
 local SageGearLevelTooltipUpdater do
 	local class = newClass{name="TooltipUpdater"}

+	-- class function
+	function class:_Initialize(instance, methodsToHook)
+		-- no call to super needed
+		instance.evals = {}
+		instance.commenters = {}
+		return instance:_HookFrameMethods(methodsToHook)
+	end
+
+	-- Updates the tooltip with all the comments from the item commenters
+	-- @param tooltip A "tooltip" support :AddLine and :AddDoubleLine *only*
 	function class:UpdateTooltip(tooltip)
 		local _,itemLink = tooltip:GetItem()
-		for _,adder in ipairs(self.adders) do
-			adder:AddLines(itemLink, tooltip)
+		for _,commenter in ipairs(self.commenters) do
+			commenter:Comment(itemLink, tooltip)
 		end
 	end

-	function class:_HookFrameMethods(methodsToHook)
-		for tooltipName, methods in pairs(methodsToHook) do
-			local tooltip = _G[tooltipName]
-			local update =
-					function(tooltip, ...)
-							self:UpdateTooltip(tooltip)
-					end
-			for _, method in ipairs(methods) do
-				self:Debug((tooltip and tooltipName or "whoops") .. "/" .. type(tooltip) .. "+" .. method .. "/" .. type(method))
-				hooksecurefunc(tooltip, method, update)
-			end
-		end
+	function class:_HookFrameMethods()
+--		for tooltipName, methods in pairs(methodsToHook) do
+--			self:HookTooltip(tooltipName, methods)
+--		end
 		self:Print("SageGearLevelTooltip loaded.")
 		return self
 	end

+	function class:HookTooltip(tooltipName, methods)
+		local tooltip = _G[tooltipName]
+		local update =
+				function(tooltip, ...)
+						self:UpdateTooltip(tooltip)
+				end
+		for _, method in ipairs(methods) do
+--			self:Debug((tooltip and tooltipName or "whoops") .. "/" .. type(tooltip) .. "+" .. method .. "/" .. type(method))
+			hooksecurefunc(tooltip, method, update)
+		end
+		return self;
+	end
+
 	function class:AddEvaluator(e)
-		return self:AddLineAdder(EvaluatorToLineAdderAdaptor:New(e))
+		return self:AddItemCommenter(EvaluatorToLineAdderAdaptor:New(e))
 	end

-	function class:AddLineAdder(adder)
-		local adders = self.adders
-		adders[#adders + 1] = adder
+	-- Adds an item commenter to this tooltip annotator
+	-- @param commenter an ItemCommenter to give comment to this tooltip
+	function class:AddItemCommenter(commenter)
+		local commenters = self.commenters
+		commenters[#commenters + 1] = commenter
 		return self
 	end

-	-- class function
-	function class:_Initialize(instance, methodsToHook)
-		-- no call to super needed
-		instance.evals = {}
-		instance.adders = {}
-		return instance:_HookFrameMethods(methodsToHook)
-	end
-
 	SageGearLevelTooltipUpdater = class
 end

 ----------------------------------------------------------------------------------------------------
-print(type(GameTooltip))
-local methodsToHook = {
-	GameTooltip = {"SetBagItem", "SetInventoryItem", "SetHyperlink", "SetAuctionItem",
-				"SetQuestItem", "SetQuestLogItem"},
-	ItemRefTooltip = {"SetHyperlink", "Show", "Hide"},
-	ShoppingTooltip1 = {"SetHyperlinkCompareItem"},
-	ShoppingTooltip2 = {"SetHyperlinkCompareItem"}}
-
-local foo = SageGearLevelTooltipUpdater:New(methodsToHook)
-		:AddEvaluator(PairEvaluator:New(ItemLevelEvaluator:New(), ItemIdEvaluator:New()):Cache())
+--local methodsToHook = {
+--	GameTooltip = {"SetBagItem", "SetInventoryItem", "SetHyperlink", "SetAuctionItem",
+--				"SetQuestItem", "SetQuestLogItem"},
+--	ItemRefTooltip = {"SetHyperlink", "Show", "Hide"},
+--	ShoppingTooltip1 = {"SetHyperlinkCompareItem"},
+--	ShoppingTooltip2 = {"SetHyperlinkCompareItem"}}
+
+SageGearLevelTooltipUpdater:New(methodsToHook)
+		:HookTooltip("GameTooltip", {"SetBagItem", "SetInventoryItem", "SetHyperlink", "SetAuctionItem",
+					"SetQuestItem", "SetQuestLogItem"})
+		:HookTooltip("ItemRefTooltip", {"SetHyperlink", "Show", "Hide"})
+		:HookTooltip("ShoppingTooltip1", {"SetHyperlinkCompareItem"})
+		:HookTooltip("ShoppingTooltip2", {"SetHyperlinkCompareItem"})
+
+
+		:AddItemCommenter(ItemLevelIdCommenter:New())

 		--Warlock
 --		:AddEvaluator(BestReforgedEvaluator:New({label = "Wk.Aff", r=1.0, g=0.2, b=1.0},
diff --git a/todo.txt b/todo.txt
index 9bb96b7..bbf786a 100644
--- a/todo.txt
+++ b/todo.txt
@@ -2,8 +2,9 @@ TODO:

 1. Deal with gems.
 2. Normalize to gear level. I think this means to normalize to iLvl purps.
-3. Change model to one that generates lines in the tooltip rather than computes a value.
-4. Enable all vectors, but only report "interesting" ones. What's interesting?
+3. Deal with equal weighted stats
+4. Change model to one that generates lines in the tooltip rather than computes a value.
+5. Enable all vectors, but only report "interesting" ones. What's interesting?
    * All vectors for the current class.
    * (Variant) All vectors for the current class where gear is appropriate type.

@@ -31,3 +32,18 @@ Q: Information a player wants to know about gear for an alt:
 Q: Information a player wants to know about gear for a raidmate:
    * When: Items which drop? Items while in a raid?

+--------------------------------------------------------------------------------
+For the current toon's class and spec:
+   * ALWAYS show SGL
+   * Show which reforging will be used to produce that SGL
+   * Highlight suggested actions to optimize gear (reforging/gems/enchants)
+
+For the current toon's class and offspecs: ???
+
+For the current toon's alts:
+   * Show SGL only for equippable upgrades.
+
+For raidmates:
+   * Show SGL only for equipment which drops in instance
+   * (Variant) Show SGL except for items known bound to another player.
+   * Show SGL only when the item is an upgrade for some raidmate
\ No newline at end of file