Quantcast

Fix and extend the tooltips shown when hovering over an icon.

Johnny C. Lam [05-05-14 - 18:02]
Fix and extend the tooltips shown when hovering over an icon.

SVN revision r1117 -- that implemented a true timespan implementation --
broke the tooltip that showed the name of the spell being shown when
hovering over an icon.  Fix the tooltip to show the name of the spell
again and extend the facility to allow for showing item or macro names in
the future.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1370 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleBestAction.lua
OvaleFrame.lua
OvaleIcone.lua
diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua
index 263294c..fcf1240 100644
--- a/OvaleBestAction.lua
+++ b/OvaleBestAction.lua
@@ -80,7 +80,7 @@ local function ComputeAction(element, state)
 	local self = OvaleBestAction
 	local action = element.params[1]
 	local actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration,
-		actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId = self:GetActionInfo(element, state)
+		actionUsable, actionShortcut, actionIsCurrent, actionEnable, actionType, actionId = self:GetActionInfo(element, state)
 	local timeSpan = element.timeSpan
 	timeSpan:Reset()

@@ -96,7 +96,8 @@ local function ComputeAction(element, state)
 	end

 	-- Set the cast time of the action.
-	if spellId then
+	if actionType == "spell" then
+		local spellId = actionId
 		local si = spellId and OvaleData.spellInfo[spellId]
 		if si and si.casttime then
 			element.castTime = si.casttime
@@ -724,7 +725,8 @@ function OvaleBestAction:GetActionInfo(element, state)
 	local target = element.params.target or OvaleCondition.defaultTarget
 	local action
 	local actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration,
-		actionUsable, actionShortcut, actionIsCurrent, actionEnable
+		actionUsable, actionShortcut, actionIsCurrent, actionEnable,
+		actionType, actionId

 	if element.func == "spell" then
 		local spellId = element.params[1]
@@ -737,6 +739,8 @@ function OvaleBestAction:GetActionInfo(element, state)
 		actionTexture = actionTexture or API_GetSpellTexture(spellId)
 		actionInRange = API_IsSpellInRange(OvaleSpellBook:GetSpellName(spellId), target)
 		actionCooldownStart, actionCooldownDuration, actionEnable = state:GetSpellCooldown(spellId)
+		actionType = "spell"
+		actionId = spellId

 		-- Verify that the spell may be cast given restrictions specified in SpellInfo().
 		local si = OvaleData.spellInfo[spellId]
@@ -810,6 +814,8 @@ function OvaleBestAction:GetActionInfo(element, state)
 		actionInRange = API_IsActionInRange(action, target)
 		actionCooldownStart, actionCooldownDuration, actionEnable = API_GetActionCooldown(action)
 		actionUsable = API_IsUsableAction(action)
+		actionType = "macro"
+		actionId = macro

 	elseif element.func == "item" then
 		local itemId = element.params[1]
@@ -829,6 +835,8 @@ function OvaleBestAction:GetActionInfo(element, state)

 		local spellName = API_GetItemSpell(itemId)
 		actionUsable = (spellName ~= nil)
+		actionType = "item"
+		actionId = itemId

 	elseif element.func == "texture" then
 		local texture = element.params[1]
@@ -838,6 +846,8 @@ function OvaleBestAction:GetActionInfo(element, state)
 		actionCooldownDuration = 0
 		actionEnable = 1
 		actionUsable = true
+		actionType = "texture"
+		actionId = texture
 	end

 	if action then
@@ -846,7 +856,7 @@ function OvaleBestAction:GetActionInfo(element, state)
 	end

 	return actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration,
-		actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId, target, element.params.nored
+		actionUsable, actionShortcut, actionIsCurrent, actionEnable, actionType, actionId, target, element.params.nored
 end

 function OvaleBestAction:Compute(element, state)
diff --git a/OvaleFrame.lua b/OvaleFrame.lua
index b0d2866..a0287de 100644
--- a/OvaleFrame.lua
+++ b/OvaleFrame.lua
@@ -215,25 +215,31 @@ do
 					end
 				else
 					local actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration,
-							actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId, actionTarget, noRed = OvaleBestAction:GetActionInfo(element, state)
+						actionUsable, actionShortcut, actionIsCurrent, actionEnable,
+						actionType, actionId, actionTarget, noRed = OvaleBestAction:GetActionInfo(element, state)
 					if noRed then
 						start = actionCooldownStart + actionCooldownDuration
 						if start < state.currentTime then
 							start = state.currentTime
 						end
 					end
-						-- Dans le cas de canStopChannelling, on risque de demander d'interrompre le channelling courant, ce qui est stupide
-					if start and state.currentSpellId and state.nextCast and spellId == state.currentSpellId and start < state.nextCast then
+					-- Dans le cas de canStopChannelling, on risque de demander d'interrompre le channelling courant, ce qui est stupide
+					if start and state.currentSpellId and state.nextCast and actionType == "spell" and actionId == state.currentSpellId and start < state.nextCast then
 						start = state.nextCast
 					end
-						if (node.params.nocd and start~=nil and now < start - node.params.nocd) then
+					if start and node.params.nocd and now < start - node.params.nocd then
 						icons[1]:Update(element, nil)
 					else
 						icons[1]:Update(element, start, actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration,
-							actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId, actionTarget)
+							actionUsable, actionShortcut, actionIsCurrent, actionEnable, actionType, actionId, actionTarget)
 					end

-					action.spellId = spellId
+					-- TODO: Scoring should allow for other actions besides spells.
+					if actionType == "spell" then
+						action.spellId = actionId
+					else
+						action.spellId = nil
+					end
 					if start and start <= now and actionUsable then
 						if not action.waitStart then
 							action.waitStart = now
diff --git a/OvaleIcone.lua b/OvaleIcone.lua
index 9cb91ff..2bd2032 100644
--- a/OvaleIcone.lua
+++ b/OvaleIcone.lua
@@ -18,6 +18,7 @@ local OvaleOptions = Ovale.OvaleOptions
 local OvaleSpellBook = Ovale.OvaleSpellBook
 local OvaleState = Ovale.OvaleState

+local format = string.format
 local next = next
 local pairs = pairs
 local strfind = string.find
@@ -36,8 +37,8 @@ local function SetValue(self, value, actionTexture)
 	self.aPortee:Hide()
 	self.shortcut:Hide()
 	if value then
+		self.actionType = "value"
 		self.value = value
-		self.spellId = nil
 		if value < 10 then
 			self.remains:SetFormattedText("%.1f", value)
 		elseif value == math.huge then
@@ -53,8 +54,9 @@ local function SetValue(self, value, actionTexture)
 end

 local function Update(self, element, minAttente, actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration,
-				actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId, actionTarget)
-	self.spellId = spellId
+				actionUsable, actionShortcut, actionIsCurrent, actionEnable, actionType, actionId, actionTarget)
+	self.actionType = actionType
+	self.actionId = actionId
 	self.value = nil

 	local now = API_GetTime()
@@ -241,26 +243,31 @@ function OvaleIcone_OnMouseUp(self)
 end

 function OvaleIcone_OnEnter(self)
-	if self.help or next(Ovale.casesACocher) or next(Ovale.listes) or self.spellId or self.value then
+	if self.help or next(Ovale.casesACocher) or next(Ovale.listes) or self.actionType then
 		GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT")
 		if self.help then
 			GameTooltip:SetText(L[self.help])
 		end
-		if self.spellId then
-			GameTooltip:AddLine(OvaleSpellBook:GetSpellName(self.spellId), 0.5, 1, 0.75)
-		elseif self.value then
-			local value = (self.value < math.huge) and tostring(self.value) or "infinity"
-			GameTooltip:AddLine(value, 0.5, 1, 0.75)
+		if self.actionType then
+			local text
+			if self.actionType == "spell" then
+				text = OvaleSpellBook:GetSpellName(self.actionId)
+			elseif self.actionType == "value" then
+				text = (self.value < math.huge) and tostring(self.value) or "infinity"
+			else
+				text = format("%s %s", self.actionType, tostring(self.actionId))
+			end
+			GameTooltip:AddLine(text, 0.5, 1, 0.75)
 		end
 		if next(Ovale.casesACocher) or next(Ovale.listes) then
-			GameTooltip:AddLine(L["Cliquer pour afficher/cacher les options"],1,1,1)
+			GameTooltip:AddLine(L["Cliquer pour afficher/cacher les options"], 1, 1, 1)
 		end
 		GameTooltip:Show()
 	end
 end

 function OvaleIcone_OnLeave(self)
-	if self.help  or next(Ovale.casesACocher) or next(Ovale.listes)  then
+	if self.help or next(Ovale.casesACocher) or next(Ovale.listes)  then
 		GameTooltip:Hide()
 	end
 end
@@ -285,7 +292,6 @@ function OvaleIcone_OnLoad(self)
 	self.cdShown = true
 	self.shouldClick = false
 	self.help = nil
-	self.spellId = nil
 	self.value = nil
 	self.fontScale = nil
 	self.lastSound = nil
@@ -295,6 +301,8 @@ function OvaleIcone_OnLoad(self)
 	self.actionCourante = nil
 	self.params = nil
 	self.actionButton = false
+	self.actionType = nil
+	self.actionId = nil
 --</public-properties>

 	self:SetScript("OnMouseUp", OvaleIcone_OnMouseUp)