diff --git a/server-data/resources/[esx]/esx_context/main.lua b/server-data/resources/[esx]/esx_context/main.lua index 9826ebb00..65a2bdae4 100644 --- a/server-data/resources/[esx]/esx_context/main.lua +++ b/server-data/resources/[esx]/esx_context/main.lua @@ -1,273 +1,272 @@ -local defaultPosition = "right" -- [ left | center | right ] local activeMenu local Debug = ESX.GetConfig().EnableDebug --- Global functions +-- Global fuctions -- [ Post | Open | Closed ] -function Post(fn,...) - SendNUIMessage({ - func = fn, - args = {...} - }) +function Post(fn, ...) + SendNUIMessage({ + func = fn, + args = {...} + }) end -function Open(position,eles,onSelect,onClose,canClose) - local canClose = canClose == nil and true or canClose - activeMenu = { - position = position, - eles = eles, - canClose = canClose, - onSelect = onSelect, - onClose = onClose - } +function Open(position, eles, onSelect, onClose, canClose) + local canClose = canClose == nil and true or canClose + activeMenu = { + position = position, + eles = eles, + canClose = canClose, + onSelect = onSelect, + onClose = onClose + } - LocalPlayer.state:set("context:active",true) + LocalPlayer.state:set("context:active",true) - Post("Open",eles,position) + Post("Open", eles, position) end function Closed() - SetNuiFocus(false,false) + SetNuiFocus(false, false) - local menu = activeMenu - local cb = menu.onClose + local menu = activeMenu + local cb = menu.onClose - activeMenu = nil + activeMenu = nil - LocalPlayer.state:set("context:active",false) + LocalPlayer.state:set("context:active", false) - if cb then - cb(menu) - end + if cb then + cb(menu) + end end -- Exports -- [ Preview | Open | Close ] -exports("Preview",Open) +exports("Preview", Open) -exports("Open",function(...) - Open(...) - SetNuiFocus(true,true) +exports("Open", function(...) + Open(...) + SetNuiFocus(true, true) end) -exports("Close",function() - if not activeMenu then - return - end +exports("Close", function() + if not activeMenu then + return + end - Post("Closed") + Post("Close") - Closed() + Closed() end) -exports("Refresh",function(eles,position) - if not activeMenu then - return - end +exports("Refresh", function(eles, position) + if not activeMenu then + return + end - activeMenu.eles = eles or activeMenu.eles - activeMenu.position = position or activeMenu.position + activeMenu.eles = eles or activeMenu.eles + activeMenu.position = position or activeMenu.position - Post("Open",activeMenu.eles,activeMenu.position) + Post("Open", activeMenu.eles, activeMenu.position) end) -- NUI Callbacks -- [ closed | selected | changed ] -RegisterNUICallback("closed",function(data,cb) - if not activeMenu or (activeMenu and not activeMenu.canClose) then - return cb(false) - end - cb(true) - Closed() +RegisterNUICallback("closed", function(_, cb) + if not activeMenu or (activeMenu and not activeMenu.canClose) then + return cb(false) + end + cb(true) + Closed() end) -RegisterNUICallback("selected",function(data,cb) - if not activeMenu - or not activeMenu.onSelect - or not data.index - then - return - end - - local index = tonumber(data.index) - local ele = activeMenu.eles[index] - - if not ele - or ele.input - then - return - end - - activeMenu:onSelect(ele) - if cb then cb('ok') end +RegisterNUICallback("selected", function(data, cb) + if not activeMenu + or not activeMenu.onSelect + or not data.index + then + return + end + + local index = tonumber(data.index) + local ele = activeMenu.eles[index] + + if not ele + or ele.input + then + return + end + + activeMenu:onSelect(ele) + if cb then cb('ok') end end) -RegisterNUICallback("changed",function(data,cb) - if not activeMenu - or not data.index - or not data.value - then - return - end - - local index = tonumber(data.index) - local ele = activeMenu.eles[index] - - if not ele - or not ele.input - then - return - end - - if ele.inputType == "number" then - ele.inputValue = tonumber(data.value) - - if ele.inputMin then - ele.inputValue = math.max(ele.inputMin,ele.inputValue) - end - - if ele.inputMax then - ele.inputValue = math.min(ele.inputMax,ele.inputValue) - end - elseif ele.inputType == "text" then - ele.inputValue = data.value - elseif ele.inputType == "radio" then - ele.inputValue = data.value - end - if cb then cb('ok') end +RegisterNUICallback("changed", function(data, cb) + if not activeMenu + or not data.index + or not data.value + then + return + end + + local index = tonumber(data.index) + local ele = activeMenu.eles[index] + + if not ele + or not ele.input + then + return + end + + if ele.inputType == "number" then + ele.inputValue = tonumber(data.value) + + if ele.inputMin then + ele.inputValue = math.max(ele.inputMin, ele.inputValue) + end + + if ele.inputMax then + ele.inputValue = math.min(ele.inputMax, ele.inputValue) + end + elseif ele.inputType == "text" then + ele.inputValue = data.value + elseif ele.inputType == "radio" then + ele.inputValue = data.value + end + if cb then cb('ok') end end) -- Keybind local function focusPreview() - if not activeMenu - or not activeMenu.onSelect - then - return - end + if not activeMenu + or not activeMenu.onSelect + then + return + end - SetNuiFocus(true,true) + SetNuiFocus(true, true) end if PREVIEW_KEYBIND then - RegisterCommand("previewContext",focusPreview) + RegisterCommand("previewContext", focusPreview) - RegisterKeyMapping("previewContext","Preview Active Context","keyboard",PREVIEW_KEYBIND) + RegisterKeyMapping("previewContext", "Preview Active Context", "Keyboard", PREVIEW_KEYBIND) end -exports("focusPreview",focusPreview) +exports("focusPreview", focusPreview) -- Debug/Test -- Commands: -- [ ctx:preview | ctx:open | ctx:close | ctx:form ] if Debug then - local position = "right" - - local eles = { - { - unselectable=true, - icon="fas fa-info-circle", - title="Unselectable Item (Header/Label?)", - }, - { - icon="fas fa-check", - title="Item A", - description="Some description here. Add some words to make the text overflow." - }, - { - disabled=true, - icon="fas fa-times", - title="Disabled Item", - description="Some description here. Add some words to make the text overflow." - }, - { - icon="fas fa-check", - title="Item B", - description="Some description here. Add some words to make the text overflow." - }, - } - - local function onSelect(menu,ele) - print("Ele selected",ele.title) - - if ele.name == "close" then - exports["esx_context"]:Close() - end - - if ele.name ~= "submit" then - return - end - - for _,ele in ipairs(menu.eles) do - if ele.input then - print(ele.name,ele.inputType,ele.inputValue) - end - end - - exports["esx_context"]:Close() - end - - local function onClose(menu) - print("Menu closed.") - end - - RegisterCommand("ctx:preview",function() - exports["esx_context"]:Preview(position,eles) - end) - - RegisterCommand("ctx:open",function() - exports["esx_context"]:Open(position,eles,onSelect,onClose) - end) - - RegisterCommand("ctx:close",function() - exports["esx_context"]:Close() - end) - - RegisterCommand("ctx:form",function() - local eles = { - { - unselectable=true, - icon="fas fa-info-circle", - title="Unselectable Item (Header/Label?)", - }, - { - icon="", - title="Input Text", - input=true, - inputType="text", - inputPlaceholder="Placeholder...", - name="firstname", - }, - { - icon="", - title="Input Text", - input=true, - inputType="text", - inputPlaceholder="Placeholder...", - name="lastname", - }, - { - icon="", - title="Input Number", - input=true, - inputType="number", - inputPlaceholder="Placeholder...", - inputValue=0, - inputMin=0, - inputMax=50, - name="age", - }, - { - icon = "fas fa-check", - title = "Submit", - name = "submit" - } - } - - exports["esx_context"]:Open(position,eles,onSelect,onClose) - end) + local position = "right" + + local eles = { + { + unselectable = true, + icon = "fas fa-infi-circle", + title = "Unselectable Item (Header/Label?)", + }, + { + icon = "fas fa-check", + title = "Item A", + description = "Some description here. Add some words to make the text overflow." + }, + { + disable = true, + icon = "fas fa-times", + title = "Disabled Item", + description = "Dome description here. Add some words to make the text overflow." + }, + { + icon = "fas fa-check", + title = "Item B", + description = "Some description here. Add some words to make the text overflow" + }, + } + + local function onSelect(menu, ele) + print("Ele selected", ele.title) + + if ele.name == "close" then + exports["esx_context"]:Close() + end + + if ele.name ~= "submit" then + return + end + + for _, ele in ipairs(menu.eles) do + if ele.input then + print(ele.name, ele.inputType, ele.inputValue) + end + end + + exports["esx_context"]:Close() + end + + local function onClose() + print("Menu closed.") + end + + RegisterCommand("ctx:preview", function() + exports["esx_context"]:Preview(position, eles) + end) + + RegisterCommand("ctx:open", function() + exports["esx_context"]:Open(position, eles, onSelect, onClose) + end) + + RegisterCommand("ctx:close", function() + exports["esx_context"]:Close() + end) + + RegisterCommand("ctx:form", function() + local eles = { + { + unselectable = true, + icon = "fas- fa-info-circle", + title = "Unselectable Item (Header/Label?)", + }, + { + icon = "", + title = "Input Text", + input = true, + inputType = "text", + inputPlaceholder = "Placeholder...", + name = "firsname", + }, + { + icon = "", + title = "Input Text", + input = true, + inputType = "text", + inputPlaceholder = "Placeholder...", + name = "lastname", + }, + { + icon = "", + title = "Input Number", + input = true, + inputType = "number", + inputPlaceholder = "Placeholder...", + inputValue = 0, + inputMin = 0, + inputMax = 50, + name = "age", + }, + { + icon = "fas fa-check", + title = "Submit", + name = "submit" + } + } + + exports["esx_context"]:Open(position, eles, onSelect, onClose) + end) end \ No newline at end of file diff --git a/server-data/server.cfg b/server-data/server.cfg index 317ebf185..30de21ad7 100644 --- a/server-data/server.cfg +++ b/server-data/server.cfg @@ -61,5 +61,4 @@ ensure [phone] #Executables cfg exec inventory.cfg -exec easyadmin_permissions.cfg set SCREENSHOT_BASIC_TOKEN "" \ No newline at end of file