Advertisement
HangMan23

WriteFieldUIv2

Mar 19th, 2019
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. local x, y, w, text, filter, evf = table.unpack({...})
  2. local EU = require("ExtraUtilits")
  3. local gpu = require("component").gpu
  4. local unicode = require("unicode")
  5.  
  6. local reason = false
  7.  
  8. local function wind()
  9.  
  10. gpu.setBackground(0x323232)
  11. gpu.fill(x, y, w + 2, 3, " ")
  12.  
  13. if text then
  14.  
  15. gpu.setForeground(0x00ffff)
  16. gpu.set(x, y, text)
  17.  
  18. end
  19.  
  20. gpu.setBackground(0x161616)
  21. gpu.fill(x + 1, y + 1, w, 1, " ")
  22.  
  23. end
  24.  
  25. local buttons = {
  26. {x + w + 2 - 5, y + 2, 4, 1, 2499366, 15563520, "OK"}
  27. }
  28.  
  29. local text = ""
  30.  
  31. local function filtrate(byte, filter)
  32.  
  33. local char = unicode.char(byte)
  34.  
  35. if not filter then
  36.  
  37. if byte >= 21 and byte <= 126 or byte >= 1040 and byte <= 1103 then
  38.  
  39. return char
  40.  
  41. end
  42.  
  43. elseif filter == "number" then
  44.  
  45. if tonumber(char) then
  46.  
  47. return tonumber(char)
  48.  
  49. end
  50.  
  51. elseif filter == "string" then
  52.  
  53. if tonumber(char) == nil then
  54.  
  55. if byte <= 21 and byte <= 126 or byte >= 1040 and byte <= 1103 then
  56.  
  57. return char
  58.  
  59. end
  60.  
  61. end
  62.  
  63. end
  64.  
  65. end
  66.  
  67. local function drawText()
  68.  
  69. if gpu.getBackground ~= 0x161616 then gpu.setBackground(0x161616) end
  70. if gpu.getForeground ~= 0x00ffff then gpu.setForeground(0x00ffff) end
  71.  
  72. local visible_text = string.sub(text, -w)
  73.  
  74. gpu.fill(x+1, y+1, w, 1, " ")
  75. gpu.set(x + 1, y + 1, visible_text)
  76.  
  77. end
  78.  
  79. buttons.eventFunc = function(ev)
  80.  
  81. local eventType = ev[1]
  82.  
  83. if eventType == "key_down" then
  84.  
  85. local eventType, _, key = table.unpack(ev)
  86.  
  87. if key == 9 then buttons.close = true reason = "closed" elseif key == 13 then buttons.close = true elseif key == 8 then text = string.sub(text, 0, -2) else
  88.  
  89. local char = filtrate(key, filter)
  90.  
  91. if char then text = text .. char end
  92.  
  93. end
  94.  
  95. drawText()
  96.  
  97. end
  98.  
  99. end
  100.  
  101. buttons[1][8] = function()
  102.  
  103. buttons.close = true
  104.  
  105. end
  106.  
  107. EU.screenBackup(function()
  108.  
  109. wind()
  110. EU.draw(buttons)
  111. EU.buttonPress(buttons)
  112.  
  113. end)
  114.  
  115. if not reason then
  116.  
  117. if filter == "number" then
  118.  
  119. text = tonumber(text)
  120.  
  121. end
  122.  
  123. return text
  124.  
  125. else
  126.  
  127. return nil, reason
  128.  
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement