mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
refactor(client/interface): micro-optimise menu callbacks
Remove short-lived objects and set local refs to the openMenu to reduce table-lookups.
This commit is contained in:
@@ -25,7 +25,10 @@ function lib.showMenu(id)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function lib.hideMenu(onExit)
|
function lib.hideMenu(onExit)
|
||||||
if onExit and registeredMenus[openMenu].onClose then registeredMenus[openMenu].onClose() end
|
if onExit and registeredMenus[openMenu].onClose then
|
||||||
|
registeredMenus[openMenu].onClose()
|
||||||
|
end
|
||||||
|
|
||||||
SetNuiFocus(false, false)
|
SetNuiFocus(false, false)
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
action = 'closeMenu'
|
action = 'closeMenu'
|
||||||
@@ -44,27 +47,47 @@ function lib.getOpenMenu() return openMenu end
|
|||||||
|
|
||||||
RegisterNUICallback('confirmSelected', function(data, cb)
|
RegisterNUICallback('confirmSelected', function(data, cb)
|
||||||
cb(1)
|
cb(1)
|
||||||
local selected = {data[1] + 1, data[2] and data[2] + 1} -- data = [selected, scrollIndex]
|
data[1] += 1 -- selected
|
||||||
|
|
||||||
|
if data[2] then
|
||||||
|
data[2] += 1 -- scrollIndex
|
||||||
|
end
|
||||||
|
|
||||||
local menu = registeredMenus[openMenu]
|
local menu = registeredMenus[openMenu]
|
||||||
if menu.options[selected[1]].close ~= false then SetNuiFocus(false, false) end
|
|
||||||
local args = menu.options[selected[1]].args
|
if menu.options[data[1]].close ~= false then
|
||||||
registeredMenus[openMenu].cb(selected[1], selected[2], args)
|
SetNuiFocus(false, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
return menu.cb and menu.cb(data[1], data[2], menu.options[data[1]].args)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNUICallback('changeIndex', function(data, cb)
|
RegisterNUICallback('changeIndex', function(data, cb)
|
||||||
cb(1)
|
cb(1)
|
||||||
if not registeredMenus[openMenu].onSideScroll then return end
|
local menu = registeredMenus[openMenu]
|
||||||
local selected = {data[1] + 1, data[2] and data[2] + 1} -- data = [selected, scrollIndex]
|
if not menu.onSideScroll then return end
|
||||||
local args = registeredMenus[openMenu].options[selected[1]].args
|
|
||||||
registeredMenus[openMenu].onSideScroll(selected[1], selected[2], args)
|
data[1] += 1 -- selected
|
||||||
|
|
||||||
|
if data[2] then
|
||||||
|
data[2] += 1 -- scrollIndex
|
||||||
|
end
|
||||||
|
|
||||||
|
menu.onSideScroll(data[1], data[2], menu.options[data[1]].args)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNUICallback('changeSelected', function(data, cb)
|
RegisterNUICallback('changeSelected', function(data, cb)
|
||||||
cb(1)
|
cb(1)
|
||||||
if not registeredMenus[openMenu].onSelected then return end
|
local menu = registeredMenus[openMenu]
|
||||||
local selected = {data[1] + 1, data[2] and data[2] + 1} -- data = [selected, scrollIndex]
|
if not menu.onSelected then return end
|
||||||
local args = registeredMenus[openMenu].options[selected[1]].args
|
|
||||||
registeredMenus[openMenu].onSelected(selected[1], selected[2], args)
|
data[1] += 1 -- selected
|
||||||
|
|
||||||
|
if data[2] then
|
||||||
|
data[2] += 1 -- scrollIndex
|
||||||
|
end
|
||||||
|
|
||||||
|
menu.onSelected(data[1], data[2], menu.options[data[1]].args)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNUICallback('closeMenu', function(data, cb)
|
RegisterNUICallback('closeMenu', function(data, cb)
|
||||||
|
|||||||
Reference in New Issue
Block a user