Quantcast

Detects and prints simple stats at the bottom of the tooltip

Kevin Lyles [09-12-09 - 07:46]
Detects and prints simple stats at the bottom of the tooltip

Seems to do it twice for some reason
Filename
Regexps.lua
WeightsWatcher.lua
WeightsWatcher.toc
diff --git a/Regexps.lua b/Regexps.lua
new file mode 100644
index 0000000..290a4f3
--- /dev/null
+++ b/Regexps.lua
@@ -0,0 +1,3 @@
+ProcessedLines = {
+	"%+(%d+) (%a[%a ]+)"
+}
diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua
index b01f6ba..8e23599 100644
--- a/WeightsWatcher.lua
+++ b/WeightsWatcher.lua
@@ -67,7 +67,7 @@ end

 function DisplayItemInfo(tooltip, ttname)
 	local _, link = tooltip:GetItem()
-	local itemType
+	local itemType, text, start, name, value

 	if link == nil then
 		return
@@ -75,7 +75,15 @@ function DisplayItemInfo(tooltip, ttname)

 	_, _, _, _, _, itemType, _, stackSize = GetItemInfo(link)
 	if IsEquippableItem(link) or (itemType == "Gem" and stackSize == 1) then
-		tooltip:AddLine("Weights needed here")
+		for i = 1, tooltip:NumLines() do
+			text = getglobal(ttname .. "TextLeft" .. i):GetText()
+			for _, regex in pairs(ProcessedLines) do
+				start, _, value, name = string.find(text, regex)
+				if start then
+					tooltip:AddDoubleLine(name, value)
+				end
+			end
+		end
 		tooltip:Show()
 	end
 end
diff --git a/WeightsWatcher.toc b/WeightsWatcher.toc
index ab78fb3..ae29aa9 100644
--- a/WeightsWatcher.toc
+++ b/WeightsWatcher.toc
@@ -14,5 +14,6 @@ Libs\AceAddon-2.0\AceAddon-2.0.lua
 Libs\AceEvent-2.0\AceEvent-2.0.lua
 Libs\AceHook-2.1\AceHook-2.1.lua

+Regexps.lua
 WeightsWatcher.lua
 WeightsWatcher.xml