mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
fix(esx_context): Formatting
This commit is contained in:
+83
-95
@@ -4,14 +4,14 @@ local Debug = ESX.GetConfig().EnableDebug
|
||||
-- Global functions
|
||||
-- [ Post | Open | Closed ]
|
||||
|
||||
function Post(fn,...)
|
||||
function Post(fn, ...)
|
||||
SendNUIMessage({
|
||||
func = fn,
|
||||
args = {...}
|
||||
args = { ... }
|
||||
})
|
||||
end
|
||||
|
||||
function Open(position,eles,onSelect,onClose,canClose)
|
||||
function Open(position, eles, onSelect, onClose, canClose)
|
||||
local canClose = canClose == nil and true or canClose
|
||||
activeMenu = {
|
||||
position = position,
|
||||
@@ -21,20 +21,20 @@ function Open(position,eles,onSelect,onClose,canClose)
|
||||
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
|
||||
|
||||
activeMenu = nil
|
||||
|
||||
LocalPlayer.state:set("context:active",false)
|
||||
LocalPlayer.state:set("context:active", false)
|
||||
|
||||
if cb then
|
||||
cb(menu)
|
||||
@@ -44,14 +44,14 @@ end
|
||||
-- Exports
|
||||
-- [ Preview | Open | Close ]
|
||||
|
||||
exports("Preview",Open)
|
||||
exports("Preview", Open)
|
||||
|
||||
exports("Open",function(...)
|
||||
exports("Open", function(...)
|
||||
Open(...)
|
||||
SetNuiFocus(true,true)
|
||||
SetNuiFocus(true, true)
|
||||
end)
|
||||
|
||||
exports("Close",function()
|
||||
exports("Close", function()
|
||||
if not activeMenu then
|
||||
return
|
||||
end
|
||||
@@ -61,7 +61,7 @@ exports("Close",function()
|
||||
Closed()
|
||||
end)
|
||||
|
||||
exports("Refresh",function(eles,position)
|
||||
exports("Refresh", function(eles, position)
|
||||
if not activeMenu then
|
||||
return
|
||||
end
|
||||
@@ -69,13 +69,13 @@ exports("Refresh",function(eles,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(_,cb)
|
||||
RegisterNUICallback("closed", function(_, cb)
|
||||
if not activeMenu or (activeMenu and not activeMenu.canClose) then
|
||||
return cb(false)
|
||||
end
|
||||
@@ -83,20 +83,15 @@ RegisterNUICallback("closed",function(_,cb)
|
||||
Closed()
|
||||
end)
|
||||
|
||||
RegisterNUICallback("selected",function(data,cb)
|
||||
if not activeMenu
|
||||
or not activeMenu.onSelect
|
||||
or not data.index
|
||||
then
|
||||
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
|
||||
if not ele or ele.input then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -104,20 +99,15 @@ RegisterNUICallback("selected",function(data,cb)
|
||||
if cb then cb('ok') end
|
||||
end)
|
||||
|
||||
RegisterNUICallback("changed",function(data,cb)
|
||||
if not activeMenu
|
||||
or not data.index
|
||||
or not data.value
|
||||
then
|
||||
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
|
||||
if not ele or not ele.input then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -125,11 +115,11 @@ RegisterNUICallback("changed",function(data,cb)
|
||||
ele.inputValue = tonumber(data.value)
|
||||
|
||||
if ele.inputMin then
|
||||
ele.inputValue = math.max(ele.inputMin,ele.inputValue)
|
||||
ele.inputValue = math.max(ele.inputMin, ele.inputValue)
|
||||
end
|
||||
|
||||
if ele.inputMax then
|
||||
ele.inputValue = math.min(ele.inputMax,ele.inputValue)
|
||||
ele.inputValue = math.min(ele.inputMax, ele.inputValue)
|
||||
end
|
||||
elseif ele.inputType == "text" then
|
||||
ele.inputValue = data.value
|
||||
@@ -142,22 +132,20 @@ end)
|
||||
-- Keybind
|
||||
|
||||
local function focusPreview()
|
||||
if not activeMenu
|
||||
or not activeMenu.onSelect
|
||||
then
|
||||
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:
|
||||
@@ -167,31 +155,31 @@ 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."
|
||||
},
|
||||
{
|
||||
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)
|
||||
local function onSelect(menu, ele)
|
||||
print("Ele selected", ele.title)
|
||||
|
||||
if ele.name == "close" then
|
||||
exports["esx_context"]:Close()
|
||||
@@ -201,9 +189,9 @@ if Debug then
|
||||
return
|
||||
end
|
||||
|
||||
for _,ele in ipairs(menu.eles) do
|
||||
for _, ele in ipairs(menu.eles) do
|
||||
if ele.input then
|
||||
print(ele.name,ele.inputType,ele.inputValue)
|
||||
print(ele.name, ele.inputType, ele.inputValue)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -214,51 +202,51 @@ if Debug then
|
||||
print("Menu closed.")
|
||||
end
|
||||
|
||||
RegisterCommand("ctx:preview",function()
|
||||
exports["esx_context"]:Preview(position,eles)
|
||||
RegisterCommand("ctx:preview", function()
|
||||
exports["esx_context"]:Preview(position, eles)
|
||||
end)
|
||||
|
||||
RegisterCommand("ctx:open",function()
|
||||
exports["esx_context"]:Open(position,eles,onSelect,onClose)
|
||||
RegisterCommand("ctx:open", function()
|
||||
exports["esx_context"]:Open(position, eles, onSelect, onClose)
|
||||
end)
|
||||
|
||||
RegisterCommand("ctx:close",function()
|
||||
RegisterCommand("ctx:close", function()
|
||||
exports["esx_context"]:Close()
|
||||
end)
|
||||
|
||||
RegisterCommand("ctx:form",function()
|
||||
RegisterCommand("ctx:form", function()
|
||||
local eles = {
|
||||
{
|
||||
unselectable=true,
|
||||
icon="fas fa-info-circle",
|
||||
title="Unselectable Item (Header/Label?)",
|
||||
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 = "firstname",
|
||||
},
|
||||
{
|
||||
icon="",
|
||||
title="Input Text",
|
||||
input=true,
|
||||
inputType="text",
|
||||
inputPlaceholder="Placeholder...",
|
||||
name="lastname",
|
||||
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 = "",
|
||||
title = "Input Number",
|
||||
input = true,
|
||||
inputType = "number",
|
||||
inputPlaceholder = "Placeholder...",
|
||||
inputValue = 0,
|
||||
inputMin = 0,
|
||||
inputMax = 50,
|
||||
name = "age",
|
||||
},
|
||||
{
|
||||
icon = "fas fa-check",
|
||||
@@ -267,6 +255,6 @@ if Debug then
|
||||
}
|
||||
}
|
||||
|
||||
exports["esx_context"]:Open(position,eles,onSelect,onClose)
|
||||
exports["esx_context"]:Open(position, eles, onSelect, onClose)
|
||||
end)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user