nucular

Moviemaker by gamax92 (nucular's mod)

Jan 10th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.03 KB | None | 0 0
  1. --MOVIEMAKER NUCULAR'S MOD V. 1.1
  2. --ORIGINAL WRITTEN BY GAMAX92
  3. --VER 1.1 UPDATE http://pastebin.com/raw.php?i=HxMMxSpY
  4.  
  5. -- This is my modification of gamax92's awesome idea of a simple screenvideo-program for TPT.
  6. -- gamax92 has done everything, I just tried to make it compatible with the new PNG output
  7. -- format of the screenshots and fix a few glitches... and added a few functions.
  8. -- I hope you like it. Have fun!
  9.  
  10. -- Based on official Moviemaker version 1.6
  11. -- All changes made by me are commented.
  12.  
  13. --SETTINGS:
  14. local qual = 3 -- default quality bigger is worse ranges from 1 to 31
  15. local nob = 6 --insert the number of buttons on top here
  16.  
  17. --TODO:
  18. --More output formats (but I dont know where to put this option, maybe drop-down-like)
  19. --convert & clean folder automatically after converting
  20. --sort more things into functions
  21. --port GUI to new TPTPPs Interface API (i should really learn more advanced lua...)
  22. --eye-candy: blinking circle when recording (very simple to do, but where to place it without recording it?)
  23. --show ffmpegs download page if it not exists. (maybe open it per os.execute?)
  24. --allow the user to place the script in a subdirectory of TPT's folder
  25. --repair/recode the file counting procedure before converting
  26. --of course speed improvements. i've got a rapid framedrop when recording...
  27. --use inrct function when checking mouseclicks in gui
  28.  
  29. --CHANGES:
  30. --  FROM ORIGINAL 1.6 TO MOD 1.0:
  31. --   fixed MANY graphical glitches of TPT++
  32. --   changed arguments for ffmpeg to support new screenshot format .png
  33. --   changed arguments for del to support .png & delete only screenshot-png's, no other
  34. --   changed pre-set fps setting to not overspeed the output video
  35. --  FROM 1.0 TO 1.1:
  36. --   now shows the recorded frames while recording.
  37. --   now saves/loads settings in/from file, probably more useful if there would be more settings
  38. --   added dialogs after recording/converting
  39. --   changed a few button descriptions
  40. --   new option: record toolbar too
  41. --   added TODO list, documentation of changes and BUG list... maybe this will be a bigger project...
  42. --   replaced not working video counting with ugly os.time()
  43. --   now using the new fileSystem API for checking existing files instead of the ugly io.open method.
  44. --   now checking if Videos-folder exists (and creates them) and if ffmpeg.exe exists.
  45. --   defined all variables and functions as local just to be secure
  46. --   mouse now doesn't draw particles when GUI is opened
  47. --   AVI/GIF buttons are now direct clickable. Freed space in GUI by removing these useless buttons. Moved Record & Clean Folder down.
  48. --   added hackstrife's Quality Option! Thanks, thanks thanks! (added save line too)
  49. --   working update line for cracker64's Autorun Manager
  50.  
  51. --KNOWN BUGS:
  52. --   TPT freezes while converting a video
  53. --   TPTs settings, console and stamp browser aren't recorded, script simply pauses (unable to fix in actual version due to TPTs intern code)
  54. --   bad news for Lua coders: Doesn't records the new Interface API
  55. --   if fullscreen records is enabled, it records frame and second text too.
  56.  
  57. local recording = 0
  58. local recordfps = 25 -- more realistic fps
  59. local recordframes = 0
  60. local recordft = ".avi"
  61. local recorduiseen = 0
  62. local recorduitype = 0
  63. local fullscreen = 0
  64.  
  65. if package.config:sub(1,1) == "\\" then
  66.    recordds = "\\"
  67. else
  68.    recordds = "/"
  69. end
  70.  
  71. -- check if Videos folder exists, create it if not, show mesagebox if creating failed
  72. if not fs.exists("Videos") then
  73.    if not fs.makeDirectory("Videos") then
  74.       tpt.message_box("Moviemaker - Creating folder failed","Please create folder 'Videos' in\nTPTs directory manually.")
  75.    end
  76. end
  77.  
  78. -- check if FFMPEG exists
  79. if not fs.exists("ffmpeg.exe") then
  80.    tpt.message_box("Moviemaker - FFMPEG not found","Please copy an version of FFMPEG in\nTPTs directory and name it 'ffmpeg.exe'.")
  81. end
  82.  
  83. local uix = (612 / 2) - (146 / 2)
  84. local uiy = (384 / 2) - (58 / 2)
  85.  
  86. -- load settings based on code from cracker64's awesome Autorun Script Manager
  87. local function load_last()
  88.     local f = io.open("moviemakersettings.txt","r")
  89.     if f then
  90.         local lines = {}
  91.         local line = f:read("*l")
  92.         while line do
  93.             table.insert(lines,line)
  94.             line = f:read("*l")
  95.         end
  96.         f:close()
  97.         for i=1, #lines do
  98.             local tok=lines[i]:sub(1,3)
  99.             local str=lines[i]:sub(5)
  100.             if tok=="FPS" then
  101.                 recordfps = tonumber(str)
  102.             elseif tok=="COD" then
  103.                 recordft = str
  104.             elseif tok=="FUL" then
  105.                 fullscreen = tonumber(str)
  106.             elseif tok=="QUA" then
  107.                 qual = tonumber(str)
  108.             end
  109.         end
  110.     end
  111. end
  112. load_last()
  113.  
  114. --save settings
  115. local function save_last()
  116.     local savestring = "FPS "..tostring(recordfps).."\nCOD "..recordft.."\nFUL "..tostring(fullscreen).."\nQUA "..tostring(qual)
  117.     local f = io.open("moviemakersettings.txt","w")
  118.     if f then
  119.         f:write(savestring)
  120.         f:close()
  121.     end
  122. end
  123.  
  124. local function recordsui()
  125.    tpt.fillrect(612,nob * 16,14,14) --fix tptpp's fillrect glitch
  126.    tpt.drawtext(618,nob * 16 + 5,"S",0,0,0)
  127.    recordframes = recordframes + 1
  128.    tpt.drawtext(5,385,tostring(math.floor(recordframes / recordfps)) .. " s")
  129.    tpt.drawtext(5,395,tostring(math.floor(recordframes)) .. " F") --show recorded frames too
  130. end
  131.  
  132. --new screenshot function
  133. local function screensh()
  134.    tpt.screenshot(fullscreen)
  135. end
  136.  
  137. local function recordui()
  138.    if recorduiseen == 1 then
  139.       tpt.fillrect(uix,uiy,146,58,0,0,0) --fix tptpp's fillrect glitch
  140.       tpt.drawrect(uix,uiy,146,58)
  141.       tpt.drawrect(uix + 107, uiy + 2, 37, 12)
  142.       if recorduitype == 0 then
  143.          tpt.drawtext(uix + 109, uiy + 5, "Options")
  144.          tpt.drawrect(uix + 2, uiy + 2, 12, 12)
  145.          tpt.drawrect(uix + 54, uiy + 2, 12, 12)
  146.  
  147.          if recordft == ".avi" then
  148.             tpt.fillrect(uix + 2, uiy + 2, 10, 10, 0, 255, 0) --fix tptpp's fillrect glitch
  149.             tpt.fillrect(uix + 54, uiy + 2, 10, 10, 0, 63, 0) --fix tptpp's fillrect glitch
  150.          else
  151.             tpt.fillrect(uix + 2, uiy + 2, 10, 10, 0, 63, 0) --fix tptpp's fillrect glitch
  152.             tpt.fillrect(uix + 54, uiy + 2, 10, 10, 0, 255, 0) --fix tptpp's fillrect glitch
  153.          end
  154.          tpt.drawrect(uix + 2, uiy + 30, 70, 12)
  155.          tpt.drawrect(uix + 74, uiy + 30, 70, 12)
  156.          --removed borders of select... buttons
  157.          tpt.drawrect(uix + 2, uiy + 44, 142, 12)
  158.          tpt.drawtext(uix + 16, uiy + 5, "AVI Out")
  159.          tpt.drawtext(uix + 68, uiy + 5, "GIF Out")
  160.          tpt.drawtext(uix + 9, uiy + 32, "Clean folder")
  161.          tpt.drawtext(uix + 93, uiy + 32, "Record") --better description, I thought
  162.          --removed 'Select GIF' and 'Select AVI'
  163.          
  164.          tpt.drawtext(287, uiy + 47, "CONVERT") --better description, I thought
  165.       else
  166.          tpt.drawtext(uix + 115, uiy + 5, "Main")
  167.          -- draw fps selecter with offset
  168.          tpt.drawrect(uix + 25, uiy + 16 - 14, 12, 12)
  169.          tpt.drawrect(uix + 39, uiy + 16 - 14, 19, 12)
  170.          tpt.drawrect(uix + 60, uiy + 16 - 14, 12, 12)
  171.          tpt.drawtext(uix + 2, uiy + 18 - 14, "FPS:")
  172.          tpt.drawline(uix + 28, uiy + 22 - 14, uix + 34, uiy + 22 - 14)
  173.          tpt.drawtext(uix + (48 - (tpt.textwidth(tostring(recordfps)) / 2)), uiy + 19 - 14, tostring(recordfps))
  174.          tpt.drawline(uix + 63, uiy + 22 - 14, uix + 69, uiy + 22 - 14)
  175.          tpt.drawline(uix + 66, uiy + 19 - 14, uix + 66, uiy + 25 - 14)
  176.          -- %%quality menu part THANKS TO HACKSTRIFE!
  177.          tpt.drawrect(uix + 76, uiy + 33, 12, 12)
  178.          tpt.drawrect(uix + 90, uiy + 33, 19, 12)
  179.          tpt.drawrect(uix + 111, uiy + 33, 12, 12)
  180.          tpt.drawtext(uix + 2, uiy + 36, "COMPRESSION:")
  181.          tpt.drawline(uix + 79, uiy + 39, uix + 85, uiy + 39)
  182.          tpt.drawtext(uix + (72 - (tpt.textwidth(tostring(qual)) / 2)) + 27, uiy + 36, tostring(qual))
  183.          tpt.drawline(uix + 114, uiy + 39, uix + 120, uiy + 39)
  184.          tpt.drawline(uix + 117, uiy + 36, uix + 117, uiy + 42)
  185.          -- add fullscreen option
  186.          tpt.drawtext(uix + 16, uiy + 35 - 13, "Record menus")
  187.          tpt.drawrect(uix + 2, uiy + 32 - 13, 12, 12)
  188.          if fullscreen == 0 then
  189.             tpt.fillrect(uix + 2, uiy + 32 - 13, 10, 10, 0, 63, 0)
  190.          else
  191.             tpt.fillrect(uix + 2, uiy + 32 - 13, 10, 10, 0, 255, 0)
  192.          end
  193.          -- add info button (maybe next version
  194.          --tpt.drawrect(uix + 132, uiy + 16, 12, 12)
  195.          --tpt.drawtext(uix + 138, uiy + 19, "!")
  196.       end
  197.    end
  198.    tpt.drawrect(613,nob * 16 + 1,14,14,200,200,200)
  199.    tpt.drawtext(618,nob * 16 + 5,"S")
  200. end
  201.  
  202. local function recordmouse(x,y,b,e)
  203.    if recording == 1 and x > 612 and y > (nob * 16) and x < 629 and y < (nob * 16 + 16) and b == 1 and e == 1 then
  204.       tpt.unregister_step(recordsui)
  205.       tpt.unregister_step(screensh)
  206.       tpt.register_step(recordui)
  207.       tpt.set_pause(1)
  208.       recording = 0
  209.       recorduiseen = 1 --block mouse too in the frame between gui open and recording
  210.       tpt.message_box("Recording finished", "Recorded " .. tostring(recordframes) .. " Frames.\nDon't forget to Convert them to a video!") --show finish message
  211.    elseif recording == 0 and x > 612 and y > (nob * 16) and x < 629 and y < (nob * 16 + 16) and b == 1 and e == 1 then
  212.       recorduiseen = math.mod(recorduiseen + 1, 2)
  213.       tpt.set_pause(recorduiseen)
  214.       save_last()
  215.    end
  216.    if x > uix + 106 and y > uiy + 1 and x < uix + 148 and y < uiy + 15 and b == 1 and e == 1 then
  217.       recorduitype = math.mod(recorduitype + 1, 2)
  218.    end
  219.    if b == 1 and e == 1 and recorduiseen == 1 and recorduitype == 0 then
  220.       if x > uix + 1 and y > uiy + 29 and x < uix + 73 and y < uiy + 43 then
  221.      -- deleting only screenshot pngs
  222.          if recordds == "\\" then
  223.             os.execute("del screenshot_*.png")
  224.          else
  225.             os.execute("rm screenshot_*.png")
  226.          end
  227.       elseif x > uix + 73 and y > uiy + 29 and x < uix + 145 and y < uiy + 43 then
  228.          save_last()
  229.          tpt.unregister_step(recordui)
  230.          tpt.register_step(recordsui)
  231.          tpt.register_step(screensh) --new screenshot function
  232.          tpt.set_pause(0)
  233.          recording = 1
  234.       elseif x > uix + 1 and y > uiy + 1 and x < uix + 15 and y < uiy + 15 then --avi icon is now direct clickable
  235.          recordft = ".avi"
  236.       elseif x > uix + 54 and y > uiy + 1 and x < uix + 67 and y < uiy + 15 then --gif icon too
  237.          recordft = ".gif"
  238.       elseif x > uix + 1 and y > uiy + 43 and x < uix + 145 and y < uiy + 57 then
  239.  
  240.          -- replaced non-working file counting with ugly os.time()
  241.      
  242.          -- working png converting
  243.          os.execute("ffmpeg -r " .. tostring(recordfps) .. "  -i screenshot_%06d.png -q:v " .. tostring(qual) .. " Videos" .. recordds .. "tptvideo" .. tostring(os.time()).. recordft)
  244.          tpt.message_box("Converting finished", "Converted " .. tostring(math.floor(recordframes / recordfps)) .. " Seconds of video.\nDon't forget to clean your folder!") --show finish message
  245.       end
  246.    elseif b == 1 and e == 1 and recorduiseen == 1 and recorduitype == 1 then
  247.    -- check fps element with offset
  248.       if x > uix + 24 and y > uiy + 15 - 14 and x < uix + 38 and y < uiy + 29 - 14 then
  249.          if recordfps > 1 then recordfps = recordfps - 1 end
  250.       elseif x > uix + 59 and y > uiy + 15 - 14 and x < uix + 73 and y < uiy + 29 - 14 then
  251.          if recordfps < 60 then recordfps = recordfps + 1 end
  252.          -- %% quality menu mouse click check THANKS TO HACKSTRIFE!
  253.       elseif x > uix + 75 and y > uiy + 34 and x < uix + 88 and y < uiy + 49 then
  254.          if qual > 1 then qual = qual - 1 end
  255.       elseif x > uix + 110 and y > uiy + 34 and x < uix + 123 and y < uiy + 49 then
  256.          if qual < 31 then qual = qual + 1 end
  257.       elseif x > uix + 1 and y > uiy + 31 - 13 and x < uix + 15 and y < uiy + 44 - 13 then --check fullscreen option
  258.          if fullscreen == 1 then fullscreen = 0 else fullscreen = 1 end
  259.       end
  260.    end
  261.    --block mouse from interacting with tpt when GUI is open
  262.    if recorduiseen == 1 then
  263.        if recording == 1 then
  264.            recorduiseen = 0
  265.        end
  266.        return false
  267.    end
  268. end
  269.  
  270. tpt.register_step(recordui)
  271. tpt.register_mouseclick(recordmouse)
Add Comment
Please, Sign In to add comment