From 3025e7cd7d1266ace917f32aef32f064da963e91 Mon Sep 17 00:00:00 2001 From: local9 Date: Sun, 27 Mar 2022 12:55:17 +0100 Subject: [PATCH 1/4] add attribute dictionary --- VORP-Inputs/vorpinputs_cl/Models/InputMessage.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/VORP-Inputs/vorpinputs_cl/Models/InputMessage.cs b/VORP-Inputs/vorpinputs_cl/Models/InputMessage.cs index f6e6b22..261ae15 100644 --- a/VORP-Inputs/vorpinputs_cl/Models/InputMessage.cs +++ b/VORP-Inputs/vorpinputs_cl/Models/InputMessage.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using System.Collections.Generic; using System.Runtime.Serialization; namespace VorpInputs.Models @@ -7,7 +8,7 @@ namespace VorpInputs.Models public class InputMessage { [DataMember(Name = "type")] - public string Type { get; } = "enableinput"; + public string Type = "enableinput"; [DataMember(Name = "style")] public string Style; @@ -21,6 +22,9 @@ public class InputMessage [DataMember(Name = "inputType")] public string InputType; + [DataMember(Name = "attributes")] + public Dictionary Attributes = new(); + public override string ToString() { return JsonConvert.SerializeObject(this); From c0dba7aad5680fb3ba222661736e6708c9f69756 Mon Sep 17 00:00:00 2001 From: local9 Date: Sun, 27 Mar 2022 12:56:50 +0100 Subject: [PATCH 2/4] add event --- VORP-Inputs/vorpinputs_cl/Plugin.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/VORP-Inputs/vorpinputs_cl/Plugin.cs b/VORP-Inputs/vorpinputs_cl/Plugin.cs index 7ecf95f..d92f1ff 100644 --- a/VORP-Inputs/vorpinputs_cl/Plugin.cs +++ b/VORP-Inputs/vorpinputs_cl/Plugin.cs @@ -17,6 +17,7 @@ public Plugin() EventHandlers["vorpinputs:getInput"] += new Action(getInputs); EventHandlers["vorpinputs:getInputsWithInputType"] += new Action(getInputsWithInputType); + EventHandlers["vorpinputs:advancedInput"] += new Action(OnAdvancedInput); API.RegisterNuiCallbackType("submit"); EventHandlers["__cfx_nui:submit"] += new Action(SetSubmit); @@ -25,6 +26,11 @@ public Plugin() EventHandlers["__cfx_nui:close"] += new Action(SetClose); } + private void OnAdvancedInput(string inputConfig, dynamic callback) + { + + } + private void SetClose(dynamic result) { text = result.stringtext; From 3c296fbe194931f41005b8a44570842fc39c0fb0 Mon Sep 17 00:00:00 2001 From: local9 Date: Sun, 27 Mar 2022 12:57:55 +0100 Subject: [PATCH 3/4] add development config --- VORP-Inputs/VORP-Inputs.sln | 3 +++ VORP-Inputs/vorpinputs_cl/VorpInputs.csproj | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/VORP-Inputs/VORP-Inputs.sln b/VORP-Inputs/VORP-Inputs.sln index cf8acac..118b406 100644 --- a/VORP-Inputs/VORP-Inputs.sln +++ b/VORP-Inputs/VORP-Inputs.sln @@ -13,11 +13,14 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Development|Any CPU = Development|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {61F282D4-73FB-475F-899F-D78C6A9E26E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {61F282D4-73FB-475F-899F-D78C6A9E26E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61F282D4-73FB-475F-899F-D78C6A9E26E8}.Development|Any CPU.ActiveCfg = Development|Any CPU + {61F282D4-73FB-475F-899F-D78C6A9E26E8}.Development|Any CPU.Build.0 = Development|Any CPU {61F282D4-73FB-475F-899F-D78C6A9E26E8}.Release|Any CPU.ActiveCfg = Release|Any CPU {61F282D4-73FB-475F-899F-D78C6A9E26E8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection diff --git a/VORP-Inputs/vorpinputs_cl/VorpInputs.csproj b/VORP-Inputs/vorpinputs_cl/VorpInputs.csproj index c8be8da..e1e1dd2 100644 --- a/VORP-Inputs/vorpinputs_cl/VorpInputs.csproj +++ b/VORP-Inputs/vorpinputs_cl/VorpInputs.csproj @@ -31,6 +31,15 @@ prompt 4 + + true + Y:\GTA\FXServer\RedM\server-data\resources\[vorp_core]\vorp_inputs\ + DEBUG;TRACE + full + AnyCPU + latest + prompt + ..\dependancies\RedM\CitizenFX.Core.dll From 43f7fdbc4e2564f42a418e13bb3e1757d964b956 Mon Sep 17 00:00:00 2001 From: local9 Date: Sun, 27 Mar 2022 13:41:41 +0100 Subject: [PATCH 4/4] can now send attributes for input --- .../build/vorp_inputs/html/assets/script.js | 93 ++++++++++++------- VORP-Inputs/vorpinputs_cl/Plugin.cs | 17 +++- 2 files changed, 72 insertions(+), 38 deletions(-) diff --git a/VORP-Inputs/build/vorp_inputs/html/assets/script.js b/VORP-Inputs/build/vorp_inputs/html/assets/script.js index d89d109..e04c60c 100644 --- a/VORP-Inputs/build/vorp_inputs/html/assets/script.js +++ b/VORP-Inputs/build/vorp_inputs/html/assets/script.js @@ -1,38 +1,59 @@ -$(function() { - window.addEventListener('message', function(event) { - if (event.data.type == "enableinput") { - document.body.style.display = event.data.style; - if (event.data.inputType) { - document.getElementById('inputUser').type = event.data.inputType - } - if (event.data.style == "block") { - document.getElementById("subButton").innerHTML = event.data.button; - document.getElementById("inputUser").placeholder = event.data.placeholder; - document.getElementById("inputUser").value = ""; - } - $("#inputUser").focus() - } - }); +$(function () { + window.addEventListener("message", function (event) { + if (event.data.type == "enableinput") { + const data = event.data; + document.body.style.display = data.style; + + const inputEle = document.getElementById("inputUser"); + const buttonEle = document.getElementById("subButton"); + + if (event.data.inputType) { + inputEle.type = data.inputType; + } - document.onkeyup = function(data) { - if (data.which == 27) { // Escape key - $.post('http://vorp_inputs/close', JSON.stringify({ - stringtext: "close" - })); + if (data.style == "block") { + buttonEle.innerHTML = data.button; + inputEle.placeholder = data.placeholder; + inputEle.value = data?.attributes?.value ?? ""; + + for (const key in data?.attributes) { + inputEle.setAttribute(`${key}`, `${data.attributes[key]}`); } - }; - - $("#notButton").click(function() { - $.post('http://vorp_inputs/close', JSON.stringify({ - stringtext: "close" - })); - }); - - $("#formInputs").submit(function(event) { - //event.preventDefault(); // Prevent form from submitting - - $.post('http://vorp_inputs/submit', JSON.stringify({ - stringtext: $("#inputUser").val() - })); - }); -}); \ No newline at end of file + } + + $("#inputUser").focus(); + } + }); + + document.onkeyup = function (data) { + if (data.which == 27) { + // Escape key + $.post( + "http://vorp_inputs/close", + JSON.stringify({ + stringtext: "close", + }) + ); + } + }; + + $("#notButton").click(function () { + $.post( + "http://vorp_inputs/close", + JSON.stringify({ + stringtext: "close", + }) + ); + }); + + $("#formInputs").submit(function (event) { + //event.preventDefault(); // Prevent form from submitting + + $.post( + "http://vorp_inputs/submit", + JSON.stringify({ + stringtext: $("#inputUser").val(), + }) + ); + }); +}); diff --git a/VORP-Inputs/vorpinputs_cl/Plugin.cs b/VORP-Inputs/vorpinputs_cl/Plugin.cs index d92f1ff..8336d25 100644 --- a/VORP-Inputs/vorpinputs_cl/Plugin.cs +++ b/VORP-Inputs/vorpinputs_cl/Plugin.cs @@ -26,9 +26,22 @@ public Plugin() EventHandlers["__cfx_nui:close"] += new Action(SetClose); } - private void OnAdvancedInput(string inputConfig, dynamic callback) + private async void OnAdvancedInput(string inputConfig, dynamic callback) { - + API.SetNuiFocus(true, true); + + API.SendNuiMessage(inputConfig); + + while (text == null) + { + await Delay(1); + } + + callback.Invoke(text); + + await Delay(1); + text = null; + CloseInput(); } private void SetClose(dynamic result)