Advertisement
Guest User

Video rpgMaker with resolution script

a guest
Jul 30th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.77 KB | None | 0 0
  1. ==============================================================================
  2. #
  3. # [ACE]EST_SOV_Video_Player ++ Conversion
  4. #
  5. # v1.4
  6. #==============================================================================
  7. # Author : Estriole
  8. # (Conversion to ace and improving)
  9. # VX version author: SuperOverlord
  10. #
  11. # also credit Crystal Noel for solution for title that have encoding problem character
  12. # also credit ruin for fixes he made to this script.
  13. #
  14. # History :
  15. # version 1.4 2013.05.16 - apply fixes from ruin. typo error and ability to use
  16. # play video using battle event page.
  17. # version 1.3 2013.03.05 - create configuration for people that have encoding character
  18. # problem with their title. ex: Pokémon Ace.
  19. # set the IGNORE_TITLE to true inside module Sov::Video
  20. # version 1.2 2012.09.27 - made if game at fullscreen automaticly become windowed
  21. # version 1.1 2012.09.25 - some bug fix. now avi video can played at full screen mode(alt enter) with some position error.
  22. # - can play other format such as mkv but it will play full screen and when played at full screen
  23. # mode (alt enter) the size will be smaller and the game switched.
  24. # - basicly this script not support full screen game yet. will try to fix this in next version
  25. # version 1.0 2012.09.23 - finish converting + some change
  26. #
  27. #
  28. #==============================================================================
  29. # Features:
  30. #------------------------------------------------------------------------------
  31. # o Play video's on the map or in battle using a simple script event command.
  32. #
  33. # o Optionally pause or exit video's while they play.
  34. #
  35. # o View the video in the game window or in fullscreen.
  36. #
  37. # o Setup video skills, which show the video before damage effects.
  38. #
  39. # o ACE version also made not only video skill but can use video item too
  40. #
  41. # o ACE version also can play video before title scene
  42. #
  43. #==============================================================================
  44. # Instructions:
  45. #------------------------------------------------------------------------------
  46. # o Place all videos in a folder with the same name as in configuration.
  47. # This folder is created automatically the first time the game is played if
  48. # it doesn't already exist.
  49. #
  50. # o Playing Videos when on the map.
  51. #
  52. # - See script calls below.
  53. #
  54. # o Playing videos in battle.
  55. #
  56. # - As when on the map the script event command can be used in battle also.
  57. #
  58. # - As well as this you can setup skills as video skills which display
  59. # a video before damaging the enemy.
  60. #
  61. # <now below setup can be also used for item video too>
  62. # To do this the following tags can be used in the skills notebox:
  63. # 1) <video_name = "filename">
  64. # ~ name is the name of the video file. If the filename extension is
  65. # missing the first file matching that name is used.
  66. # (Quotes are necessary around the filename)
  67. #
  68. # As well as the first tag 2 others are available. These tags will only
  69. # take effect if placed on a line below the first tag.
  70. # If these don't exist they are assumed true.
  71. #
  72. # 2) <video_exitable = n> ~ Can the video be exited by the exit input?
  73. # 3) <video_pausable = n> ~ Can the video be paused?
  74. # ~ n is replaced with either t or f (t : true, f : false)
  75. #
  76. # For other Video properties (x,y,width,height,fullscreen) the default
  77. # settings are used. (See script calls below)
  78. #
  79. # o Playing videos before title screen
  80. # ctrl + f this : CONFIGURATION FOR VIDEO BEFORE TITLE
  81. # and change the
  82. # @video_title = nil
  83. # to
  84. # @video_title = "yourvideonamewithoutextensionhere"
  85. #
  86. #==============================================================================
  87. # Script Calls:
  88. #------------------------------------------------------------------------------
  89. # Commands (From the script call command on page three of event commands)
  90. #------------------------------------------------------------------------------
  91. # o To change default values for video properties.
  92. #
  93. # 1) Video.default_x = n
  94. # 2) Video.default_y = n
  95. # 3) Video.default_width = n
  96. # 4) Video.default_height = n
  97. # 5) Video.fullscreen = bool #disabled now since could make error
  98. #
  99. # In all 5 commands above:
  100. # ~ n is an integer value
  101. # ~ bool is either true or false
  102. #
  103. # o To play videos
  104. #
  105. # play_video(filename,exitable,pausable)
  106. # ~ filename : name of video file (Must be in quotes)
  107. # ~ exitable : Can the video be exited? (When left out = true)
  108. # ~ pausable : Can the video be paused? (When left out = true)
  109. #
  110. # For all other values the default's are used.
  111. #==============================================================================
  112. # Compatibility:
  113. #------------------------------------------------------------------------------
  114. # o Skill videos will depend on the battle system but sould work.
  115. #==============================================================================
  116. # Credit:
  117. #------------------------------------------------------------------------------
  118. # o Credit goes to Trebor and Berka whose scripts helped be figure out the
  119. # mci_send_stringA function.
  120. #==============================================================================
  121.  
  122. module SOV
  123. module Video
  124. #--------------------------------------------------------------------------
  125. # Configuration
  126. #--------------------------------------------------------------------------
  127. # Name of folder for videos to be held in.
  128. DIR_NAME = "Videos"
  129. # Exit video input
  130. EXIT_INPUT = Input::B
  131. # Pause video input
  132. PAUSE_INPUT = Input::C
  133.  
  134. IGNORE_TITLE = true
  135. #set to true if your title contain strange character such as é or other.
  136. #--------------------------------------------------------------------------
  137. # End Configuration
  138. #--------------------------------------------------------------------------
  139. end
  140. end
  141.  
  142. module SceneManager
  143. ################ CONFIGURATION FOR VIDEO BEFORE TITLE #######################
  144. @video_title = nil # "example" # FILENAME OF THE VIDEO IN VIDEO FOLDER IN QUOTES
  145. #IF YOU DON'T WANT TO USE THIS FEATURE JUST CHANGE TO NIL
  146. ################ END CONFIGURATION ##########################################
  147. def self.run
  148. DataManager.init
  149. Audio.setup_midi if use_midi?
  150. if @video_title != nil
  151. video = Cache.video(@video_title)
  152. video.exitable = true # True/False
  153. video.pausable = true # True/False
  154. Video.play(video)
  155. end
  156. @scene = first_scene_class.new
  157. @scene.main while @scene
  158. end
  159. end
  160.  
  161.  
  162.  
  163. #==============================================================================
  164. # Import
  165. #------------------------------------------------------------------------------
  166. $imported = {} if $imported == nil
  167. $imported['Videos'] = true
  168. #==============================================================================
  169.  
  170. #==============================================================================
  171. # ** SOV::Video::Commands
  172. #==============================================================================
  173.  
  174. module SOV::Video::Commands
  175. #--------------------------------------------------------------------------
  176. # * Play a video
  177. # filename : video's filename (with or without extension)
  178. # exitable : Can the video be exited
  179. # pausable : Can the video be paused
  180. #--------------------------------------------------------------------------
  181. def play_video(filename,exitable=true,pausable=true)
  182. video = Cache.video(filename)
  183. video.exitable = exitable
  184. video.pausable = pausable
  185. $game_map.video = video
  186. end
  187. #---------------------------------------------------------------------------
  188. # Define as module function
  189. #---------------------------------------------------------------------------
  190. module_function :play_video
  191. end
  192.  
  193. #==============================================================================
  194. # ** SOV::Video::Regexp
  195. #==============================================================================
  196.  
  197. module SOV::Video::Regexp
  198. #--------------------------------------------------------------------------
  199. # * Skill
  200. #--------------------------------------------------------------------------
  201. module Skill
  202. FILENAME = /<video[_ ]?(?:file)?name = "(.+)">/i
  203. PAUSABLE = /<video[_ ]?paus(?:e|able) = (t|f)>/i
  204. EXITABLE = /<video[_ ]?exit(?:able)? = (t|f)>/i
  205. end
  206. end
  207.  
  208. #==============================================================================
  209. # ** SOV::Game
  210. #==============================================================================
  211.  
  212. module SOV::Game
  213. #--------------------------------------------------------------------------
  214. # Constants
  215. #--------------------------------------------------------------------------
  216. INI = 'Game'
  217. #--------------------------------------------------------------------------
  218. # * Get the game windows handle
  219. #--------------------------------------------------------------------------
  220. def self.hwnd
  221. unless defined?(@@hwnd)
  222. find_window = Win32API.new('user32','FindWindow','pp','i')
  223. # @@hwnd = find_window.call('RGSS Player',title)
  224. gamefullscreen = Graphics.fullscreen?
  225. @@hwnd = find_window.call('RGSS Player',title)
  226. end
  227. return @@hwnd
  228. end
  229. #--------------------------------------------------------------------------
  230. # * Get game title
  231. #--------------------------------------------------------------------------
  232. def self.title
  233. unless defined?(@@title)
  234. @@title = read_ini('title')
  235. end
  236. return @@title
  237. end
  238. #--------------------------------------------------------------------------
  239. # * Read ini (Returns nil or match)
  240. #--------------------------------------------------------------------------
  241. def self.read_ini(variable,filename=INI)
  242. return nil if variable == 'title' && SOV::Video::IGNORE_TITLE
  243. reg = /^#{variable}=(.*)$/
  244. File.foreach(filename+'.ini') { |line| break($1) if line =~ reg }
  245. end
  246. end
  247.  
  248. #==============================================================================
  249. # ** Cache
  250. #==============================================================================
  251.  
  252. module Cache
  253. #--------------------------------------------------------------------------
  254. # Class Variables
  255. #--------------------------------------------------------------------------
  256. @@vcache = {}
  257. #--------------------------------------------------------------------------
  258. # Define as class methods
  259. #--------------------------------------------------------------------------
  260. class << self
  261. #------------------------------------------------------------------------
  262. # Alias List
  263. #------------------------------------------------------------------------
  264. alias sov_video_clear clear unless $@
  265. #------------------------------------------------------------------------
  266. # * Get a video object
  267. # filename : basename of file
  268. #------------------------------------------------------------------------
  269. def video(filename)
  270. # Get full filename if extension is missing
  271. if File.extname(filename) == ''
  272. files = Dir["#{SOV::Video::DIR_NAME}/#{filename}.*"]
  273. filename = File.basename(files[0]) # Set as first matching file
  274. end
  275. # Create or get the video object.
  276. if @@vcache.has_key?(filename)
  277. @@vcache[filename]
  278. else
  279. @@vcache[filename] = Video.new(filename)
  280. end
  281. end
  282. #------------------------------------------------------------------------
  283. # * Clear
  284. #------------------------------------------------------------------------
  285. def clear
  286. @@vcache.clear
  287. sov_video_clear
  288. end
  289. end
  290. end
  291.  
  292. #==============================================================================
  293. # ** RPG::Skill
  294. #==============================================================================
  295.  
  296. class RPG::UsableItem
  297. #--------------------------------------------------------------------------
  298. # * Determine if skill has a video skill
  299. #--------------------------------------------------------------------------
  300. def video
  301. if @video == nil
  302. @note.each_line { |line|
  303. if @video == nil
  304. @video = Cache.video($1) if line =~ SOV::Video::Regexp::Skill::FILENAME
  305. else
  306. @video.pausable = ($1 == 't') if line =~ SOV::Video::Regexp::Skill::PAUSABLE
  307. @video.exitable = ($1 == 't') if line =~ SOV::Video::Regexp::Skill::EXITABLE
  308. end
  309. }
  310. @video = :invalid if @video == nil
  311. end
  312. return @video
  313. end
  314. end
  315.  
  316. #==============================================================================
  317. # ** Video
  318. #------------------------------------------------------------------------------
  319. # Class handling playing videos.
  320. #==============================================================================
  321.  
  322. class Video
  323. #--------------------------------------------------------------------------
  324. # Constants
  325. #--------------------------------------------------------------------------
  326. TYPE_AVI = 'avivideo'
  327. TYPE_MPEG = 'mpegvideo'
  328. #--------------------------------------------------------------------------
  329. # Class Variables
  330. #--------------------------------------------------------------------------
  331. @@default_x = 0
  332. @@default_y = 0
  333. @@default_width = Graphics.width
  334. @@default_height = Graphics.height
  335. @@fullscreen = true
  336. #--------------------------------------------------------------------------
  337. # * Get and Set default_x/y/width/height
  338. #--------------------------------------------------------------------------
  339. for d in %w(x y width height)
  340. # Define setter method
  341. module_eval(%Q(def self.default_#{d}=(i); @@default_#{d} = i; end))
  342. # Define getter method
  343. module_eval(%Q(def self.default_#{d}; @@default_#{d}; end))
  344. end
  345. #--------------------------------------------------------------------------
  346. # * Get fullscreen
  347. #--------------------------------------------------------------------------
  348. def self.fullscreen
  349. @@fullscreen
  350. end
  351. #--------------------------------------------------------------------------
  352. # * Set fullscreen
  353. #--------------------------------------------------------------------------
  354. def self.fullscreen=(val)
  355. @@fullscreen = val
  356. end
  357. #--------------------------------------------------------------------------
  358. # * Win32API
  359. #--------------------------------------------------------------------------
  360. @@mciSendStringA = Win32API.new('winmm','mciSendStringA','pplp','i')
  361. #--------------------------------------------------------------------------
  362. # * Video Command
  363. # command_string : string following mci_command_string format
  364. # buffer : string to retrieve return data
  365. # buffer_size : number of characters in buffer
  366. # callback_handle : handle of window to callback to. Used if notify is used
  367. # in the command string. (Not supported by game window)
  368. #--------------------------------------------------------------------------
  369. def self.send_command(cmnd_string,buffer='',buffer_size=0,callback_handle=0)
  370. # Returns error code. No error if NULL
  371. err = @@mciSendStringA.call(cmnd_string,buffer,buffer_size,callback_handle)
  372. if err != 0
  373. buffer = ' ' * 255
  374. Win32API.new('winmm','mciGetErrorString','LPL','V').call(err,buffer,255)
  375. raise(buffer.squeeze(' ').chomp('\000'))
  376. end
  377. end
  378.  
  379. #--------------------------------------------------------------------------
  380. # * Play a video
  381. #--------------------------------------------------------------------------
  382. def self.play(video)
  383. # Make path and buffer
  384. path = "#{SOV::Video::DIR_NAME}/#{video.filename}"
  385. buffer = ' ' * 255
  386. # Initialize device and dock window with game window as parent.
  387. type = " type #{video.type}" if video.type != ''
  388. send_command("open #{path}#{type} alias VIDEO style child parent #{SOV::Game.hwnd}")
  389. # Display video in client rect at x,y with width and height.
  390. x = video.x
  391. y = video.y
  392. width = Graphics.get_screen_width
  393. height = Graphics.get_screen_height
  394. send_command("put VIDEO window at #{x} #{y} #{width} #{height}")
  395. # Begin playing video
  396. screen = @@fullscreen ? 'fullscreen' : 'window'
  397. gamefullscreen = Graphics.fullscreen?
  398. case video.type
  399. when "avivideo"
  400. if gamefullscreen == true
  401. #send_command("put VIDEO window at #{x} #{y} 640 480")
  402. #Graphics.toggle_fullscreen
  403. send_command("play VIDEO window")
  404. else
  405. send_command("play VIDEO window")
  406. end
  407. when "mpegvideo"
  408. if gamefullscreen == true
  409. Graphics.toggle_fullscreen
  410. send_command("play VIDEO window")
  411. else
  412. send_command("play VIDEO fullscreen")
  413. end
  414. else
  415. end
  416. flag = 0
  417. # Start Input and status processing loop
  418. while buffer !~ /^stopped/
  419. # Idle processing for a frame
  420. sleep(1.0/Graphics.frame_rate)
  421. # Get mode string
  422. send_command('status VIDEO mode',buffer,255)
  423. Input.update
  424. if Input.trigger?(SOV::Video::PAUSE_INPUT) and video.pausable?
  425. Sound.play_cursor
  426. if buffer =~ /^paused/ # If already paused
  427. send_command("resume VIDEO") # Resume video
  428. else # Otherwise
  429. send_command("pause VIDEO") # Pause video
  430. end
  431. elsif Input.trigger?(SOV::Video::EXIT_INPUT) and video.exitable?
  432. Sound.play_cancel
  433. # Terminate loop on exit input
  434. break
  435. end
  436. end
  437. # Terminate the device
  438. send_command('close VIDEO')
  439. end
  440. #--------------------------------------------------------------------------
  441. # Public Instance Variables
  442. #--------------------------------------------------------------------------
  443. attr_accessor :x
  444. attr_accessor :y
  445. attr_accessor :width
  446. attr_accessor :height
  447. attr_writer :exitable
  448. attr_writer :pausable
  449. attr_reader :filename
  450. #--------------------------------------------------------------------------
  451. # * Initialize
  452. #--------------------------------------------------------------------------
  453. def initialize(filename)
  454. unless FileTest.file?("#{SOV::Video::DIR_NAME}/#{filename}")
  455. raise(Errno::ENOENT,filename)
  456. end
  457. @filename = filename
  458. @x = @@default_x
  459. @y = @@default_y
  460. @width = @@default_width
  461. @height = @@default_height
  462. @exitable = true
  463. @pausable = true
  464. end
  465. #--------------------------------------------------------------------------
  466. # * Get Type
  467. #--------------------------------------------------------------------------
  468. def type
  469. if @type == nil
  470. case File.extname(@filename)
  471. when '.avi'; @type = TYPE_AVI
  472. when '.mpeg'||'.mpg'; @type = TYPE_MPEG
  473. else
  474. @type = TYPE_MPEG#''
  475. end
  476. end
  477. @type
  478. end
  479. #--------------------------------------------------------------------------
  480. # * Is the video exitable?
  481. #--------------------------------------------------------------------------
  482. def exitable?
  483. @exitable
  484. end
  485. #--------------------------------------------------------------------------
  486. # * Is the video pausable?
  487. #--------------------------------------------------------------------------
  488. def pausable?
  489. @pausable
  490. end
  491. #--------------------------------------------------------------------------
  492. # Access
  493. #--------------------------------------------------------------------------
  494. private_class_method :send_command
  495. end
  496.  
  497. #==============================================================================
  498. # ** Game_Interpreter
  499. #==============================================================================
  500.  
  501. class Game_Interpreter
  502. #--------------------------------------------------------------------------
  503. # Import
  504. #--------------------------------------------------------------------------
  505. include(SOV::Video::Commands)
  506. end
  507.  
  508. #==============================================================================
  509. # ** Game_Map
  510. #==============================================================================
  511.  
  512. class Game_Map
  513. #--------------------------------------------------------------------------
  514. # Public Instance Variables
  515. #--------------------------------------------------------------------------
  516. attr_accessor :video
  517. end
  518.  
  519. #==============================================================================
  520. # ** Scene_Map
  521. #==============================================================================
  522.  
  523. class Scene_Map
  524. #--------------------------------------------------------------------------
  525. # Alias List
  526. #--------------------------------------------------------------------------
  527. alias sov_video_update update unless $@
  528. #--------------------------------------------------------------------------
  529. # * Play Video
  530. #--------------------------------------------------------------------------
  531. def play_video(video)
  532. # Memorize and stop current bgm and bgs
  533. bgm = RPG::BGM.last
  534. bgs = RPG::BGS.last
  535. RPG::BGM.stop
  536. RPG::BGS.stop
  537. # Play video
  538. Video.play(video)
  539. # Restart bgm and bgs
  540. bgm.play
  541. bgs.play
  542. end
  543. #--------------------------------------------------------------------------
  544. # * Update
  545. #--------------------------------------------------------------------------
  546. def update
  547. if $game_map.video != nil
  548. play_video($game_map.video)
  549. $game_map.video = nil
  550. Input.update
  551. else
  552. sov_video_update
  553. end
  554. end
  555. end
  556.  
  557. #==============================================================================
  558. # ** Scene_Battle
  559. #==============================================================================
  560.  
  561. class Scene_Battle
  562. #--------------------------------------------------------------------------
  563. # * Alias list
  564. #--------------------------------------------------------------------------
  565. alias sov_video_update_battle update unless $@
  566. alias sov_video_use_item use_item unless $@
  567. #--------------------------------------------------------------------------
  568. # * Play Video
  569. #--------------------------------------------------------------------------
  570. def play_video(video)
  571. # Memorize and stop current bgm
  572. bgm = RPG::BGM.last
  573. RPG::BGM.stop
  574. # Play video
  575. Video.play(video)
  576. # Restart bgm
  577. bgm.play
  578. end
  579. #--------------------------------------------------------------------------
  580. # * Execute Action Skill
  581. #--------------------------------------------------------------------------
  582. def use_item
  583. skill = @subject.current_action.item
  584. if skill.video.is_a?(Video)
  585. execute_action_video(skill)
  586. sov_video_use_item
  587. else
  588. sov_video_use_item
  589. end
  590. end
  591. #--------------------------------------------------------------------------
  592. # * Execute Action Video
  593. #--------------------------------------------------------------------------
  594. def execute_action_video(skill)
  595. br = Graphics.brightness
  596. 120.times { |i| Graphics.brightness = 255 - 255/60 * i; Graphics.update }
  597. # Play video
  598. play_video(skill.video)
  599. # Reset brightness
  600. Graphics.brightness = br
  601. end
  602. #ADDED UPDATE FUNCTION FROM SCENE_MAP TO SCENE_BATTLE
  603. def update
  604. if $game_map.video != nil
  605. play_video($game_map.video)
  606. $game_map.video = nil
  607. Input.update
  608. else
  609. sov_video_update_battle
  610. end
  611. end
  612.  
  613. end
  614.  
  615.  
  616.  
  617.  
  618.  
  619. #==============================================================================
  620. # Pre-Main Processing
  621. #==============================================================================
  622.  
  623. unless FileTest.directory?(SOV::Video::DIR_NAME) # If directory doesn't exist.
  624. Dir.mkdir(SOV::Video::DIR_NAME) # Make the directory
  625. end
  626.  
  627. =begin
  628. =end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement