Autofocus on input, enter acts like enter, cleanup

This commit is contained in:
ElPumpo
2018-06-09 13:12:58 +02:00
parent 3a7ce7039c
commit b3bccf4a50
12 changed files with 119 additions and 120 deletions
+37 -1
View File
@@ -1,2 +1,38 @@
# esx_menu_dialog
Simple script used for inputs.
Simple script used for inputs.
## Download & Installation
### Using [fvm](https://github.com/qlaffont/fvm-installer)
```
fvm install --save --folder=esx esx-org/esx_menu_dialog
```
### Using Git
```
cd resources
git clone https://github.com/ESX-Org/esx_menu_dialog [esx]/esx_menu_dialog
```
### Manually
- Download https://github.com/ESX-Org/esx_menu_dialog/archive/master.zip
- Put it in the `[esx]` directory
## Installation
- Add this to your `server.cfg`:
```
start esx_menu_dialog
```
# Legal
### License
esx_menu_dialog - input dialog for ESX
Copyright (C) 2015-2018 Jérémie N'gadi
This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.
This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details.
You should have received a copy Of the GNU General Public License along with this program. If Not, see http://www.gnu.org/licenses/.
+7 -11
View File
@@ -2,24 +2,20 @@ resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
description 'ESX Menu Dialog'
version '1.0.0'
version '1.1.0'
client_scripts {
'client/main.lua'
}
client_script 'client/main.lua'
ui_page {
'html/ui.html'
}
ui_page 'html/ui.html'
files {
'html/ui.html',
'html/css/app.css',
'html/js/mustache.min.js',
'html/js/app.js',
'html/fonts/pdown.ttf',
'html/fonts/bankgothic.ttf',
'html/img/cursor.png',
'html/img/keys/enter.png',
'html/img/keys/return.png',
'html/fonts/bankgothic.ttf'
}
+39 -65
View File
@@ -1,32 +1,18 @@
ESX = nil
local Timeouts = {}
Citizen.CreateThread(function()
-- internal variables
ESX = nil
local Timeouts = {}
local GUI = {}
GUI.Time = 0
local MenuType = 'dialog'
local OpenedMenus = {}
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
local Keys = {
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}
local GUI = {}
GUI.Time = 0
local MenuType = 'dialog'
local OpenedMenus = {}
local openMenu = function(namespace, name, data)
for i=1, #Timeouts, 1 do
ESX.ClearTimeout(Timeouts[i])
end
@@ -45,11 +31,9 @@ Citizen.CreateThread(function()
end)
table.insert(Timeouts, timeoutId)
end
local closeMenu = function(namespace, name)
OpenedMenus[namespace .. '_' .. name] = nil
local OpenedMenuCount = 0
@@ -75,24 +59,23 @@ Citizen.CreateThread(function()
ESX.UI.Menu.RegisterType(MenuType, openMenu, closeMenu)
RegisterNUICallback('menu_submit', function(data, cb)
local menu = ESX.UI.Menu.GetOpened(MenuType, data._namespace, data._name)
local post = true
if menu.submit ~= nil then
-- Is the submitted data a number?
if tonumber(data.value) ~= nil then
-- Round float values
data.value = round(tonumber(data.value))
-- Check for negative value
if tonumber(data.value) <= 0 then
post = false
end
end
-- Don't post if the value is negative or if it's 0
if post then
menu.submit(data, menu)
@@ -100,14 +83,13 @@ Citizen.CreateThread(function()
ESX.ShowNotification('That input is invalid!')
end
end
cb('OK')
end)
RegisterNUICallback('menu_cancel', function(data, cb)
local menu = ESX.UI.Menu.GetOpened(MenuType, data._namespace, data._name)
if menu.cancel ~= nil then
menu.cancel(data, menu)
end
@@ -116,49 +98,41 @@ Citizen.CreateThread(function()
end)
RegisterNUICallback('menu_change', function(data, cb)
local menu = ESX.UI.Menu.GetOpened(MenuType, data._namespace, data._name)
if menu.change ~= nil then
menu.change(data, menu)
end
cb('OK')
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
local OpenedMenuCount = 0
Wait(0)
for k,v in pairs(OpenedMenus) do
if v == true then
OpenedMenuCount = OpenedMenuCount + 1
end
end
local OpenedMenuCount = 0
for k,v in pairs(OpenedMenus) do
if v == true then
OpenedMenuCount = OpenedMenuCount + 1
end
end
if OpenedMenuCount > 0 then
DisableControlAction(0, 1, true) -- LookLeftRight
DisableControlAction(0, 2, true) -- LookUpDown
DisableControlAction(0, 142, true) -- MeleeAttackAlternate
DisableControlAction(0, 106, true) -- VehicleMouseControlOverride
DisableControlAction(0, 12, true) -- WeaponWheelUpDown
DisableControlAction(0, 14, true) -- WeaponWheelNext
DisableControlAction(0, 15, true) -- WeaponWheelPrev
DisableControlAction(0, 16, true) -- SelectNextWeapon
DisableControlAction(0, 17, true) -- SelectPrevWeapon
end
end
if OpenedMenuCount > 0 then
DisableControlAction(0, 1, true) -- LookLeftRight
DisableControlAction(0, 2, true) -- LookUpDown
DisableControlAction(0, 142, true) -- MeleeAttackAlternate
DisableControlAction(0, 106, true) -- VehicleMouseControlOverride
DisableControlAction(0, 12, true) -- WeaponWheelUpDown
DisableControlAction(0, 14, true) -- WeaponWheelNext
DisableControlAction(0, 15, true) -- WeaponWheelPrev
DisableControlAction(0, 16, true) -- SelectNextWeapon
DisableControlAction(0, 17, true) -- SelectPrevWeapon
end
end
end)
end)
function round(x)
return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end
function round(x)
return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end
end)
-6
View File
@@ -8,12 +8,6 @@
src: url('../fonts/pdown.ttf');
}
#cursor {
position: absolute;
z-index: 999999999;
display: none;
}
#controls {
font-family : pcdown;
font-size : 3em;
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1015 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 941 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 B

+18 -17
View File
@@ -3,7 +3,7 @@
let MenuTpl =
'<div id="menu_{{_namespace}}_{{_name}}" class="dialog {{#isBig}}big{{/isBig}}">' +
'<div class="head"><span>{{title}}</span></div>' +
'{{#isDefault}}<input type="text" name="value"/>{{/isDefault}}' +
'{{#isDefault}}<input type="text" name="value" id="inputText"/>{{/isDefault}}' +
'{{#isBig}}<textarea name="value"/>{{/isBig}}' +
'<button type="button" name="submit">Envoyer</button>' +
'<button type="button" name="cancel">Annuler</button>'
@@ -17,7 +17,7 @@
ESX_MENU.focus = [];
ESX_MENU.pos = {};
ESX_MENU.open = function(namespace, name, data){
ESX_MENU.open = function(namespace, name, data) {
if(typeof ESX_MENU.opened[namespace] == 'undefined')
ESX_MENU.opened[namespace] = {};
@@ -45,18 +45,19 @@
namespace: namespace,
name : name
});
document.onkeyup = function (key) {
if (key.which == 27) { // Escape key
$.post('http://' + ESX_MENU.ResourceName + '/menu_cancel', JSON.stringify(data));
}
};
document.onkeyup = function (key) {
if (key.which == 27) { // Escape key
$.post('http://' + ESX_MENU.ResourceName + '/menu_cancel', JSON.stringify(data));
} else if (key.which == 13) { // Enter key
$.post('http://' + ESX_MENU.ResourceName + '/menu_submit', JSON.stringify(data));
}
};
ESX_MENU.render();
}
ESX_MENU.close = function(namespace, name){
ESX_MENU.close = function(namespace, name) {
delete ESX_MENU.opened[namespace][name];
@@ -70,7 +71,7 @@
ESX_MENU.render();
}
ESX_MENU.render = function(){
ESX_MENU.render = function() {
let menuContainer = $('#menus')[0];
@@ -101,7 +102,6 @@
}
default : break;
}
let menu = $(Mustache.render(MenuTpl, view))[0];
@@ -129,21 +129,22 @@
}
$(menuContainer).show();
$("#inputText").focus();
}
ESX_MENU.submit = function(namespace, name, data){
ESX_MENU.submit = function(namespace, name, data) {
$.post('http://' + ESX_MENU.ResourceName + '/menu_submit', JSON.stringify(data));
}
ESX_MENU.cancel = function(namespace, name, data){
ESX_MENU.cancel = function(namespace, name, data) {
$.post('http://' + ESX_MENU.ResourceName + '/menu_cancel', JSON.stringify(data));
}
ESX_MENU.change = function(namespace, name, data){
ESX_MENU.change = function(namespace, name, data) {
$.post('http://' + ESX_MENU.ResourceName + '/menu_change', JSON.stringify(data));
}
ESX_MENU.getFocused = function(){
ESX_MENU.getFocused = function() {
return ESX_MENU.focus[ESX_MENU.focus.length - 1];
}
+18 -17
View File
@@ -3,7 +3,7 @@
let MenuTpl =
'<div id="menu_{{_namespace}}_{{_name}}" class="dialog {{#isBig}}big{{/isBig}}">' +
'<div class="head"><span>{{title}}</span></div>' +
'{{#isDefault}}<input type="text" name="value"/>{{/isDefault}}' +
'{{#isDefault}}<input type="text" name="value" id="inputText"/>{{/isDefault}}' +
'{{#isBig}}<textarea name="value"/>{{/isBig}}' +
'<button type="button" name="submit">Submit</button>' +
'<button type="button" name="cancel">Cancel</button>'
@@ -17,7 +17,7 @@
ESX_MENU.focus = [];
ESX_MENU.pos = {};
ESX_MENU.open = function(namespace, name, data){
ESX_MENU.open = function(namespace, name, data) {
if(typeof ESX_MENU.opened[namespace] == 'undefined')
ESX_MENU.opened[namespace] = {};
@@ -45,18 +45,19 @@
namespace: namespace,
name : name
});
document.onkeyup = function (key) {
if (key.which == 27) { // Escape key
$.post('http://' + ESX_MENU.ResourceName + '/menu_cancel', JSON.stringify(data));
}
};
document.onkeyup = function (key) {
if (key.which == 27) { // Escape key
$.post('http://' + ESX_MENU.ResourceName + '/menu_cancel', JSON.stringify(data));
} else if (key.which == 13) { // Enter key
$.post('http://' + ESX_MENU.ResourceName + '/menu_submit', JSON.stringify(data));
}
};
ESX_MENU.render();
}
ESX_MENU.close = function(namespace, name){
ESX_MENU.close = function(namespace, name) {
delete ESX_MENU.opened[namespace][name];
@@ -70,7 +71,7 @@
ESX_MENU.render();
}
ESX_MENU.render = function(){
ESX_MENU.render = function() {
let menuContainer = $('#menus')[0];
@@ -101,7 +102,6 @@
}
default : break;
}
let menu = $(Mustache.render(MenuTpl, view))[0];
@@ -129,21 +129,22 @@
}
$(menuContainer).show();
$("#inputText").focus();
}
ESX_MENU.submit = function(namespace, name, data){
ESX_MENU.submit = function(namespace, name, data) {
$.post('http://' + ESX_MENU.ResourceName + '/menu_submit', JSON.stringify(data));
}
ESX_MENU.cancel = function(namespace, name, data){
ESX_MENU.cancel = function(namespace, name, data) {
$.post('http://' + ESX_MENU.ResourceName + '/menu_cancel', JSON.stringify(data));
}
ESX_MENU.change = function(namespace, name, data){
ESX_MENU.change = function(namespace, name, data) {
$.post('http://' + ESX_MENU.ResourceName + '/menu_change', JSON.stringify(data));
}
ESX_MENU.getFocused = function(){
ESX_MENU.getFocused = function() {
return ESX_MENU.focus[ESX_MENU.focus.length - 1];
}
-3
View File
@@ -3,13 +3,10 @@
<link rel="stylesheet" href="css/app.css" />
</head>
<body>
<div id="menus"></div>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> -->
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<script src="js/mustache.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>