mrWhiskasss

либа волосатика

Oct 31st, 2024
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. local oc = {}
  2. local component = require("component")
  3. local s = require("serialization")
  4. local unicode = require("unicode")
  5. local g = component.gpu -- +++
  6. local CTEXT = 0xD38FFE -- осн текст ++
  7.  
  8. function oc.right(x,y,text) -- центровка по правому краю
  9. local _, n = string.gsub(text, "&", "")
  10. local l = unicode.len(text) - n * 2
  11. oc.text(x-l, y, text)
  12. end
  13.  
  14. function oc.text(x,y,text) --Цветной текст +++
  15. local n = 1
  16. for i = 1, unicode.len(text) do
  17. if unicode.sub(text, i,i) == "&" then
  18. oc.setColor(unicode.sub(text, i + 1, i + 1))
  19. elseif unicode.sub(text, i - 1, i - 1) ~= "&" then
  20. g.set(x+n,y, unicode.sub(text, i,i))
  21. n = n + 1
  22. end
  23. end
  24. g.setForeground(CTEXT)
  25. end
  26.  
  27. function oc.setColor(index) --Список цветов +++
  28. if (index ~= "r") then back = g.getForeground() end
  29. if (index == "0") then g.setForeground(0x333333) end
  30. if (index == "1") then g.setForeground(0x0000ff) end
  31. if (index == "2") then g.setForeground(0x00ff00) end
  32. if (index == "3") then g.setForeground(0x24b3a7) end
  33. if (index == "4") then g.setForeground(0xff0000) end
  34. if (index == "5") then g.setForeground(0x8b00ff) end
  35. if (index == "6") then g.setForeground(0xffa500) end
  36. if (index == "7") then g.setForeground(0xbbbbbb) end
  37. if (index == "8") then g.setForeground(0x808080) end
  38. if (index == "9") then g.setForeground(0x0000ff) end
  39. if (index == "a") then g.setForeground(0x66ff66) end
  40. if (index == "b") then g.setForeground(0x00ffff) end
  41. if (index == "c") then g.setForeground(0xff6347) end
  42. if (index == "d") then g.setForeground(0xff00ff) end
  43. if (index == "e") then g.setForeground(0xffff00) end
  44. if (index == "f") then g.setForeground(0xffffff) end
  45. if (index == "g") then g.setForeground(0x00ff00) end
  46. if (index == "r") then g.setForeground(back) end
  47. end
  48.  
  49. function oc.savef(cd,data) -- сохранение переменной в файл +++
  50. local file = io.open("/home/"..cd, "w")
  51. file:write(s.serialize(data))
  52. file:close()
  53. end
  54.  
  55. function oc.loadf(cd) -- загрузка в переменную из файла +++
  56. local file = io.open("/home/"..cd, "r")
  57. local str = s.unserialize(file:read("*a"))
  58. file:close()
  59. return str
  60. end
  61.  
  62. function oc.drawbutton(x,y,w,h,col1,col2,text) -- отрисовка кнопки // +++
  63. g.setForeground(col1)
  64. g.set(x + w/2 - unicode.len(text)/2, y+h/2, text)
  65. if col2 then
  66. g.setForeground(col2)
  67. for i = 1, w-2 do
  68. g.set(x+i,y,"─")
  69. g.set(x+i,y+h-1,"─")
  70. end
  71. for i = 1, h-2 do
  72. g.set(x,y+i,"│")
  73. g.set(x+w-1,y+i,"│")
  74. end
  75. g.set(x,y,"┌")
  76. g.set(x+w-1,y,"┐")
  77. g.set(x,y+h-1,"└")
  78. g.set(x+w-1,y+h-1,"┘")
  79. end
  80. g.setForeground(CTEXT)
  81. end
  82.  
  83. function oc.drawscroll(x,y,w,h,scroll,maxh,col1,col2) -- отрисовка скролла // ++
  84. local lenght = 1
  85. g.setBackground(col1)
  86. g.fill(x, y, w, h, " ")
  87. g.setBackground(col2)
  88. if h < maxh then
  89. lenght = h * (h / maxh)
  90. scroll = math.ceil((scroll-1) * (h/maxh))
  91. else
  92. lenght = h
  93. scroll = scroll - 1
  94. end
  95. g.fill(x,y+scroll,w,lenght, " ")
  96. g.setBackground(0x000000)
  97. end
  98.  
  99. return oc
Advertisement
Add Comment
Please, Sign In to add comment