Guest User

Untitled

a guest
Jul 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 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 getKeys()
  103. return oldkey
  104. end
  105.  
  106. local history = ""
  107.  
  108. function winRead(param1, param2)
  109. term.setCursorPos(param1, param2)
  110. if(getKeys() == 28) then
  111. history = ""
  112. else
  113. history = history.. "" ..getKeys()
  114. write(history)
  115. end
  116. end
  117.  
  118. --- END OF API ---
  119. function start()
  120. newLine(1, y-10, "----------+")
  121. files = fs.list("windows/programs/start")
  122. for n=1,#files do
  123. if not fs.isDir("windows/programs/start" ..files[n])then
  124. local x2,y2 = term.getCursorPos()
  125. -- if programCap < 7 then
  126. newButton(1, y2+1, "" ..files[n], files[n], "windows/programs/start/")
  127. -- programCap = programCap +1
  128. -- end
  129. end
  130. end
  131. newButton(1, y-2, "Shutdown", "shutdown", "/rom/programs/")
  132. newLine(11, y-9, "|")
  133. newLine(11, y-8, "|")
  134. newLine(11, y-7, "|")
  135. newLine(11, y-6, "|")
  136. newLine(11, y-5, "|")
  137. newLine(11, y-4, "|")
  138. newLine(11, y-3, "|")
  139. newLine(11, y-2, "|")
  140. end
  141.  
  142. function newButton(x1, y1, title, do22, path2)
  143. term.setCursorPos(x1+1, y1)
  144. write(title)
  145. if pressed == true then
  146. if currentX == x1 then
  147. if currentY == y1 then
  148. path = path2
  149. if do22 == "start" and isStart == true then
  150. isStart = false
  151. elseif do22 == "start" and isStart == false then
  152. isStart = true
  153. else
  154. running = do22
  155. isStart = false
  156. end
  157. end
  158. end
  159. end
  160. end
  161.  
  162. function newLine(x1, y1, title)
  163. term.setCursorPos(x1, y1)
  164. if title == "stretch" then
  165. print("--------------------------------------------------")
  166. else
  167. write(title)
  168. end
  169. end
  170.  
  171. function drawDesktop()
  172. term.setCursorPos(1,1)
  173. files = fs.list("windows/programs")
  174. for n=1,#files do
  175. local x2, y2 = term.getCursorPos()
  176. if not fs.isDir("windows/programs/" ..files[n]) then
  177. newButton(1, y2+1, "-+-+-+-+", files[n], "windows/programs/")
  178. newLine(1, y2+2, " " ..files[n])
  179. end
  180. end
  181. end
  182.  
  183. function drawButtons()
  184. newLine(1, y-1, "stretch")
  185. if running == "start" then
  186. newButton(1, y, "Start | ", "start", path)
  187. else
  188. newButton(1, y, "Start | " ..running, "start", path)
  189. end
  190. end
  191.  
  192. function reDraw(derp)
  193. if pirated == false then
  194. term.clear()
  195. if running == "" or running == "start" then
  196. drawDesktop()
  197. end
  198. drawButtons()
  199. term.setCursorPos(1,1)
  200. if running == "" then
  201. if isStart == true then
  202. start()
  203. end
  204. else
  205. shell.run(path.. "" ..running)
  206. if isStart == true then
  207. start()
  208. end
  209. end
  210.  
  211. term.setCursorPos(currentX, currentY)
  212. write(Cursor)
  213. end
  214. end
  215.  
  216. function piratecheck()
  217. rednet.open("top")
  218. rednet.send(744, "IDcheck")
  219. id, message = rednet.receive()
  220. if id == 744 then
  221. if message == "faduejdjs" then
  222. pirated = false
  223. reDraw(running)
  224. else
  225. print("Pirated version detected! Rebooting!")
  226. sleep(3)
  227. os.reboot()
  228. end
  229. end
  230. end
  231.  
  232. --piratecheck()
  233.  
  234. while true do
  235. reDraw(running)
  236. local e,key = os.pullEvent( "key" )
  237. local a,char = os.pullEvent( "char" )
  238. if key == 17 or key == 200 then --up
  239. if currentY > 1 then
  240. currentY = currentY -1
  241. end
  242. reDraw(running)
  243. elseif key == 31 or key == 208 then --down
  244. if currentY < y then
  245. currentY = currentY +1
  246. end
  247. reDraw(running)
  248. elseif key == 203 or key == 30 then --left
  249. if currentX > 1 then
  250. currentX = currentX -1
  251. end
  252. reDraw(running)
  253. elseif key == 205 or key == 32 then --right
  254. if currentX < x-1 then
  255. currentX = currentX +1
  256. end
  257. reDraw(running)
  258. elseif key == 28 then
  259. pressed = true;
  260. reDraw(running)
  261. sleep(0.0001)
  262. pressed = false;
  263. end
  264.  
  265. oldkey = char
  266. end
Add Comment
Please, Sign In to add comment