Advertisement
aceyo369

AceOS 3.0

Nov 11th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.13 KB | None | 0 0
  1. --[[AceyoOS 2.0 done by aceyo369]]--
  2. --[[Inspired by Nitrogen Fingers]]--
  3.  
  4. --[[ Side functions ]]--
  5.  
  6. local w, h = term.getSize()
  7. local select = 1
  8. local nF = true
  9.  
  10. local function clear()
  11. term.clear()
  12. term.setCursorPos(1, 1)
  13. end
  14.  
  15. local function printCentered(msg, ypos)
  16. term.setCursorPos(w/2 - #msg/2, ypos)
  17. term.write(msg)
  18. end
  19.  
  20. local function printAcross(bar,ypos)
  21. for i = 1, w-1 do
  22. term.setCursorPos(i, ypos)
  23. term.write(bar)
  24. end
  25. end
  26.  
  27. local function printLeft(msg, ypos)
  28. term.setCursorPos(3, ypos)
  29. term.write(msg)
  30. end
  31.  
  32. local function printBottom(msg)
  33. term.setCursorPos(w/2 - #msg/2, h - 1)
  34. term.write(msg)
  35. end
  36.  
  37. local function printRight(msg)
  38. term.setCursorPos(w/2 - 3, h/2 + 1)
  39. term.write(msg)
  40. end
  41.  
  42. local function printMiddle(msg, xpos)
  43. term.setCursorPos(xpos, h/2)
  44. term.write(msg)
  45. end
  46.  
  47. local function printBotline()
  48. printAcross("-", h - 2)
  49. end
  50.  
  51. --[[ Main Desktop ]]--
  52.  
  53. runningTime = os.time()
  54.  
  55. mm = "Ace_Desktop"
  56.  
  57. local title = mm
  58.  
  59. local pID = os.getComputerID()
  60.  
  61. local user = "Anon"
  62.  
  63. local function printHeader()
  64. print("AceyoOS 1.0")
  65. printCentered(title,1)
  66. term.setCursorPos(1,2)
  67. term.write("Time: "..textutils.formatTime(runningTime,false))
  68. term.setCursorPos(w - 20, 2)
  69. print("Desktop_User:"..user)
  70. term.setCursorPos(w - 5, 1)
  71. print("ID: "..pID) term.setCursorPos(w - 20, 2)
  72. printAcross("-", 3)
  73. printBotline()
  74. end
  75.  
  76. --[[Extra loading screen]]--
  77.  
  78. local function runningPercent()
  79. clear()
  80. printHeader()
  81. printCentered("Loading...", h/2)
  82. for i = 0, 100 do
  83. term.setCursorPos(1, h/2 + 1)
  84. term.clearLine()
  85. printCentered(i.."%", h/2 + 1)
  86. sleep(0.001)
  87. end
  88. term.setCursorPos(1, h/2 + 1)
  89. term.clearLine()
  90. printCentered("100%", h/2 + 1)
  91. sleep(0.5)
  92. clear()
  93. printHeader()
  94. printCentered("Loading Complete", h/2)
  95. sleep(2)
  96. clear()
  97. end
  98.  
  99. --[[All Menus with inputs]]--
  100.  
  101. local function printMain()
  102. if select == 1 then
  103. printCentered("[".."Computer List".."]", 4)
  104. printBottom("**Locate Computer IDs**")
  105. else printCentered("Computer List", 4) end
  106.  
  107. if select == 2 then
  108. printCentered("[".."Command".."]", 6)
  109. printBottom("**Command Wireless Computers**")
  110. else printCentered("Command", 6) end
  111.  
  112. if select == 3 then
  113. printCentered("[".."Simple Math".."]", 8)
  114. printBottom("**Solve Mathematics here**")
  115. else printCentered("Simple Math", 8) end
  116.  
  117. if select == 4 then
  118. printCentered("[".."Games".."]", 10)
  119. printBottom("**Play available games here**")
  120. else printCentered("Games", 10) end
  121.  
  122. if select == 5 then
  123. printCentered("[".."Programs".."]", 12)
  124. printBottom("**Edit and Run Computer Programs**")
  125. else printCentered("Programs", 12) end
  126.  
  127. if select == 6 then
  128. printCentered("[".."Options".."]", 14)
  129. printBottom("**Change Setting**")
  130. else printCentered("Options", 14) end
  131.  
  132. if select == 7 then
  133. printCentered("[".."Exit".."]", 16)
  134. printBottom("**Terminate the AceyoOS 1.0**")
  135. else printCentered("Exit", 16) end
  136. end
  137.  
  138. local function inputMain()
  139. event, key = os.pullEvent("key")
  140. if key == 200 and select > 1 then
  141. select = select - 1
  142. end
  143. if key == 208 and select < 7 then
  144. select = select + 1
  145. end
  146. if key == 28 and select == 1 then
  147. title = "Computer_List"
  148. changeState("Computer_List")
  149. end
  150. if key == 28 and select == 2 then
  151. title = "Command"
  152. changeState("Command")
  153. end
  154. if key == 28 and select == 3 then
  155. title = "Simple_Math"
  156. changeState("Simple_Math")
  157. end
  158. if key == 28 and select == 4 then
  159. title = "Games"
  160. changeState("Games")
  161. end
  162. if key == 28 and select == 5 then
  163. title = "Program_System"
  164. changeState("Programs")
  165. end
  166. if key == 28 and select == 6 then
  167. title = "Options"
  168. changeState("Options")
  169. end
  170. if key == 28 and select == 7 then
  171. clear()
  172. nF = false
  173. end
  174. end
  175.  
  176. local function printList()
  177. printCentered("No recorded Computer", h/2)
  178. printCentered("Press backspace", h/2 + 2)
  179. printCentered("to return to main menu", h/2 + 3)
  180. end
  181.  
  182. local function inputList()
  183. event, key = os.pullEvent("key")
  184. if key == keys.backspace then
  185. title = mm
  186. changeState("main")
  187. end
  188. end
  189.  
  190. local function printCommand()
  191. rednet.open("bottom")
  192. printCentered("Select Computer ID: ", h/2)
  193. CompID = tonumber(read())
  194. clear()
  195. printHeader()
  196. printCentered("Command for computer: ", h/2)
  197. cmd = read()
  198. clear()
  199. printHeader()
  200. end
  201.  
  202. local sendmsg = "Sending..."
  203.  
  204. local function inputCommand()
  205. term.setCursorPos(w/2 - #sendmsg/2, h/2)
  206. textutils.slowPrint(sendmsg)
  207. rednet.send(CompID, cmd)
  208. sleep(1)
  209. clear()
  210. printHeader()
  211. printCentered("Command Sent", h/2)
  212. sleep(1)
  213. rednet.close("bottom")
  214. title = mm
  215. changeState("main")
  216. end
  217.  
  218. local function printGames()
  219. if select == 1 then
  220. printCentered("[".."Snake Game".."]", 7)
  221. printBottom("**Play a classical Snakes**")
  222. else printCentered("Snake Game", 7) end
  223.  
  224. if select == 2 then
  225. printCentered("[".."T3".."]", 9)
  226. printBottom("**Play TicTacToe**")
  227. else printCentered("T3", 9) end
  228.  
  229. if select == 3 then
  230. printCentered("[".."Back to Main Menu".."]", 11)
  231. printBottom("**To Main Menu**")
  232. else printCentered("Back to Main Menu", 11) end
  233. end
  234.  
  235. local function inputGames()
  236. event, key = os.pullEvent("key")
  237. if key == 200 and select > 1 then
  238. select = select - 1
  239. elseif key == 208 and select < 3 then
  240. select = select + 1
  241. elseif key == 28 and select == 1 then
  242. runningPercent()
  243. shell.run("worm")
  244. nF = false
  245. elseif key == 28 and select == 2 then
  246. runningPercent()
  247. shell.run("t3")
  248. nF = false
  249. elseif key == 28 and select == 3 then
  250. title = mm
  251. changeState("main")
  252. end
  253. end
  254.  
  255. local function printMath()
  256. printCentered("Insert your first number: ", h/2)
  257. first = tonumber(read())
  258. clear()
  259. printHeader()
  260. printCentered("<+,-,*,/>", h/2 - 1)
  261. printCentered("Insert your sign: ", h/2)
  262. sign = read()
  263. clear()
  264. printHeader()
  265. end
  266.  
  267. local function inputMath()
  268. printCentered("Insert your second number: ", h/2)
  269. second = tonumber(read())
  270. clear()
  271. printHeader()
  272. if sign == "+" then
  273. total = first + second
  274. elseif sign == "-" then
  275. total = first - second
  276. elseif sign == "*" then
  277. total = first * second
  278. elseif sign == "/" then
  279. total = first / second
  280. end
  281. printCentered("Solution: "..total, h/2)
  282. printCentered("Press any key to go to Main Menu", h/2 + 2)
  283. event, key = os.pullEvent()
  284. title = mm
  285. changeState("main")
  286. end
  287.  
  288. local function printprog()
  289. if select == 1 then
  290. printCentered("[".."Run a program".."]", 5)
  291. printBottom("**Program can be from computer or disk**")
  292. else printCentered("Run a program", 5) end
  293. if select == 2 then
  294. printCentered("[".."Edit a program".."]", 7)
  295. printBottom("**Able to edit and create script**")
  296. else printCentered("Edit a program", 7) end
  297. if select == 3 then
  298. printCentered("[".."Create a program".."]", 9)
  299. printBottom("**Make your own program**")
  300. else printCentered("Create a program", 9) end
  301. if select == 4 then
  302. printCentered("[".."Back to Main Menu".."]", 11)
  303. printBottom("**To Main Menu**")
  304. else printCentered("Back to Main Menu", 11) end
  305. end
  306.  
  307. local function inputprog()
  308. event, key = os.pullEvent("key")
  309. if key == 200 and select > 1 then
  310. select = select - 1
  311. elseif key == 208 and select < 4 then
  312. select = select + 1
  313. end
  314. if key == 28 and select == 1 then
  315. clear()
  316. printHeader()
  317. term.setCursorPos(1, h/2)
  318. shell.run("dir")
  319. sleep(3)
  320. clear()
  321. printHeader()
  322. printCentered("Program to run: ", h/2)
  323. prog = read()
  324. if fs.exists(prog) == true then
  325. changeState("main")
  326. title = mm
  327. clear()
  328. shell.run(prog)
  329. else
  330. clear()
  331. printHeader()
  332. printCentered("No Such Program", h/2)
  333. sleep(1)
  334. changeState("Programs")
  335. end
  336. elseif key == 28 and select == 2 then
  337. clear()
  338. printHeader()
  339. term.setCursorPos(1, h/2)
  340. shell.run("dir")
  341. sleep(3)
  342. clear()
  343. printHeader()
  344. printCentered("Which program to edit?", h/2)
  345. term.setCursorPos(w/2 - 6, h/2 + 1)
  346. prog = read()
  347. shell.run("edit",prog)
  348. elseif key == 28 and select == 3 then
  349. clear()
  350. printHeader()
  351. printCentered("Name of your program: ", h/2)
  352. term.setCursorPos(w/2 - 6, h/2 + 1)
  353. prog = read()
  354. shell.run("edit",prog)
  355. elseif key == 28 and select == 4 then
  356. title = mm
  357. changeState("main")
  358. end
  359. end
  360.  
  361. local function printOp()
  362. if select == 1 then
  363. printCentered("[".."Refresh Time".."]", h/2 - 1)
  364. printBottom("**See Current Time**")
  365. else printCentered("Refresh Time", h/2 - 1) end
  366. if select == 2 then
  367. printCentered("[".."Password".."]", h/2 + 1)
  368. printBottom("**Password Setting**")
  369. else printCentered("Password", h/2 + 1) end
  370. if select == 3 then
  371. printCentered("[".."Back to Main Menu".."]", h/2 + 3)
  372. printBottom("**To Main Menu**")
  373. else printCentered("Back to Main Menu", h/2 + 3) end
  374. end
  375.  
  376. local function inputOp()
  377. event, key = os.pullEvent("key")
  378. if key == 200 and select > 1 then
  379. select = select - 1
  380. elseif key == 208 and select < 3 then
  381. select = select + 1
  382. elseif key == 28 and select == 1 then
  383. os.reboot()
  384. elseif key == 28 and select == 2 then
  385. title = "Password_Setting"
  386. changeState("Password")
  387. elseif key == 28 and select == 3 then
  388. title = mm
  389. changeState("main")
  390. end
  391. end
  392.  
  393. local function printpwR()
  394. printCentered("Your Username: ", h/2 - 1)
  395. printCentered("Your Password: ", h/2)
  396. end
  397.  
  398. local function inputpwR()
  399. term.setCursorPos(w/2 + 8, h/2 - 1)
  400. inputuser = read()
  401. term.setCursorPos(w/2 + 8, h/2)
  402. inputpw = read("*")
  403. if fs.exists("/user/"..inputuser) then
  404. clear()
  405. printHeader()
  406. printCentered("Account already exists", h/2)
  407. sleep(1.5)
  408. else
  409. fs.makeDir("/user/"..inputuser.."/"..inputpw)
  410. clear()
  411. printHeader()
  412. printCentered("Registration Complete", h/2)
  413. sleep(1)
  414. title = mm
  415. changeState("main")
  416. end
  417. end
  418.  
  419. local function printpwL()
  420. printCentered("Your Username: ", h/2 - 1)
  421. printCentered("Your Password: ", h/2)
  422. end
  423.  
  424. local function inputpwL()
  425. term.setCursorPos(w/2 + 8, h/2 - 1)
  426. inputuser = read()
  427. term.setCursorPos(w/2 + 8, h/2)
  428. inputpw = read("*")
  429. if fs.exists("/user/"..inputuser.."/"..inputpw) == true then
  430. user = inputuser
  431. clear()
  432. printHeader()
  433. printCentered("Welcome back, "..user.."!", h/2)
  434. sleep(1.5)
  435. else
  436. clear()
  437. printHeader()
  438. printCentered("Wrong Username or Password!", h/2)
  439. sleep(2)
  440. end
  441. clear()
  442. printHeader()
  443. title = mm
  444. changeState("main")
  445. end
  446.  
  447. local function printpw()
  448. if select == 1 then
  449. printCentered("[".."Create Account".."]", h/2 - 1)
  450. printBottom("**New Account on Desktop**")
  451. else printCentered("Create Account", h/2 - 1) end
  452. if select == 2 then
  453. printCentered("[".."Login Account".."]", h/2 + 1)
  454. printBottom("**Access Available Account**")
  455. else printCentered("Login Account", h/2 + 1) end
  456. if select == 3 then
  457. printCentered("[".."Back to Main Menu".."]", h/2 + 3)
  458. printBottom("**To Main Menu**")
  459. else printCentered("Back to Main Menu", h/2 + 3) end
  460. end
  461.  
  462. local function inputpw()
  463. event, key = os.pullEvent("key")
  464. if key == 200 and select > 1 then
  465. select = select - 1
  466. elseif key == 208 and select < 3 then
  467. select = select + 1
  468. elseif key == 28 and select == 1 then
  469. title = "Account Registration"
  470. changeState("Register")
  471. elseif key == 28 and select == 2 then
  472. changeState("Login")
  473. elseif key == 28 and select == 3 then
  474. title = mm
  475. changeState("main")
  476. end
  477. end
  478.  
  479. --[[Menu Tables]]--
  480.  
  481.  
  482. local state = {
  483. ["main"] = {
  484. printfunc = printMain,
  485. inputfunc = inputMain
  486. },
  487. ["Computer_List"] = {
  488. printfunc = printList,
  489. inputfunc = inputList
  490. },
  491. ["Command"] = {
  492. printfunc = printCommand,
  493. inputfunc = inputCommand
  494. },
  495. ["Simple_Math"] = {
  496. printfunc = printMath,
  497. inputfunc = inputMath
  498. },
  499. ["Games"] = {
  500. printfunc = printGames,
  501. inputfunc = inputGames
  502. },
  503. ["Programs"] = {
  504. printfunc = printprog,
  505. inputfunc = inputprog
  506. },
  507. ["Options"] = {
  508. printfunc = printOp,
  509. inputfunc = inputOp
  510. },
  511. ["Password"] = {
  512. printfunc = printpw,
  513. inputfunc = inputpw
  514. },
  515. ["Register"] = {
  516. printfunc = printpwR,
  517. inputfunc = inputpwR
  518. },
  519. ["Login"] = {
  520. printfunc = printpwL,
  521. inputfunc = inputpwL
  522. }
  523. }
  524.  
  525. --[[For Changing Menus]]--
  526.  
  527. local menustate = state["main"]
  528.  
  529. function changeState(newstate)
  530. menustate = state[newstate]
  531. select = 1
  532. end
  533.  
  534. local function Update()
  535. runningTime = os.time()
  536. printHeader()
  537. end
  538.  
  539. --[[Overall compiled functions]]--
  540.  
  541. local function Main()
  542. os.startTimer(0.1)
  543. local event = os.pullEvent()
  544. if event == "timer" then
  545. clear()
  546. Update()
  547. menustate.printfunc()
  548. menustate.inputfunc()
  549. else
  550. runningTime = os.time()
  551. end
  552. end
  553.  
  554.  
  555. --[[Looping the main function]]--
  556.  
  557. while nF do
  558. if term.isColor() then
  559. term.setBackgroundColour(colours.blue)
  560. term.setTextColour(colours.white)
  561. end
  562. Main()
  563. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement