Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GameTooltip HookScript OnTooltipSetItem does not take effect in other people's display #16

Open
GoMateoGo opened this issue Sep 10, 2024 · 0 comments

Comments

@GoMateoGo
Copy link

I have encountered a troublesome problem. This problem is most likely not AIO's problem, I hope you can get help.

server file name: myaddon_server.lua

  • Lua Code:
local AIO = AIO or require("AIO")
 
local ItemStateHandler = AIO.AddHandlers("ItemStateUI", {})
 
-- Receive messages from the client
function ItemStateHandler.GetItemBonus(player)
    -- Handling messages here....
 
    AIO.Handle(player, "ItemStateUI", "ModifyState", 10000) -- Send the message back to the client side
end

client file name: myaddon_client.lua

  • Lua Code:
local AIO = AIO or require("AIO")
 
if AIO.AddAddon() then
    return
end
 
local ItemStateHandler = AIO.AddHandlers("ItemStateUI", {})
 
-- global GameTooltip Obj
local globalItemObj = nil
local function ModifyShow(tooltip)
    if not tooltip then return end
 
    local _, ItemLink = tooltip:GetItem()
 
    if not ItemLink then
        return
    end
 
    local typ, _, _, _, _, _, _, _, _, _ = strsplit(":", string.match(ItemLink, "item[%-?%d:]+"))
    if typ ~= "item" then
        return
    end
 
    globalItemObj = tooltip
 
    AIO.Handle("ItemStateUI", "GetItemBonus"); -- req server
end
 
GameTooltip:HookScript("OnTooltipSetItem", function(self)
    --getglobal("GameTooltipTextLeft1"):SetText("This is the newly added content.")
    ModifyShow(self)
end)
 
ItemRefTooltip:HookScript("OnTooltipSetItem", function(self)
    ModifyShow(self)
end)
 
 
function ItemStateHandler.ModifyState(player, serverStr)
    if not globalItemObj  then return end
 
    local _, ItemLink = globalItemObj:GetItem()
 
    if not ItemLink then
        return
    end
 
    local typ, _, _, _, _, _, _, _, _, _ = strsplit(":", string.match(ItemLink, "item[%-?%d:]+"))
    if typ ~= "item" then
        return
    end
 
    for i = 1, globalItemObj:NumLines() do
        local tooltip = getglobal(globalItemObj:GetName() .. "TextLeft" .. tostring(i)):GetText()
        local tmpStr = tooltip .. serverStr
        getglobal(globalItemObj:GetName() .. "TextLeft" .. tostring(i)):SetText(tmpStr)
    end
end

At this point, when using the two previously created characters to view their own items, GameToolpoint is called, and everything works fine, but when viewing each other's items through the characters, the item text does not change.

However, the ItemRefToolTip object is valid. There are always changes.

The above are the problems encountered when using GameToolpoint.

To solve this problem, I added some print information. The code is as follows:

  • Lua Code:
GameTooltip:HookScript("OnTooltipSetItem", function(self)
    --getglobal("GameTooltipTextLeft1"):SetText("This is the newly added content.")
    print("this is gameTooltip", self)
    ModifyShow(self, self:GetName())
end)
 
 
function ItemStateHandler.ModifyState(player, serverStr)
    if not globalItemObj then return end
 
    local _, ItemLink = globalItemObj:GetItem()
 
    if not ItemLink then
        return
    end
 
    local typ, _, _, _, _, _, _, _, _, _ = strsplit(":", string.match(ItemLink, "item[%-?%d:]+"))
    if typ ~= "item" then
        return
    end
 
    print("this is globalItemObj", globalItemObj, globalItemObj:GetName())
    for i = 1, globalItemObj:NumLines() do
        local tooltip = getglobal(globalItemObj:GetName() .. "TextLeft" .. tostring(i)):GetText()
        local tmpStr = tooltip .. serverStr
        getglobal(globalItemObj:GetName() .. "TextLeft" .. tostring(i)):SetText(tmpStr)
 
        local printStr = getglobal(globalItemObj:GetName() .. "TextLeft" .. tostring(i)):GetText()
        print("after str:", printStr)
    end
end

The result after str is indeed appended, but it is not displayed (when character 1 views character 2 items, the tooltip display of character 1 is not updated.)

Thank you for listening to my long-winded. Any help I really appreciate :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant