Thread Tools Display Modes
01-19-21, 03:48 AM   #1
Tranzalore
A Murloc Raider
Join Date: Jan 2021
Posts: 6
GameToolTip Update Event

I am creating an addon to automatically switch to your gathering skill set when you mouse over a node. The addon is currently getting its information from the GameToolTip.

I could not find any event linked to changes in theGameToolTip so I overrode the OnShow, OnHide and OnUpdate scripts. This works for my addon but it has broken any dynamic GameToolTips that updat when you hold down the shift modifier (eg show the item that you have equiped in the same slot at the item you are mousing over or with TSM when if updates the GameToolTip to show the prices for a stack instead of a single item.

Code:
-- CreateEvent when GameToolTip Shows
local function ToolTipOnShow()
    if (inDebugMode) then
        DEFAULT_CHAT_FRAME:AddMessage("Tooltip OnShow Event fired!")
    end
    GameTooltipLine1 = GameTooltipTextLeft1:GetText()
    GameTooltipLine2 = GameTooltipTextLeft2:GetText()
    GameTooltipLine3 = GameTooltipTextLeft3:GetText()
    GameTooltipChangeHandler()
end

GameTooltip:SetScript("OnShow", ToolTipOnShow)

-- CreateEvent when GameToolTip Hides
local function ToolTipOnHide()
    if (inDebugMode) then
        DEFAULT_CHAT_FRAME:AddMessage("Tooltip OnHide Event fired!")
    end
    GameTooltipLine1 = GameTooltipTextLeft1:GetText()
    GameTooltipLine2 = GameTooltipTextLeft2:GetText()
    GameTooltipLine3 = GameTooltipTextLeft3:GetText()
    GameTooltipChangeHandler()
end

GameTooltip:SetScript("OnHide", ToolTipOnHide)

-- CreateEvent when GameToolTip Update
local function ToolTipOnUpdate()
    if not (GameTooltipLine1 == GameTooltipTextLeft1:GetText() and GameTooltipLine2 == GameTooltipTextLeft2:GetText() and GameTooltipLine3 == GameTooltipTextLeft3:GetText()) then
        if (inDebugMode) then
            DEFAULT_CHAT_FRAME:AddMessage("Tooltip OnUpdate Event fired!")
        end
        GameTooltipLine1 = GameTooltipTextLeft1:GetText()
        GameTooltipLine2 = GameTooltipTextLeft2:GetText()
        GameTooltipLine3 = GameTooltipTextLeft3:GetText()
        GameTooltipChangeHandler()
    end
end

GameTooltip:SetScript("OnUpdate", ToolTipOnUpdate)
If i Comment out the last line the normal GameToolTip works again. Any idea on how i can get the GameTooltip OnUpdate script to trigger stuff in my addonwithout breaking the normal functionality.

Any help would be apreciated.
  Reply With Quote
01-19-21, 04:51 AM   #2
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
Why don't you hook the scripts instead of overriding them?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
01-19-21, 04:20 PM   #3
Tranzalore
A Murloc Raider
Join Date: Jan 2021
Posts: 6
Thank you for the response LudiusMaximus.

I had tried to hook it instead of override but keept running into errors.

When trying to do this I found this forum post and was basing my code off it. https://forum.elysium-project.org/to...tooltip-event/

So I tried...

-- CreateEvent when GameToolTip Update
function CustomToolTipOnUpdate()
if not (GameTooltipLine1 == GameTooltipTextLeft1:GetText() and GameTooltipLine2 == GameTooltipTextLeft2:GetText() and GameTooltipLine3 == GameTooltipTextLeft3:GetText()) then
if (inDebugMode) then
DEFAULT_CHAT_FRAME:AddMessage("Tooltip OnUpdate Event fired!")
end
GameTooltipLine1 = GameTooltipTextLeft1:GetText()
GameTooltipLine2 = GameTooltipTextLeft2:GetText()
GameTooltipLine3 = GameTooltipTextLeft3:GetText()
GameTooltipChangeHandler()
end
end

local BlizzardGameTooltipOnUpdateRetention = GameTooltip.OnUpdate
function GameTooltip.OnUpdate()
CustomToolTipOnUpdate()
GameTooltip.OnUpdate()
end
This did not trigger the CustomToolTipOnUpdate() function when the GameToolTip was updated. So i tried the following.

-- CreateEvent when GameToolTip Update
function CustomToolTipOnUpdate()
if not (GameTooltipLine1 == GameTooltipTextLeft1:GetText() and GameTooltipLine2 == GameTooltipTextLeft2:GetText() and GameTooltipLine3 == GameTooltipTextLeft3:GetText()) then
if (inDebugMode) then
DEFAULT_CHAT_FRAME:AddMessage("Tooltip OnUpdate Event fired!")
end
GameTooltipLine1 = GameTooltipTextLeft1:GetText()
GameTooltipLine2 = GameTooltipTextLeft2:GetText()
GameTooltipLine3 = GameTooltipTextLeft3:GetText()
GameTooltipChangeHandler()
end
end

local BlizzardGameTooltipOnUpdateRetention = GameTooltip.OnUpdate
function ProxyGameToolTipOnUpdate()
CustomToolTipOnUpdate()
BlizzardGameTooltipOnUpdateRetention()
end

GameTooltip:SetScript("OnUpdate", ProxyGameToolTipOnUpdate)
This did trigger the CustomToolTipOnUpdate() function but throws and error

" Interface\AddOns\ClassicAutoGearChanger\main.lua:334: attempt to call upvalue 'BlizzardGameTooltipOnUpdateRetention' (a nil value)
Time: Wed Jan 20 09:11:12 2021
Count: 1765
Stack: Interface\AddOns\ClassicAutoGearChanger\main.lua:334: attempt to call upvalue 'BlizzardGameTooltipOnUpdateRetention' (a nil value)
[C]: ?
Interface\AddOns\ClassicAutoGearChanger\main.lua:334: in function <Interface\AddOns\ClassicAutoGearChanger\main.lua:332>
[C]: ?
[C]: ?

Locals: "

This makes me think that GameTooltip.OnUpdate does not exist but if it did not exist overriding it should not cause any issues so I am a bit lost.
  Reply With Quote
01-19-21, 04:32 PM   #4
Tranzalore
A Murloc Raider
Join Date: Jan 2021
Posts: 6
Just fount this on https://wowwiki.fandom.com/wiki/UIOBJECT_GameTooltip

"When you mouse over things in the game world, the game engine internally calls the equivalent of :Set____() - not the actual Lua method. In particular, this means that hooked GameTooltip methods will never trigger for engine-generated tooltips. Hooks will however catch all other tooltips generated from the UI itself. For non-item/unit tooltips you will even see :AddLine and :AddDoubleLine calls."

Does this mean that I need to hook the AddLine and AddDoubleLine scripts instead?
  Reply With Quote
01-19-21, 06:16 PM   #5
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 320
Instead of
Code:
local BlizzardGameTooltipOnUpdateRetention = GameTooltip.OnUpdate
you would have to do
Code:
local BlizzardGameTooltipOnUpdateRetention = GameTooltip:GetScript("OnUpdate")
But what you are doing then, overriding the original OnUpdate script is an insecure hook.

Is it important that your CustomToolTipOnUpdate() gets called before BlizzardGameTooltipOnUpdateRetention()? If not, just do a HookScript:

Lua Code:
  1. GameTooltip:HookScript("OnUpdate", function(self)
  2.    -- Your stuff here. E.g.:
  3.    for i = 1, self:NumLines(), 1 do
  4.      local line = _G[self:GetName().."TextLeft"..i]:GetText()
  5.      print (i, line)
  6.    end  
  7. end)
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
01-20-21, 03:25 PM   #6
Tranzalore
A Murloc Raider
Join Date: Jan 2021
Posts: 6
Thank you again for your response. It was very helpful.

To start with I changed the code to the following and got things to work.

-- CreateEvent when GameToolTip Update
function CustomToolTipOnUpdate()
if not (GameTooltipLine1 == GameTooltipTextLeft1:GetText() and GameTooltipLine2 == GameTooltipTextLeft2:GetText() and GameTooltipLine3 == GameTooltipTextLeft3:GetText()) then
if (inDebugMode) then
DEFAULT_CHAT_FRAME:AddMessage("Tooltip OnUpdate Event fired!")
end
GameTooltipLine1 = GameTooltipTextLeft1:GetText()
GameTooltipLine2 = GameTooltipTextLeft2:GetText()
GameTooltipLine3 = GameTooltipTextLeft3:GetText()
GameTooltipChangeHandler()
end
end

local BlizzardGameTooltipOnUpdateRetention = GameTooltip:GetScript("OnUpdate")
function ProxyGameToolTipOnUpdate(self, event, ...)
CustomToolTipOnUpdate()
BlizzardGameTooltipOnUpdateRetention(self, event, ...)
end

GameTooltip:SetScript("OnUpdate", ProxyGameToolTipOnUpdate)
I then updated it to the following so it used a secure script like you suggested and it is still working.

-- CreateEvent when GameToolTip Update
local function ToolTipOnUpdate()
if not (GameTooltipLine1 == GameTooltipTextLeft1:GetText() and GameTooltipLine2 == GameTooltipTextLeft2:GetText() and GameTooltipLine3 == GameTooltipTextLeft3:GetText()) then
if (inDebugMode) then
DEFAULT_CHAT_FRAME:AddMessage("Tooltip OnUpdate Event fired!")
end
GameTooltipLine1 = GameTooltipTextLeft1:GetText()
GameTooltipLine2 = GameTooltipTextLeft2:GetText()
GameTooltipLine3 = GameTooltipTextLeft3:GetText()
GameTooltipChangeHandler()
end
end

GameTooltip:HookScript("OnUpdate", ToolTipOnUpdate)
I will go back and update the OnSho and OnHide to use the secure hook as well.

Again thanks alot for you assistance I really apreciated it.
  Reply With Quote

WoWInterface » Classic - AddOns, Compliations, Macros » Classic - AddOn Help/Support » GameToolTip Update Event

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off