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.