xXm0dzXx

Untitled

Sep 7th, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 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.  
  40. if not fs.exists("windows") then
  41. fs.makeDir("windows")
  42. fs.makeDir("windows/programs")
  43. fs.makeDir("windows/programs/start")
  44. end
  45. --- API ---
  46. function getX()
  47. return currentX
  48. end
  49.  
  50. function getY()
  51. return currentY
  52. end
  53.  
  54. function isAt(param1, param2)
  55. if currentX == param1 and currentY == param2 then
  56. return true
  57. else
  58. return false
  59. end
  60. end
  61.  
  62. function changeCursor(param1)
  63. Cursor = param1
  64. end
  65.  
  66. function moveTo(param1, param2)
  67. currentX = param1
  68. currentY = param2
  69. end
  70.  
  71. function newFrame(param1, param2, param3, param4)
  72. local length = 0
  73. local width = 1
  74. local sized = ""
  75. for i=1,param3 do
  76. term.setCursorPos(param1 + length, param2)
  77. if length == 0 then
  78. write("+-")
  79. sized = sized.. "+"
  80. elseif length == param3-1 then
  81. write("-+")
  82. sized = sized.. "-+"
  83. else
  84. write("-")
  85. sized = sized.. "-"
  86. end
  87. length = length+1
  88. end
  89. for i=1,param4 do
  90. term.setCursorPos(param1, param2 + width)
  91. write("|")
  92. term.setCursorPos(param1 + length, param2 + width)
  93. write("|")
  94. width = width+1
  95. end
  96.  
  97. term.setCursorPos(param1, param2 + width - 1)
  98. write(sized)
  99. end
  100.  
  101. --- END OF API ---
  102. function start()
  103. newLine(1, y-10, "----------+")
  104. files = fs.list("windows/programs/start")
  105. for n=1,#files do
  106. if not fs.isDir("windows/programs/start" ..files[n])then
  107. local x2,y2 = term.getCursorPos()
  108. -- if programCap < 7 then
  109. newButton(1, y2+1, "" ..files[n], files[n], "windows/programs/start/")
  110. -- programCap = programCap +1
  111. -- end
  112. end
  113. end
  114. newButton(1, y-2, "Shutdown", "shutdown", "/rom/programs/")
  115. newLine(11, y-9, "|")
  116. newLine(11, y-8, "|")
  117. newLine(11, y-7, "|")
  118. newLine(11, y-6, "|")
  119. newLine(11, y-5, "|")
  120. newLine(11, y-4, "|")
  121. newLine(11, y-3, "|")
  122. newLine(11, y-2, "|")
  123. end
  124.  
  125. function newButton(x1, y1, title, do22, path2)
  126. term.setCursorPos(x1+1, y1)
  127. write(title)
  128. if pressed == true then
  129. if currentX == x1 then
  130. if currentY == y1 then
  131. path = path2
  132. if do22 == "start" and isStart == true then
  133. isStart = false
  134. elseif do22 == "start" and isStart == false then
  135. isStart = true
  136. else
  137. running = do22
  138. isStart = false
  139. end
  140. end
  141. end
  142. end
  143. end
  144.  
  145. function newLine(x1, y1, title)
  146. term.setCursorPos(x1, y1)
  147. if title == "stretch" then
  148. print("--------------------------------------------------")
  149. else
  150. write(title)
  151. end
  152. end
  153.  
  154. function drawDesktop()
  155. term.setCursorPos(1,1)
  156. files = fs.list("windows/programs")
  157. for i=1,#files do
  158. if fs.isDir(files[i]) then
  159. print("/-/")
  160. print("| " ..string.sub(files[i],1,1).. " |")
  161. print("+-+\n")
  162. else
  163. print("+-X")
  164. print("|" ..string.sub(files[i],1,1).. "|")
  165. print("+-+\n")
  166. end
  167. end
  168. end
  169.  
  170. function drawButtons()
  171. newLine(1, y-1, "stretch")
  172. if running == "start" then
  173. newButton(1, y, "Start | ", "start", "windows/programs/start/")
  174. else
  175. newButton(1, y, "Start | " ..running, "start", "windows/programs/start/")
  176. end
  177. end
  178.  
  179. function reDraw(derp)
  180. if pirated == false then
  181. term.clear()
  182. if running == "" or running == "start" then
  183. drawDesktop()
  184. end
  185. drawButtons()
  186. term.setCursorPos(1,1)
  187. if running == "" then
  188. if isStart == true then
  189. start()
  190. end
  191. else
  192. shell.run(path.. "" ..running)
  193. if isStart == true then
  194. start()
  195. end
  196. end
  197.  
  198. term.setCursorPos(currentX, currentY)
  199. write(Cursor)
  200. end
  201. end
  202.  
  203. function piratecheck()
  204. rednet.open("top")
  205. rednet.send(744, "IDcheck")
  206. id, message = rednet.receive()
  207. if id == 744 then
  208. if message == "faduejdjs" then
  209. pirated = false
  210. reDraw(running)
  211. else
  212. print("Pirated version detected! Rebooting!")
  213. sleep(3)
  214. os.reboot()
  215. end
  216. end
  217. end
  218.  
  219. --piratecheck()
  220.  
  221. while true do
  222. reDraw(running)
  223. local e,key = os.pullEvent( "key" )
  224. if key == 17 or key == 200 then --up
  225. if currentY > 1 then
  226. currentY = currentY -1
  227. end
  228. reDraw(running)
  229. elseif key == 31 or key == 208 then --down
  230. if currentY < y then
  231. currentY = currentY +1
  232. end
  233. reDraw(running)
  234. elseif key == 203 or key == 30 then --left
  235. if currentX > 1 then
  236. currentX = currentX -1
  237. end
  238. reDraw(running)
  239. elseif key == 205 or key == 32 then --right
  240. if currentX < x-1 then
  241. currentX = currentX +1
  242. end
  243. reDraw(running)
  244. elseif key == 28 then
  245. pressed = true;
  246. reDraw(running)
  247. sleep(0.0001)
  248. pressed = false;
  249. end
  250. end
Advertisement
Add Comment
Please, Sign In to add comment