Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function Inrange( v, min, max )
- return ( ( v >= min ) and ( v <= max ) )
- end
- local left_border_offset = 40
- local char_w = 7
- local char_h = 20
- local ForceErase = false
- local F = vgui.Create('DFrame')
- F:SetSize(500, 500)
- F:Center()
- F:SetTitle('ENTITY FIRMWARE (VERTEX JSON SCRIPT)')
- F:SetSizable(true)
- F:MakePopup()
- F.TextField = vgui.Create('Panel', F)
- F.TextField:Dock(FILL)
- F.TextField.TEXT = 'lol kek\nchaburek\nYA EBU SOBAAAAAAAAAAAAK'
- F.TextField.CaretPos = { 1, 1 }
- F.TextField.Scroll = { 0, 0 }
- F.TextField.DirectPos = 1
- local function pasteSymbol(c)
- local A = string.Explode('\n', F.TextField.TEXT)
- local B = { }
- for i, kv in pairs(A) do
- local chars = string.Explode('', kv)
- table.insert(B, chars)
- end
- table.insert(B[F.TextField.CaretPos[2]], F.TextField.CaretPos[1], c)
- local tmp = ''
- for i, kv in pairs(B) do
- local strline = table.concat(kv, '')
- tmp = tmp .. strline .. ( i < #B and '\n' or '' )
- end
- F.TextField.TEXT = tmp
- F.TextField.CaretPos[1] = (c == ' ') and F.TextField.CaretPos[1] + 4 or F.TextField.CaretPos[1] + 1
- end
- local function getTextTable()
- local A = string.Explode('\n', F.TextField.TEXT)
- local B = { }
- for i, kv in pairs(A) do
- local chars = string.Explode('', kv)
- table.insert(B, chars)
- end
- return B
- end
- local function backToText(t)
- local tmp = ''
- for i, kv in pairs(t) do
- local strline = table.concat(kv, '')
- tmp = tmp .. strline .. ( i < #t and '\n' or '' )
- end
- F.TextField.TEXT = tmp
- end
- local function caretLeft()
- if F.TextField.CaretPos[1]-1 < 1 and F.TextField.CaretPos[2]-1 > 0 then
- local t = getTextTable()
- local prevT = table.concat(t[F.TextField.CaretPos[2]-1], '')
- F.TextField.CaretPos[1] = string.len(prevT)+1
- F.TextField.CaretPos[2] = F.TextField.CaretPos[2] - 1
- else
- F.TextField.CaretPos = {F.TextField.CaretPos[1]-1, F.TextField.CaretPos[2]}
- end
- end
- local function caretRight()
- local t = getTextTable()
- if F.TextField.CaretPos[2] < #t+1 then
- local prevT = table.concat(t[F.TextField.CaretPos[2]], '')
- if F.TextField.CaretPos[1] > string.len(prevT) and F.TextField.CaretPos[2] < #t then
- F.TextField.CaretPos[1] = 1
- F.TextField.CaretPos[2] = F.TextField.CaretPos[2] + 1
- elseif F.TextField.CaretPos[1] < string.len(prevT)+1 then
- F.TextField.CaretPos = {F.TextField.CaretPos[1]+1, F.TextField.CaretPos[2]}
- end
- end
- end
- local function erasing()
- if input.IsKeyDown(KEY_BACKSPACE) then
- ForceErase = true
- timer.Stop('ERASER')
- end
- end
- timer.Create('ERASER', 0.5, 0, erasing )
- timer.Stop('ERASER')
- local function deleteSymbol(caretX, caretY)
- -- берём текущую строку, и удаляем из неё символ
- local tt = getTextTable()
- local T = tt[caretY]
- local T2 = tt[caretY-1]
- local BOOL = caretY > 1 and caretX-1 > -1 or caretX-1 > 0
- if BOOL then
- table.remove(T, caretX-1)
- tt[caretY] = T
- caretLeft()
- if caretX == 1 then
- table.Add(T2, T)
- tt[caretY] = T2
- table.remove(tt, caretY)
- end
- backToText(tt)
- end
- end
- F.TextField.Keys = {
- [1] = '0';
- [2] = '1';
- [3] = '2';
- [4] = '3';
- [5] = '4';
- [6] = '5';
- [7] = '6';
- [8] = '7';
- [9] = '8';
- [10] = '9';
- [11] = 'a';
- [12] = 'b';
- [13] = 'c';
- [14] = 'd';
- [15] = 'e';
- [16] = 'f';
- [17] = 'g';
- [18] = 'h';
- [19] = 'i';
- [20] = 'j';
- [21] = 'k';
- [22] = 'l';
- [23] = 'm';
- [24] = 'n';
- [25] = 'o';
- [26] = 'p';
- [27] = 'q';
- [28] = 'r';
- [29] = 's';
- [30] = 't';
- [31] = 'u';
- [32] = 'v';
- [33] = 'w';
- [34] = 'x';
- [35] = 'y';
- [36] = 'z';
- [53] = '[';
- [54] = ']';
- [55] = ';';
- [56] = "'";
- [60] = '/';
- [58] = ',';
- [59] = '.';
- [61] = '\\';
- [62] = '-';
- [63] = '=';
- [64] = '\n';
- [65] = ' ';
- [67] = ' ';
- }
- F.TextField.ShiftKeys = {
- [1] = ')';
- [2] = '!';
- [3] = '@';
- [4] = '#';
- [5] = '$';
- [6] = '%';
- [7] = '^';
- [8] = '&';
- [9] = '*';
- [10] = '(';
- [62] = '_';
- [63] = '+';
- [53] = '{';
- [55] = ':';
- [56] = '"';
- [58] = '<';
- [59] = '>';
- [54] = '}';
- [60] = '?';
- [61] = '|';
- }
- F.TextField.Paint = function(self, w, h)
- draw.RoundedBox(5, 0, 0, w, h, Color(25, 25, 25))
- draw.NoTexture()
- surface.SetTextColor( 255, 255, 255, 255 )
- surface.SetFont('DermaDefault')
- local s = string.Explode('\n', self.TEXT)
- local lnc = 0
- draw.NoTexture()
- surface.SetDrawColor(70, 70, 70, 255)
- surface.DrawRect(5, 0, left_border_offset-10, h)
- for id, line in pairs(s) do
- surface.SetTextPos(10, 20+id*char_h - char_h)
- surface.DrawText(tostring(id))
- for ID, char in pairs(string.Explode('', line)) do
- lnc = lnc + 1
- surface.SetTextPos(left_border_offset+ID*char_w - char_w, 20+id*char_h - char_h)
- surface.DrawText(char)
- end
- end
- draw.NoTexture()
- surface.SetDrawColor( 255, 255, 255, 255+math.sin(CurTime()*5)*255 )
- surface.DrawRect( self.CaretPos[1]*char_w + left_border_offset - char_w, self.CaretPos[2]*char_h, 2, 10 )
- // little thinking
- if ForceErase then
- deleteSymbol(F.TextField.CaretPos[1], F.TextField.CaretPos[2])
- end
- end
- F.TextField.OnMousePressed = function(self, mcode)
- local s = string.Explode('\n', self.TEXT)
- if mcode == MOUSE_LEFT then
- local x, y = self:LocalCursorPos()
- for id = 0, #s do
- local line = s[id == 0 and 1 or id]
- for ID = 0, #string.Explode('', line) do
- local char = string.Explode('', line)[ID]
- local x___lastSymbol = ID < #line and ( left_border_offset+(ID*char_w)+char_w*1.5 ) or ( self:GetWide() - left_border_offset+(ID*char_w)-char_w/2 )
- if Inrange( x, left_border_offset+(ID*char_w)-char_w/2, x___lastSymbol ) and Inrange( y, (id*char_h), (id*char_h)+char_h ) then
- F.TextField.CaretPos = { ID+1, id } -- x, y
- F.DirectPos = id*ID
- end
- end
- end
- self:RequestFocus()
- --self:SetSelected(true)
- --self:MakePopup()
- end
- end
- F.TextField.OnKeyCodePressed = function(self, key)
- chat.AddText(''..key)
- for i, VAL in pairs(self.Keys) do
- if key == i then
- if input.IsKeyDown(KEY_LSHIFT) then
- if self.ShiftKeys[i] != nil then
- pasteSymbol(self.ShiftKeys[i])
- else
- pasteSymbol(string.upper(VAL))
- end
- else
- pasteSymbol(VAL)
- end
- end
- if key == 64 and i == 64 then
- F.TextField.CaretPos = {1, F.TextField.CaretPos[2]+1}
- end
- if key == 89 and i == 1 then
- caretLeft()
- end
- if key == 91 and i == 1 then
- caretRight()
- end
- if key == 67 and i == 1 then
- self:StartBoxSelection()
- end
- if key == 66 and i == 1 then
- deleteSymbol(F.TextField.CaretPos[1], F.TextField.CaretPos[2])
- timer.Start('ERASER')
- end
- end
- end
- F.TextField.OnKeyCodeReleased = function(self, key)
- if key == 66 then
- ForceErase = false
- timer.Stop('ERASER')
- end
- end
- --btn.isEditing = true
- F.OnClose = function()
- -- ~~
- timer.Remove('ERASER')
- --btn.isEditing = false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement