Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. --Originally coded by Direwolf20, this version has been modified by Julian B., @langeweile1533, Copyyy
  2. local mon = peripheral.wrap("back")
  3. mon.setTextScale(1)
  4. mon.setTextColor(colors.white)
  5. local button={}
  6. mon.setBackgroundColor(colors.black)
  7.  
  8. function load()
  9. local file = fs.open("reactor", "r")
  10. if not file then return; end
  11. loaddata = textutils.unserialize(file.readAll())
  12. for name, active in pairs(loaddata) do
  13. if not button[name]["active"] == active then
  14. button[name]["func"]()
  15. end
  16.  
  17. end
  18. file.close()
  19. screen()
  20. end
  21. function clearTable()
  22. button = {}
  23. end
  24.  
  25. function setTable(name, func, param, xmin, xmax, ymin, ymax)
  26. button[name] = {}
  27. button[name]["func"] = func
  28. button[name]["active"] = false
  29. button[name]["param"] = param
  30. button[name]["xmin"] = xmin
  31. button[name]["ymin"] = ymin
  32. button[name]["xmax"] = xmax
  33. button[name]["ymax"] = ymax
  34. end
  35.  
  36. function active(name1)
  37. for name, data in pairs(button) do
  38. if name == name1 then
  39. return data["active"]
  40. end
  41. end
  42. end
  43. function funcName()
  44. print("You clicked buttonText")
  45. end
  46.  
  47. function fillTable()
  48. setTable("ButtonText", funcName, 5, 25, 4, 8)
  49. end
  50.  
  51. function fill(text, color, bData)
  52. mon.setBackgroundColor(color)
  53. local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  54. local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  55. for j = bData["ymin"], bData["ymax"] do
  56. mon.setCursorPos(bData["xmin"], j)
  57. if j == yspot then
  58. for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  59. if k == xspot then
  60. mon.write(text)
  61. else
  62. mon.write(" ")
  63. end
  64. end
  65. else
  66. for i = bData["xmin"], bData["xmax"] do
  67. mon.write(" ")
  68. end
  69. end
  70. end
  71. mon.setBackgroundColor(colors.black)
  72. end
  73.  
  74. function screen()
  75. local currColor
  76. for name,data in pairs(button) do
  77. local on = data["active"]
  78. if on == true then currColor = colors.lime else currColor = colors.red end
  79. fill(name, currColor, data)
  80. end
  81. end
  82.  
  83. function save()
  84. local file = fs.open("debitorreactor", "w")
  85. local savedata = { }
  86. for name,data in pairs(button) do
  87. local on = data["active"]
  88. if on == true then
  89. active = "true"
  90. else
  91. active = "false"
  92. end
  93. savedata[name] = on
  94. end
  95. file.write(textutils.serialize(savedata))
  96. file.close()
  97.  
  98. end
  99.  
  100. function toggleButton(name)
  101. button[name]["active"] = not button[name]["active"]
  102. screen()
  103. end
  104.  
  105. function flash(name)
  106. toggleButton(name)
  107. screen()
  108. sleep(0.15)
  109. toggleButton(name)
  110. screen()
  111. end
  112.  
  113. function checkxy(x, y)
  114. for name, data in pairs(button) do
  115. if y>=data["ymin"] and y <= data["ymax"] then
  116. if x>=data["xmin"] and x<= data["xmax"] then
  117. if data["param"] == "" then
  118. data["func"]()
  119. else
  120. data["func"](data["param"])
  121. end
  122. save()
  123. return true
  124. --data["active"] = not data["active"]
  125. --print(name)
  126. end
  127. end
  128. end
  129. return false
  130. end
  131.  
  132. function heading(text)
  133. w, h = mon.getSize()
  134. mon.setCursorPos((w-string.len(text))/2+1, 1)
  135. mon.write(text)
  136. end
  137.  
  138. function label(w, h, text)
  139. mon.setCursorPos(w, h)
  140. mon.write(text)
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement