From b3bccf4a50c25f73f355cae930d55cd1436ae511 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sat, 9 Jun 2018 13:12:58 +0200 Subject: [PATCH] Autofocus on input, enter acts like enter, cleanup --- README.md | 38 ++++++++++- __resource.lua | 18 ++---- client/main.lua | 104 +++++++++++------------------- html/css/app.css | 6 -- html/img/accounts/bank.png | Bin 1015 -> 0 bytes html/img/accounts/black_money.png | Bin 1030 -> 0 bytes html/img/cursor.png | Bin 431 -> 0 bytes html/img/keys/enter.png | Bin 941 -> 0 bytes html/img/keys/return.png | Bin 376 -> 0 bytes html/js/app.js | 35 +++++----- html/js/app_en.js | 35 +++++----- html/ui.html | 3 - 12 files changed, 119 insertions(+), 120 deletions(-) delete mode 100644 html/img/accounts/bank.png delete mode 100644 html/img/accounts/black_money.png delete mode 100644 html/img/cursor.png delete mode 100644 html/img/keys/enter.png delete mode 100644 html/img/keys/return.png diff --git a/README.md b/README.md index 9f6478a1..53522b3f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,38 @@ # esx_menu_dialog -Simple script used for inputs. \ No newline at end of file +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/. \ No newline at end of file diff --git a/__resource.lua b/__resource.lua index 1a597038..081c5dfc 100644 --- a/__resource.lua +++ b/__resource.lua @@ -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' } \ No newline at end of file diff --git a/client/main.lua b/client/main.lua index bedc532e..b419cd73 100644 --- a/client/main.lua +++ b/client/main.lua @@ -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 \ No newline at end of file + function round(x) + return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5) + end +end) \ No newline at end of file diff --git a/html/css/app.css b/html/css/app.css index 55577105..e50e4d31 100644 --- a/html/css/app.css +++ b/html/css/app.css @@ -8,12 +8,6 @@ src: url('../fonts/pdown.ttf'); } -#cursor { - position: absolute; - z-index: 999999999; - display: none; -} - #controls { font-family : pcdown; font-size : 3em; diff --git a/html/img/accounts/bank.png b/html/img/accounts/bank.png deleted file mode 100644 index eb36dc8e70242136858874dc04024f41a4a0ffe4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1015 zcmV(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fd zMgRZowVTiq@}o(XxOP=4eyC973P=U1kRsFroRJ#! z(58{#776h;aLEM;L{SeVNSr|QQXy1+3PCF$LRAh>$;D}$6yr9(+&K1ncOM65H{N(1 z#D$Kuhc`R(oq6-#%=d|SpP}3h7iYue{}eqbkx7XFRFr{CNQ8)Xb~jy=7uE?4gk`F&OBwm4 zCoMHTH>$?xM%AIWM*@A{$sTp={U_D<+^9-VTDxK-EK`kLJ+5RzDnM!ek$H}yvF_~J zI*(=_0U-a;0)z8Wb)S zQLZ90W&QVw7&*Bd#kDto4a&FO>rT+B>2t%_D-HHP*Nt0qx&3jG%#?*w*}g}u7*V?q zC7?WT9&9^T7ittfS!~IwsWS)S-1}*T;uj^>ZdO>nzDliBXXNxy;O7swHVm3ETF1EN z4>(O1#JYDsk>%W4c>Lb8d62J?Ix`%Uf2Yk(iFNB}y6}hU)_oQ5>d!CYZn)gNQs$4D zKRXVhm%qw}1`)u%qg{dS$JcVyN_M3G6VnGdaH2iso z*ZbP|p!QdtrOPGu48|kL$mfBbu>v}-m+cT8XD>e8k&fM(*Y<#MYaY*k@Ki@S_G~Xi l#{maD><5W>*iW*51^`FRlAF&_hJ*kB002ovPDHLkV1iBj&&U7( diff --git a/html/img/accounts/black_money.png b/html/img/accounts/black_money.png deleted file mode 100644 index a42f6aa5191115bd04d04a728fb3c3463e6f4345..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1030 zcmV+h1o``kP)(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fd zMgRZT+Hn2g&!y2+1h(>773hKd&LYji7 zJxDS2q!OyV*_F1(HYnsEh!-iPJ(ZSP4aAjfgeH{rV4AN*TFttfb$4bmZx7v>?##{# z?V&y}hv%8+>;1pa$1D1}yJgw3cww6SpVXsi=&FhUWSBxsRZ)ZpHLjQ@PC%vrF-;5A zcci3ZS)uWZC+3;63 zP5NhNQG_7k$iD&Ti^Y6K$y>Lur5_yG;D0)PoSwjGx9WA?yK@Hs5kM{?1izg=O;;2A zE;12U>4j-}Ke7u86iTH~$S#kLGN9`%@&R4v!+raho}Ul3%PuT1H9YLaYQ8!YA?Of- zVztV(#YN7~&4oJYkHxr{N_qVKVv+mBqQ_rKrRWbJ>C*YRIj$`(Qmj_#5W-hqGN!6> zV{%d^3_~`GGW5GJG9sN!Mmm{{ygWMU$&U>V%5RSxkxnKfFN}=5(nrED_VAxIbo05=N-zC3)GHzE;!+1%vw@o_Ie!Z2_5K&81r!?IKr zh1|)L^k^EFQYm)L%mA>fvlD<*LqnXsdzb!LjLmA5H@mvL+HiFMpO3e$U&jh*>&SnZ zV$Kc?zZa1REj@pHO6~;d1>2x z`tTvs=`>qSb=2%5?DW0_oIrm*E|tjU^S*KVxKv_5*ZFQ`g|C;En1A||AJ*1bt5o_1QC~4jk~{59$PIcV{Q6qIgLP zKq^8|I&+4yWpT4m;NyGu+76Wq2dk9|S8_RzKNyeuf?vty+6KQmHpaPRl6W-Aj+7n(5dsSW zU}|`nua=fVm(h*oWj@%uw`CvvUM_QEd6{>0J#-nldmtFgTgU5_if`vg<{vZ*r`$_iK0G#)*@UBUHMF0Q*07*qoM6N<$f`k9( AtN;K2 diff --git a/html/img/cursor.png b/html/img/cursor.png deleted file mode 100644 index 6ada58a4e3550f496cac2c9d447ea33829dc3148..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 431 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvI6;>1s;*b3=DjSK$uZf!>a)(C|TkfQ4*Y=R#Ki=l*&+$n3-3imzP?iV4`QB zXK3b~uOhs#!ahWd2$lKAA=PHj|R?Wsg9S z`&IHf2TyHlIAOqZsdTPq)6`tXk4zn|Njeo`DMAiTswGpzq8#fu6%>W6+_={&lrx=B z=9FF78YZCCu*UO6c2ovyq=>^bl`o>YTbkBzDfl?`XD$?dvXJ3ZxKn?|!l?<2DS8Y0 zw_G?i*Wv#6pzB}7&rSE3^kmiIEf=_qI1?&ELnG>f__R}!4{lb7OW5{jGVi-q@r>JL zQS0`+Vdg%_of6shpK-s;hJ$+xD(A&NJAGfzAl~K>+jpi;ra%QQmqv{b^I4DFWiZrz V^21*%)dLuw44$rjF6*2UngBc`p>O~I diff --git a/html/img/keys/enter.png b/html/img/keys/enter.png deleted file mode 100644 index 3eb9a1f69f58c651517329c92d28cdb1c605f165..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 941 zcmeAS@N?(olHy`uVBq!ia0vp^4M6O`!2~2@x4h5*QjEnx?oJHr&dIz4a#+$GeH|GX zHuiJ>Nn{1`ISV`@iy0XB4ude`@%$Aj3=GUpo-U3d6>)E`8wN=`3bZEbov^iFaeu%P z(=cbwj44wlOz4rm5xb{;*Ri~}uR6cp(A&Mg;nJ7c^H#o^DiE{vT2%I1{SRyZiuLSP z%I`LO*R@CY*bePa+aw;ZJ8?S+Bq+DcEWq?az(jNYVCfZ787ofAZePh8!fO)pBkQX z_v_cMN3~tQ9xnRXb?ICkwaPbd-|8+sfB5~ocaKb5*$ZEQP2MMD?ps&IpveBkTdrZ6 zxw-l0$rY8AfmJN&5XWi1Tr~N;qpPCYQm=EdrvtPXJvz5h@~FDPw92D`R+fPvAFW@~ zU8c75`%1Gbh1a`Q>?qE0`*<(h^|W${-y)Ec<2}XS`n>x2)3WZB?5;)4TWYMP-*<76OIq zPp@4X%Z+C%*K#BUX=ORzsAov;Kl`m>i&y`Jz)nzj*Qmyplm-1%6v*YUbiCHwmEO<$ zF|Z@`-}HhOKR<9>X}?rT5Bm9ye^tw4euv}#-v4JmQzRDkY{|X*_d_{Xwfto_xNQ|y z-^Qlff58%JWZtYCU#*y5vIf?_WBTiPU(9hK5Tmx!-~Iodkpb3zr{Lwk`bljQz#(xy zvE05v9vtTHlU}QP{nuV*08Uf+$??{$l9IqgWxio$Zh{XeF$LeaxXn-#^iFnsKzTLkWYeXNfKEXTvUB0pJdzPZ}OMgdS+TyQ( lJso37+@RE7f9~qla<)GklNn{1`ISV`@iy0XBj({-ZRBb+Kpaxz~7srr_xVN`&cQqS`I9#;&|Ns0smZ-L@ zqu)%cbtmkrE=&Hfsn_t^{^k|)kLw3AbqG7mVR+;>`#|k>^_ZL6&QAQlndu0pf*(U6 zREkAFy}^PJuTYF$!{g|Ur7IbD{_6-gJlsE>3DGO)9eE;D=anIC*ESQi{xCV$~42}L!4TJCrkQD1~tJw zr&teYqgpL=o@s|#!;B|~71m*K{{title}}' + - '{{#isDefault}}{{/isDefault}}' + + '{{#isDefault}}{{/isDefault}}' + '{{#isBig}}