From 5428d1c768c998fce40e4ba5bb16ddf7a2179f49 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Thu, 23 Feb 2023 23:35:20 +1100 Subject: [PATCH] feat(client/radial): refresh menu when current menu is removed Possibly weird. --- resource/interface/client/radial.lua | 50 ++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/resource/interface/client/radial.lua b/resource/interface/client/radial.lua index 1f2de5c..aca3680 100644 --- a/resource/interface/client/radial.lua +++ b/resource/interface/client/radial.lua @@ -106,18 +106,54 @@ end ---Removes an item from the global radial menu with the given id. ---@param id string function lib.removeRadialItem(id) + local menuItem + for i = 1, #menuItems do - local item = menuItems[i] - if item.id == id then + menuItem = menuItems[i] + + if menuItem.id == id then table.remove(menuItems, i) break end end - if isOpen and not currentRadial then - SendNUIMessage({ - action = 'refreshItems', - data = menuItems - }) + + if isOpen then + if currentRadial then + local refresh + + -- Top level submenu + if menuItem.menu == currentRadial.id then + refresh = true + else + -- Nested submenu + for i = 1, #menuHistory do + local subMenuId = menuHistory[i] + + if subMenuId == menuItem.menu then + refresh = true + break + end + end + end + + if refresh then + table.wipe(menuHistory) + + currentRadial = nil + + SendNUIMessage({ + action = 'openRadialMenu', + data = { + items = menuItems + } + }) + end + else + SendNUIMessage({ + action = 'refreshItems', + data = menuItems + }) + end end end