Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- autor: Pat
- Nie zezwalam na używanie skryptu bez mojej zgody
- kontakt: igormeger@gmail.com
- ]]
- editboxes={}
- local sx,sy = guiGetScreenSize()
- local scale = 1920 / sx
- local tick = getTickCount()
- local prepared_text =function(text,x,y,w,h,color,font,alignX)
- dxDrawText(text,x,y,w+x,h+y,color,0.8,font,alignX,"center",true,false,true,false,false)
- end
- local texture = dxCreateTexture('images/editbox_h.png', 'argb', false, 'clamp')
- local texture_empty = dxCreateTexture('images/editbox.png', 'argb', false, 'clamp')
- --[[drawEditboxHovered=function(x,y,w,h,color)
- local circle1Pos = (w+x)-h
- local circle2Pos = (x+h)-h
- dxDrawImage(circle1Pos,y,h,h,texture_full, 180, 0, 0, color,true)
- dxDrawImage(circle2Pos,y,h,h,texture_full, 0, 0, 0, color,true)
- --dxDrawRectangle(x+(h/2) - 2,y,w-(h) + 4,h, color)
- dxDrawRectangle(circle2Pos + h/2,y,w - h,h,color,true)
- end --]]
- drawEditboxHovered=function(x,y,w,h,color)
- dxDrawImage(x,y,h,h,texture,0,0,0,color,true)
- dxDrawRectangle(x+h/2 - h/40,y,w-h + h/25,h,color,true)
- dxDrawImage(x+w - h,y,h,h,texture,180,0,0,color,true)
- end
- getAnyStates=function()
- local state = 0
- for i,v in ipairs(editboxes) do
- if v['state'] then
- state=state+1
- end
- end
- return state>0 and true or false
- end
- addEventHandler('onClientClick',root,function(b,s)
- if b=='left' and s=='down' then
- for i,v in ipairs(editboxes) do
- local text=v['text']
- local x,y,w,h = v['pos']['x'],v['pos']['y'],v['pos']['w'],v['pos']['h']
- local color = v['color']
- --v['state']=false
- if isMouseInPosition(x,y,w,h) and v['visible'] then
- v['state']=not v['state']
- if v['state']==true then
- guiSetInputEnabled(true)
- else
- guiSetInputEnabled(false)
- end
- else
- v['state']=false
- if not getAnyStates() then
- guiSetInputEnabled(false)
- end
- end
- end
- end
- end )
- local numbers = {
- ["0"] = true,
- ["1"] = true,
- ["2"] = true,
- ["3"] = true,
- ["4"] = true,
- ["5"] = true,
- ["6"] = true,
- ["7"] = true,
- ["8"] = true,
- ["9"] = true,
- }
- local letters={
- ['a']=true,
- ['b']=true,
- ['c']=true,
- ['d']=true,
- ['e']=true,
- ['f']=true,
- ['g']=true,
- ['h']=true,
- ['i']=true,
- ['j']=true,
- ['k']=true,
- ['l']=true,
- ['m']=true,
- ['n']=true,
- ['o']=true,
- ['p']=true,
- ['r']=true,
- ['s']=true,
- ['t']=true,
- ['u']=true,
- ['w']=true,
- ['y']=true,
- ['x']=true,
- ['z']=true,
- ['q']=true,
- -- polskie litery
- ['ę']=true,
- ['ó']=true,
- ['ą']=true,
- ['ś']=true,
- ['ł']=true,
- ['ż']=true,
- ['ź']=true,
- ['ć']=true,
- ['ń']=true,
- }
- addEventHandler('onClientCharacter',root,function(key)
- for i,v in ipairs(editboxes) do
- if v['state'] == true then
- if (string.len(v['text'])) >= v['maxLenght'] then return end
- if v['onlyNumbers'] and not numbers[key] then return end
- if v['onlyLetters'] and not letters[key] then return end
- v['text']=v['text'] .. key
- end
- end
- end)
- local sx,sy=guiGetScreenSize()
- addEventHandler('onClientRender',root,function()
- for i,v in ipairs(editboxes) do
- if v['visible'] then
- local text=v['text']
- local x,y,w,h = v['pos']['x'],v['pos']['y'],v['pos']['w'],v['pos']['h']
- local color = v['color']
- --dxDrawRoundedRectangle(x,y,w,h,color,h/2)
- local r = bitExtract ( color, 0, 8 )
- local g = bitExtract ( color, 8, 8 )
- local b = bitExtract ( color, 16, 8 )
- local a = bitExtract ( color, 24, 8 )
- -- if v['iconPath'] then
- -- dxDrawImage(x-h + sx*02/1920,y,h,h,v['iconPath'],0,0,0,tocolor(255,255,255,a),true)
- --end
- --drawEditboxHovered(x,y,w,h,color)
- -- dxDrawRectangle(x,y,w,h,color,true)
- if v['state']==true then
- dxDrawImage(x,y,w,h,texture,0,0,0,color,true)
- else
- dxDrawImage(x,y,w,h,texture_empty,0,0,0,color,true)
- end
- local preparedText = v['hashed'] and string.gsub(text,".","•") or text
- local alignX = dxGetTextWidth(preparedText,0.8,v['font']) <= w and "left" or "right"
- local width=dxGetTextWidth(preparedText,0.8,v['font'])
- local text_color = v['state'] == true and tocolor(255,255,0,a) or tocolor(255,255,255,a)
- if text == '' and v['state']==false then
- prepared_text(v['startText'],x+(w/10),y-20/scale,w-30/scale,h,text_color,v['font'],'left')
- else
- prepared_text(preparedText,x+15/scale,y,w-30/scale,h,text_color,v['font'],alignX)
- prepared_text(v['startText'],x+(w/10),y-20/scale,w-30/scale,h,text_color,v['font'],'left')
- end
- if v['state']==true then
- local alpha = interpolateBetween(100,0,0,255,0,0,(getTickCount()-tick)/1000, "SineCurve")
- dxDrawLine(x+width + 15,y + 05,x+width + 15,y+h - 05,tocolor(175,238,238,alpha),1,true)
- end
- end
- end
- if getKeyState("backspace") then
- for k,v in pairs(editboxes) do
- if v['visible'] and v['state'] then
- if not keyState then
- keyState = getTickCount() + 400
- v['text'] = string.sub(v['text'],1,string.len(v['text'])-1)
- elseif keyState and keyState < getTickCount() then
- keyState = getTickCount()+100
- v['text'] = string.sub(v['text'],1,string.len(v['text'])-1)
- end
- return
- end
- end
- keyState = nil
- end
- end)
- dxCreateEditbox=function(x,y,w,h,color,font,startText,maxLenght,iconPath)
- table.insert(editboxes,{
- ['pos']={
- ['x']=x,
- ['y']=y,
- ['w']=w,
- ['h']=h,
- },
- ['color']=color,
- ['font']=dxGetFont(font),
- ['startText']=startText,
- ['text']='',
- ['state']=false,
- ['onlyLetters']=false,
- ['onlyNumbers']=false,
- ['hashed']=false,
- ['visible']=true,
- ['maxLenght']=maxLenght,
- })
- return #editboxes
- end
- dxEditboxSetColor=function(editbox,color)
- for i,v in ipairs(editboxes) do
- if i==editbox then
- v['color'] = color
- end
- end
- end
- dxEditboxSetPosition = function(editbox,x,y,w,h)
- for i,v in ipairs(editboxes) do
- if i==editbox then
- v['pos']['x']=x
- v['pos']['y']=y
- v['pos']['w']=w
- v['pos']['h']=h
- end
- end
- end
- dxDestroyEditbox = function(editbox)
- for i,v in ipairs(editboxes) do
- if i==editbox then
- if v['state']==true then
- v['state']=false
- guiSetInputEnabled(false)
- end
- table.remove(editboxes,i)
- end
- end
- end
- dxEditboxSetStartText=function(editbox,string)
- for i,v in ipairs(editboxes) do
- if i==editbox then
- v['startText']=string
- end
- end
- end
- dxEditboxSetVisible=function(editbox,bool)
- for i,v in ipairs(editboxes) do
- if i==editbox then
- v['visible']=bool
- end
- end
- end
- dxEditboxSetInputMode=function(editbox,string,bool)
- for i,v in ipairs(editboxes) do
- if i==editbox then
- if string=='onlyLetters' then
- v['onlyLetters']=bool
- elseif string=='onlyNumbers' then
- v['onlyNumbers']=bool
- elseif string=='hashed' then
- v['hashed']=bool
- end
- end
- end
- end
- dxEditboxSetText=function(editbox,string)
- for i,v in ipairs(editboxes) do
- if i==editbox then
- v['text']=string
- end
- end
- end
- dxEditboxGetText=function(editbox)
- for i,v in ipairs(editboxes) do
- if i==editbox then
- return v['text']
- end
- end
- end
- dxGetEditboxByStartText=function(string)
- for i,v in ipairs(editboxes) do
- if v['startText']==string then
- return i
- end
- end
- end
- --[[
- local edit1 = dxCreateEditbox(0, 0, 200, 50, tocolor(33,33,33,255), 'default', 'hej', 5)
- local edit2 = dxCreateEditbox(0, 0+100, 200, 50, tocolor(33,33,33,255), 'default', 'hej2', 5)
- dxEditboxSetVisible(edit2, false)]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement