Thread Tools Display Modes
08-07-24, 06:38 AM   #1
wmcarlos
A Defias Bandit
Join Date: Mar 2024
Posts: 3
Question How to refresh new Blizzard_Menu?

I have the following code for adding a button to the context menu:
Code:
Menu.ModifyMenu("MENU_UNIT_PLAYER", function(ownerRegion, rootDescription, contextData)
    local button = MenuUtil.CreateButton(L["OFFER_TOOLTIP"])
    rootDescription:Insert(button, 13)

    button:SetResponder(function(data, menuInputData, menu)
        ns.SendAddonMessage("offer"); DEFAULT_CHAT_FRAME:AddMessage(L["OFFER"], 1.000, 1.000, 0.000)
        return MenuResponse.Close
    end)

    button:AddInitializer(function()
        if not UnitAffectingCombat("player") and not UnitAffectingCombat("target") then
            if unit.playable then
                button:SetEnabled(true)
            elseif UnitIsSameServer(UnitName("target")) and not unit.playable then
                button:SetEnabled(false)
                button:SetTooltip(function(tooltip, elementDescription)
                    GameTooltip_SetTitle(tooltip, MenuUtil.GetElementText(elementDescription));
                    GameTooltip_AddErrorLine(tooltip, L["NO_ADDON"]);
                end)
            elseif not UnitIsSameServer(UnitName("target")) and not unit.playable then
                button:SetEnabled(false)
                button:SetTooltip(function(tooltip, elementDescription)
                    GameTooltip_SetTitle(tooltip, MenuUtil.GetElementText(elementDescription));
                    GameTooltip_AddErrorLine(tooltip, L["NO_PARTY"]);
                end)
            end
        else
            button:SetEnabled(false)
            if UnitAffectingCombat("player") then
                button:SetTooltip(function(tooltip, elementDescription)
                    GameTooltip_SetTitle(tooltip, MenuUtil.GetElementText(elementDescription));
                    GameTooltip_AddErrorLine(tooltip, L["PLAYER_IN_COMBAT"]);
                end)
            elseif UnitAffectingCombat("target") then
                button:SetTooltip(function(tooltip, elementDescription)
                    GameTooltip_SetTitle(tooltip, MenuUtil.GetElementText(elementDescription));
                    GameTooltip_AddErrorLine(tooltip, L["UNIT_IN_COMBAT"]);
                end)
            end
        end
    end)

But I need the menu to update when receiving the callback, if it is open:
Code:
EventRegistry:RegisterFrameEventAndCallback("CHAT_MSG_ADDON", function(_, prefix, text, channel, sender, _, _, _, _, _)
    if prefix == "testing" then
          if text == 'offer' then
          ns.SendAddonMessage('playable')
          elseif text == 'playable' then
                                   <— refresh is needed here.
          end
    end
end)
I tried to somehow use MenuResponse.Refresh, but it doesn't work outside the SetResponder construct.

For example, in this case, the menu updates when I click the button I added:
Code:
    button:SetResponder(function(data, menuInputData, menu)
        return MenuResponse.Refresh
    end)
But I haven't found another way to make the menu update without using SetResponder.

I would be very grateful if someone could help me.

Last edited by wmcarlos : 08-16-24 at 04:40 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to refresh new Blizzard_Menu?


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