Advertisement
Bigbadke12

RPG Maker VX Ace volume control

Mar 21st, 2013
1,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.87 KB | None | 0 0
  1. # encoding: utf-8
  2. #===============================================================================
  3. # �¡ Volume Control For RGSS3
  4. #-------------------------------------------------------------------------------
  5. #�@2011/12/01�@Ru/‚Þ‚Á‚­R
  6. #-------------------------------------------------------------------------------
  7. # English Translation By: Elemental Crisis (http://RPGMakerVXAce.com)
  8. #-------------------------------------------------------------------------------
  9. #-------------------------------------------------------------------------------
  10. # Bug fixes and menu bars added by Kal.
  11. #-------------------------------------------------------------------------------
  12. #
  13. #�@Adds the ability to change volume control.
  14. #
  15. #�@�œ The following methods are added to the Audio Module
  16. #�@Audio.volBGM �c�c Maximum BGM volume setting.
  17. #�@Audio.volBGS �c�c Maximum BGS volume setting.
  18. #�@Audio.volSE  �c�c Maximum SE volume setting.
  19. #�@Audio.volME  �c�c  Maximum ME volume setting.
  20. #�@Audio.volBGM=�”’l �c�cSet BGM maximum volume (0-100)
  21. #�@Audio.volBGM=�”’l �c�c Set BGS maximum volume (0-100)
  22. #�@Audio.volSE=�”’l  �c�c Set SE maximum volume (0-100)
  23. #�@Audio.volME=�”’l  �c�c Set ME maximum volume (0-100)
  24. #
  25. #�@�œ Volume control is added to the main menu.
  26. #
  27. #-------------------------------------------------------------------------------
  28. # �yKnown Issues�z
  29. #�@Created before VXAce's official release so unable to properly test.
  30. #-------------------------------------------------------------------------------
  31. #==============================================================================
  32. # �œ Settings
  33. #==============================================================================
  34. module HZM_VXA
  35.   module AudioVol
  36.     # Display Volume Control on Main Menu?
  37.     # �@true  �c�c Display.
  38.     # �@false �c�c Don't Display.
  39.     MENU_FLAG = false
  40.  
  41.     # Volume Control Name in Main Menu.
  42.     MENU_NAME       = "Volume Settings"
  43.  
  44.     # Volume Control Settings Name.
  45.     CONFIG_BGM_NAME  = "BGM"
  46.     CONFIG_BGS_NAME  = "BGS"
  47.     CONFIG_SE_NAME   = "SE"
  48.     CONFIG_ME_NAME   = "ME"
  49.     CONFIG_EXIT_NAME = "Exit"
  50.  
  51.     # Volume Change Variation.
  52.     # ADD_VOL_NORMAL �c�c Variation of Left/Right Keys.
  53.     # ADD_VOL_HIGH   �c�c Variation of LR Key.
  54.     ADD_VOL_NORMAL = 5
  55.     ADD_VOL_HIGH   = 25
  56.  
  57.     # Use bars or numbers.
  58.     # :bars  => use bars
  59.     # :numbers  => use numbers
  60.     DISPLAY = :bars
  61.  
  62.     # Bar display options.
  63.     # The higher BAR_X the more to the right the bar is drawn.
  64.     # BAR_WIDTH sets the width of the bar.
  65.     # Y_ADJUST allows you to precisely adjust the y value (how high or low
  66.     # the bar is rendered).
  67.     BAR_X      = 55  
  68.     BAR_WIDTH   = 70
  69.     Y_ADJUST    = -3
  70.   end
  71. end
  72. #==============================================================================
  73. # �ª �@ Settings Above �@ �ª
  74. # �«  Script Below    �«
  75. #==============================================================================
  76. # Additonal Methods.
  77. # class << Audio means we open up the Audio module and all methods defined
  78. # get defined on self (that is, the Audio module itself)
  79. class << Audio
  80.  
  81.   def volBGM=(vol)
  82.     @hzmVolBGM = normalize_volume(vol)
  83.   end
  84.  
  85.   def volBGS=(vol)
  86.     @hzmVolBGS = normalize_volume(vol)
  87.   end
  88.  
  89.   def volSE=(vol)
  90.     @hzmVolSE = normalize_volume(vol)
  91.   end
  92.  
  93.   def volME=(vol)
  94.     @hzmVolME = normalize_volume(vol)
  95.   end
  96.  
  97.   def volBGM
  98.     @hzmVolBGM.nil? ? @hzmVolBGM = 100 : @hzmVolBGM
  99.   end
  100.  
  101.   def volBGS
  102.     @hzmVolBGS.nil? ? @hzmVolBGS = 100 : @hzmVolBGS
  103.   end
  104.  
  105.   def volSE
  106.     @hzmVolSE.nil? ? @hzmVolSE = 100 : @hzmVolSE
  107.   end
  108.  
  109.   def volME
  110.     @hzmVolME.nil? ? @hzmVolME = 100 : @hzmVolME
  111.   end
  112.  
  113.   # Make sure volume does not go over 100 or under 0.
  114.   def normalize_volume(vol)
  115.     vol = 100 if vol > 100
  116.     vol = 0   if vol < 0
  117.     vol
  118.   end  
  119.   # Playback
  120.   alias hzm_Vol_Audio_bgm_play bgm_play
  121.   def bgm_play(filename, volume=100, pitch=100, pos=0)
  122.     volume = self.volBGM * volume.to_f / 100
  123.     hzm_Vol_Audio_bgm_play(filename, volume, pitch, pos)
  124.   end
  125.  
  126.   alias hzm_Vol_Audio_bgs_play bgs_play
  127.   def bgs_play(filename, volume=100, pitch=100)
  128.     volume = self.volBGS * volume.to_f / 100
  129.     hzm_Vol_Audio_bgs_play(filename, volume, pitch)
  130.   end
  131.  
  132.   alias hzm_Vol_Audio_se_play se_play
  133.   def se_play(filename, volume=100, pitch=100)
  134.     volume = self.volSE * volume.to_f / 100
  135.     hzm_Vol_Audio_se_play(filename, volume, pitch)
  136.   end
  137.  
  138.   alias hzm_Vol_Audio_me_play me_play
  139.   def me_play(filename, volume=100, pitch=100)
  140.     volume = self.volME * volume.to_f / 100
  141.     hzm_Vol_Audio_me_play(filename, volume, pitch)
  142.   end
  143. end
  144. # Add To Menu.
  145. if HZM_VXA::AudioVol::MENU_FLAG
  146.   class Window_MenuCommand
  147.     alias hzm_Vol_Window_MenuCommand_add_original_commands add_original_commands
  148.     def add_original_commands
  149.       hzm_Vol_Window_MenuCommand_add_original_commands
  150.       add_command(HZM_VXA::AudioVol::MENU_NAME, :hzm_vxa_vol)  
  151.     end
  152.   end
  153.   class Scene_Menu
  154.     alias hzm_Vol_create_command_window create_command_window
  155.     def create_command_window
  156.       hzm_Vol_create_command_window
  157.       @command_window.set_handler(:hzm_vxa_vol, method(:hzm_vxa_vol))
  158.     end
  159.  
  160.     def hzm_vxa_vol
  161.       SceneManager.call(HZM_VXA::AudioVol::Scene_VolConfig)
  162.     end
  163.   end
  164. end
  165. # Volume Change Window
  166. module HZM_VXA
  167.   module AudioVol
  168.     class Window_VolConfig < Window_Command
  169.       def initialize
  170.         super(0, 0)
  171.         self.x = (Graphics.width - self.window_width)/2
  172.         self.y = (Graphics.height - self.window_height)/2
  173.       end
  174.    
  175.       def make_command_list
  176.         add_command(HZM_VXA::AudioVol::CONFIG_BGM_NAME,  :bgm)
  177.         add_command(HZM_VXA::AudioVol::CONFIG_BGS_NAME,  :bgs)
  178.         add_command(HZM_VXA::AudioVol::CONFIG_SE_NAME,   :se)
  179.         add_command(HZM_VXA::AudioVol::CONFIG_ME_NAME,   :me)
  180.         add_command(HZM_VXA::AudioVol::CONFIG_EXIT_NAME, :cancel)
  181.       end
  182.    
  183.       def draw_item(index)
  184.         super
  185.         return unless index < 4
  186.         case index
  187.         when 0
  188.           vol = Audio.volBGM
  189.         when 1
  190.           vol = Audio.volBGS
  191.         when 2
  192.           vol = Audio.volSE
  193.         when 3
  194.           vol = Audio.volME
  195.         end
  196.      
  197.         # Draws vol as a number or as a bar.
  198.         if DISPLAY == :bars
  199.           y = (index * line_height) + Y_ADJUST
  200.           draw_gauge(BAR_X, y, BAR_WIDTH, vol / 100.0, normal_color, normal_color)
  201.         else
  202.           draw_text(item_rect_for_text(index), vol, 2)
  203.         end
  204.       end
  205.    
  206.       def volAdd(index, val)
  207.         case index
  208.         when 0
  209.           Audio.volBGM += val
  210.           now = RPG::BGM.last
  211.           Audio.bgm_play('Audio/BGM/' + now.name, now.volume, now.pitch, now.pos) if now
  212.         when 1
  213.           Audio.volBGS += val
  214.         when 2
  215.           Audio.volSE += val
  216.         when 3
  217.           Audio.volME += val
  218.         end
  219.         Sound.play_cursor
  220.         redraw_item(index)
  221.       end
  222.    
  223.       def cursor_left(wrap = false)
  224.         volAdd(@index, -HZM_VXA::AudioVol::ADD_VOL_NORMAL)
  225.       end
  226.    
  227.       def cursor_right(wrap = false)
  228.         volAdd(@index,  HZM_VXA::AudioVol::ADD_VOL_NORMAL)
  229.       end
  230.    
  231.       def cursor_pageup
  232.         volAdd(@index,  -HZM_VXA::AudioVol::ADD_VOL_HIGH)
  233.       end
  234.    
  235.       def cursor_pagedown
  236.         volAdd(@index,  HZM_VXA::AudioVol::ADD_VOL_HIGH)
  237.       end
  238.     end
  239.  
  240.     class Scene_VolConfig < Scene_MenuBase
  241.       def start
  242.         super
  243.         @command_window = Window_VolConfig.new
  244.         @command_window.viewport = @viewport
  245.         @command_window.set_handler(:cancel,   method(:return_scene))
  246.       end
  247.    
  248.       def terminate
  249.         super
  250.         @command_window.dispose
  251.       end
  252.     end
  253.   end
  254. end
  255. # Reading/Saving
  256. class << DataManager
  257.   alias hzm_Vol_make_save_contents make_save_contents
  258.   def make_save_contents
  259.     contents = hzm_Vol_make_save_contents
  260.     contents[:hzm_vxa_vol]   = {
  261.       :bgm => Audio.volBGM,
  262.       :bgs => Audio.volBGS,
  263.       :se  => Audio.volSE,
  264.       :me  => Audio.volME
  265.     }
  266.     contents
  267.   end
  268.  
  269.   alias hzm_Vol_extract_save_contents extract_save_contents
  270.   def extract_save_contents(contents)
  271.     hzm_Vol_extract_save_contents(contents)
  272.     Audio.volBGM = contents[:hzm_vxa_vol][:bgm]
  273.     Audio.volBGS = contents[:hzm_vxa_vol][:bgs]
  274.     Audio.volSE  = contents[:hzm_vxa_vol][:se]
  275.     Audio.volME  = contents[:hzm_vxa_vol][:me]
  276.   end
  277. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement