Advertisement
9551

Untitled

May 24th, 2021
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. local arg = {...}
  2. if arg[1] == "func" then
  3. print(
  4. "FEATURES:\nb.API(): function to make your own button APIs\nb.counter(): function too add counter buttons\na function to add really ;simple buttons"
  5. )
  6. end
  7. out = 0
  8. local function API(ins, cord1, cord2, length, height)
  9. if ins == true then
  10. ins = {os.pullEvent("monitor_touch")}
  11. end
  12. out = 0
  13. for x = 0, height - 1 do
  14. for i = 0, length - 1 do
  15. if (ins[3] == cord1 + i) and (ins[4] == cord2 + x) then
  16. out = 1
  17. return true
  18. end
  19. end
  20. end
  21. if out ~= 1 then
  22. return false
  23. end
  24. end
  25.  
  26. local function button(ins, cord1, cord2, lenght, height)
  27. return API(ins, cord1, cord2, length, height)
  28. end
  29.  
  30. local function counter(monitor, ins, cc, cord1, cord2, cv, max, min, col)
  31. local m = peripheral.wrap(monitor)
  32. if data == nil then
  33. data = {}
  34. for is = 0, 1000 do
  35. data[is] = 0
  36. end
  37. end
  38. m.setCursorPos(cord1, cord2)
  39. m.write("\24" .. " " .. data[cc])
  40. m.setCursorPos(cord1, cord2 + 1)
  41. m.write("\25")
  42. if API(ins, cord1, cord2, 1, 1) == true then
  43. if data[cc] < max then
  44. data[cc] = data[cc] + cv
  45. m.setCursorPos(cord1, cord2)
  46. m.setTextColor(colors.green)
  47. m.write("\24" .. " " .. data[cc] .. " ")
  48. m.setCursorPos(cord1, cord2 + 1)
  49. m.setTextColor(colors.red)
  50. m.write("\25")
  51. m.setTextColor(colors[col])
  52. end
  53. end
  54. if API(ins, cord1, cord2 + 1, 1, 1) == true then
  55. if data[cc] > min then
  56. data[cc] = data[cc] - cv
  57. m.setCursorPos(cord1, cord2)
  58. m.setTextColor(colors.green)
  59. m.write("\24" .. " " .. data[cc] .. " ")
  60. m.setCursorPos(cord1, cord2 + 1)
  61. m.setTextColor(colors.red)
  62. m.write("\25")
  63. m.setTextColor(colors[col])
  64. end
  65. return data[cc]
  66. end
  67. end
  68.  
  69. local function switch(monitor, cc, ins, pos1, pos2, col1, col2, col3, text)
  70. local m = peripheral.wrap(monitor)
  71. if data1 == nil then
  72. data1 = {}
  73. for is = 0, 1000 do
  74. data1[is] = false
  75. end
  76. end
  77. local function ff()
  78. data1[cc] = not data1[cc]
  79. end
  80. if API(ins, pos1, pos2, string.len(text), 1) == true then
  81. ff()
  82. end
  83. local oldcol1 = m.getTextColor()
  84. local oldcol2 = m.getBackgroundColor()
  85. if data1[cc] == true then
  86. m.setBackgroundColor(colors[col2])
  87. else
  88. m.setBackgroundColor(colors[col1])
  89. end
  90. m.setCursorPos(pos1, pos2)
  91. m.write(text)
  92. m.setTextColor(oldcol1)
  93. m.setBackgroundColor(oldcol2)
  94. return (data1[cc])
  95. end
  96.  
  97. local function switchn(monitor, cc, ins, pos1, pos2, col1, col2, col3, text, text2)
  98. if string.len(text) ~= string.len(text2) then
  99. if string.len(text) > string.len(text2) then
  100. re = string.len(text)
  101. else
  102. re = string.len(text2)
  103. end
  104. end
  105. print(re)
  106. local m = peripheral.wrap(monitor)
  107. if data2 == nil then
  108. data2 = {}
  109. for is = 0, 1000 do
  110. data2[is] = false
  111. end
  112. end
  113. local function ff()
  114. data2[cc] = not data2[cc]
  115. end
  116. if API(ins, pos1, pos2, re, 1) == true then
  117. print()
  118. ff()
  119. end
  120. local oldcol1 = m.getTextColor()
  121. local oldcol2 = m.getBackgroundColor()
  122. if data2[cc] == true then
  123. m.setCursorPos(pos1, pos2)
  124. if string.len(text) ~= string.len(text2) then
  125. m.write(string.rep(" ", re))
  126. end
  127. m.setBackgroundColor(colors[col2])
  128. m.setCursorPos(pos1, pos2)
  129. m.write(text2)
  130. else
  131. m.setCursorPos(pos1, pos2)
  132. if string.len(text) ~= string.len(text2) then
  133. m.write(string.rep(" ", re))
  134. end
  135. m.setBackgroundColor(colors[col1])
  136. m.setCursorPos(pos1, pos2)
  137. m.write(text)
  138. end
  139. m.setTextColor(oldcol1)
  140. m.setBackgroundColor(oldcol2)
  141. return (data2[cc])
  142. end
  143. return {
  144. API = API,
  145. counter = counter,
  146. switch = switch,
  147. button = button,
  148. switchn = switchn
  149. --slider = slider,
  150. --timeswitch = timeswitch,
  151. }
  152.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement