Advertisement
Guest User

Untitled

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