Advertisement
diamondandplatinum3

Sound Test Scene ~ Non-Customisable Version ~ RGSS3

Jun 18th, 2013
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 34.58 KB | None | 0 0
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #             Sound Test Scene (Non-Customisable Version)
  3. #             Version: 1.0
  4. #             Author: DiamondandPlatinum3
  5. #             Date: June 18, 2013
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. #  Description:
  8. #
  9. #    This script creates a new scene in your menu which allows you to listen to
  10. #    music in your game. This Version does not allow the control the other
  11. #    version has, but instead allows you to simply select a folder for audio to
  12. #    be added and never have to update the script again for any new sounds in
  13. #    that folder.
  14. #
  15. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. #------------------------------------------------------------------------------
  17. #  Instructions:
  18. #
  19. #  ~  Go into the Script and Modify the Editable Region as Needed
  20. #
  21. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  22. module DiamondandPlatinum3
  23.   module SoundTestScene
  24.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  25.     #                                                        -=
  26.     #                 Editable Region        ////            ==
  27.     #                                                        =-
  28.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  29.    
  30.     # The Text that is displayed for the Option in the Menu
  31.     MenuCommandText = "Sound Test"
  32.    
  33.     # Text to be displayed on the help window when Selecting a Sound
  34.     SoundSelectHelpWindowTextLine1      = "Select a Sound"
  35.     SoundSelectHelpWindowTextLine2      = "Press 'Esc or X' to Exit"
  36.    
  37.     # Text to be displayed on the help window when Hovering over the 'Play Sound' Option
  38.     PlaySoundOptionHelpWindowTextLine1  = "Select To Play Sound"
  39.     PlaySoundOptionHelpWindowTextLine2  = "(Default Settings)"
  40.    
  41.     # Text to be displayed on the help window when Hovering over the 'Volume' Option
  42.     VolumeOptionHelpWindowTextLine1     = "Select To Play Sound"
  43.     VolumeOptionHelpWindowTextLine2     = "(At Specific Volume)"
  44.    
  45.     # Text to be displayed on the help window when Hovering over the 'Pitch' Option
  46.     PitchOptionHelpWindowTextLine1      = "Select To Play Sound"
  47.     PitchOptionHelpWindowTextLine2      = "(At Specific Pitch)"
  48.    
  49.     # Text to be displayed on the help window when Hovering over the 'Position' Option
  50.     PositionOptionHelpWindowTextLine1   = "Select To Play Sound At Specific Position"
  51.     PositionOptionHelpWindowTextLine2   = "(Only works for WAV & OGG Files)"
  52.    
  53.     # Text to be displayed on the help window when inputting a value in the NuberInput Window
  54.     NumberInputHelpWindowTextLine1      = "Input A Value"
  55.     NumberInputHelpWindowTextLine2      = ""
  56.    
  57.    
  58.     # Filename of background Image to be displayed when using the scene (Located in Pictures Folder)
  59.     BackgroundSpriteFilename            = "SoundTest_BackgroundImage"
  60.    
  61.    
  62.     # Default Audio Volume/Pitch
  63.     DefaultVolume = 100
  64.     DefaultPitch  = 100
  65.    
  66.    
  67.     # Path to RTP Audio. This May be different on your own Computer
  68.     IncludeRTP     = true
  69.     PathToRTPAudio = "C:/Program Files (x86)/Common Files/Enterbrain/RGSS3/RPGVXAce/Audio/BGM/"
  70.    
  71.    
  72.     # Custom Audio Paths
  73.     CustomAudioPaths =
  74.     [
  75.           "Audio/BGM/",     # Regular Custom Audio Path
  76.           "",               # Put A Custom Audio Path Here if Desired
  77.                             # Make As Many Custom Audio Paths as you would Like
  78.          
  79.     ]
  80.    
  81.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  82.     #                                           \/
  83.     #               End of Editable Region      /\
  84.     #                                           \/
  85.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  86.     #---------------------------------------------------------
  87.     # No touchie past here unless you know what you are
  88.     # doing. Failure to heed this warning could cause your
  89.     # computer to yell and scream at you.
  90.     #
  91.     # Edit at your own risk.
  92.     #--------------------------------------------------------
  93.   end
  94. end
  95.  
  96.  
  97.  
  98.  
  99. #==============================================================================
  100. # ** SoundTestSound
  101. #------------------------------------------------------------------------------
  102. #  This is a class which hold Individual Sound Information for Play
  103. #==============================================================================
  104.  
  105. class SoundTestSound
  106.   include DiamondandPlatinum3::SoundTestScene
  107.   #--------------------------------------------------------------------------
  108.   # * Public Instance Variables
  109.   #--------------------------------------------------------------------------
  110.   attr_accessor :filename
  111.   attr_accessor :display_name
  112.   attr_accessor :volume
  113.   attr_accessor :pitch
  114.   #--------------------------------------------------------------------------
  115.   # * Intialize
  116.   #--------------------------------------------------------------------------
  117.   def initialize( filename, volume, pitch, display )
  118.     @filename     = filename
  119.     @volume       = volume
  120.     @pitch        = pitch
  121.     @display_name = display
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # * Play Sound
  125.   #--------------------------------------------------------------------------
  126.   def play()
  127.     RPG::BGM.stop()
  128.     Audio.bgm_play( @filename, @volume, @pitch )
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Play Sound at Position
  132.   #--------------------------------------------------------------------------
  133.   def play_at_position( position )
  134.     RPG::BGM.stop()
  135.     Audio.bgm_play( @filename, @volume, @pitch, position )
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # * Play Sound ( Default )
  139.   #--------------------------------------------------------------------------
  140.   def default_play()
  141.     RPG::BGM.stop()
  142.     Audio.bgm_play( @filename, DefaultVolume, DefaultPitch )
  143.   end
  144. end
  145.  
  146.  
  147.  
  148.  
  149.  
  150. #==============================================================================
  151. # ** Scene_SoundTest
  152. #------------------------------------------------------------------------------
  153. #  This Clas Holds the Scene Information for the SoundTest
  154. #==============================================================================
  155.  
  156. class Scene_SoundTest < Scene_Base
  157.   include DiamondandPlatinum3::SoundTestScene
  158.   #--------------------------------------------------------------------------
  159.   # * Start Processing
  160.   #--------------------------------------------------------------------------
  161.   def start
  162.     super()
  163.    
  164.     save_current_bgm()
  165.     create_background_image()
  166.     create_soundtestfiles_array()
  167.     create_command_windows()
  168.     create_help_window()
  169.     create_soundinfo_window()
  170.     create_numberinput_window()
  171.     set_input_variables()
  172.     setup_scene_intro_animation()
  173.     # Current Selected Sound
  174.     @current_sound_symbol = nil
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * Post-Start Processing
  178.   #--------------------------------------------------------------------------
  179.   def post_start
  180.     super()
  181.     animate_intro_scene()
  182.   end  
  183.   #--------------------------------------------------------------------------
  184.   # * Frame Update
  185.   #--------------------------------------------------------------------------
  186.   def update
  187.     super()
  188.    
  189.     update_window_info_text()
  190.     update_help_text()
  191.     update_scene_changes()
  192.     update_user_input()
  193.   end
  194.   #--------------------------------------------------------------------------
  195.   # * Pre-Termination Processing
  196.   #--------------------------------------------------------------------------
  197.   def pre_terminate
  198.     super()
  199.    
  200.     @current_map_bgm.replay()
  201.   end
  202.   #--------------------------------------------------------------------------
  203.   # * Termination Processing
  204.   #--------------------------------------------------------------------------
  205.   def terminate
  206.     @sound_select_cmmdwindow.dispose()  unless @sound_select_cmmdwindow.disposed?
  207.     @sound_play_cmmdwindow.dispose()    unless @sound_play_cmmdwindow.disposed?
  208.     @help_window.dispose()              unless @help_window.disposed?
  209.     @sound_info_window.dispose()        unless @sound_info_window.disposed?
  210.     @numberinput_window.dispose()       unless @numberinput_window.disposed?
  211.    
  212.     unless @background_image.disposed?
  213.       @background_image.bitmap.dispose()
  214.       @background_image.dispose()
  215.     end
  216.    
  217.     super()
  218.   end  
  219.   #--------------------------------------------------------------------------
  220.   # * Save Current BGM
  221.   #--------------------------------------------------------------------------
  222.   def save_current_bgm()
  223.     # Get Current BGM
  224.     @current_map_bgm = RPG::BGM.last
  225.     RPG::BGM.stop()
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Create Background Image
  229.   #--------------------------------------------------------------------------
  230.   def create_background_image()
  231.     @background_image = Sprite.new()
  232.     @background_image.bitmap = Cache.picture(BackgroundSpriteFilename)
  233.     @background_image.x = 0
  234.     @background_image.y = 0
  235.     @background_image.z = 1
  236.     @background_image.zoom_x = (Graphics.width.to_f / @background_image.bitmap.width)
  237.     @background_image.zoom_y = (Graphics.height.to_f / @background_image.bitmap.height)
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   # * Create SoundTest Files Array
  241.   #--------------------------------------------------------------------------
  242.   def create_soundtestfiles_array()
  243.     @soundfiles_hash = {}
  244.     # Add Custom Sound Folders
  245.     for folder_name in CustomAudioPaths
  246.       next if folder_name == ""
  247.       if does_directory_exist?( folder_name )
  248.         sounds_array = get_sounds_in_directory( folder_name )
  249.         for filename in sounds_array
  250.           @soundfiles_hash[ (folder_name + filename).to_sym ] = SoundTestSound.new( (folder_name + filename), DefaultVolume, DefaultPitch, filename )
  251.         end
  252.       end
  253.     end
  254.     # Add RTP
  255.     if IncludeRTP && does_directory_exist?( PathToRTPAudio )
  256.       sounds_array = get_sounds_in_directory( PathToRTPAudio )
  257.       for filename in sounds_array
  258.         @soundfiles_hash[ filename.to_sym ] = SoundTestSound.new( (PathToRTPAudio + filename), DefaultVolume, DefaultPitch, filename )
  259.       end
  260.     end
  261.   end
  262.   #--------------------------------------------------------------------------
  263.   # * Check if Directory Exists?
  264.   #--------------------------------------------------------------------------
  265.   def does_directory_exist?( directory_name )
  266.     if Dir.exists?( directory_name )
  267.       return true
  268.     else
  269.       msgbox_p( "Error: Cannot Find Folder Directory '#{directory_name}'") unless !$TEST
  270.       return false
  271.     end
  272.   end
  273.   #--------------------------------------------------------------------------
  274.   # * Get Sounds in Directory
  275.   #--------------------------------------------------------------------------
  276.   def get_sounds_in_directory( directory_name )
  277.     sound_array = Dir.entries(directory_name)
  278.     sound_array.delete( "." )   # Removes Directory Filenames
  279.     sound_array.delete( ".." )  # "." = Self, ".." = Parent | <= Not Sound Filenames
  280.    
  281.     # Only Get Audio Files
  282.     accepted_formats = [ ".MP3", ".M4A", ".AAC", ".WAV", ".WMA", ".OGG", ".FLAC", ".APE", ".MID", ".MIDI", ]
  283.     delete_indexes = []
  284.     # If any FileExtension Does Not Match Above, Add it to the Delete Array
  285.     for i in 0..(sound_array.size - 1)
  286.       unless accepted_formats.include?(File.extname(sound_array[i]).upcase)
  287.         delete_indexes.push(i)
  288.       end
  289.     end
  290.     # Delete All Elements in the Sound_Array that have not been designated as a Sound_File
  291.     index = delete_indexes.size - 1
  292.     while( index >= 0 )
  293.       sound_array.delete_at(delete_indexes[index])
  294.       index -= 1
  295.     end
  296.     return sound_array
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # * Create Command Windows
  300.   #--------------------------------------------------------------------------
  301.   def create_command_windows()
  302.    
  303.     # Setting Up Command Window for Sounds
  304.     command_window_ypos = 72
  305.     @sound_select_cmmdwindow = Window_SoundTest_SoundCommand.new(0, command_window_ypos, @soundfiles_hash)
  306.     @sound_select_cmmdwindow.height = Graphics.height - command_window_ypos
  307.     set_soundcommand_window_handlers()
  308.    
  309.     # Setting Up Command Window for Play Sound
  310.     @sound_play_cmmdwindow = Window_SoundTest_PlayCommand.new(Graphics.width * 0.5, command_window_ypos)
  311.     @sound_play_cmmdwindow.deactivate()
  312.     set_soundplay_window_handlers()
  313.   end
  314.   #--------------------------------------------------------------------------
  315.   # * Set Command Handlers
  316.   #--------------------------------------------------------------------------
  317.   def set_soundcommand_window_handlers
  318.     @soundfiles_hash.each_key do |key_name|
  319.       @sound_select_cmmdwindow.set_handler(key_name.to_sym, method(:deactivate_soundcommand_window))
  320.     end
  321.   end
  322.   #--------------------------------------------------------------------------
  323.   # * Set SoundPlay Handlers
  324.   #--------------------------------------------------------------------------
  325.   def set_soundplay_window_handlers
  326.     @sound_play_cmmdwindow.set_handler(:play_sound, method(:playsound_command))
  327.     @sound_play_cmmdwindow.set_handler(:volume,     method(:playsound_at_volume))
  328.     @sound_play_cmmdwindow.set_handler(:pitch,      method(:playsound_at_pitch))
  329.     @sound_play_cmmdwindow.set_handler(:position,   method(:playsound_at_position))
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # * Create Help Window
  333.   #--------------------------------------------------------------------------
  334.   def create_help_window()
  335.     # Setting up Help Window
  336.     @help_window = Window_Help.new()
  337.     @help_window.set_text(SoundSelectHelpWindowTextLine1 + "\n" + SoundSelectHelpWindowTextLine2)
  338.   end
  339.   #--------------------------------------------------------------------------
  340.   # * Create SoundInfo Window
  341.   #--------------------------------------------------------------------------
  342.   def create_soundinfo_window()
  343.     # Setting up Sound Info Window
  344.     @sound_info_window = Window_SoundInfo.new()
  345.     @sound_info_window.x = Graphics.width * 0.5
  346.     @sound_info_window.y = 192
  347.     @sound_info_window.openness = 255
  348.   end
  349.   #--------------------------------------------------------------------------
  350.   # * Create NumberInput Window
  351.   #--------------------------------------------------------------------------
  352.   def create_numberinput_window()
  353.     # Setting Up Number Input
  354.     @numberinput_window = Window_SoundTest_NumberInput.new()
  355.     @numberinput_window.z = 200
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # * Set Input Variables
  359.   #--------------------------------------------------------------------------
  360.   def set_input_variables()
  361.     @user_currently_inputting_value     = false
  362.     @currently_entering_volume_value    = false
  363.     @currently_entering_pitch_value     = false
  364.     @currently_entering_position_value  = false
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # * Setup Scene Intro Animation
  368.   #--------------------------------------------------------------------------
  369.   def setup_scene_intro_animation()
  370.     @background_image.opacity    = 0
  371.     @sound_select_cmmdwindow.x  -= 500
  372.     @sound_play_cmmdwindow.x    += 500
  373.     @help_window.y              -= 400
  374.     @sound_info_window.y        += 300
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   # * Animate Intro Sequence
  378.   #--------------------------------------------------------------------------
  379.   def animate_intro_scene()
  380.     while( true )
  381.       bool1 = animate_sceneintro_background_image()
  382.       bool2 = animate_sceneintro_soundselectcmmdwindow()
  383.       bool3 = animate_sceneintro_soundplaycmmdwindow()
  384.       bool4 = animate_sceneintro_helpwindow()
  385.       bool5 = animate_sceneintro_soundinfowindow()
  386.       Graphics.update()
  387.       break if bool1 && bool2 && bool3 && bool4 && bool5
  388.     end
  389.   end
  390.   #--------------------------------------------------------------------------
  391.   # * Animate BackgroundImage Opacity for Intro Sequence
  392.   #--------------------------------------------------------------------------
  393.   def animate_sceneintro_background_image()
  394.     return true if @background_image.opacity == 255
  395.     @background_image.opacity += 5
  396.     return @background_image.opacity == 255
  397.   end
  398.   #--------------------------------------------------------------------------
  399.   # * Animate SoundSelectCommand Window for Intro Sequence
  400.   #--------------------------------------------------------------------------
  401.   def animate_sceneintro_soundselectcmmdwindow()
  402.     return true if @sound_select_cmmdwindow.x == 0
  403.     @sound_select_cmmdwindow.x += 20
  404.     return @sound_select_cmmdwindow.x == 0
  405.   end
  406.   #--------------------------------------------------------------------------
  407.   # * Animate SoundPlayCommand Window for Intro Sequence
  408.   #--------------------------------------------------------------------------
  409.   def animate_sceneintro_soundplaycmmdwindow()
  410.     return true if @sound_play_cmmdwindow.x == (Graphics.width * 0.5)
  411.     @sound_play_cmmdwindow.x -= 20
  412.     return @sound_play_cmmdwindow.x == (Graphics.width * 0.5)
  413.   end
  414.   #--------------------------------------------------------------------------
  415.   # * Animate Help Window for Intro Sequence
  416.   #--------------------------------------------------------------------------
  417.   def animate_sceneintro_helpwindow()
  418.     return true if @help_window.y == 0
  419.     @help_window.y += 10
  420.     return @help_window.y == 0
  421.   end
  422.   #--------------------------------------------------------------------------
  423.   # * Animate Sound Info Window
  424.   #--------------------------------------------------------------------------
  425.   def animate_sceneintro_soundinfowindow()
  426.     return true if @sound_info_window.y == 192
  427.     @sound_info_window.y -= 6
  428.     return @sound_info_window.y == 192
  429.   end
  430.   #--------------------------------------------------------------------------
  431.   # * Deactivate Sound Command Windows
  432.   #--------------------------------------------------------------------------
  433.   def deactivate_soundcommand_windows()
  434.     @sound_select_cmmdwindow.deactivate()
  435.     @sound_play_cmmdwindow.deactivate()
  436.   end
  437.   #--------------------------------------------------------------------------
  438.   # * Deactivate Sound Command Window
  439.   #--------------------------------------------------------------------------
  440.   def deactivate_soundcommand_window()
  441.     @sound_select_cmmdwindow.deactivate()
  442.     @sound_play_cmmdwindow.activate()
  443.   end
  444.   #--------------------------------------------------------------------------
  445.   # * Deactivate SoundPlay Command Window
  446.   #--------------------------------------------------------------------------
  447.   def deactivate_soundplaycommand_window()
  448.     @sound_select_cmmdwindow.activate()
  449.     @sound_play_cmmdwindow.deactivate()
  450.   end
  451.   #--------------------------------------------------------------------------
  452.   # * Update Info Window Text
  453.   #--------------------------------------------------------------------------
  454.   def update_window_info_text()
  455.     @current_sound_symbol = @sound_select_cmmdwindow.current_symbol
  456.   end
  457.   #--------------------------------------------------------------------------
  458.   # * Update Help Text
  459.   #--------------------------------------------------------------------------
  460.   def update_help_text()
  461.     # If SoundSelect Command Window is Active
  462.     if @sound_select_cmmdwindow.active
  463.       @help_window.set_text(SoundSelectHelpWindowTextLine1 + "\n" + SoundSelectHelpWindowTextLine2)
  464.     # If NumberInput Window is Active
  465.     elsif @numberinput_window.active
  466.       @help_window.set_text(NumberInputHelpWindowTextLine1 + "\n" + NumberInputHelpWindowTextLine2)
  467.      # If Hovering Over PlaySound
  468.     elsif @sound_play_cmmdwindow.current_symbol == :play_sound
  469.       @help_window.set_text(PlaySoundOptionHelpWindowTextLine1 + "\n" + PlaySoundOptionHelpWindowTextLine2)
  470.      # If Hovering Over Volume Input
  471.     elsif @sound_play_cmmdwindow.current_symbol == :volume
  472.       @help_window.set_text(VolumeOptionHelpWindowTextLine1 + "\n" + VolumeOptionHelpWindowTextLine2)
  473.      # If Hovering Over Pitch Input
  474.     elsif @sound_play_cmmdwindow.current_symbol == :pitch
  475.       @help_window.set_text(PitchOptionHelpWindowTextLine1 + "\n" + PitchOptionHelpWindowTextLine2)
  476.      # If Hovering Over Position Input
  477.     else
  478.       @help_window.set_text(PositionOptionHelpWindowTextLine1 + "\n" + PositionOptionHelpWindowTextLine2)
  479.     end
  480.   end
  481.   #--------------------------------------------------------------------------
  482.   # * Update Scene Changes
  483.   #--------------------------------------------------------------------------
  484.   def update_scene_changes()
  485.     return_scene()                        if Input.trigger?(:B) && @sound_select_cmmdwindow.active
  486.     deactivate_soundplaycommand_window()  if Input.trigger?(:B) && @sound_play_cmmdwindow.active
  487.   end
  488.   #--------------------------------------------------------------------------
  489.   # * Update User Input
  490.   #--------------------------------------------------------------------------
  491.   def update_user_input()
  492.     if @user_currently_inputting_value && @numberinput_window.completed
  493.       receive_volume_value()    if @currently_entering_volume_value
  494.       receive_pitch_value()     if @currently_entering_pitch_value
  495.       receive_position_value()  if @currently_entering_position_value  
  496.     end
  497.   end
  498.   #--------------------------------------------------------------------------
  499.   # * Play Sound Command
  500.   #--------------------------------------------------------------------------
  501.   def playsound_command()
  502.     @soundfiles_hash[@current_sound_symbol].default_play()    
  503.     @sound_play_cmmdwindow.activate()
  504.   end
  505.   #--------------------------------------------------------------------------
  506.   # * Play Sound 'At Volume' Command
  507.   #--------------------------------------------------------------------------
  508.   def playsound_at_volume()
  509.     deactivate_soundcommand_windows()
  510.     @user_currently_inputting_value = true
  511.     @currently_entering_volume_value = true
  512.     number = @soundfiles_hash[@current_sound_symbol].volume
  513.     @numberinput_window.start( number, 3 )
  514.   end
  515.   #--------------------------------------------------------------------------
  516.   # * Play Sound 'At Pitch' Command
  517.   #--------------------------------------------------------------------------
  518.   def playsound_at_pitch()
  519.     deactivate_soundcommand_windows()
  520.     @user_currently_inputting_value = true
  521.     @currently_entering_pitch_value = true
  522.     number = @soundfiles_hash[@current_sound_symbol].pitch
  523.     @numberinput_window.start( number, 3 )
  524.   end
  525.   #--------------------------------------------------------------------------
  526.   # * Play Sound 'At Position' Command
  527.   #--------------------------------------------------------------------------
  528.   def playsound_at_position()
  529.     @currently_entering_position_value = true
  530.     @user_currently_inputting_value = true
  531.     deactivate_soundcommand_windows()
  532.     @numberinput_window.start( 0, 9 )
  533.   end
  534.   #--------------------------------------------------------------------------
  535.   # * Receive Volume Value
  536.   #--------------------------------------------------------------------------
  537.   def receive_volume_value()
  538.     if @numberinput_window.processed_ok
  539.       @soundfiles_hash[@current_sound_symbol].volume = @numberinput_window.result
  540.       @soundfiles_hash[@current_sound_symbol].play()
  541.     end
  542.     @sound_play_cmmdwindow.activate()
  543.     set_input_variables()
  544.   end
  545.   #--------------------------------------------------------------------------
  546.   # * Receive Pitch Value
  547.   #--------------------------------------------------------------------------
  548.   def receive_pitch_value()
  549.     if @numberinput_window.processed_ok
  550.       @soundfiles_hash[@current_sound_symbol].pitch = @numberinput_window.result
  551.       @soundfiles_hash[@current_sound_symbol].play()
  552.     end
  553.     @sound_play_cmmdwindow.activate()
  554.     set_input_variables()
  555.   end
  556.   #--------------------------------------------------------------------------
  557.   # * Receive Position Value
  558.   #--------------------------------------------------------------------------
  559.   def receive_position_value()
  560.     if @numberinput_window.processed_ok
  561.       @soundfiles_hash[@current_sound_symbol].play_at_position( @numberinput_window.result )
  562.     end
  563.     @sound_play_cmmdwindow.activate()
  564.     set_input_variables()
  565.   end
  566. end
  567.  
  568.  
  569. #==============================================================================
  570. # ** Window_MenuCommand
  571. #------------------------------------------------------------------------------
  572. #  This command window appears on the menu screen.
  573. #==============================================================================
  574.  
  575. class Window_MenuCommand < Window_Command
  576.   #--------------------------------------------------------------------------
  577.   # * Add Exit Game to Command List
  578.   #--------------------------------------------------------------------------
  579.   alias dp3_soundtestscene_windowmenucommd_addgameendcmmd_ofa     add_game_end_command
  580.   #--------------------------------------------------------------------------
  581.   def add_game_end_command
  582.     add_command(DiamondandPlatinum3::SoundTestScene::MenuCommandText, :sound_test)
  583.     dp3_soundtestscene_windowmenucommd_addgameendcmmd_ofa()
  584.   end
  585. end
  586.  
  587.  
  588.  
  589. #==============================================================================
  590. # ** Scene_Menu
  591. #------------------------------------------------------------------------------
  592. #  This class performs the menu screen processing.
  593. #==============================================================================
  594.  
  595. class Scene_Menu < Scene_MenuBase
  596.   #--------------------------------------------------------------------------
  597.   # * Create Command Window
  598.   #--------------------------------------------------------------------------
  599.   alias dp3_soundtestscene_scenemenu_creatcmmdwind_ofa      create_command_window
  600.   #--------------------------------------------------------------------------
  601.   def create_command_window
  602.     dp3_soundtestscene_scenemenu_creatcmmdwind_ofa() # Call original Method    
  603.     @command_window.set_handler(:sound_test,    method(:command_soundtest))
  604.   end
  605.   #--------------------------------------------------------------------------
  606.   # * Command Sound Test
  607.   #--------------------------------------------------------------------------
  608.   def command_soundtest
  609.     SceneManager.call(Scene_SoundTest)
  610.   end
  611. end
  612.  
  613.  
  614.  
  615. #==============================================================================
  616. # ** SoundTest_Command
  617. #------------------------------------------------------------------------------
  618. # The Command Window that is used when selecting a sound
  619. #==============================================================================
  620.  
  621. class Window_SoundTest_SoundCommand < Window_Command
  622.   include DiamondandPlatinum3::SoundTestScene
  623.   #--------------------------------------------------------------------------
  624.   # * Initialize
  625.   #--------------------------------------------------------------------------
  626.   alias old_init    initialize
  627.   def initialize( x, y, soundfiles_hash )
  628.     @soundfiles_hash = soundfiles_hash
  629.     old_init( x, y )
  630.   end
  631.   #--------------------------------------------------------------------------
  632.   # * Get Window Width
  633.   #--------------------------------------------------------------------------
  634.   def window_width
  635.     return Graphics.width * 0.5
  636.   end
  637.   #--------------------------------------------------------------------------
  638.   # * Make Command List
  639.   #--------------------------------------------------------------------------
  640.   def make_command_list
  641.     @soundfiles_hash.each_key do |key_name|
  642.       add_command(@soundfiles_hash[key_name].display_name, key_name)
  643.     end
  644.   end  
  645. end
  646.  
  647.  
  648. #==============================================================================
  649. # ** PlaySound_Command
  650. #------------------------------------------------------------------------------
  651. # The Command Window that is used for playing a sound
  652. #==============================================================================
  653.  
  654. class Window_SoundTest_PlayCommand < Window_Command
  655.   include DiamondandPlatinum3::SoundTestScene
  656.   #--------------------------------------------------------------------------
  657.   # * Get Window Width
  658.   #--------------------------------------------------------------------------
  659.   def window_width
  660.     return Graphics.width * 0.5
  661.   end
  662.   #--------------------------------------------------------------------------
  663.   # * Make Command List
  664.   #--------------------------------------------------------------------------
  665.   def make_command_list
  666.     add_command("Play Sound", :play_sound)
  667.     add_command("Volume",     :volume)
  668.     add_command("Pitch",      :pitch)
  669.     add_command("Position",   :position)
  670.   end  
  671. end
  672.  
  673.  
  674.  
  675.  
  676. #==============================================================================
  677. # ** Window_SoundInfo
  678. #------------------------------------------------------------------------------
  679. #  This message window is used to display Sound Information
  680. #==============================================================================
  681.  
  682. class Window_SoundInfo < Window_Message
  683.   #--------------------------------------------------------------------------
  684.   # * Set Font
  685.   #--------------------------------------------------------------------------
  686.   def set_font
  687.     contents.font.size = 18
  688.   end
  689.   #--------------------------------------------------------------------------
  690.   # * Get Window Width
  691.   #--------------------------------------------------------------------------
  692.   def window_width
  693.     return Graphics.width * 0.5
  694.   end
  695.   #--------------------------------------------------------------------------
  696.   # * Get Window Height
  697.   #--------------------------------------------------------------------------
  698.   def window_height
  699.     return Graphics.height - 192
  700.   end  
  701.   #--------------------------------------------------------------------------
  702.   # * Draw Text
  703.   #--------------------------------------------------------------------------
  704.   def draw_text_soundinfo(text)
  705.     contents.clear
  706.     set_font()
  707.     draw_text_ex(0, 0, word_wrapping(text))
  708.   end  
  709.   #--------------------------------------------------------------------------
  710.   # * Draw Text with Control Characters
  711.   #--------------------------------------------------------------------------
  712.   def draw_text_ex(x, y, text)
  713.     text = convert_escape_characters(text)
  714.     pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  715.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  716.   end
  717.   #--------------------------------------------------------------------------
  718.   # * Wait After Output of One Character
  719.   #--------------------------------------------------------------------------
  720.   def wait_for_one_character
  721.   end
  722.   #--------------------------------------------------------------------------
  723.   # * Word Wrapping
  724.   #--------------------------------------------------------------------------
  725.   def word_wrapping(text, pos = 0)
  726.    
  727.     # Current Text Position
  728.     current_text_position = 0    
  729.    
  730.     for i in 0..(text.length - 1)
  731.       if text[i] == "\n"
  732.         current_text_position = 0
  733.         next
  734.       end
  735.      
  736.       # Current Position += character width
  737.       current_text_position += contents.text_size(text[i]).width
  738.      
  739.       # If Current Position > Window Width
  740.       if (pos + current_text_position) >= (contents.width)
  741.         # Then Format the Sentence to fit Line
  742.         current_element = i
  743.         while(text[current_element] != " ")
  744.           break if current_element == 0
  745.           current_element -= 1
  746.         end
  747.        
  748.         temp_text = ""
  749.         for j in 0..(text.length - 1)
  750.           temp_text += text[j]
  751.           temp_text += "\n" if j == current_element
  752.         end
  753.         text = temp_text
  754.         i = current_element
  755.         current_text_position = 0
  756.       end
  757.     end
  758.     return text
  759.   end
  760. end
  761.  
  762.  
  763.  
  764. #==============================================================================
  765. # ** Window_NumberInput
  766. #------------------------------------------------------------------------------
  767. #  This window is used for the event command [Input Number].
  768. #==============================================================================
  769.  
  770. class Window_SoundTest_NumberInput < Window_NumberInput
  771.   #--------------------------------------------------------------------------
  772.   # * Public Instance Variables
  773.   #--------------------------------------------------------------------------
  774.   attr_reader :result       # The Result of User Input
  775.   attr_reader :completed    # User Finished Input Processing?
  776.   attr_reader :processed_ok # User Did not Cancel User Input?
  777.   #--------------------------------------------------------------------------
  778.   # * Initialize
  779.   #--------------------------------------------------------------------------
  780.   def initialize()
  781.     super( self )
  782.     @result       = 0
  783.     @completed    = true
  784.     @processed_ok = false
  785.   end
  786.   #--------------------------------------------------------------------------
  787.   # * Start Input Processing
  788.   #--------------------------------------------------------------------------
  789.   def start( number, digits )
  790.     @digits_max = digits
  791.     @number = number
  792.     @index = 0
  793.     @completed = false
  794.     update_placement
  795.     create_contents
  796.     refresh
  797.     open
  798.     activate
  799.   end
  800.   #--------------------------------------------------------------------------
  801.   # * Update Window Position
  802.   #--------------------------------------------------------------------------
  803.   def update_placement
  804.     self.width = @digits_max * 20 + padding * 2
  805.     self.height = fitting_height(1)
  806.     self.x = (Graphics.width - width) / 2
  807.     self.y = 192
  808.   end
  809.   #--------------------------------------------------------------------------
  810.   # * Processing When OK Button Is Pressed
  811.   #--------------------------------------------------------------------------
  812.   def process_ok
  813.     Sound.play_ok
  814.     @result = @number
  815.     @completed = true
  816.     @processed_ok = true
  817.     deactivate
  818.     close
  819.   end
  820.   #--------------------------------------------------------------------------
  821.   # * Processing When Cancel Button Is Pressed
  822.   #--------------------------------------------------------------------------
  823.   def process_cancel
  824.     Sound.play_cancel
  825.     @completed    = true
  826.     @processed_ok = false
  827.     deactivate
  828.     close
  829.   end
  830. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement