Advertisement
Guest User

Untitled

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