Quantcast

Added a tooltip showing a more detailed breakdown of mount types

Christopher Rosell [04-06-10 - 00:15]
Added a tooltip showing a more detailed breakdown of mount types
Filename
CompanionCount.lua
CompanionCount.toc
diff --git a/CompanionCount.lua b/CompanionCount.lua
index 6183472..dfea4b6 100644
--- a/CompanionCount.lua
+++ b/CompanionCount.lua
@@ -1,17 +1,138 @@
--- Localization
-local TOTAL_FORMAT = ' ('..NUMBER_OF_RESULTS_TEMPLATE:match('%( (.-) %)')..')'
+-- Scanning functions
+local GetMountInfo, GetMountTypeSpeed
+do
+	local L = {
+		fast = 'This is a very fast %w+',
+		fastest = 'This is an extremely fast %w+',
+		flying = 'Outland %w+ Northrend',
+		turtle = '[Tt]urtle',
+		aq = 'Emits a high frequency sound, forcing a silithid tank',
+	}
+	local speeds = {
+		flying_fastest = 310, flying_fast = 280, flying = 150,
+		ground_fast = 100, ground = 60, ground_slow = 0
+	}

-hooksecurefunc("PetPaperDollFrame_SetCompanionPage", function(num)
-	local text = CompanionPageNumber:GetText()
-	local count = GetNumCompanions(PetPaperDollFrameCompanionFrame.mode)
+	local cache = {}
+	local scantt = CreateFrame('GameTooltip', 'CompanionCountTooltip', UIParent, 'GameTooltipTemplate')

-	CompanionPageNumber:SetFormattedText(text..TOTAL_FORMAT, count)
-end)
+	function GetMountType(spellid)
+		local rval
+		if not cache[spellid] then
+			local link = GetSpellLink(spellid)

-local point1, parent, point2, x, y = CompanionPrevPageButton:GetPoint(1)
-CompanionPrevPageButton:ClearAllPoints()
-CompanionPrevPageButton:SetPoint(point1, parent, point2, x-20, y)
+			scantt:SetOwner(UIParent, 'ANCHOR_NONE')
+			scantt:SetHyperlink(link)

-point1, parent, point2, x, y = CompanionNextPageButton:GetPoint(1)
-CompanionNextPageButton:ClearAllPoints()
-CompanionNextPageButton:SetPoint(point1, parent, point2, x+33, y)
+			if CompanionCountTooltipTextLeft3 then
+				local text = CompanionCountTooltipTextLeft3:GetText()
+
+				scantt:Hide()
+
+				if text:match(L.flying) then
+					if text:match(L.fastest) then
+						rval = 'flying_fastest'
+					elseif text:match(L.fast) then
+						rval = 'flying_fast'
+					else
+						rval = 'flying'
+					end
+				else
+					if text:match(L.fast) then
+						rval = 'ground_fast'
+					elseif text:match(L.turtle) then
+							rval = 'ground_slow'
+					elseif text:match(L.aq) then
+						rval = 'ground'
+					else
+						rval = 'ground'
+					end
+				end
+			end
+			cache[spellid] = rval
+		else
+			rval = cache[spellid]
+		end
+
+		return rval
+	end
+
+	function GetMountTypeSpeed(typ)
+		return speeds[typ] or 0
+	end
+end
+
+
+-- Text update
+do
+	local TOTAL_FORMAT = ' ('..NUMBER_OF_RESULTS_TEMPLATE:match('%( (.-) %)')..')'
+
+	hooksecurefunc("PetPaperDollFrame_SetCompanionPage", function(num)
+		local text = CompanionPageNumber:GetText()
+		local count = GetNumCompanions(PetPaperDollFrameCompanionFrame.mode)
+
+		CompanionPageNumber:SetFormattedText(text..TOTAL_FORMAT, count)
+	end)
+
+	local point1, parent, point2, x, y = CompanionPrevPageButton:GetPoint(1)
+	CompanionPrevPageButton:ClearAllPoints()
+	CompanionPrevPageButton:SetPoint(point1, parent, point2, x-20, y)
+
+	point1, parent, point2, x, y = CompanionNextPageButton:GetPoint(1)
+	CompanionNextPageButton:ClearAllPoints()
+	CompanionNextPageButton:SetPoint(point1, parent, point2, x+33, y)
+end
+
+
+-- Tooltip
+do
+	local mounts = {}
+	local function DoMountTooltip(self, tt)
+		local show = function(msg, typ)
+			if mounts[typ] then
+				tt:AddDoubleLine(msg:format(GetMountTypeSpeed(typ)), mounts[typ], 1, 1, 1)
+			end
+		end
+
+		table.wipe(mounts)
+		for i=1, GetNumCompanions'MOUNT' do
+			local id, name, spellid = GetCompanionInfo('MOUNT', i)
+			local typ = GetMountType(spellid)
+
+			mounts[typ] = (mounts[typ] or 0) + 1
+		end
+
+		tt:SetOwner(self, 'ANCHOR_NONE')
+		tt:SetPoint('BOTTOMLEFT', self, 'TOPRIGHT')
+		tt:ClearLines()
+		tt:AddLine'Detailed Info'
+
+		show('Flying (%d%%)', 'flying_fastest')
+		show('Flying (%d%%)', 'flying_fast')
+		show('Flying (%d%%)', 'flying')
+		show('Ground (%d%%)', 'ground_fast')
+		show('Ground (%d%%)', 'ground')
+		show('Ground (%d%%)', 'ground_slow')
+
+		tt:Show()
+	end
+
+	local function OnEnter(self)
+
+		if PetPaperDollFrameCompanionFrame.mode == 'MOUNT' then
+			DoMountTooltip(self, GameTooltip)
+		end
+	end
+
+	local function OnLeave(self)
+		GameTooltip:Hide()
+	end
+
+	local ttparent = CreateFrame('Frame', nil, CompanionPageNumber:GetParent())
+	ttparent:SetWidth(CompanionPageNumber:GetWidth())
+	ttparent:SetHeight(CompanionPageNumber:GetHeight())
+	ttparent:SetAllPoints(CompanionPageNumber)
+	ttparent:EnableMouse(true)
+	ttparent:SetScript('OnEnter', OnEnter)
+	ttparent:SetScript('OnLeave', OnLeave)
+end
diff --git a/CompanionCount.toc b/CompanionCount.toc
index 69be9c2..765aba0 100644
--- a/CompanionCount.toc
+++ b/CompanionCount.toc
@@ -1,7 +1,7 @@
 ## Interface: 30300
 ## Title: Companion Count
 ## Notes: Display number of companions on pet/mount tab
-## Version: 1.0
+## Version: 1.1
 ## Author: chrippa

 ## LoadManagers: AddonLoader