DarkSiders061

test sp

May 8th, 2024
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. --Look throughout the code for comments like this. They explain what to do to change things.
  2.  
  3. --What side the monitor will be on (change this if needed)
  4. side = "top"
  5.  
  6.  
  7.  
  8. m = peripheral.wrap(side)
  9.  
  10.  
  11. --button on/off color
  12. bactive = colors.cyan
  13. binactive=colors.gray
  14. --text on/off color
  15. tactive=colors.white
  16. tinactive=colors.black
  17. --Background color
  18. bgcolor = colors.black
  19.  
  20.  
  21. buttons = {}
  22.  
  23.  
  24.  
  25. function newButton(id,xmin,xmax,ymin,ymax,text,func)
  26. buttons[id] = {}
  27. buttons[id]["xmin"] = xmin
  28. buttons[id]["xmax"] = xmax
  29. buttons[id]["ymin"] = ymin
  30. buttons[id]["ymax"] = ymax
  31. buttons[id]["active"] = false
  32. buttons[id]["text"] = text
  33. buttons[id]["func"] = func
  34.  
  35. end
  36. ---------------------------------------------------------------------------------
  37. function printButton(id)
  38. ymin = buttons[id]["ymin"]
  39. ymax = buttons[id]["ymax"]
  40. xmin = buttons[id]["xmin"]
  41. xmax = buttons[id]["xmax"]
  42. text = buttons[id]["text"]
  43. ia = buttons[id]["active"]
  44.  
  45.  
  46.  
  47. width = xmax - xmin
  48. height = ymax - ymin
  49.  
  50. if ia then m.setBackgroundColor(bactive) m.setTextColor(tactive)
  51. else m.setBackgroundColor(binactive) m.setTextColor(tinactive) end
  52.  
  53. for j = ymin,ymax do
  54. m.setCursorPos(xmin,j)
  55. for i = xmin,xmax do
  56.  
  57. m.write(" ")
  58.  
  59. end
  60.  
  61. end
  62.  
  63.  
  64. m.setCursorPos(xmin + width / 2 - #text / 2 + 1,ymin + height / 2)
  65.  
  66. m.write(text)
  67. m.setBackgroundColor(bgcolor)
  68.  
  69. end
  70. ----------------------------------------------------------------------------------
  71. function refreshButtons()
  72. for i = 1,#buttons do
  73. printButton(i)
  74. end
  75. end
  76. function checkxy( x,y )
  77. for i = 1, #buttons do
  78. if y >= buttons[i]["ymin"] and y <= buttons[i]["ymax"] then
  79. if x >= buttons[i]["xmin"] and x <= buttons[i]["xmax"] then
  80.  
  81.  
  82. buttons[i]["active"] = not buttons[i]["active"]
  83. clicked = i
  84. if buttons[i]["func"] ~= nil then
  85.  
  86. buttons[i]["func"]()
  87.  
  88.  
  89. end
  90. end
  91. end
  92. end
  93. end
  94.  
  95.  
  96. bool1 = false
  97. bool2 = false
  98. bool3 = false
  99. rs.setBundledOutput("back",0)
  100.  
  101.  
  102.  
  103.  
  104. --White is pigman, Orange is witch, purple is wither skele (Bundled cable)
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. function pigman()
  112. current = rs.getBundledOutput("back")
  113. bool1 = not bool1
  114. if bool1 then
  115. rs.setBundledOutput("back",current+colors.white)
  116. else
  117. rs.setBundledOutput("back",current-colors.white)
  118. end
  119. end
  120.  
  121. function witch()
  122. current = rs.getBundledOutput("back")
  123. bool2 = not bool2
  124. if bool2 then
  125. rs.setBundledOutput("back",current+colors.orange)
  126. else
  127. rs.setBundledOutput("back",current-colors.orange)
  128. end
  129. end
  130.  
  131. function wither()
  132. current = rs.getBundledOutput("back")
  133. bool3 = not bool3
  134. if bool3 then
  135. rs.setBundledOutput("back",current+colors.magenta)
  136. else
  137. rs.setBundledOutput("back",current-colors.magenta)
  138. end
  139. end
  140.  
  141.  
  142. --You can add more buttons and also change the size of them. The format is startingx,startingy,endingx,endingy,text,function
  143.  
  144. --The buttons
  145. newButton(1, 2,11,2,8,"Pigman",pigman)
  146. newButton(2, 13,22,2,8,"Witch",witch)
  147. newButton(3, 24,37,2,8,"Wither Skele",wither)
  148. ------------------------------------------------
  149.  
  150.  
  151.  
  152. m.clear()
  153. refreshButtons()
  154.  
  155.  
  156. --main loop
  157. while true do
  158. e,side,x,y = os.pullEvent("monitor_touch")
  159. checkxy(x,y)
  160.  
  161. refreshButtons()
  162. end
Tags: test
Add Comment
Please, Sign In to add comment