Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.81 KB | None | 0 0
  1. --[[
  2.     autor: Pat
  3.     Nie zezwalam na używanie skryptu bez mojej zgody
  4.     kontakt: igormeger@gmail.com
  5. ]]
  6.  
  7. editboxes={}
  8.  
  9. local sx,sy = guiGetScreenSize()
  10.  
  11. local scale = 1920 / sx
  12.  
  13. local tick = getTickCount()
  14.  
  15. local prepared_text =function(text,x,y,w,h,color,font,alignX)
  16.     dxDrawText(text,x,y,w+x,h+y,color,0.8,font,alignX,"center",true,false,true,false,false)
  17. end
  18.  
  19. local texture = dxCreateTexture('images/editbox_h.png', 'argb', false, 'clamp')
  20. local texture_empty = dxCreateTexture('images/editbox.png', 'argb', false, 'clamp')
  21.  
  22. --[[drawEditboxHovered=function(x,y,w,h,color)
  23.     local circle1Pos = (w+x)-h
  24.     local circle2Pos = (x+h)-h
  25.     dxDrawImage(circle1Pos,y,h,h,texture_full, 180, 0, 0, color,true)
  26.     dxDrawImage(circle2Pos,y,h,h,texture_full, 0, 0, 0, color,true)
  27.     --dxDrawRectangle(x+(h/2) - 2,y,w-(h) + 4,h, color)
  28.     dxDrawRectangle(circle2Pos + h/2,y,w - h,h,color,true)
  29. end --]]
  30.  
  31. drawEditboxHovered=function(x,y,w,h,color)
  32.     dxDrawImage(x,y,h,h,texture,0,0,0,color,true)
  33.     dxDrawRectangle(x+h/2 - h/40,y,w-h + h/25,h,color,true)
  34.     dxDrawImage(x+w - h,y,h,h,texture,180,0,0,color,true)
  35. end
  36.  
  37. getAnyStates=function()
  38.     local state = 0
  39.     for i,v in ipairs(editboxes) do
  40.         if v['state'] then
  41.             state=state+1
  42.         end
  43.     end
  44.     return state>0 and true or false
  45. end
  46.  
  47. addEventHandler('onClientClick',root,function(b,s)
  48.     if b=='left' and s=='down' then
  49.         for i,v in ipairs(editboxes) do
  50.             local text=v['text']
  51.             local x,y,w,h = v['pos']['x'],v['pos']['y'],v['pos']['w'],v['pos']['h']
  52.             local color = v['color']
  53.             --v['state']=false
  54.             if isMouseInPosition(x,y,w,h) and v['visible'] then
  55.                 v['state']=not v['state']
  56.                 if v['state']==true then
  57.                     guiSetInputEnabled(true)
  58.                 else
  59.                     guiSetInputEnabled(false)
  60.                 end
  61.             else
  62.                 v['state']=false
  63.                 if not getAnyStates() then
  64.                     guiSetInputEnabled(false)
  65.                 end
  66.             end
  67.         end
  68.     end
  69. end )
  70.  
  71. local numbers = {
  72.     ["0"] = true,
  73.     ["1"] = true,
  74.     ["2"] = true,
  75.     ["3"] = true,
  76.     ["4"] = true,
  77.     ["5"] = true,
  78.     ["6"] = true,
  79.     ["7"] = true,
  80.     ["8"] = true,
  81.     ["9"] = true,
  82. }
  83.  
  84. local letters={
  85.     ['a']=true,
  86.     ['b']=true,
  87.     ['c']=true,
  88.     ['d']=true,
  89.     ['e']=true,
  90.     ['f']=true,
  91.     ['g']=true,
  92.     ['h']=true,
  93.     ['i']=true,
  94.     ['j']=true,
  95.     ['k']=true,
  96.     ['l']=true,
  97.     ['m']=true,
  98.     ['n']=true,
  99.     ['o']=true,
  100.     ['p']=true,
  101.     ['r']=true,
  102.     ['s']=true,
  103.     ['t']=true,
  104.     ['u']=true,
  105.     ['w']=true,
  106.     ['y']=true,
  107.     ['x']=true,
  108.     ['z']=true,
  109.     ['q']=true,
  110.     -- polskie litery
  111.     ['ę']=true,
  112.     ['ó']=true,
  113.     ['ą']=true,
  114.     ['ś']=true,
  115.     ['ł']=true,
  116.     ['ż']=true,
  117.     ['ź']=true,
  118.     ['ć']=true,
  119.     ['ń']=true,
  120. }
  121.  
  122. addEventHandler('onClientCharacter',root,function(key)
  123.     for i,v in ipairs(editboxes) do
  124.         if v['state'] == true then
  125.             if (string.len(v['text'])) >= v['maxLenght'] then return end
  126.             if v['onlyNumbers'] and not numbers[key] then return end
  127.             if v['onlyLetters'] and not letters[key] then return end
  128.             v['text']=v['text'] .. key
  129.         end
  130.     end
  131. end)
  132.  
  133. local sx,sy=guiGetScreenSize()
  134.  
  135. addEventHandler('onClientRender',root,function()
  136.     for i,v in ipairs(editboxes) do
  137.         if v['visible'] then
  138.             local text=v['text']
  139.             local x,y,w,h = v['pos']['x'],v['pos']['y'],v['pos']['w'],v['pos']['h']
  140.             local color = v['color']
  141.             --dxDrawRoundedRectangle(x,y,w,h,color,h/2)
  142.  
  143.             local r = bitExtract ( color, 0, 8 )
  144.             local g = bitExtract ( color, 8, 8 )
  145.             local b = bitExtract ( color, 16, 8 )
  146.             local a = bitExtract ( color, 24, 8 )
  147.  
  148.            -- if v['iconPath'] then
  149.              --   dxDrawImage(x-h + sx*02/1920,y,h,h,v['iconPath'],0,0,0,tocolor(255,255,255,a),true)
  150.             --end
  151.  
  152.             --drawEditboxHovered(x,y,w,h,color)
  153.           --  dxDrawRectangle(x,y,w,h,color,true)
  154.             if v['state']==true then
  155.                 dxDrawImage(x,y,w,h,texture,0,0,0,color,true)
  156.             else
  157.                 dxDrawImage(x,y,w,h,texture_empty,0,0,0,color,true)
  158.             end
  159.             local preparedText = v['hashed'] and string.gsub(text,".","•") or text
  160.  
  161.             local alignX = dxGetTextWidth(preparedText,0.8,v['font']) <= w and "left" or "right"
  162.             local width=dxGetTextWidth(preparedText,0.8,v['font'])
  163.  
  164.             local text_color = v['state'] == true and tocolor(255,255,0,a) or tocolor(255,255,255,a)
  165.  
  166.  
  167.             if text == '' and v['state']==false then
  168.                 prepared_text(v['startText'],x+(w/10),y-20/scale,w-30/scale,h,text_color,v['font'],'left')
  169.             else
  170.                 prepared_text(preparedText,x+15/scale,y,w-30/scale,h,text_color,v['font'],alignX)
  171.                 prepared_text(v['startText'],x+(w/10),y-20/scale,w-30/scale,h,text_color,v['font'],'left')
  172.             end
  173.            
  174.             if v['state']==true then
  175.                 local alpha = interpolateBetween(100,0,0,255,0,0,(getTickCount()-tick)/1000, "SineCurve")
  176.                 dxDrawLine(x+width + 15,y + 05,x+width + 15,y+h - 05,tocolor(175,238,238,alpha),1,true)
  177.             end
  178.         end
  179.     end
  180.  
  181.  
  182.     if getKeyState("backspace") then
  183.         for k,v in pairs(editboxes) do
  184.             if v['visible'] and v['state'] then
  185.                 if not keyState then
  186.                     keyState = getTickCount() + 400
  187.                     v['text'] = string.sub(v['text'],1,string.len(v['text'])-1)
  188.                 elseif keyState and keyState < getTickCount() then
  189.                     keyState = getTickCount()+100
  190.                     v['text'] = string.sub(v['text'],1,string.len(v['text'])-1)
  191.                 end
  192.                 return
  193.             end
  194.         end
  195.         keyState = nil
  196.     end
  197.  
  198. end)
  199.  
  200. dxCreateEditbox=function(x,y,w,h,color,font,startText,maxLenght,iconPath)
  201.     table.insert(editboxes,{
  202.         ['pos']={
  203.             ['x']=x,
  204.             ['y']=y,
  205.             ['w']=w,
  206.             ['h']=h,
  207.         },
  208.         ['color']=color,
  209.         ['font']=dxGetFont(font),
  210.         ['startText']=startText,
  211.         ['text']='',
  212.         ['state']=false,
  213.         ['onlyLetters']=false,
  214.         ['onlyNumbers']=false,
  215.         ['hashed']=false,
  216.         ['visible']=true,
  217.         ['maxLenght']=maxLenght,
  218.        
  219.     })
  220.     return #editboxes
  221. end
  222.  
  223. dxEditboxSetColor=function(editbox,color)
  224.     for i,v in ipairs(editboxes) do
  225.         if i==editbox then
  226.             v['color'] = color
  227.         end
  228.     end
  229. end
  230.  
  231. dxEditboxSetPosition = function(editbox,x,y,w,h)
  232.     for i,v in ipairs(editboxes) do
  233.         if i==editbox then
  234.             v['pos']['x']=x
  235.             v['pos']['y']=y
  236.             v['pos']['w']=w
  237.             v['pos']['h']=h
  238.         end
  239.     end
  240. end
  241.  
  242.  
  243.  
  244.  
  245. dxDestroyEditbox = function(editbox)
  246.     for i,v in ipairs(editboxes) do
  247.         if i==editbox then
  248.             if v['state']==true then
  249.                 v['state']=false
  250.                 guiSetInputEnabled(false)
  251.             end
  252.             table.remove(editboxes,i)
  253.         end
  254.     end
  255. end
  256.  
  257. dxEditboxSetStartText=function(editbox,string)
  258.     for i,v in ipairs(editboxes) do
  259.         if i==editbox then
  260.             v['startText']=string
  261.         end
  262.     end
  263. end
  264.  
  265. dxEditboxSetVisible=function(editbox,bool)
  266.     for i,v in ipairs(editboxes) do
  267.         if i==editbox then
  268.             v['visible']=bool
  269.         end
  270.     end
  271. end
  272.  
  273. dxEditboxSetInputMode=function(editbox,string,bool)
  274.     for i,v in ipairs(editboxes) do
  275.         if i==editbox then
  276.             if string=='onlyLetters' then
  277.                 v['onlyLetters']=bool
  278.             elseif string=='onlyNumbers' then
  279.                 v['onlyNumbers']=bool
  280.             elseif string=='hashed' then
  281.                 v['hashed']=bool
  282.             end
  283.         end
  284.     end
  285. end
  286.  
  287. dxEditboxSetText=function(editbox,string)
  288.     for i,v in ipairs(editboxes) do
  289.         if i==editbox then
  290.             v['text']=string
  291.         end
  292.     end
  293. end
  294.  
  295. dxEditboxGetText=function(editbox)
  296.     for i,v in ipairs(editboxes) do
  297.         if i==editbox then
  298.             return v['text']
  299.         end
  300.     end
  301. end
  302.  
  303. dxGetEditboxByStartText=function(string)
  304.     for i,v in ipairs(editboxes) do
  305.         if v['startText']==string then
  306.             return i
  307.         end
  308.     end
  309. end
  310. --[[
  311. local edit1 = dxCreateEditbox(0, 0, 200, 50, tocolor(33,33,33,255), 'default', 'hej', 5)
  312. local edit2 = dxCreateEditbox(0, 0+100, 200, 50, tocolor(33,33,33,255), 'default', 'hej2', 5)
  313. dxEditboxSetVisible(edit2, false)]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement