Guest User

Untitled

a guest
Jul 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.93 KB | None | 0 0
  1. --- Credits: ---
  2. --- Made by ComputerCraftFan11 (IGN: xXm0dzXx)
  3. --- Please do not steal without giving credits
  4.  
  5. --- Functions:
  6. --- getX() returns the cursor's X
  7. --- getY() returns the cursor's Y
  8. --- isAt(x, y) returns true if the cursor is at the x, y
  9. --- newFrame(x, y, length, width) will make a frame
  10. --- See post for more
  11.  
  12. --- FAQ ---
  13.  
  14. --- How to add a new program ?
  15. --- New programs are added automatically if they are in windows/programs/start
  16.  
  17. --- How to add a new shortcut/program on the desktop ?
  18. --- Desktop programs are stored in windows/programs
  19.  
  20. --- I made a folder and its not showing up, why ?
  21. --- Only files show up, folders do not. To make a folder you'll have to manually make a program that opens the folder or you will have to wait.
  22.  
  23. --- How do I contact you ?
  24. --- My IGN (In-Game-Name) is xXm0dzXx, or you can contact my forums accounts:
  25. --- Computercraft.info : ComputerCraftFan11
  26. --- minecraftforum.net : ComputerCraftFan1
  27.  
  28. --- CODE ---
  29. local x, y = term.getSize()
  30. local currentX = 1;
  31. local currentY = 1;
  32. local Cursor = ">";
  33. local pressed = false;
  34. local running = "";
  35. local pirated = false; --for a server to prevent piracy
  36. local path = "";
  37. local programCap = 0
  38. local isStart = false
  39. local oldkey = 0
  40.  
  41. if not fs.exists("windows") then
  42. fs.makeDir("windows")
  43. fs.makeDir("windows/programs")
  44. fs.makeDir("windows/programs/start")
  45. end
  46. --- API ---
  47. function getX()
  48. return currentX
  49. end
  50.  
  51. function getY()
  52. return currentY
  53. end
  54.  
  55. function isAt(param1, param2)
  56. if currentX == param1 and currentY == param2 then
  57. return true
  58. else
  59. return false
  60. end
  61. end
  62.  
  63. function changeCursor(param1)
  64. Cursor = param1
  65. end
  66.  
  67. function moveTo(param1, param2)
  68. currentX = param1
  69. currentY = param2
  70. end
  71.  
  72. function newFrame(param1, param2, param3, param4)
  73. local length = 0
  74. local width = 1
  75. local sized = ""
  76. for i=1,param3 do
  77. term.setCursorPos(param1 + length, param2)
  78. if length == 0 then
  79. write("+-")
  80. sized = sized.. "+"
  81. elseif length == param3-1 then
  82. write("-+")
  83. sized = sized.. "-+"
  84. else
  85. write("-")
  86. sized = sized.. "-"
  87. end
  88. length = length+1
  89. end
  90. for i=1,param4 do
  91. term.setCursorPos(param1, param2 + width)
  92. write("|")
  93. term.setCursorPos(param1 + length, param2 + width)
  94. write("|")
  95. width = width+1
  96. end
  97.  
  98. term.setCursorPos(param1, param2 + width - 1)
  99. write(sized)
  100. end
  101.  
  102. function getChar()
  103. return oldkey
  104. end
  105.  
  106. function getKey()
  107. return odlkey
  108. end
  109.  
  110. local history = ""
  111.  
  112. function winRead(param1, param2)
  113. term.setCursorPos(param1, param2)
  114. if(getKey() == 28) then
  115. return history
  116. history = ""
  117. else
  118. history = history.. "" ..getChar()
  119. write(history)
  120. end
  121. end
  122.  
  123. --- END OF API ---
  124. function start()
  125. newLine(1, y-10, "----------+")
  126. files = fs.list("windows/programs/start")
  127. for n=1,#files do
  128. if not fs.isDir("windows/programs/start" ..files[n])then
  129. local x2,y2 = term.getCursorPos()
  130. -- if programCap < 7 then
  131. newButton(1, y2+1, "" ..files[n], files[n], "windows/programs/start/")
  132. -- programCap = programCap +1
  133. -- end
  134. end
  135. end
  136. newButton(1, y-2, "Shutdown", "shutdown", "/rom/programs/")
  137. newLine(11, y-9, "|")
  138. newLine(11, y-8, "|")
  139. newLine(11, y-7, "|")
  140. newLine(11, y-6, "|")
  141. newLine(11, y-5, "|")
  142. newLine(11, y-4, "|")
  143. newLine(11, y-3, "|")
  144. newLine(11, y-2, "|")
  145. end
  146.  
  147. function newButton(x1, y1, title, do22, path2)
  148. term.setCursorPos(x1+1, y1)
  149. write(title)
  150. if pressed == true then
  151. if currentX == x1 then
  152. if currentY == y1 then
  153. path = path2
  154. if do22 == "start" and isStart == true then
  155. isStart = false
  156. elseif do22 == "start" and isStart == false then
  157. isStart = true
  158. else
  159. running = do22
  160. isStart = false
  161. end
  162. end
  163. end
  164. end
  165. end
  166.  
  167. function newLine(x1, y1, title)
  168. term.setCursorPos(x1, y1)
  169. if title == "stretch" then
  170. print("--------------------------------------------------")
  171. else
  172. write(title)
  173. end
  174. end
  175.  
  176. function drawDesktop()
  177. term.setCursorPos(1,1)
  178. files = fs.list("windows/programs")
  179. for n=1,#files do
  180. local x2, y2 = term.getCursorPos()
  181. if not fs.isDir("windows/programs/" ..files[n]) then
  182. newButton(1, y2+1, "-+-+-+-+", files[n], "windows/programs/")
  183. newLine(1, y2+2, " " ..files[n])
  184. end
  185. end
  186. end
  187.  
  188. function drawButtons()
  189. newLine(1, y-1, "stretch")
  190. if running == "start" then
  191. newButton(1, y, "Start | ", "start", path)
  192. else
  193. newButton(1, y, "Start | " ..running, "start", path)
  194. end
  195. end
  196.  
  197. function reDraw(derp)
  198. if pirated == false then
  199. term.clear()
  200. if running == "" or running == "start" then
  201. drawDesktop()
  202. end
  203. drawButtons()
  204. term.setCursorPos(1,1)
  205. if running == "" then
  206. if isStart == true then
  207. start()
  208. end
  209. else
  210. shell.run(path.. "" ..running)
  211. if isStart == true then
  212. start()
  213. end
  214. end
  215.  
  216. term.setCursorPos(currentX, currentY)
  217. write(Cursor)
  218. end
  219. end
  220.  
  221. function piratecheck()
  222. rednet.open("top")
  223. rednet.send(744, "IDcheck")
  224. id, message = rednet.receive()
  225. if id == 744 then
  226. if message == "faduejdjs" then
  227. pirated = false
  228. reDraw(running)
  229. else
  230. print("Pirated version detected! Rebooting!")
  231. sleep(3)
  232. os.reboot()
  233. end
  234. end
  235. end
  236.  
  237. --piratecheck()
  238.  
  239. while true do
  240. reDraw(running)
  241. local e,key = os.pullEvent( "key" )
  242. local a,char = os.pullEvent( "char" )
  243. if key == 17 or key == 200 then --up
  244. if currentY > 1 then
  245. currentY = currentY -1
  246. end
  247. reDraw(running)
  248. elseif key == 31 or key == 208 then --down
  249. if currentY < y then
  250. currentY = currentY +1
  251. end
  252. reDraw(running)
  253. elseif key == 203 or key == 30 then --left
  254. if currentX > 1 then
  255. currentX = currentX -1
  256. end
  257. reDraw(running)
  258. elseif key == 205 or key == 32 then --right
  259. if currentX < x-1 then
  260. currentX = currentX +1
  261. end
  262. reDraw(running)
  263. elseif key == 28 then
  264. pressed = true;
  265. reDraw(running)
  266. sleep(0.0001)
  267. pressed = false;
  268. end
  269.  
  270. oldkey = char
  271. odlkey = key
  272. end
Add Comment
Please, Sign In to add comment