CR14T1V3

Untitled

Mar 27th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. local mon = peripheral.wrap("top")
  2. mon.setTextScale(1)
  3. mon.setTextColor(colors.white)
  4. local button={}
  5. mon.setBackgroundColor(colors.black)
  6.  
  7. function setTable(name, func, xmin, xmax, ymin, ymax)
  8. button[name] = {}
  9. button[name]["func"] = func
  10. button[name]["active"] = false
  11. button[name]["xmin"] = xmin
  12. button[name]["ymin"] = ymin
  13. button[name]["xmax"] = xmax
  14. button[name]["ymax"] = ymax
  15. end
  16.  
  17. function funcName()
  18. print("You clicked buttonText")
  19. end
  20.  
  21. function fillTable()
  22. setTable("ButtonText", funcName, 5, 25, 4, 8)
  23. end
  24.  
  25. function fill(text, color, bData)
  26. mon.setBackgroundColor(color)
  27. local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  28. local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  29. for j = bData["ymin"], bData["ymax"] do
  30. mon.setCursorPos(bData["xmin"], j)
  31. if j == yspot then
  32. for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  33. if k == xspot then
  34. mon.write(text)
  35. else
  36. mon.write(" ")
  37. end
  38. end
  39. else
  40. for i = bData["xmin"], bData["xmax"] do
  41. mon.write(" ")
  42. end
  43. end
  44. end
  45. mon.setBackgroundColor(colors.black)
  46. end
  47.  
  48. function screen()
  49. local currColor
  50. for name,data in pairs(button) do
  51. local on = data["active"]
  52. if on == true then currColor = colors.lime else currColor = colors.red end
  53. fill(name, currColor, data)
  54. end
  55. end
  56.  
  57. function toggleButton(name)
  58. button[name]["active"] = not button[name]["active"]
  59. screen()
  60. end
  61.  
  62. function flash(name)
  63. toggleButton(name)
  64. screen()
  65. sleep(0.15)
  66. toggleButton(name)
  67. screen()
  68. end
  69.  
  70. function checkxy(x, y)
  71. for name, data in pairs(button) do
  72. if y>=data["ymin"] and y <= data["ymax"] then
  73. if x>=data["xmin"] and x<= data["xmax"] then
  74. data["func"]()
  75. return true
  76. --data["active"] = not data["active"]
  77. --print(name)
  78. end
  79. end
  80. end
  81. return false
  82. end
  83.  
  84. function heading(text)
  85. w, h = mon.getSize()
  86. mon.setCursorPos((w-string.len(text))/2+1, 1)
  87. mon.write(text)
  88. end
  89.  
  90. function label(w, h, text)
  91. mon.setCursorPos(w, h)
  92. mon.write(text)
  93. end
Add Comment
Please, Sign In to add comment