From 3000eb8aa6820bd5254321720d93e59275ce0dbc Mon Sep 17 00:00:00 2001 From: Benzo <102178921+Benzo00@users.noreply.github.com> Date: Tue, 2 Aug 2022 16:23:32 +0200 Subject: [PATCH] fix - ehm something, --- [esx]/esx_context/config.lua | 1 + [esx]/esx_context/fxmanifest.lua | 1 + [esx]/esx_context/index.html | 11 ++- [esx]/esx_context/main.lua | 113 +++++++++++++++++++------------ 4 files changed, 78 insertions(+), 48 deletions(-) create mode 100644 [esx]/esx_context/config.lua diff --git a/[esx]/esx_context/config.lua b/[esx]/esx_context/config.lua new file mode 100644 index 00000000..909b3805 --- /dev/null +++ b/[esx]/esx_context/config.lua @@ -0,0 +1 @@ +PREVIEW_KEYBIND = false -- "LMENU" \ No newline at end of file diff --git a/[esx]/esx_context/fxmanifest.lua b/[esx]/esx_context/fxmanifest.lua index 164a2b59..d46be98c 100644 --- a/[esx]/esx_context/fxmanifest.lua +++ b/[esx]/esx_context/fxmanifest.lua @@ -11,6 +11,7 @@ ui_page 'index.html' shared_script '@es_extended/imports.lua' client_scripts { + 'config.lua', 'main.lua', } diff --git a/[esx]/esx_context/index.html b/[esx]/esx_context/index.html index d504747c..27168ec1 100644 --- a/[esx]/esx_context/index.html +++ b/[esx]/esx_context/index.html @@ -3,6 +3,7 @@
+ @@ -286,9 +287,13 @@ }) window.addEventListener("keydown",(e) => { - if (e.key == "Escape" || e.key == "Backspace") { - Close() - } + if (e.key == "Escape" || e.key == "Backspace") { + if (e.target.tagName.toLowerCase() == "input") { + return + } + + Close() + } }) // Open([ diff --git a/[esx]/esx_context/main.lua b/[esx]/esx_context/main.lua index 43fb66f3..6f3634d7 100644 --- a/[esx]/esx_context/main.lua +++ b/[esx]/esx_context/main.lua @@ -20,6 +20,8 @@ function Open(position,eles,onSelect,onClose) onClose = onClose } + LocalPlayer.state:set("context:active",true) + Post("Open",eles,position) end @@ -31,6 +33,8 @@ function Closed() activeMenu = nil + LocalPlayer.state:set("context:active",false) + if cb then cb(menu) end @@ -95,7 +99,7 @@ RegisterNUICallback("selected",function(data) return end - activeMenu.onSelect(activeMenu,ele) + activeMenu:onSelect(ele) end) RegisterNUICallback("changed",function(data) @@ -130,62 +134,81 @@ RegisterNUICallback("changed",function(data) end end) +-- Keybind + +local function focusPreview() + if not activeMenu + or not activeMenu.onSelect + then + return + end + + SetNuiFocus(true,true) +end + +if PREVIEW_KEYBIND then + RegisterCommand("previewContext",focusPreview) + + RegisterKeyMapping("previewContext","Preview Active Context","keyboard",PREVIEW_KEYBIND) +end + +exports("focusPreview",focusPreview) + -- Debug/Test -- Commands: -- [ ctx:preview | ctx:open | ctx:close | ctx:form ] -local position = "right" +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 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) + 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 - if ele.name == "close" then exports["esx_context"]:Close() end - if ele.name ~= "submit" then - return + local function onClose(menu) + print("Menu closed.") 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 - - -if Debug then RegisterCommand("ctx:preview",function() exports["esx_context"]:Preview(position,eles) end)