Advertisement
Guest User

Untitled

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