Advertisement
AquaJD

[A'sP] SavviAnimation

Sep 13th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.08 KB | None | 0 0
  1. -- Default Settings
  2. local tBarColor = colors.blue
  3. local tBarTextColor = colors.white
  4. local backColor = colors.white
  5. local textColor = colors.black
  6. local boxColor = colors.lightBlue
  7.  
  8. frameCount = 10
  9. frameTime = 0.5
  10. animName = "Unnamed"
  11. playName = "Unnamed"
  12.  
  13. main = true
  14. play = false
  15. create = false
  16. help = false
  17.  
  18. local w,h = term.getSize()
  19.  
  20. function drawBox(desX,desY,desW,desH,desCol)
  21.     moveY = desY
  22.     term.setCursorPos(desX,desY)
  23.     term.setBackgroundColor(desCol)
  24.     for i=1,desH do
  25.         term.setCursorPos(desX,moveY)
  26.         print(string.rep(" ",desW))
  27.         moveY = moveY + 1
  28.     end
  29. end
  30.  
  31. function centerText(t,y)
  32.     local x = math.max(math.floor((w/2) - (#t/2)),y)
  33.     term.setCursorPos(x+1,y)
  34.     print(t)
  35. end
  36.  
  37. function drawMain()
  38.     term.setBackgroundColor(colors.white)
  39.     term.setTextColor(textColor)
  40.     centerText("                    ",6)
  41.     centerText("  Create Animation  ",7)
  42.     centerText("                    ",8)
  43.     centerText("                  ",10)
  44.     centerText("  Play Animation  ",11)
  45.     centerText("                  ",12)
  46.     term.setCursorPos(45,18)
  47.     term.setBackgroundColor(boxColor)
  48.     print(" QUIT ")
  49.     term.setCursorPos(38,18)
  50.     term.setBackgroundColor(boxColor)
  51.     print(" HELP ")
  52. end
  53.  
  54. function drawHelp()
  55.     term.setBackgroundColor(boxColor)
  56.     term.setTextColor(textColor)
  57.     centerText("Welcome to Savvi Animations!",6)
  58.     centerText("The Animation Creator and player",7)
  59.     centerText("by AutoLocK.",8)
  60.     centerText("To create an animation, just",10)
  61.     centerText("click Create Animation in the",11)
  62.     centerText("main screen.",12)
  63.     centerText("To play an animation, just",13)
  64.     centerText("click Play Animation in the",14)
  65.     centerText("main screen.",15)
  66.     term.setCursorPos(45,18)
  67.     term.setBackgroundColor(boxColor)
  68.     print(" QUIT ")
  69.     term.setCursorPos(38,18)
  70.     term.setBackgroundColor(boxColor)
  71.     print(" BACK ")
  72.     while true do
  73.         local event,button,X,Y = os.pullEvent()
  74.         if event == "mouse_click" then
  75.             if X >= 45 and X <= 50 and Y == 18 then
  76.                 term.setBackgroundColor(colors.black)
  77.                 term.clear()
  78.                 term.setCursorPos(1,1)
  79.                 break
  80.             elseif X >= 38 and X <= 43 and Y == 18 then
  81.                 help = false
  82.                 main = true
  83.                 play = false
  84.                 create = false
  85.                 drawGUI()
  86.                 break
  87.             end
  88.         end
  89.     end
  90. end
  91.  
  92. function drawCreate()
  93.     while true do
  94.         term.setBackgroundColor(boxColor)
  95.         term.setTextColor(textColor)
  96.         term.setCursorPos(6,6)
  97.         print("Name:")
  98.         term.setCursorPos(11,6)
  99.         term.setBackgroundColor(colors.gray)
  100.         print(animName)
  101.         term.setCursorPos(6,8)
  102.         term.setBackgroundColor(boxColor)
  103.         print("Frames:")
  104.         term.setCursorPos(20,8)
  105.         print(frameCount)
  106.         term.setCursorPos(30,8)
  107.         print("- +")
  108.         term.setCursorPos(6,10)
  109.         print("Frame Time:")
  110.         term.setCursorPos(20,10)
  111.         print(frameTime)
  112.         term.setCursorPos(30,10)
  113.         print("- +")
  114.         term.setBackgroundColor(backColor)
  115.         centerText("        ",12)
  116.         centerText(" CREATE ",13)
  117.         centerText("        ",14)
  118.         term.setCursorPos(38,18)
  119.         term.setBackgroundColor(boxColor)
  120.         print(" BACK ")
  121.         local event,button,X,Y = os.pullEvent()
  122.         if event == "mouse_click" then
  123.             if X >= 38 and X <= 43 and Y == 18 then
  124.                 help = false
  125.                 main = true
  126.                 play = false
  127.                 create = false
  128.                 drawGUI()
  129.                 break
  130.             elseif X >= 11 and X <= 22 and Y == 6 then
  131.                 term.setCursorPos(11,6)
  132.                 term.setBackgroundColor(colors.gray)
  133.                 term.setTextColor(tBarTextColor)
  134.                 print("               ")
  135.                 term.setCursorPos(11,6)
  136.                 animName = read()
  137.                 term.setTextColor(textColor)
  138.             elseif X == 30 and Y == 8 then
  139.                 if frameCount >= 6 then
  140.                     term.setCursorPos(20,8)
  141.                     term.setBackgroundColor(boxColor)
  142.                     print("      ")
  143.                     frameCount = frameCount - 1
  144.                 end
  145.             elseif X == 32 and Y == 8 then
  146.                 if frameCount <= 100 then
  147.                     term.setCursorPos(20,8)
  148.                     term.setBackgroundColor(boxColor)
  149.                     print("      ")
  150.                     frameCount = frameCount + 1
  151.                 end
  152.             elseif X == 30 and Y == 10 then
  153.                 term.setCursorPos(20,10)
  154.                 term.setBackgroundColor(boxColor)
  155.                 print("      ")
  156.                 frameTime = frameTime - 0.01
  157.             elseif X == 32 and Y == 10 then
  158.                 term.setCursorPos(20,10)
  159.                 term.setBackgroundColor(boxColor)
  160.                 print("      ")
  161.                 frameTime = frameTime + 0.01
  162.             elseif X >= 22 and X <= 29 and Y >= 12 and Y <= 14 then
  163.                 local name,status = createAnim()
  164.                 if status == true then
  165.                     centerText("Successfully created!",15)
  166.                     sleep(1)
  167.                     help = false
  168.                     main = true
  169.                     play = false
  170.                     create = false
  171.                     drawGUI()
  172.                     break
  173.                 elseif status == false then
  174.                     centerText("Unsuccessful.",15)
  175.                     sleep(1)
  176.                     help = false
  177.                     main = true
  178.                     play = false
  179.                     create = false
  180.                     drawGUI()
  181.                     break
  182.                 end
  183.             end
  184.         end
  185.     end
  186. end
  187.  
  188. function drawPlay()
  189.     while true do
  190.         term.setBackgroundColor(boxColor)
  191.         term.setTextColor(textColor)
  192.         term.setCursorPos(6,6)
  193.         print("Name:")
  194.         term.setCursorPos(11,6)
  195.         term.setBackgroundColor(colors.gray)
  196.         print(playName)
  197.         term.setBackgroundColor(backColor)
  198.         centerText("      ",12)
  199.         centerText(" PLAY ",13)
  200.         centerText("      ",14)
  201.         term.setCursorPos(38,18)
  202.         term.setBackgroundColor(boxColor)
  203.         print(" BACK ")
  204.         local event,button,X,Y = os.pullEvent()
  205.         if event == "mouse_click" then
  206.             if X >= 38 and X <= 43 and Y == 18 then
  207.                 help = false
  208.                 main = true
  209.                 play = false
  210.                 create = false
  211.                 drawGUI()
  212.                 break
  213.             elseif X >= 11 and X <= 22 and Y == 6 then
  214.                 term.setCursorPos(11,6)
  215.                 term.setBackgroundColor(colors.gray)
  216.                 term.setTextColor(tBarTextColor)
  217.                 print("               ")
  218.                 term.setCursorPos(11,6)
  219.                 playName = read()
  220.             elseif X >= 23 and X <= 28 and Y >= 12 and Y <= 14 then
  221.                 if fs.exists("/"..playName) then
  222.                     local file = fs.open("/"..playName.."/"..playName..".cfg","r")
  223.                     local fCount = file.readLine()
  224.                     local fTime = file.readLine()
  225.                     local fCount = tonumber(fCount)
  226.                     local fTime = tonumber(fTime)
  227.                     local loadingFrame = 1
  228.                     for i=1,fCount do
  229.                         term.setBackgroundColor(colors.black)
  230.                         term.clear()
  231.                         term.setCursorPos(1,1)
  232.                         local frm = paintutils.loadImage("/"..playName.."/"..playName..loadingFrame)
  233.                         paintutils.drawImage(frm,1,1)
  234.                         sleep(fTime)
  235.                         loadingFrame = loadingFrame + 1
  236.                     end
  237.                     term.setBackgroundColor(colors.black)
  238.                     term.setTextColor(colors.white)
  239.                     centerText("Complete. Returning...",15)
  240.                     sleep(1)
  241.                     help = false
  242.                     main = true
  243.                     play = false
  244.                     create = false
  245.                     drawGUI()
  246.                     break
  247.                 end
  248.             end
  249.         end
  250.     end
  251. end
  252.  
  253. function drawGUI()
  254.     term.setBackgroundColor(backColor)
  255.     term.clear()
  256.     term.setBackgroundColor(tBarColor)
  257.     term.setTextColor(tBarTextColor)
  258.     term.setCursorPos(1,1)
  259.     term.clearLine()
  260.     term.setCursorPos(1,1)
  261.     print("  SavviAnimations  ")
  262.     term.setCursorPos(40,1)
  263.     print(" by AutoLocK")
  264.     drawBox(5,5,43,12,boxColor)
  265.     if main == true then
  266.         drawMain()
  267.     elseif play == true then
  268.         drawPlay()
  269.     elseif create == true then
  270.         drawCreate()
  271.     elseif help == true then
  272.         drawHelp()
  273.     end
  274. end
  275.  
  276. function createAnim()
  277.     currentFrame = 1
  278.     if not fs.exists("/"..animName) then
  279.         fs.makeDir("/"..animName)
  280.         local file = fs.open("/"..animName.."/"..animName..".cfg","w")
  281.         file.writeLine(frameCount)
  282.         file.writeLine(frameTime)
  283.         file.close()
  284.         for i=1,frameCount do
  285.             shell.run("paint /"..animName.."/"..animName..currentFrame)
  286.             currentFrame = currentFrame + 1
  287.         end
  288.         return animName,true
  289.     else
  290.         return animName,false
  291.     end
  292. end
  293.  
  294. function startup()
  295.     drawGUI()
  296.     while true do
  297.         local event,button,X,Y = os.pullEvent()
  298.         if event == "mouse_click" then
  299.             if X >= 45 and X <= 50 and Y == 18 then
  300.                 term.setBackgroundColor(colors.black)
  301.                 term.clear()
  302.                 term.setCursorPos(1,1)
  303.                 break
  304.             elseif X >= 38 and X <= 43 and Y == 18 then
  305.                 help = true
  306.                 main = false
  307.                 play = false
  308.                 create = false
  309.                 drawGUI()
  310.             elseif X >= 16 and X <= 35 and Y >= 6 and Y <= 8 then
  311.                 help = false
  312.                 main = false
  313.                 play = false
  314.                 create = true
  315.                 drawGUI()
  316.             elseif X >= 17 and X <= 34 and Y >= 10 and Y <= 12 then
  317.                 help = false
  318.                 main = false
  319.                 play = true
  320.                 create = false
  321.                 drawGUI()
  322.             end
  323.         end
  324.     end
  325. end
  326.  
  327. startup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement