Skip to content

Commit

Permalink
feat(client/radial): refresh menu when parent is re-registered
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Feb 23, 2023
1 parent 5f16781 commit e2650b7
Showing 1 changed file with 46 additions and 35 deletions.
81 changes: 46 additions & 35 deletions resource/interface/client/radial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,57 @@ local function refreshRadial()
return showRadial(currentRadial.id)
end

table.wipe(menuHistory)

-- Hide current menu and allow for transition
SendNUIMessage({
action = 'refreshItems',
data = menuItems
action = 'openRadialMenu',
data = false
})

Wait(100)

-- If menu was closed during transition, don't open the submenu
if not isOpen then return end

SendNUIMessage({
action = 'openRadialMenu',
data = {
items = menuItems
}
})
end

---Check if the menuId is currently open or part of the menu history.
---@param menuId string
---@return boolean
local function isMenuOrChildOpen(menuId)
if not currentRadial then return false end

if menuId == currentRadial.id then
return true
end

for i = 1, #menuHistory do
local subMenuId = menuHistory[i]

if subMenuId == menuId then
return true
end
end

return false
end

---Registers a radial sub menu with predefined options.
---@param radial RadialMenuProps
function lib.registerRadial(radial)
menus[radial.id] = radial

if currentRadial and radial.id == currentRadial.id then
currentRadial = radial
if currentRadial then
if not isMenuOrChildOpen(radial.id) then return end

currentRadial = nil
refreshRadial()
end
end
Expand Down Expand Up @@ -136,38 +173,12 @@ function lib.removeRadialItem(id)

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
refreshRadial()
if not isMenuOrChildOpen(menuItem.menu) then return end

currentRadial = nil
end

refreshRadial()
end
end

Expand Down

0 comments on commit e2650b7

Please sign in to comment.