xXm0dzXx

Untitled

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