Advertisement
Guest User

Untitled

a guest
Aug 10th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1. rednet.open("back")
  2. controller = 0
  3.  
  4. function checkInArray(x,a)
  5. for i,v in ipairs(a) do
  6. if v == x then
  7. return v
  8. end
  9. end
  10.  
  11. return nil
  12. end
  13.  
  14. local function findClickArea(x,y,w,h)
  15. xs = {}
  16. ys = {}
  17.  
  18. i = 0
  19. while i < w do
  20. table.insert(xs, x + i)
  21. i = i + 1
  22. end
  23.  
  24. i = 0
  25. while i < h do
  26. table.insert(ys, y + i)
  27. i = i + 1
  28. end
  29.  
  30. return {xs, ys}
  31. end
  32.  
  33. function drawBox(x,y,w,h,color)
  34.  
  35. if color ~= nil then
  36. term.setBackgroundColor(color)
  37. end
  38.  
  39. i = 0
  40. while i < w do
  41. i2 = 0
  42. while i2 < h do
  43. term.setCursorPos(x + i, y + i2)
  44. term.write(" ")
  45. i2 = i2 + 1
  46. end
  47. i = i + 1
  48. end
  49. end
  50.  
  51. function checkClickArea(x,y,a)
  52. area = {}
  53. area = a
  54.  
  55. xFound = false
  56. yFound = false
  57.  
  58. if checkInArray(x,area[1]) == nil then
  59. return false
  60. end
  61.  
  62. if checkInArray(y,area[2]) == nil then
  63. return false
  64. end
  65.  
  66. return true
  67. end
  68.  
  69. function drawArray(a,startY,fixedW)
  70. if a == nil then
  71. error("The array is nil")
  72. end
  73.  
  74. tab = {}
  75. tab = a
  76.  
  77. pages = 1
  78.  
  79. curPage = 1
  80.  
  81. bPoint = 1
  82.  
  83. if fixedW == nil then
  84. w,h = term.getSize()
  85. else
  86. _,h = term.getSize()
  87. w = fixedW
  88. end
  89.  
  90.  
  91.  
  92. if tab[1] ~= nil then
  93.  
  94. term.setBackgroundColor(colors.white)
  95. term.setTextColor(colors.black)
  96.  
  97.  
  98. x = 3
  99. if startY == nil then
  100. y = 3
  101. else
  102. y = startY
  103. end
  104.  
  105. areas = {}
  106. items = {}
  107.  
  108. for i,v in ipairs(tab) do
  109. if v == ".DS_Store" then
  110. table.remove(tab, i)
  111. end
  112. end
  113.  
  114. for i,v in ipairs(tab) do
  115. if x + string.len(v) + 2 > w then
  116. x = 3
  117. y = y + 2
  118. end
  119.  
  120. drawBox(x,y,string.len(v) + 2, 1, colors.white)
  121. term.setCursorPos(x + 1, y)
  122. term.setBackgroundColor(colors.white)
  123. term.setTextColor(colors.black)
  124. term.write(v)
  125.  
  126. table.insert(areas, findClickArea(x,y,string.len(v) + 2, 1))
  127.  
  128. if x > w-2 then
  129. x = 3
  130. y = y + 4
  131. else
  132. x = x + string.len(v) + 3
  133. end
  134.  
  135. end
  136.  
  137. for i,v in ipairs(tab) do
  138. table.insert(items, {v, areas[i]})
  139. end
  140.  
  141. term.setTextColor(colors.white)
  142.  
  143. while true do
  144. e,p1,p2,p3 = os.pullEvent()
  145.  
  146. if e == "mouse_click" and p1 == 1 then
  147. for i,v in ipairs(items) do
  148. if checkClickArea(p2,p3,v[2]) then
  149. return v[1]
  150. end
  151. end
  152. return
  153. end
  154. end
  155.  
  156. end
  157. term.setBackgroundColor(colors.black)
  158. end
  159.  
  160. function clear()
  161. term.clear()
  162. term.setCursorPos(1,1)
  163. end
  164.  
  165. term.setBackgroundColor(colors.lightGray)
  166. clear()
  167. term.write("PASSWORD: ")
  168. password = read()
  169.  
  170. while true do
  171. message = {"getTypes",password}
  172. message = textutils.serialize(message)
  173. rednet.send(controller,message)
  174. id,msg,d = rednet.receive(1)
  175.  
  176. if msg == nil then
  177. print("PASSCODE IS PROBABLY WRONG")
  178. break
  179. end
  180.  
  181. allTypes = textutils.unserialize(msg)
  182. term.setBackgroundColor(colors.lightGray)
  183. clear()
  184. table.insert(allTypes,"EXIT")
  185. print("ALL TYPES")
  186. while true do
  187. choiceType = drawArray(allTypes)
  188. if choiceType ~= nil then
  189. break
  190. end
  191. end
  192. if choiceType == "EXIT" then
  193. term.setBackgroundColor(colors.black)
  194. clear()
  195. break
  196. end
  197. while true do
  198. term.setBackgroundColor(colors.lightGray)
  199. clear()
  200. device = ""
  201. command = ""
  202. params = {}
  203.  
  204.  
  205. message = {"getAllOfType", password, choiceType}
  206. message = textutils.serialize(message)
  207. rednet.send(controller,message)
  208. id,msg,d = rednet.receive()
  209.  
  210. term.setBackgroundColor(colors.lightGray)
  211. clear()
  212.  
  213. deviceList = textutils.unserialize(msg)
  214. table.insert(deviceList,"BACK")
  215. print("TYPE: "..choiceType)
  216. while true do
  217. device = drawArray(deviceList)
  218. if device ~= nil then
  219. break
  220. end
  221. end
  222. if device == "BACK" then
  223. term.setBackgroundColor(colors.lightGray)
  224. clear()
  225. break
  226. else
  227. message = {"getDeviceSpecs",password,device}
  228. message = textutils.serialize(message)
  229. rednet.send(controller,message)
  230. id,msg,d = rednet.receive()
  231.  
  232. deviceSpecs = textutils.unserialize(msg)
  233. table.insert(deviceSpecs[2], "PARAMS ON/OFF")
  234. table.insert(deviceSpecs[2],"BACK")
  235.  
  236. paramsExist = false
  237.  
  238. while true do
  239. term.setBackgroundColor(colors.lightGray)
  240. clear()
  241. print("DEVICE: "..device)
  242. print("TYPE: "..deviceSpecs[1])
  243. print("PARAMS: "..textutils.serialize(paramsExist))
  244. while true do
  245. command = drawArray(deviceSpecs[2],5)
  246. if command ~= nil then
  247. break
  248. end
  249. end
  250. if command ~= "BACK" then
  251.  
  252. if command == "PARAMS ON/OFF" then
  253. paramsExist = not paramsExist
  254. else
  255.  
  256. while true do
  257. if paramsExist then
  258. term.setBackgroundColor(colors.lightGray)
  259. clear()
  260. print("TYPE IN ARGUMENTS, TYPE SEND TO SEND, TYPE EXIT TO LEAVE (PRESS ENTER AFTER EACH ARGUMENT)")
  261. print()
  262. param = read()
  263. if string.upper(param) == "EXIT" then
  264. break
  265. elseif string.upper(param) == "SEND" then
  266. fullMessage = {"sendCommand",password,device,command,params}
  267. fullMessage = textutils.serialize(fullMessage)
  268. print(fullMessage)
  269. rednet.send(controller,fullMessage)
  270. params = {}
  271. break
  272. else
  273. table.insert(params, param)
  274. end
  275. else
  276. fullMessage = {"sendCommand", password, device, command, {" "}}
  277. fullMessage = textutils.serialize(fullMessage)
  278. rednet.send(controller, fullMessage)
  279. break
  280. end
  281. end
  282. end
  283. else
  284. break
  285. end
  286. end
  287. end
  288. end
  289. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement