JdogAwesome

JDA Tools GUI [WIP]

Mar 15th, 2016
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --JDA Tools GUI By: JdogAwesome
  2.  
  3. os.unloadAPI("gui")
  4. os.loadAPI("gui")
  5. local disk = "disk2" --Replace "disk2" with whatever your disk is called when you type in "dir"
  6.  
  7. function waitMouse()
  8.     while true do
  9.         ev,mb,x,y = os.pullEvent("mouse_click")
  10.         if (mb == 1 and gui.detect(x,y, false) ~= nil) then
  11.             return gui.detect(x,y, false)
  12.         end
  13.     end
  14. end
  15.  
  16. function gamesFunc()
  17.     term.setBackgroundColor(colors.black)
  18.     term.clear()
  19.     firstButton:remove()
  20.     secondButton:remove()
  21.     gamesButton:remove()
  22.  
  23.     exitButton2 = gui.createButton("Exit")
  24.     tronButton = gui.createButton("Tron", tronGame)
  25.     flappyButton = gui.createButton("Flappy Pixel", flappyGame)
  26.     tronButton:draw(23, 2, 3, colors.blue, colors.black)
  27.     flappyButton:draw(22, 6, 3, colors.blue, colors.black)
  28.     exitButton2:draw(2, 1, 3, colors.blue, colors.black)
  29.     clicked2 = waitMouse()
  30.     if clicked2 == "Tron" then
  31.         tronButton:remove()
  32.         mazeButton:remove()
  33.         exitButton2:remove()
  34.         tronGame()
  35.     end
  36.     if clicked2 == "Flappy Pixel" then
  37.         tronButton:remove()
  38.         flappyButton:remove()
  39.         exitButton2:remove()
  40.         flappyGame()
  41.     end
  42.     if clicked2 == "Exit" then
  43.         tronButton:remove()
  44.         mazeButton:remove()
  45.         exitButton2:remove()
  46.     end
  47.  
  48. end
  49.  
  50. function tronGame()
  51.     term.setBackgroundColor(colors.black)
  52.     term.clear()
  53.     term.setCursorPos(10,10)
  54.     env = {}
  55.     os.run(env,"Tron") 
  56. end
  57.  
  58. function flappyGame()
  59.     term.setBackgroundColor(colors.black)
  60.     term.clear()
  61.     term.setCursorPos(10,10)
  62.     env2 = {}
  63.     os.run(env2,"FlappyPixel") 
  64. end
  65.  
  66. function pastebinGet()
  67.     term.setBackgroundColor(colors.black)
  68.     term.clear()
  69.     term.setCursorPos(10,10)
  70.     print("What you want to name the file:")
  71.     local filename = gui.newTextBox(15,13,20, colors.red, colors.black)
  72.     term.setCursorPos(10,15)
  73.     print("Pastebin URL thing, example: KwJ87j7A")
  74.     local pastebinUrl = gui.newTextBox(15,16,20, colors.red, colors.black)
  75.     shell.run("pastebin get ",pastebinUrl, filename)
  76.  
  77.     sleep(2)
  78.    
  79. end
  80.  
  81. function diskCopy()
  82.     term.setBackgroundColor(colors.black)
  83.     term.clear()
  84.    
  85.     term.setCursorPos(10,10)
  86.     print("Name of file to copy to disk: ")
  87.     local userinput = gui.newTextBox(15,16,20, colors.white, colors.black)
  88.     shell.run("cp",userinput, disk)
  89.     sleep(3)
  90. end
  91.  
  92. function exitProgram()
  93.     term.clear()
  94.     term.setTextColor(colors.white)
  95.     term.setBackgroundColor(colors.black)
  96.     term.setCursorPos(1,1)
  97.     term.clear()
  98.     error()
  99. end
  100.  
  101. function main()
  102.     term.setBackgroundColor(colors.blue)
  103.     term.clear()
  104.     term.setCursorPos(20,2)
  105.     term.setTextColor(colors.white)
  106.     print("JDA Tools")
  107.     term.setCursorPos(2,19)
  108.     print("By JdogAwesome")
  109.    
  110.     firstButton = gui.createButton("Pastebin Get ", pastebinGet)
  111.     secondButton = gui.createButton("Disk Copy", diskCopy)
  112.     exitButton = gui.createButton("Exit", exitProgram)
  113.     gamesButton = gui.createButton("Games", gamesFunc)
  114.    
  115.     firstButton:draw(18, 3, 3, colors.red, colors.white)
  116.     secondButton:draw(20, 9, 3, colors.orange, colors.white)
  117.     exitButton:draw(2, 1, 3, colors.red, colors.black)
  118.     gamesButton:draw(22, 15, 3, colors.green, colors.white)
  119.    
  120.     clicked = waitMouse()
  121.    
  122.     if clicked == "Pastebin Get " then
  123.         pastebinGet()
  124.     elseif clicked == "Disk Copy" then
  125.         diskCopy()
  126.     elseif clicked == "Exit" then
  127.         exitProgram()
  128.     elseif clicked == "Games" then
  129.         gamesFunc()
  130.     end
  131. end
  132.  
  133. while true do
  134.     main()
  135. end
  136.  
  137. --Base code credits:
  138. --https://www.youtube.com/watch?v=-oXDm92KZRc
  139. --http://www.computercraft.info/forums2/index.php?/topic/18977-guiapi-simple-powerful-buttonsdialogue-boxes-text-boxes-and-more/
Add Comment
Please, Sign In to add comment