Advertisement
Guest User

RPG Maker VX Ace - Video Player

a guest
Aug 31st, 2015
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.01 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # [ACE]EST_SOV_Video_Player ++ Conversion (Tłumaczenie - Yoroiookami)
  4. #
  5. # v1.4
  6. #==============================================================================
  7. # Autor : Estriole
  8. # (Konwersja na Ace i usprawnienia)
  9. # Autor wersji pod VX: SuperOverlord
  10. #
  11. # do Credits dodajcie także Crystal Noel za solucję problemu z enkodowaniem
  12. # do Credits dodajcie też Ruin za poprawki w tym skrypcie.
  13. #
  14. # Historia/Rzeczy nieważne :
  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. # Na co skrypt pozwala:
  30. #------------------------------------------------------------------------------
  31. # o Odtwarzanie wideo na mapie lub w walce.
  32. #
  33. # o Pauza lub przerwanie wideo podczas odtwarzania.
  34. #
  35. # o Odtwarzanie wideo w okienku gry lub na pełnym ekranie.
  36. #
  37. # o Ustawianie wideo od umiejętności, wyświetlane przed obrażeniami.
  38. #
  39. # o Wersja Ace pozwala na podobną rzecz z przedmiotami.
  40. #
  41. # o Wersja Ace pozwala na uruchomienie wideo przed ekranem tytułowym.
  42. #
  43. #==============================================================================
  44. # Instrukcje:
  45. #------------------------------------------------------------------------------
  46. # o Umieść wszystkie wideo w folderze z taką samą nazwą jak w konfiguracji.
  47. # Ten folder tworzy się automatycznie za pierwszym razem, gdy odpalana jest gra jeśli
  48. # już nie istnieje.
  49. #
  50. # o Odtwarzanie wideo na mapie.
  51. #
  52. # - Zobacz wywołanie skryptów poniżej.
  53. #
  54. # o Odtwarzanie wideo w walce..
  55. #
  56. # - Funkcja wywoływania skryptów może być użyta zarówno na mapie jak i podczas walki.
  57. #
  58. # - Oprócz tego możesz ustawić umiejętności tak, żeby odtwarzały wideo przed
  59. # tym jak przeciwnik otrzymuje obrażenia.
  60. #
  61. # <to co wymienione poniżej może być też użyte przy dodawaniu wideo do przedmiotów>
  62. # Żeby tego użyć, następujące tagi muszą być dodane w okienku na komentarze umiejętności:
  63. # 1) <video_name = "nazwapliku">
  64. # ~ "nazwapliku" to nazwa pliku wideo. Jeżeli rozszerzenie pliku nie jest zapisane
  65. # pierwszy pasujący plik zostanie automatycznie użyty.
  66. # (Znaki cudzysłowiu są konieczne przy podawaniu nazwy)
  67. #
  68. # Można używać dwóch tagów zamiast oprócz tego jednego. Te tagi zadziałają tylko
  69. # jeśli oba są umieszczone poniżej pierwszego.
  70. # Jeżeli one nie istnieją, zakłada się, że są "true".
  71. #
  72. # 2) <video_exitable = n> ~ Czy wideo może być zatrzymane klikając przycisk?
  73. # 3) <video_pausable = n> ~ Czy wideo może być pauzowane?
  74. # ~ n jest zastąpione przez t lub f (t : true, f : false)
  75. #
  76. # Dla innych ustawień wideo (x, y, szerokość, wysokość, pełny ekran) używane są
  77. # podstawowe ustawienia. (Zobacz wywołanie skryptów poniżej)
  78. #
  79. # o Odtwarzanie wideo przed ekranem tytułowym
  80. # ctrl + f i wyszukaj to : CONFIGURATION FOR VIDEO BEFORE TITLE
  81. # i zamień
  82. # @video_title = nil
  83. # na
  84. # @video_title = "yourvideonamewithoutextensionhere"
  85. #
  86. #==============================================================================
  87. # Wywołanie Skryptów:
  88. #------------------------------------------------------------------------------
  89. # Komendy (Z okienka wywołania skryptów na trzeciej stronie zdarzeń)
  90. #------------------------------------------------------------------------------
  91. # o Na zmianę podstawowych ustawień wideo.
  92. #
  93. # 1) Video.default_x = n #współrzędna x
  94. # 2) Video.default_y = n #współrzędna y
  95. # 3) Video.default_width = n #szerokość
  96. # 4) Video.default_height = n #wysokość
  97. # 5) Video.fullscreen = bool #pełny ekran; na razie wyłączony, bo może wywoływać błędy
  98. #
  99. # We wszystkich 5 komendach powyżej:
  100. # ~ n jest liczbą całkowitą
  101. # ~ bool jest albo true albo false (prawdziwe lub fałszywe)
  102. #
  103. # o Na odtwarzanie wideo
  104. #
  105. # play_video(nazwapliku,możnaprzerwać?(true/false),możnapauzować?(true/false))
  106. # ~ filename : nazwa pliku wideo (Musi być w cudzysłowiu)
  107. # ~ exitable : Czy można przerwać odtwarzanie i wyjść z wideo? (Bez zmian = true)
  108. # ~ pausable : Czy wideo można zapauzować podczas odtwarzania? (Bez zmian = true)
  109. #
  110. # Dla wszystkich innych wartości, używane są te domyślne.
  111. #==============================================================================
  112. # Kompatybilność:
  113. #------------------------------------------------------------------------------
  114. # o Wideo użytych umiejętności zależą od systemu walki, ale powinny działać.
  115. #==============================================================================
  116. # Credit/Podziękowania:
  117. #------------------------------------------------------------------------------
  118. # o Podziękowania dla Trebor i Berka których skrypty pomogły mi rozgryźć
  119. # funkcję mci_send_stringA.
  120. #==============================================================================
  121.  
  122. module SOV
  123. module Video
  124. #--------------------------------------------------------------------------
  125. # Konfiguracja
  126. #--------------------------------------------------------------------------
  127. # Nazwa folderu w którym przechowywane będą wideo.
  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. #pozostaw "true" jeśli twój Title zawiera dziwne literki, jak é lub inne. (?)
  136. #--------------------------------------------------------------------------
  137. # Koniec Konfiguracji
  138. #--------------------------------------------------------------------------
  139. end
  140. end
  141.  
  142. module SceneManager
  143. ################ KONFIGURACJA DLA WIDEO PRZED EKRANEM TYTUŁOWYM #######################
  144. @video_title = nil # "przykład" # NAZWA PLIKU W FOLDERZE WIDEO W CUDZYSŁOWIU
  145. #JEŻELI NIE CHCESZ TEGO UŻYĆ, USTAW NA "nil".
  146. ################ KONIEC KONFIGURACJI ##########################################
  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 # Czy wideo da się przerwać? (True/False)
  153. video.pausable = true # Czy wideo można zapauzować? (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. class << Graphics
  162. def Graphics.fullscreen? # Właściwości
  163. screen_size = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
  164. screen_width = screen_size.call(0); screen_height = screen_size.call(1)
  165. detect_fullscreen = false
  166. detect_fullscreen = true if screen_width == 640 and screen_height == 480
  167. return detect_fullscreen
  168. end
  169. def Graphics.toggle_fullscreen # Main function
  170. keybd = Win32API.new 'user32.dll', 'keybd_event', ['i', 'i', 'l', 'l'], 'v'
  171. keybd.call(0xA4, 0, 0, 0)
  172. keybd.call(13, 0, 0, 0)
  173. keybd.call(13, 0, 2, 0)
  174. keybd.call(0xA4, 0, 2, 0)
  175. end
  176. end
  177.  
  178. #==============================================================================
  179. # Importowanie
  180. #------------------------------------------------------------------------------
  181. $imported = {} if $imported == nil
  182. $imported['Videos'] = true
  183. #==============================================================================
  184.  
  185. #==============================================================================
  186. # ** SOV::Video::Commands
  187. #==============================================================================
  188.  
  189. module SOV::Video::Commands
  190. #--------------------------------------------------------------------------
  191. # * Odtwarzanie wideo
  192. # filename : nazwa pliku wideo (z rozszerzeniem lub bez)
  193. # exitable : Czy wideo można przerwać? (true/false)
  194. # pausable : Czy wideo można zapauzować? (true/false)
  195. #--------------------------------------------------------------------------
  196. def play_video(filename,exitable=true,pausable=true)
  197. video = Cache.video(filename)
  198. video.exitable = exitable
  199. video.pausable = pausable
  200. $game_map.video = video
  201. end
  202. #---------------------------------------------------------------------------
  203. # Define module blahblah
  204. #---------------------------------------------------------------------------
  205. module_function :play_video
  206. end
  207.  
  208. #==============================================================================
  209. # ** SOV::Video::Regexp
  210. #==============================================================================
  211.  
  212. module SOV::Video::Regexp
  213. #--------------------------------------------------------------------------
  214. # * Skill
  215. #--------------------------------------------------------------------------
  216. module Skill
  217. FILENAME = /<video[_ ]?(?:file)?name = "(.+)">/i
  218. PAUSABLE = /<video[_ ]?paus(?:e|able) = (t|f)>/i
  219. EXITABLE = /<video[_ ]?exit(?:able)? = (t|f)>/i
  220. end
  221. end
  222.  
  223. #==============================================================================
  224. # ** SOV::Game
  225. #==============================================================================
  226.  
  227. module SOV::Game
  228. #--------------------------------------------------------------------------
  229. # Constants
  230. #--------------------------------------------------------------------------
  231. INI = 'Game'
  232. #--------------------------------------------------------------------------
  233. # * Get the game windows handle
  234. #--------------------------------------------------------------------------
  235. def self.hwnd
  236. unless defined?(@@hwnd)
  237. find_window = Win32API.new('user32','FindWindow','pp','i')
  238. # @@hwnd = find_window.call('RGSS Player',title)
  239. gamefullscreen = Graphics.fullscreen?
  240. @@hwnd = find_window.call('RGSS Player',title)
  241. end
  242. return @@hwnd
  243. end
  244. #--------------------------------------------------------------------------
  245. # * Get game title
  246. #--------------------------------------------------------------------------
  247. def self.title
  248. unless defined?(@@title)
  249. @@title = read_ini('title')
  250. end
  251. return @@title
  252. end
  253. #--------------------------------------------------------------------------
  254. # * Read ini (Returns nil or match)
  255. #--------------------------------------------------------------------------
  256. def self.read_ini(variable,filename=INI)
  257. return nil if variable == 'title' && SOV::Video::IGNORE_TITLE
  258. reg = /^#{variable}=(.*)$/
  259. File.foreach(filename+'.ini') { |line| break($1) if line =~ reg }
  260. end
  261. end
  262.  
  263. #==============================================================================
  264. # ** Cache
  265. #==============================================================================
  266.  
  267. module Cache
  268. #--------------------------------------------------------------------------
  269. # Class Variables
  270. #--------------------------------------------------------------------------
  271. @@vcache = {}
  272. #--------------------------------------------------------------------------
  273. # Define as class methods
  274. #--------------------------------------------------------------------------
  275. class << self
  276. #------------------------------------------------------------------------
  277. # Alias List
  278. #------------------------------------------------------------------------
  279. alias sov_video_clear clear unless $@
  280. #------------------------------------------------------------------------
  281. # * Get a video object
  282. # filename : basename of file
  283. #------------------------------------------------------------------------
  284. def video(filename)
  285. # Get full filename if extension is missing
  286. if File.extname(filename) == ''
  287. files = Dir["#{SOV::Video::DIR_NAME}/#{filename}.*"]
  288. filename = File.basename(files[0]) # Set as first matching file
  289. end
  290. # Create or get the video object.
  291. if @@vcache.has_key?(filename)
  292. @@vcache[filename]
  293. else
  294. @@vcache[filename] = Video.new(filename)
  295. end
  296. end
  297. #------------------------------------------------------------------------
  298. # * Clear
  299. #------------------------------------------------------------------------
  300. def clear
  301. @@vcache.clear
  302. sov_video_clear
  303. end
  304. end
  305. end
  306.  
  307. #==============================================================================
  308. # ** RPG::Skill
  309. #==============================================================================
  310.  
  311. class RPG::UsableItem
  312. #--------------------------------------------------------------------------
  313. # * Determine if skill has a video skill
  314. #--------------------------------------------------------------------------
  315. def video
  316. if @video == nil
  317. @note.each_line { |line|
  318. if @video == nil
  319. @video = Cache.video($1) if line =~ SOV::Video::Regexp::Skill::FILENAME
  320. else
  321. @video.pausable = ($1 == 't') if line =~ SOV::Video::Regexp::Skill::PAUSABLE
  322. @video.exitable = ($1 == 't') if line =~ SOV::Video::Regexp::Skill::EXITABLE
  323. end
  324. }
  325. @video = :invalid if @video == nil
  326. end
  327. return @video
  328. end
  329. end
  330.  
  331. #==============================================================================
  332. # ** Video
  333. #------------------------------------------------------------------------------
  334. # Class handling playing videos.
  335. #==============================================================================
  336.  
  337. class Video
  338. #--------------------------------------------------------------------------
  339. # Constants
  340. #--------------------------------------------------------------------------
  341. TYPE_AVI = 'avivideo'
  342. TYPE_MPEG = 'mpegvideo'
  343. #--------------------------------------------------------------------------
  344. # Class Variables
  345. #--------------------------------------------------------------------------
  346. @@default_x = 0
  347. @@default_y = 0
  348. @@default_width = Graphics.width
  349. @@default_height = Graphics.height
  350. @@fullscreen = false
  351. #--------------------------------------------------------------------------
  352. # * Get and Set default_x/y/width/height
  353. #--------------------------------------------------------------------------
  354. for d in %w(x y width height)
  355. # Define setter method
  356. module_eval(%Q(def self.default_#{d}=(i); @@default_#{d} = i; end))
  357. # Define getter method
  358. module_eval(%Q(def self.default_#{d}; @@default_#{d}; end))
  359. end
  360. #--------------------------------------------------------------------------
  361. # * Get fullscreen
  362. #--------------------------------------------------------------------------
  363. def self.fullscreen
  364. @@fullscreen
  365. end
  366. #--------------------------------------------------------------------------
  367. # * Set fullscreen
  368. #--------------------------------------------------------------------------
  369. def self.fullscreen=(val)
  370. @@fullscreen = val
  371. end
  372. #--------------------------------------------------------------------------
  373. # * Win32API
  374. #--------------------------------------------------------------------------
  375. @@mciSendStringA = Win32API.new('winmm','mciSendStringA','pplp','i')
  376. #--------------------------------------------------------------------------
  377. # * Video Command
  378. # command_string : string following mci_command_string format
  379. # buffer : string to retrieve return data
  380. # buffer_size : number of characters in buffer
  381. # callback_handle : handle of window to callback to. Used if notify is used
  382. # in the command string. (Not supported by game window)
  383. #--------------------------------------------------------------------------
  384. def self.send_command(cmnd_string,buffer='',buffer_size=0,callback_handle=0)
  385. # Returns error code. No error if NULL
  386. err = @@mciSendStringA.call(cmnd_string,buffer,buffer_size,callback_handle)
  387. if err != 0
  388. buffer = ' ' * 255
  389. Win32API.new('winmm','mciGetErrorString','LPL','V').call(err,buffer,255)
  390. raise(buffer.squeeze(' ').chomp('\000'))
  391. end
  392. end
  393.  
  394. #--------------------------------------------------------------------------
  395. # * Play a video
  396. #--------------------------------------------------------------------------
  397. def self.play(video)
  398. # Make path and buffer
  399. path = "#{SOV::Video::DIR_NAME}/#{video.filename}"
  400. buffer = ' ' * 255
  401. # Initialize device and dock window with game window as parent.
  402. type = " type #{video.type}" if video.type != ''
  403. send_command("open #{path}#{type} alias VIDEO style child parent #{SOV::Game.hwnd}")
  404. # Display video in client rect at x,y with width and height.
  405. x = video.x
  406. y = video.y
  407. width = video.width
  408. height = video.height
  409. send_command("put VIDEO window at #{x} #{y} #{width} #{height}")
  410. # Begin playing video
  411. screen = @@fullscreen ? 'fullscreen' : 'window'
  412. gamefullscreen = Graphics.fullscreen?
  413. case video.type
  414. when "avivideo"
  415. if gamefullscreen == true
  416. #send_command("put VIDEO window at #{x} #{y} 640 480")
  417. Graphics.toggle_fullscreen
  418. send_command("play VIDEO window")
  419. else
  420. send_command("play VIDEO window")
  421. end
  422. when "mpegvideo"
  423. if gamefullscreen == true
  424. Graphics.toggle_fullscreen
  425. send_command("play VIDEO window")
  426. else
  427. send_command("play VIDEO fullscreen")
  428. end
  429. else
  430. end
  431. flag = 0
  432. # Start Input and status processing loop
  433. while buffer !~ /^stopped/
  434. # Idle processing for a frame
  435. sleep(1.0/Graphics.frame_rate)
  436. # Get mode string
  437. send_command('status VIDEO mode',buffer,255)
  438. Input.update
  439. if Input.trigger?(SOV::Video::PAUSE_INPUT) and video.pausable?
  440. Sound.play_cursor
  441. if buffer =~ /^paused/ # If already paused
  442. send_command("resume VIDEO") # Resume video
  443. else # Otherwise
  444. send_command("pause VIDEO") # Pause video
  445. end
  446. elsif Input.trigger?(SOV::Video::EXIT_INPUT) and video.exitable?
  447. Sound.play_cancel
  448. # Terminate loop on exit input
  449. break
  450. end
  451. end
  452. # Terminate the device
  453. send_command('close VIDEO')
  454. end
  455. #--------------------------------------------------------------------------
  456. # Public Instance Variables
  457. #--------------------------------------------------------------------------
  458. attr_accessor :x
  459. attr_accessor :y
  460. attr_accessor :width
  461. attr_accessor :height
  462. attr_writer :exitable
  463. attr_writer :pausable
  464. attr_reader :filename
  465. #--------------------------------------------------------------------------
  466. # * Initialize
  467. #--------------------------------------------------------------------------
  468. def initialize(filename)
  469. unless FileTest.file?("#{SOV::Video::DIR_NAME}/#{filename}")
  470. raise(Errno::ENOENT,filename)
  471. end
  472. @filename = filename
  473. @x = @@default_x
  474. @y = @@default_y
  475. @width = @@default_width
  476. @height = @@default_height
  477. @exitable = true
  478. @pausable = true
  479. end
  480. #--------------------------------------------------------------------------
  481. # * Get Type
  482. #--------------------------------------------------------------------------
  483. def type
  484. if @type == nil
  485. case File.extname(@filename)
  486. when '.avi'; @type = TYPE_AVI
  487. when '.mpeg'||'.mpg'; @type = TYPE_MPEG
  488. else
  489. @type = TYPE_MPEG#''
  490. end
  491. end
  492. @type
  493. end
  494. #--------------------------------------------------------------------------
  495. # * Is the video exitable?
  496. #--------------------------------------------------------------------------
  497. def exitable?
  498. @exitable
  499. end
  500. #--------------------------------------------------------------------------
  501. # * Is the video pausable?
  502. #--------------------------------------------------------------------------
  503. def pausable?
  504. @pausable
  505. end
  506. #--------------------------------------------------------------------------
  507. # Access
  508. #--------------------------------------------------------------------------
  509. private_class_method :send_command
  510. end
  511.  
  512. #==============================================================================
  513. # ** Game_Interpreter
  514. #==============================================================================
  515.  
  516. class Game_Interpreter
  517. #--------------------------------------------------------------------------
  518. # Import
  519. #--------------------------------------------------------------------------
  520. include(SOV::Video::Commands)
  521. end
  522.  
  523. #==============================================================================
  524. # ** Game_Map
  525. #==============================================================================
  526.  
  527. class Game_Map
  528. #--------------------------------------------------------------------------
  529. # Public Instance Variables
  530. #--------------------------------------------------------------------------
  531. attr_accessor :video
  532. end
  533.  
  534. #==============================================================================
  535. # ** Scene_Map
  536. #==============================================================================
  537.  
  538. class Scene_Map
  539. #--------------------------------------------------------------------------
  540. # Alias List
  541. #--------------------------------------------------------------------------
  542. alias sov_video_update update unless $@
  543. #--------------------------------------------------------------------------
  544. # * Play Video
  545. #--------------------------------------------------------------------------
  546. def play_video(video)
  547. # Memorize and stop current bgm and bgs
  548. bgm = RPG::BGM.last
  549. bgs = RPG::BGS.last
  550. RPG::BGM.stop
  551. RPG::BGS.stop
  552. # Play video
  553. Video.play(video)
  554. # Restart bgm and bgs
  555. bgm.play
  556. bgs.play
  557. end
  558. #--------------------------------------------------------------------------
  559. # * Update
  560. #--------------------------------------------------------------------------
  561. def update
  562. if $game_map.video != nil
  563. play_video($game_map.video)
  564. $game_map.video = nil
  565. Input.update
  566. else
  567. sov_video_update
  568. end
  569. end
  570. end
  571.  
  572. #==============================================================================
  573. # ** Scene_Battle
  574. #==============================================================================
  575.  
  576. class Scene_Battle
  577. #--------------------------------------------------------------------------
  578. # * Alias list
  579. #--------------------------------------------------------------------------
  580. alias sov_video_update_battle update unless $@
  581. alias sov_video_use_item use_item unless $@
  582. #--------------------------------------------------------------------------
  583. # * Play Video
  584. #--------------------------------------------------------------------------
  585. def play_video(video)
  586. # Memorize and stop current bgm
  587. bgm = RPG::BGM.last
  588. RPG::BGM.stop
  589. # Play video
  590. Video.play(video)
  591. # Restart bgm
  592. bgm.play
  593. end
  594. #--------------------------------------------------------------------------
  595. # * Execute Action Skill
  596. #--------------------------------------------------------------------------
  597. def use_item
  598. skill = @subject.current_action.item
  599. if skill.video.is_a?(Video)
  600. execute_action_video(skill)
  601. sov_video_use_item
  602. else
  603. sov_video_use_item
  604. end
  605. end
  606. #--------------------------------------------------------------------------
  607. # * Execute Action Video
  608. #--------------------------------------------------------------------------
  609. def execute_action_video(skill)
  610. br = Graphics.brightness
  611. 120.times { |i| Graphics.brightness = 255 - 255/60 * i; Graphics.update }
  612. # Play video
  613. play_video(skill.video)
  614. # Reset brightness
  615. Graphics.brightness = br
  616. end
  617. #ADDED UPDATE FUNCTION FROM SCENE_MAP TO SCENE_BATTLE
  618. def update
  619. if $game_map.video != nil
  620. play_video($game_map.video)
  621. $game_map.video = nil
  622. Input.update
  623. else
  624. sov_video_update_battle
  625. end
  626. end
  627.  
  628. end
  629.  
  630.  
  631.  
  632.  
  633.  
  634. #==============================================================================
  635. # Pre-Main Processing
  636. #==============================================================================
  637.  
  638. unless FileTest.directory?(SOV::Video::DIR_NAME) # If directory doesn't exist.
  639. Dir.mkdir(SOV::Video::DIR_NAME) # Make the directory
  640. end
  641.  
  642. =begin
  643. =end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement