Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change(input/event): Added "vorpinputs:advancedInput" #8

Merged
merged 4 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions VORP-Inputs/VORP-Inputs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
93 changes: 57 additions & 36 deletions VORP-Inputs/build/vorp_inputs/html/assets/script.js
Original file line number Diff line number Diff line change
@@ -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()
}));
});
});
}

$("#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(),
})
);
});
});
6 changes: 5 additions & 1 deletion VORP-Inputs/vorpinputs_cl/Models/InputMessage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace VorpInputs.Models
Expand All @@ -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;
Expand All @@ -21,6 +22,9 @@ public class InputMessage
[DataMember(Name = "inputType")]
public string InputType;

[DataMember(Name = "attributes")]
public Dictionary<string, string> Attributes = new();

public override string ToString()
{
return JsonConvert.SerializeObject(this);
Expand Down
19 changes: 19 additions & 0 deletions VORP-Inputs/vorpinputs_cl/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public Plugin()

EventHandlers["vorpinputs:getInput"] += new Action<string, string, dynamic>(getInputs);
EventHandlers["vorpinputs:getInputsWithInputType"] += new Action<string, string, string, dynamic>(getInputsWithInputType);
EventHandlers["vorpinputs:advancedInput"] += new Action<string, dynamic>(OnAdvancedInput);

API.RegisterNuiCallbackType("submit");
EventHandlers["__cfx_nui:submit"] += new Action<ExpandoObject>(SetSubmit);
Expand All @@ -25,6 +26,24 @@ public Plugin()
EventHandlers["__cfx_nui:close"] += new Action<ExpandoObject>(SetClose);
}

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)
{
text = result.stringtext;
Expand Down
9 changes: 9 additions & 0 deletions VORP-Inputs/vorpinputs_cl/VorpInputs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Development|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>Y:\GTA\FXServer\RedM\server-data\resources\[vorp_core]\vorp_inputs\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>latest</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="CitizenFX.Core">
<HintPath>..\dependancies\RedM\CitizenFX.Core.dll</HintPath>
Expand Down