WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Strange GameTooltip behavior with SetPoint (https://www.wowinterface.com/forums/showthread.php?t=56271)

Theroxis 06-09-18 02:02 AM

Strange GameTooltip behavior with SetPoint
 
So basically, I'm trying to learn lua and AddOn development by adding the features and UI elements I like from big already done stuff, but by only manipulating stock blizzard frames. It's been a neat way to learn how both the stock Blizzard UI and AddOns in general work.
I really like having a tooltip underneath the mouse cursor when I'm hovering over players, and other things in the world. It helps bring attention to what my pointy thing is pointing at. So I wrote this:
Code:

GameTooltip:HookScript("OnUpdate", function(self, elpased)
                local x, y = GetCursorPosition()
                local effScale = self:GetEffectiveScale()
                self:ClearAllPoints()
                self:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", (x / effScale + 25), (y / effScale + -25))
end)

While this does work, and moves the ToolTip frame 25 pixels to the right and 25 pixels below the cursor - I notice that as I rapidly mouse over things, the tooltip appears to draw in the bottom right of the screen at it's default position, then scale to the TOPLEFT position, followed by finally settling on the correct size and position. This results in a twitchy flashing tooltip as I move around. This only happens when the tooltip changes, that is to say if I hover over something and then move while hovered over the same thing it behaves normally, but if I changed the mousefocus to something else, the behavior becomes erratic.

What causes this, and how can I stop it?
I've tried also hooking OnShow and doing the same math there, but that doesn't seem to help.

Kakjens 06-09-18 06:03 AM

You could add
Code:

print(elpased)
after
Code:

local x, y = GetCursorPosition()
to understand what happens.
I think you might want to use UPDATE_MOUSEOVER_UNIT event though.

JDoubleU00 06-09-18 09:39 AM

Have you looked at other ToolTip addons that place the tip at the cursor? Here is just one that does that:

https://www.wowinterface.com/downloa...fsTooltip.html

Ammako 06-09-18 11:38 AM

Have a look at my reply to your comment from last night. Just adjust the SetPoint coordinates to your liking.

Theroxis 06-09-18 01:34 PM

Here's what I have that's almost perfect:

Code:

--This function handles actually moving the GameTooltip frame
local function MouseAnchor(frame,parent)

        --Preserve Auction House Tooltip Behavior
        if AuctionFrame and AuctionFrame:IsShown() then
                return
        end

        --Set the Tooltip position, if we're on WorldFrame, anchor to the mouse; if we're on a UnitFrame anchor to that.
        local mouseFocus=GetMouseFocus()
        if mouseFocus==WorldFrame then
                local x, y = GetCursorPosition()
                local scale = frame:GetEffectiveScale()
                frame:ClearAllPoints()
                frame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", (x/scale + 20), (y/scale - 20))
        else
                frame:ClearAllPoints()
                frame:SetPoint("BOTTOM",mouseFocus,"TOP",0,10)
        end
end

--Set the position once during SetDefaultAnchor or we get weird graphical stuff
hooksecurefunc("GameTooltip_SetDefaultAnchor",function(tooltip, parent) MouseAnchor(tooltip) end)

--Move it with the mouse updates, but not too often so we don't waste CPU
local Tooltip_interval=0.1
GameTooltip.TimeSinceLastUpdate=0

local function mouset_OnUpdate(self, elapsed)
        self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed
        if (self.TimeSinceLastUpdate > Tooltip_interval) then
                if (self.default) then
                        MouseAnchor(self)
                end
        end
end

--Run the above function on every update.
GameTooltip:HookScript("OnUpdate", mouset_OnUpdate)

This no longer has the strange resize clamp behavior I was experiencing before. This was fixed by setting the position once during SetDefaultAnchor, as pointed out by Ammako. I've added a conditional to NOT do any movement of the tooltip if we're on the AuctionFrame, which makes the tooltip behave stock there. I also stole the Deftooltip UnitFrame clamp behavior, as it kind of makes sense. Finally, I made it so we aren't updating every frame of mouse movement, as that's kind of a lot of CPU to use. At 0.1s interval the movement is still quite smooth.

The last things on the agenda for me:
1.) Get rid of the fadeout (a hot topic, apparently from Google) on Worldframe items.
2.) If you mouseover a PLAYER and then a Doodad (the sign for a shop, for example) the tooltip size is incorrect, I'm not sure how to approach that.

Ammako 06-09-18 03:59 PM

1) Doesn't hooksecurefunc(GameTooltip, "FadeOut", function(self) self:Hide() end) do the trick? I always had that fadeout issue back when I used TipTac, and they claimed it "wasn't fixable", but it has never been a problem with my code.
2) That doesn't happen on my end, and not sure why it occurs, so I can't help there. It has to be something your code does differently from mine, but I wouldn't be able to tell what exactly.

Theroxis 06-09-18 04:22 PM

Quote:

Originally Posted by Ammako (Post 328276)
1) Doesn't hooksecurefunc(GameTooltip, "FadeOut", function(self) self:Hide() end) do the trick? I always had that fadeout issue back when I used TipTac, and they claimed it "wasn't fixable", but it has never been a problem with my code.
2) That doesn't happen on my end, and not sure why it occurs, so I can't help there. It has to be something your code does differently from mine, but I wouldn't be able to tell what exactly.

It was actually directly related to FadeOut. Once I got FadeOut disabled, the issue with moving from a Unit to a doodad went away. If I waited for it to Fade before mousing over a doodad, the issue didn't happen, so by making it fade instantly the issue is resolved.

Also, that hooksecurefunc line doesn't work for me; I resorted to hiding based on UIParent and WorldFrame mouseover shenanigans. Unfortunately that has its issues as well. PhanxTooltip has a large block for getting rid of the fade, I might just copy that.


All times are GMT -6. The time now is 05:15 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI