Thread Tools Display Modes
01-16-15, 11:22 AM   #21
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Vrul View Post
Shouldn't that SetItemRef call in OnHyperlinkLeave be this instead?
Code:
ItemRefTooltip:Hide()
No, because (a) the OnHyperlinkEnter script uses the GameTooltip, not the ItemRefTooltip, and (b) that won't hide the special tooltips used for battle pets etc.

The default UI calls SetItemRef each time you click on a link, and for tooltips it acts as a toggle -- the first click shows the tooltip, and the second click hides it.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-16-15, 12:55 PM   #22
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
So its not possible to anchor the Pet tooltip at the same point as the normal tooltip when you hoover it?
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
01-17-15, 01:11 AM   #23
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
I tried to make it behave as consistently as I could between the real tooltip and the pseudo-tooltips:
Code:
local tooltipForLinkType = {
    -- Normal tooltip things:
    achievement  = ItemRefTooltip,
    enchant      = ItemRefTooltip,
    glyph        = ItemRefTooltip,
    item         = ItemRefTooltip,
    instancelock = ItemRefTooltip,
    quest        = ItemRefTooltip,
    spell        = ItemRefTooltip,
    talent       = ItemRefTooltip,
    unit         = ItemRefTooltip,
    currency     = ItemRefTooltip,
    -- Special tooltip things:
    battlepet           = FloatingBattlePetTooltip,
    battlePetAbil       = FloatingPetBattleAbilityTooltip,
    garrfollowerability = FloatingGarrisonFollowerAbilityTooltip,
    garrfollower        = FloatingGarrisonFollowerTooltip,
    garrmission         = FloatingGarrisonMissionTooltip,
}

local allowReposition, data = true, { }

local function RepositionTooltip(tooltip)
    local button = GetMouseFocus()
    if button:IsObjectType('HyperLinkButton') then
        data.tooltip, data.point, data.relFrame, data.relPoint, data.x, data.y = tooltip, tooltip:GetPoint()
        local uiX, uiY = UIParent:GetCenter()
        local x, y = button:GetCenter()
        tooltip:ClearAllPoints()
        if x <= uiX then
            if y <= uiY then
                tooltip:SetPoint('BOTTOMLEFT', button, 'TOPRIGHT', 2, -4)
            else
                tooltip:SetPoint('TOPLEFT', button, 'BOTTOMRIGHT', 2, 0)
            end
        elseif y <= uiY then
            tooltip:SetPoint('BOTTOMRIGHT', button, 'TOPLEFT', 0, -4)
        else
            tooltip:SetPoint('TOPRIGHT', button, 'BOTTOMLEFT', 0, 0)
        end
        if tooltip.CloseButton then
            tooltip.CloseButton:Hide()
        end
    end
end

local function RestoreTooltip(tooltip)
    if tooltip and tooltip == data.tooltip then
        data.tooltip = nil
        tooltip:ClearAllPoints()
        tooltip:SetPoint(data.point, data.relFrame, data.relPoint, data.x, data.y)
        if tooltip.CloseButton then
            tooltip.CloseButton:Show()
        end
        return tooltip
    end
end

local function OnHyperlinkEnter(frame, linkData, link)
    local tooltip = tooltipForLinkType[linkData:match("^(.-):")]
    if tooltip then
        tooltip:Hide()
        SetItemRef(linkData, link, 'LeftButton', frame)
        if allowReposition then
            RepositionTooltip(tooltip)
        end
    end
end

local function OnHyperlinkLeave(frame, linkData, link)
    local tooltip = RestoreTooltip(tooltipForLinkType[linkData:match("^(.-):")])
    if tooltip then
        tooltip:Hide()
    end
end

local function OnHyperlinkClick(frame, linkData, link, button)
    local tooltip = RestoreTooltip(tooltipForLinkType[linkData:match("^(.-):")])
    if tooltip then
        if tooltip:IsObjectType('GameTooltip') then
            allowReposition = nil
            OnHyperlinkEnter(frame, linkData, link)
            allowReposition = true
        else
            tooltip:Show()
        end
    else
        OnHyperlinkEnter(frame, linkData, link)
    end
end

local function RegisterMessageFrame(frame)
    frame:HookScript('OnHyperlinkClick', OnHyperlinkClick)
    frame:SetScript('OnHyperlinkEnter', OnHyperlinkEnter)
    frame:SetScript('OnHyperlinkLeave', OnHyperlinkLeave)
end

local frame = CreateFrame('Frame')
frame:SetScript('OnEvent', function(self, event, name)
    if event == 'PLAYER_LOGIN' then
        for index = 1, NUM_CHAT_WINDOWS do
            RegisterMessageFrame(_G['ChatFrame' .. index])
        end
    end
    if GuildBankMessageFrame then
        RegisterMessageFrame(GuildBankMessageFrame)
        self:UnregisterAllEvents()
        self:SetScript('OnEvent', nil)
    elseif event ~= 'ADDON_LOADED' then
        self:RegisterEvent('ADDON_LOADED')
    end
end)
frame:RegisterEvent('PLAYER_LOGIN')

if ItemRefTooltip and ItemRefCloseButton then
    ItemRefTooltip.CloseButton = ItemRefCloseButton
end
  Reply With Quote
01-17-15, 03:49 PM   #24
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
@Vrul also nice, but I woud still prefere to have the tooltips above chat so I can mouseover links without hiding any text in my chatwindow
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
10-27-16, 08:34 AM   #25
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
So 7.1 broke this code!

Addon still works partly but I get a spamy error, please someone help?

Error Code:
Code:
439x LinkHover\LinkHover-1.5.lua:34: attempt to index local 'linkData' (a nil value)
LinkHover\LinkHover-1.5.lua:34: in function <LinkHover\LinkHover.lua:33>

Locals:
frame = ChatFrame1 {
 0 = <userdata>
 RefreshIfNecessary = <function> defined =[C]:-1
 OnPostShow = <function> defined =[C]:-1
 isInitialized = 1
 GetNumVisibleLines = <function> defined =[C]:-1
 ScrollUp = <function> defined =[C]:-1
 SetTimeVisible = <function> defined =[C]:-1
 hasOwnFontObject = true
 OnFontObjectUpdated = <function> defined =[C]:-1
 resizeButton = ChatFrame1ResizeButton {
 }
 GetFading = <function> defined =[C]:-1
 Clear = <function> defined =[C]:-1
 shouldFadeAfterInactivity = true
 SetIndentedWordWrap = <function> defined =[C]:-1
 GetTimeVisible = <function> defined =[C]:-1
 GetJustifyV = <function> defined =[C]:-1
 SetFont = <function> defined =[C]:-1
 GetMaxLines = <function> defined =[C]:-1
 BackFillMessage = <function> defined =[C]:-1
 UnpackageEntry = <function> defined =[C]:-1
 FontStringContainer = <unnamed> {
 }
 SetShadowOffset = <function> defined =[C]:-1
 messageTypeList = <table> {
 }
 GetFont = <function> defined =[C]:-1
 checkedGMOTD = true
 SetMaxLines = <function> defined =[C]:-1
 timeVisibleSecs = 20
 PageUp = <function> defined =[C]:-1
 RefreshDisplay = <function> defined =[C]:-1
 SetFontObject = <function> defined =[C]:-1
 MakeFontObjectCustom = <function> defined =[C]:-1
 CalculateNumVisibleLines = <function> defined =[C]:-1
 fontObject = table: 0000020F9598DE60 {
 }
 overrideFadeTimestamp = 3738.725
 SetInsertMode = <function> defined =[C]:-1
 MarkDisplayDirty = <function> defined =[C]:-1
 hasBeenFaded = true
 mouseInTime = 0
 GetMessageInfo = <function> defined =[C]:-1
 ScrollDown = <function> defined =[C]:-1
 AtTop = <function> defined =[C]:-1
 GetFontObject = <function> defined =[C]:-1
 zoneChannelList = <table> {
 }
 SetScrollOffset = <function> defined =[C]:-1
 OnPostUpdate = <function> defined =[C]:-1
 fontStringPool = <table> {
 }
 buttonSide = "right"
 CanEffectivelyFade = <function> defined =[C]:-1
 ScrollToBottom = <function> defined =[C]:-1
 GetInsertMode = <function> defined =[C]:-1
 insertMode = 2
 oldAlpha = 0
 OnPreSizeChanged = <function> defined =[C]:-1
 fadeDurationSecs = 3
 GetScrollOffset = <function> defined =[C]:-1
 isDocked = 1
 GetIndentedWordWrap = <function> defined =[C]:-1
 alternativeDefaultLanguage = "Orcisch"
 defaultLanguage = "Orcisch"
 channelList = <table> {
 }
 GetTextColor = <function> defined =[C]:-1
 tellTimer = 1805.66
 ResetAllFadeTimes = <function> defined =[C]:-1
 flashTimer = 0.41700015217066
 isDisplayDirty = false
 GetSpacing = <function> defined =[C]:-1
 OnPreLoad = <function> defined =[C]:-1
 visibleLines = <table> {
 }
 PackageEntry = <function> defined =[C]:-1
 SetSpacing = <function> defined =[C]:-1
 name = "Allgemein"
 ScrollToTop = <function> defined =[C]:-1
 historyBuffer = <table> {
 }
 isLayoutDirty = false
 AdjustMessageColors = <function> defined =[C]:-1
 GetNumMessages = <function> defined =[C]:-1
 RefreshLayout = <function> defined =[C]:-1
 GetShadowColor = <function> defined =[C]:-1
 isUninteractable = false
 AddMessage = <function> defined @Ace3\AceHook-3.0\AceHook-3.0.lua:100
 GetJustifyH = <function> defined =[C]:-1
 mouseOutTime = 0
 PageDown = <function> defined =[C]:-1
 GetMaxScrollRange = <function> defined =[C]:-1
 SetJustifyH = <function> defined =[C]:-1
 SetFadeDuration = <function> defined =[C]:-1
 GetShadowOffset = <function> defined =[C]:-1
 GetPagingScrollAmount = <function> defined =[C]:-1
 SetTextColor = <function> defined =[C]:-1
 AtBottom = <function> defined =[C]:-1
 buttonFrame = ChatFrame1ButtonFrame {
 }
 SetShadowColor = <function> defined =[C]:-1
 CalculateLineSpacing = <function> defined =[C]:-1
 RemoveMessagesByPredicate = <function> defined =[C]:-1
 InitializeFontableFrame = <function> defined =[C]:-1
 HasFontObject = <function> defined =[C]:-1
 clickAnywhereButton = ChatFrame1ClickAnywhereButton {
 }
 isStaticDocked = true
 SetJustifyV = <function> defined =[C]:-1
 editBox = ChatFrame1EditBox {
 }
 CalculateLineAlphaValueFromTimestamp = <function> defined =[C]:-1
 isLocked = true
 SetFading = <function> defined =[C]:-1
 MarkLayoutDirty = <function> defined =[C]:-1
 AcquireFo
AddOn Code:
Lua Code:
  1. local showLinkType = {
  2.             -- Normal tooltip things:
  3.             achievement  = true,
  4.             enchant      = true,
  5.             glyph        = true,
  6.             item         = true,
  7.             instancelock = true,
  8.             quest        = true,
  9.             spell        = true,
  10.             talent       = true,
  11.             unit         = true,
  12.             currency       = true,
  13.             -- Special tooltip things:
  14.             battlepet           = false,
  15.             battlePetAbil       = false,
  16.             garrfollowerability = false,
  17.             garrfollower        = false,
  18.             garrmission         = false,
  19.         }
  20.          
  21.         local function OnHyperlinkEnter(frame, linkData, link)
  22.             local normal = showLinkType[linkData:match("^(.-):")]
  23.             if normal == true then
  24.                 GameTooltip:SetOwner(ChatFrame1Tab, "ANCHOR_TOPLEFT", 20, 20)
  25.                 GameTooltip:SetHyperlink(link)
  26.                 GameTooltip:Show()
  27.             elseif normal == false then
  28.                 -- Uses a special tooltip, just let the default function handle it.
  29.                 SetItemRef(linkData, link, "LeftButton", frame)
  30.             end
  31.         end
  32.      
  33.         local function OnHyperlinkLeave(frame, linkData, link)
  34.             local normal = showLinkType[linkData:match("^(.-):")]
  35.             if normal == true then
  36.                 GameTooltip:Hide()
  37.             elseif normal == false then
  38.                 -- Uses a special tooltip, just let the default function handle it.
  39.                 SetItemRef(linkData, link, "LeftButton", frame)
  40.             end
  41.         end
  42.          
  43.         local function RegisterFrame(frame)
  44.             frame:SetScript("OnHyperlinkEnter", OnHyperlinkEnter)
  45.             frame:SetScript("OnHyperlinkLeave", OnHyperlinkLeave)
  46.         end
  47.          
  48.         local f = CreateFrame("Frame")
  49.         f:RegisterEvent("PLAYER_LOGIN")
  50.         f:SetScript("OnEvent", function(self, event, name)
  51.             if event == "PLAYER_LOGIN" then
  52.                 for i = 1, NUM_CHAT_WINDOWS do
  53.                     RegisterFrame(_G["ChatFrame"..i])
  54.                 end
  55.             end
  56.             if GuildBankMessageFrame then
  57.                 RegisterFrame(GuildBankMessageFrame)
  58.                 self:UnregisterAllEvents()
  59.                 self:SetScript("OnEvent", nil)
  60.                 RegisterFrame = nil
  61.             else
  62.                 self:RegisterEvent("ADDON_LOADED")
  63.             end
  64.         end)
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
10-27-16, 11:38 PM   #26
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Try changing this:
Code:
        local function OnHyperlinkEnter(frame, linkData, link)
            local normal = showLinkType[linkData:match("^(.-):")]
to this:
Code:
        local function OnHyperlinkEnter(frame, link, text)
            local normal = showLinkType[link:match("(%a+):%d+")]
and this:
Code:
        local function OnHyperlinkLeave(frame, linkData, link)
            local normal = showLinkType[linkData:match("^(.-):")]
to this:
Code:
        local function OnHyperlinkLeave(frame, link, text)
            local normal = showLinkType[link:match("(%a+):%d+")]
and both instances of this:
Code:
                SetItemRef(linkData, link, "LeftButton", frame)
to this:
Code:
                SetItemRef(link, text, "LeftButton", frame)
The variable name changes are probably not strictly necessary (just the string.match argument change) but I'm just using the same names and techniques Blizzard is now using so I don't have to load the game client and test anything to figure out what actually changed.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-28-16, 01:20 PM   #27
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
Thanks for the reply Phanx! I think I made exactly the changes you posted but I still get exactly the same error, so I guess its something different going on here. I also disable all other addons.
Code:
13x LinkHover\LinkHover-1.6.lua:34: attempt to index local 'link' (a nil value)
LinkHover\LinkHover-1.6.lua:34: in function <LinkHover\LinkHover.lua:33>

.........
New code:

Lua Code:
  1. local showLinkType = {
  2.             -- Normal tooltip things:
  3.             achievement  = true,
  4.             enchant      = true,
  5.             glyph        = true,
  6.             item         = true,
  7.             instancelock = true,
  8.             quest        = true,
  9.             spell        = true,
  10.             talent       = true,
  11.             unit         = true,
  12.             currency       = true,
  13.             -- Special tooltip things:
  14.             battlepet           = false,
  15.             battlePetAbil       = false,
  16.             garrfollowerability = false,
  17.             garrfollower        = false,
  18.             garrmission         = false,
  19.         }
  20.          
  21.         local function OnHyperlinkEnter(frame, link, text)
  22.             local normal = showLinkType[link:match("(%a+):%d+")]
  23.             if normal == true then
  24.                 GameTooltip:SetOwner(ChatFrame1Tab, "ANCHOR_TOPLEFT", 20, 20)
  25.                 GameTooltip:SetHyperlink(link)
  26.                 GameTooltip:Show()
  27.             elseif normal == false then
  28.                 -- Uses a special tooltip, just let the default function handle it.
  29.                 SetItemRef(link, text, "LeftButton", frame)
  30.             end
  31.         end
  32.      
  33.         local function OnHyperlinkLeave(frame, link, text)
  34.             local normal = showLinkType[link:match("(%a+):%d+")]
  35.             if normal == true then
  36.                 GameTooltip:Hide()
  37.             elseif normal == false then
  38.                 -- Uses a special tooltip, just let the default function handle it.
  39.                 SetItemRef(link, text, "LeftButton", frame)
  40.             end
  41.         end
  42.          
  43.         local function RegisterFrame(frame)
  44.             frame:SetScript("OnHyperlinkEnter", OnHyperlinkEnter)
  45.             frame:SetScript("OnHyperlinkLeave", OnHyperlinkLeave)
  46.         end
  47.          
  48.         local f = CreateFrame("Frame")
  49.         f:RegisterEvent("PLAYER_LOGIN")
  50.         f:SetScript("OnEvent", function(self, event, name)
  51.             if event == "PLAYER_LOGIN" then
  52.                 for i = 1, NUM_CHAT_WINDOWS do
  53.                     RegisterFrame(_G["ChatFrame"..i])
  54.                 end
  55.             end
  56.             if GuildBankMessageFrame then
  57.                 RegisterFrame(GuildBankMessageFrame)
  58.                 self:UnregisterAllEvents()
  59.                 self:SetScript("OnEvent", nil)
  60.                 RegisterFrame = nil
  61.             else
  62.                 self:RegisterEvent("ADDON_LOADED")
  63.             end
  64.         end)
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________

Last edited by Tonyleila : 10-28-16 at 01:23 PM.
  Reply With Quote
10-29-16, 11:52 AM   #28
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
For easy testing here is a download link:
Attached Files
File Type: zip LinkHover.zip (1.3 KB, 157 views)
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
10-29-16, 02:30 PM   #29
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Replace:

Code:
local function OnHyperlinkLeave(frame, link, text)
with:

Code:
local function OnHyperlinkLeave(...)
    return print("OnHyperlinkLeave", ...)
Mouse over a link, then off, then post the printout you get in the chat frame.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-30-16, 07:46 AM   #30
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
Originally Posted by Phanx View Post
Replace:

Code:
local function OnHyperlinkLeave(frame, link, text)
with:

Code:
local function OnHyperlinkLeave(...)
    return print("OnHyperlinkLeave", ...)
Mouse over a link, then off, then post the printout you get in the chat frame.
That code did not work but I replaced it with this:

Lua Code:
  1. local function OnHyperlinkLeave(...)
  2.             if true then --debug
  3.                 return print("OnHyperlinkLeave", ...)
  4.             end
  5.             if normal == true then
  6.                 GameTooltip:Hide()
  7.             elseif normal == false then
  8.                 -- Uses a special tooltip, just let the default function handle it.
  9.                 SetItemRef(link, text, "LeftButton", frame)
  10.             end
  11.         end

and got this chat printout:
Code:
OnHyperlinkLeave table: 00000165D37D7F7
reloaded UI and disabled all addons new chat print:
Code:
OnHyperlinkLeave table: 00000165D35AEEA0
Tested it and it changes ever time.
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________

Last edited by Tonyleila : 10-30-16 at 07:51 AM.
  Reply With Quote
10-30-16, 05:39 PM   #31
Tonyleila
A Molten Giant
 
Tonyleila's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 758
Thank you for the help again Phanx, Humfras had some time today and did the rest of the fix. Thank you again.

Here is a new working version:
Attached Files
File Type: zip LinkHover17.zip (1.4 KB, 140 views)
__________________
Author of: LeilaUI and Aurora: Missing Textures
__________________
  Reply With Quote
10-31-16, 04:13 AM   #32
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
That means it's only receiving the "self" argument, without any information about the link. You'll have to keep track of that yourself:

Code:
        local lastLink, lastText, useGameTooltip

        local function OnHyperlinkEnter(frame, link, text)
            lastLink, lastText, useGameTooltip = link, text, showLinkType[link:match("(%a+):%d+")]
            if useGameTooltip then
                GameTooltip:SetOwner(ChatFrame1Tab, "ANCHOR_TOPLEFT", 20, 20)
                GameTooltip:SetHyperlink(link)
                GameTooltip:Show()
            elseif useGameTooltip == false then
                -- Uses a special tooltip, just let the default function handle it.
                SetItemRef(link, text, "LeftButton", frame)
            end
        end
     
        local function OnHyperlinkLeave(frame)
            if useGameTooltip then
                GameTooltip:Hide()
            elseif useGameTooltip == false then
                -- Uses a special tooltip, just let the default function handle it.
                SetItemRef(lastLink, lastText, "LeftButton", frame)
            end
            lastLink, lastText, lastLinkIsNormal = nil, nil, nil
        end
Green lines are new. Yellow lines are changed. A few lines were removed, too. (On a side note, you can just do "if X then" instead of "if X == true then" if your only need to to make sure X isn't false or nil.)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 10-31-16 at 04:17 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Hyperlink Tooltip Help

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