Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- # Scene Audio
- # Author: ForeverZer0
- # Version: 1.0
- # Date: 9.2.2012
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- #
- # This script is for allowing the player to sample and play the game's audio.
- # It has control for allowing adjustement of volume and pitch. All local and RTP
- # resources are automatically found and categorized by type.
- #
- # To call the scene: $scene = Scene_Audio.new
- #
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- #===============================================================================
- # ** Resources
- #===============================================================================
- module Resources
- #-----------------------------------------------------------------------------
- # * Constants
- #-----------------------------------------------------------------------------
- AUDIO_EXT = ['.mp3', '.ogg', '.wav', '.mid', '.wma']
- GRAPHIC_EXT = ['.png', '.jpg', '.bmp']
- #-----------------------------------------------------------------------------
- # * Gets an array of the game's RTP paths
- #-----------------------------------------------------------------------------
- def self.rtp_paths
- ini = Win32API.new('kernel32', 'GetPrivateProfileStringA', 'PPPPLP', 'L')
- library = "\0" * 256
- ini.call('Game', 'Library', '', library, 256, '.\\Game.ini')
- library.delete!("\0")
- rtp_path = Win32API.new(library, 'RGSSGetRTPPath', 'L', 'L')
- path_with_rtp = Win32API.new(library, 'RGSSGetPathWithRTP', 'L', 'P')
- paths = [1, 2, 3].collect {|id| path_with_rtp.call(rtp_path.call(id)) }
- return paths.find_all {|path| path != '' && File.directory?(path) }
- end
- #-----------------------------------------------------------------------------
- # * Gets a list of files found in the RTP directories
- #-----------------------------------------------------------------------------
- def self.rtp_files
- if @rtp_files == nil
- @rtp_files = []
- self.rtp_paths.each {|rtp| @rtp_files += Dir.glob(rtp + '/**/*') }
- end
- return @rtp_files
- end
- #-----------------------------------------------------------------------------
- # * Gets a list of files found in the local directories
- #-----------------------------------------------------------------------------
- def self.local_files
- if @local_files == nil
- @local_files = Dir.glob('./**/*')
- end
- return @local_files
- end
- #-----------------------------------------------------------------------------
- # * Gets a list of all audio files found locally and in the RTPs
- #-----------------------------------------------------------------------------
- def self.audio_files
- files = rtp_files.find_all {|f| AUDIO_EXT.include?(File.extname(f)) }
- files += local_files.find_all {|f| AUDIO_EXT.include?(File.extname(f))}
- return files
- end
- #-----------------------------------------------------------------------------
- # * Gets a list of all graphic files found locally and in the RTPs
- #-----------------------------------------------------------------------------
- def self.graphic_files
- files = rtp_files.find_all {|f| GRAPHIC_EXT.include?(File.extname(f)) }
- files += local_files.find_all {|f| GRAPHIC_EXT.include?(File.extname(f))}
- return files
- end
- end
- #===============================================================================
- # ** Window_AudioOptions
- #===============================================================================
- class Window_AudioOptions < Window_Selectable
- #-----------------------------------------------------------------------------
- # * Object Initialization
- #-----------------------------------------------------------------------------
- def initialize
- super(320, 128, 320, 352)
- @column_max = 1
- @commands = ['BGM Volume', 'BGS Volume', 'ME Volume', 'SE Volume',
- 'BGM Pitch', 'BGS Pitch', 'ME Pitch', 'SE Pitch']
- @params = [100, 80, 100, 80, 100, 100, 100, 100]
- @item_max = @commands.size
- refresh
- self.active = false
- self.index = -1
- end
- #-----------------------------------------------------------------------------
- # * Clear and redraw the window contents
- #-----------------------------------------------------------------------------
- def refresh
- if self.contents != nil
- self.contents = self.contents.dispose
- end
- self.contents = Bitmap.new(width - 32, @commands.size * 32)
- @commands.each_index {|i| draw_item(i) }
- end
- #-----------------------------------------------------------------------------
- # * Draw an item on the window
- #-----------------------------------------------------------------------------
- def draw_item(i)
- rect = Rect.new(0, i * 32, self.contents.width, 32)
- self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
- self.contents.font.color = system_color
- self.contents.draw_text(4, i * 32, 280, 32, @commands[i])
- self.contents.font.color = normal_color
- self.contents.draw_text(4, i * 32, 280, 32, @params[i].to_s, 2)
- end
- #-----------------------------------------------------------------------------
- # * Get the volume for the given category
- #-----------------------------------------------------------------------------
- def volume(category)
- return @params[category]
- end
- #-----------------------------------------------------------------------------
- # * Get the pitch for the given category
- #-----------------------------------------------------------------------------
- def pitch(category)
- return @params[category + 4]
- end
- #-----------------------------------------------------------------------------
- # * Frame Update
- #-----------------------------------------------------------------------------
- def update
- super
- mod = nil
- mod = -5 if Input.repeat?(Input::LEFT)
- mod = -1 if Input.trigger?(Input::LEFT)
- mod = 5 if Input.repeat?(Input::RIGHT)
- mod = 1 if Input.trigger?(Input::RIGHT)
- if mod != nil
- i = self.index
- if self.index < 4
- @params[i] = [[@params[i] + mod, 100].min, 0].max
- else
- @params[i] = [[@params[i] + mod, 150].min, 50].max
- end
- $game_system.se_play($data_system.cursor_se)
- draw_item(i)
- end
- end
- #-----------------------------------------------------------------------------
- # * Update Help Text
- #-----------------------------------------------------------------------------
- def update_help
- if @help_window != nil
- @help_window.set_text('Use LEFT and RIGHT to change values')
- end
- end
- end
- #===============================================================================
- # ** Window_AudioCommand
- #===============================================================================
- class Window_AudioCommand < Window_Selectable
- #-----------------------------------------------------------------------------
- # * Object Initialization
- #-----------------------------------------------------------------------------
- def initialize
- super(0, 64, 640, 64)
- self.contents = Bitmap.new(width - 32, height - 32)
- @item_max = 5
- @column_max = 5
- @commands = ['BGM', 'BGS', 'ME', 'SE', 'Options']
- refresh
- self.index = 0
- end
- #-----------------------------------------------------------------------------
- # * Clear and redraw the window contents
- #-----------------------------------------------------------------------------
- def refresh
- self.contents.clear
- for i in 0...@item_max
- draw_item(i)
- end
- end
- #-----------------------------------------------------------------------------
- # * Draw an item on the window
- #-----------------------------------------------------------------------------
- def draw_item(index)
- x = 4 + index * 128
- self.contents.draw_text(x, 0, 96, 32, @commands[index])
- end
- #-----------------------------------------------------------------------------
- # * Update the help text
- #-----------------------------------------------------------------------------
- def update_help
- text = case self.index
- when 0 then 'Background Music'
- when 1 then 'Background Sounds'
- when 2 then 'Musical Effects'
- when 3 then 'Sound Effects'
- when 4 then 'Change Audio Options'
- else ''
- end
- @help_window.set_text(text)
- end
- end
- #===============================================================================
- # ** Window_Audio
- #===============================================================================
- class Window_Audio < Window_Selectable
- #-----------------------------------------------------------------------------
- # * Object Initialization
- #-----------------------------------------------------------------------------
- def initialize(filenames)
- super(0, 128, 320, 352)
- @filenames = filenames
- @current_files = []
- self.index = -1
- self.active = false
- change_category(0)
- end
- #-----------------------------------------------------------------------------
- # * Clear and redraw the window contents
- #-----------------------------------------------------------------------------
- def refresh
- self.contents = Bitmap.new(width - 32, @current_files.size * 32)
- @item_max = @current_files.size
- @current_files.each_index {|i|
- file = File.basename(@current_files[i], File.extname(@current_files[i]))
- self.contents.draw_text(4, i * 32, 288, 32, file)
- }
- end
- #-----------------------------------------------------------------------------
- # * Changes the audio type to list and refresh
- #-----------------------------------------------------------------------------
- def change_category(category)
- @subfolder = case category
- when 0 then 'Audio/BGM'
- when 1 then 'Audio/BGS'
- when 2 then 'Audio/ME'
- when 3 then 'Audio/SE'
- else ''
- end
- if category == 4
- self.contents.clear
- return
- end
- @current_files = @filenames.find_all {|f| f.include?(@subfolder) }
- refresh
- end
- #-----------------------------------------------------------------------------
- # * Get the currently selected filename
- #-----------------------------------------------------------------------------
- def audio_file
- if @subfolder == ''
- return ''
- end
- return @current_files[self.index]
- end
- def update_help
- if audio_file == ''
- @help_window.set_text('')
- return
- end
- @help_window.set_text(@subfolder + '/' + File.basename(audio_file))
- end
- end
- #===============================================================================
- # ** Scene_Audio
- #===============================================================================
- class Scene_Audio
- #-----------------------------------------------------------------------------
- # * Clear and redraw the window contents
- #-----------------------------------------------------------------------------
- def main
- $game_system.bgm_memorize
- $game_system.bgs_memorize
- $game_system.bgm_stop
- $game_system.bgs_stop
- @help_window = Window_Help.new
- @command_window = Window_AudioCommand.new
- @command_window.active = true
- @command_window.help_window = @help_window
- @audio_window = Window_Audio.new(Resources.audio_files)
- @audio_window.help_window = @help_window
- @options_window = Window_AudioOptions.new
- @options_window.help_window = @help_window
- Graphics.transition
- loop { Graphics.update; Input.update; update; break if $scene != self }
- Graphics.freeze
- @audio_window.dispose
- @command_window.dispose
- @options_window.dispose
- @help_window.dispose
- $game_system.bgm_restore
- $game_system.bgs_restore
- end
- #-----------------------------------------------------------------------------
- # * Get the current category index
- #-----------------------------------------------------------------------------
- def category
- return @command_window.index
- end
- #-----------------------------------------------------------------------------
- # * Frame Update
- #-----------------------------------------------------------------------------
- def update
- @help_window.update
- if @command_window.active
- update_command
- return
- elsif @audio_window.active
- update_audio
- return
- elsif @options_window.active
- update_options
- return
- end
- end
- #-----------------------------------------------------------------------------
- # * Update the command window
- #-----------------------------------------------------------------------------
- def update_command
- @command_window.update
- if Input.trigger?(Input::B)
- $game_system.se_play($data_system.cancel_se)
- $scene = Scene_Map.new
- elsif Input.trigger?(Input::C)
- $game_system.se_play($data_system.decision_se)
- @command_window.active = false
- if category == 4
- @options_window.active = true
- @options_window.index = 0
- else
- @audio_window.active = true
- @audio_window.index = 0
- end
- elsif Input.trigger?(Input::LEFT) || Input.trigger?(Input::RIGHT) ||
- Input.trigger?(Input::L) || Input.trigger?(Input::R)
- @audio_window.change_category(category)
- end
- end
- #-----------------------------------------------------------------------------
- # * Update the audio selection window
- #-----------------------------------------------------------------------------
- def update_audio
- @audio_window.update
- if Input.trigger?(Input::B)
- @audio_window.active = false
- @audio_window.index = -1
- @command_window.active = true
- $game_system.se_play($data_system.cancel_se)
- elsif Input.trigger?(Input::C)
- volume = @options_window.volume(category)
- pitch = @options_window.pitch(category)
- file = @audio_window.audio_file
- case category
- when 0 then Audio.bgm_play(file, volume, pitch)
- when 1 then Audio.bgs_play(file, volume, pitch)
- when 2 then Audio.me_play(file, volume, pitch)
- when 3 then Audio.se_play(file, volume, pitch)
- end
- end
- end
- #-----------------------------------------------------------------------------
- # * Update the audio options window
- #-----------------------------------------------------------------------------
- def update_options
- @options_window.update
- if Input.trigger?(Input::B)
- @options_window.active = false
- @options_window.index = -1
- @command_window.active = true
- $game_system.se_play($data_system.cancel_se)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement