Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. # coding: utf-8
  2. #===============================================================================
  3. # ■ Master Volume Control for RGSS3
  4. #-------------------------------------------------------------------------------
  5. # 2016/04/23 By Ru/むっくRu (Rutan) | English translation by tale 2017/02/10
  6. # License - Public Domain
  7. #-------------------------------------------------------------------------------
  8. # Add functions related to volume adjustment
  9. #
  10. # ● Volume adjustment - items are added to the title screen and main menu
  11. #
  12. # ● Audio - The following items are added to the module
  13. # Audio.bgm_vol …… BGM
  14. # Audio.bgs_vol …… BGS
  15. # Audio.se_vol  …… SE
  16. # Audio.me_vol  …… ME
  17. # Audio.bgm_vol=Numerical variable …… BGM(0~100)
  18. # Audio.bgs_vol=Numerical variable …… BGS(0~100)
  19. # Audio.se_vol=Numerical variable  …… SE(0~100)
  20. # Audio.me_vol=Numerical variable  …… ME(0~100)
  21. #
  22. #-------------------------------------------------------------------------------
  23. # 【Changelogs】
  24. # 2016/04/23 Code reorganized
  25. # 2013/05/25 Fixed error drop when changing type of volume change item
  26. # 2012/12/17 Allows the volume to be saved without the base script. (Script organization)
  27. # 2012/06/13 Redesign layout. Added setting item. (Organizing scripts)
  28. # 2012/01/02 Ini changed reading HZM_VXA base script for RGSS3 (Change to dependent)
  29. # 2011/12/29 BGS Fixed a bug that causes error during playback
  30. # 2011/12/26 BGM Fixed a bug that causes the volume to be adjusted when mute
  31. # 2011/12/13 ini Allows cooperation with reading
  32. # 2011/12/01 Released
  33. #-------------------------------------------------------------------------------
  34.  
  35. #===============================================================================
  36. # ● Item settings
  37. #===============================================================================
  38. module HZM_VXA
  39.   module AudioVol
  40.     # ● Do you want to display the volume adjustment on the title screen?
  41.     #    ※To redefine the menu items on the title screen,
  42.     #      If you introduce another script that tamper with the menu titles
  43.     #      There's a possibility of conflict.
  44.     #  true  …… Display
  45.     #  false …… Don't display
  46.     TITLE_FLAG = true
  47.     # Item name to be displayed on title screen
  48.     TITLE_NAME        = "Âm Thanh"
  49.  
  50.     # ● Do you want the volume adjustment displayed on the menu screen?
  51.     #  true  …… Display
  52.     #  false …… Don't display
  53.     MENU_FLAG = true
  54.     # Name of the setting in Main Menu.
  55.     MENU_NAME        = "Âm Thanh"
  56.  
  57.     # ● Types of Volume arrangement
  58.     #  0 …… BGM/BGS/SE/ME Set all at once
  59.     #   1 …… BGM+BGS と SE+ME Set with 2 kinds of
  60.     #   2 …… BGM/BGS/SE/ME Set by each of 4 types
  61.     TYPE = 2
  62.  
  63.     # ● Volume Control Settings Name.
  64.     CONFIG_ALL_NAME  = "Âm Lượng"        # Used when type "0" is selected
  65.     CONFIG_BGM_NAME  = "BGM"         # Used when type "1" "2" is selected
  66.     CONFIG_BGS_NAME  = "BGS"         # Used when type "2" is selected
  67.     CONFIG_SE_NAME   = "SE"          # Used when type "1" "2" is selected
  68.     CONFIG_ME_NAME   = "ME"          # Used when type "2" is selected
  69.     CONFIG_EXIT_NAME = "Thoát"
  70.  
  71.     # ● Volume adjustment by Increments
  72.     ADD_VOL_NORMAL =  5              # Amount of increment of left and right keys
  73.     ADD_VOL_HIGH   = 25              # LR Variation amount of key
  74.  
  75.     # ● Window width of volume setting screen
  76.     WINDOW_WIDTH   = 200
  77.  
  78.     # ● Volume gauge color from the menu interface
  79.     COLOR1 = Color.new(-255, 225, 255)
  80.     COLOR2 = Color.new( 64,  64, 255)
  81.  
  82.     # ● Save function of volume setting
  83.     #    Game.ini, By storing volume information in
  84.     #    You can also adjust the volume when you start up
  85.     #    true  …… Save
  86.     #    false …… Don't save
  87.     USE_INI = true
  88.   end
  89. end
  90.  
  91. #===============================================================================
  92. # ↑ Set up here ↑
  93. # ↓ or less, script part ↓
  94. #===============================================================================
  95.  
  96. module Audio
  97.   #-----------------------------------------------------------------------------
  98.   # ● Volume setting: BGM
  99.   #-----------------------------------------------------------------------------
  100.   def self.bgm_vol=(vol)
  101.     @hzm_vxa_audioVol_bgm = self.vol_range(vol)
  102.   end
  103.   #-----------------------------------------------------------------------------
  104.   # ● Volume setting: BGS
  105.   #-----------------------------------------------------------------------------
  106.   def self.bgs_vol=(vol)
  107.     @hzm_vxa_audioVol_bgs = self.vol_range(vol)
  108.   end
  109.   #-----------------------------------------------------------------------------
  110.   # ● Volume setting: SE
  111.   #-----------------------------------------------------------------------------
  112.   def self.se_vol=(vol)
  113.     @hzm_vxa_audioVol_se = self.vol_range(vol)
  114.   end
  115.   #-----------------------------------------------------------------------------
  116.   # ● Volume setting: ME
  117.   #-----------------------------------------------------------------------------
  118.   def self.me_vol=(vol)
  119.     @hzm_vxa_audioVol_me = self.vol_range(vol)
  120.   end
  121.   #-----------------------------------------------------------------------------
  122.   # ● Volume range specification
  123.   #-----------------------------------------------------------------------------
  124.   def self.vol_range(vol)
  125.     vol = vol.to_i
  126.     vol < 0 ? 0 : vol < 100 ? vol : 100
  127.   end
  128.   #-----------------------------------------------------------------------------
  129.   # ● Volume acquisition: BGM
  130.   #-----------------------------------------------------------------------------
  131.   def self.bgm_vol
  132.     @hzm_vxa_audioVol_bgm ||= 100
  133.   end
  134.   #-----------------------------------------------------------------------------
  135.   # ● Volume acquisition: BGS
  136.   #-----------------------------------------------------------------------------
  137.   def self.bgs_vol
  138.     @hzm_vxa_audioVol_bgs ||= 100
  139.   end
  140.   #-----------------------------------------------------------------------------
  141.   # ● Volume acquisition: SE
  142.   #-----------------------------------------------------------------------------
  143.   def self.se_vol
  144.     @hzm_vxa_audioVol_se ||= 100
  145.   end
  146.   #-----------------------------------------------------------------------------
  147.   # ● Volume acquisition: ME
  148.   #-----------------------------------------------------------------------------
  149.   def self.me_vol
  150.     @hzm_vxa_audioVol_me ||= 100
  151.   end
  152. end
  153.  
  154. class << Audio
  155.   #-----------------------------------------------------------------------------
  156.   # ● Playback: BGM
  157.   #-----------------------------------------------------------------------------
  158.   alias hzm_vxa_audioVol_bgm_play bgm_play
  159.   def bgm_play(filename, volume = 100, pitch = 100, pos = 0)
  160.     hzm_vxa_audioVol_bgm_play(filename, self.bgm_vol * volume / 100, pitch, pos)
  161.   end
  162.   #-----------------------------------------------------------------------------
  163.   # ● Playback: BGS
  164.   #-----------------------------------------------------------------------------
  165.   alias hzm_vxa_audioVol_bgs_play bgs_play
  166.   def bgs_play(filename, volume = 100, pitch = 100, pos = 0)
  167.     hzm_vxa_audioVol_bgs_play(filename, self.bgs_vol * volume / 100, pitch, pos)
  168.   end
  169.   #-----------------------------------------------------------------------------
  170.   # ● Playback: SE
  171.   #-----------------------------------------------------------------------------
  172.   alias hzm_vxa_audioVol_se_play se_play
  173.   def se_play(filename, volume = 100, pitch = 100)
  174.     hzm_vxa_audioVol_se_play(filename, self.se_vol * volume / 100, pitch)
  175.   end
  176.   #-----------------------------------------------------------------------------
  177.   # ● Playback: ME
  178.   #-----------------------------------------------------------------------------
  179.   alias hzm_vxa_audioVol_me_play me_play
  180.   def me_play(filename, volume = 100, pitch = 100)
  181.     hzm_vxa_audioVol_me_play(filename, self.me_vol * volume / 100, pitch)
  182.   end
  183.   #-----------------------------------------------------------------------------
  184.   # ● Old Version Compatibility
  185.   #-----------------------------------------------------------------------------
  186.   if true
  187.     alias volBGM bgm_vol
  188.     alias volBGS bgs_vol
  189.     alias volSE se_vol
  190.     alias volME me_vol
  191.     alias volBGM= bgm_vol=
  192.     alias volBGS= bgs_vol=
  193.     alias volSE= se_vol=
  194.     alias volME= me_vol=
  195.   end
  196. end
  197.  
  198. # For the title screen
  199. if HZM_VXA::AudioVol::TITLE_FLAG
  200.   class Window_TitleCommand < Window_Command
  201.     if true
  202.       # ↑ If you change true to false,
  203.       #    This makes the menu items on title screen aliased instead of redefining
  204.       #    It will be implemented.
  205.       #    Conflicting with other menu titles extended scripts would be unlikely to happen,
  206.       #    As a side effect, the volume setting item is added under shutdown.
  207.       #    According to your needs……(・x・)
  208.       #---------------------------------------------------------------------------
  209.       # ● Create command list (redefinition)
  210.       #---------------------------------------------------------------------------
  211.       def make_command_list
  212.         add_command(Vocab::new_game, :new_game)
  213.         add_command(Vocab::continue, :continue, continue_enabled)
  214.         add_command(HZM_VXA::AudioVol::TITLE_NAME, :hzm_vxa_audioVol)
  215.         add_command(Vocab::shutdown, :shutdown)
  216.       end
  217.     else
  218.       #---------------------------------------------------------------------------
  219.       # ● Creating command list
  220.       #---------------------------------------------------------------------------
  221.       alias hzm_vxa_audioVol_make_command_list make_command_list
  222.       def make_command_list
  223.         hzm_vxa_audioVol_make_command_list
  224.         add_command(HZM_VXA::AudioVol::TITLE_NAME, :hzm_vxa_audioVol)
  225.       end
  226.     end
  227.   end
  228.   class Scene_Title < Scene_Base
  229.     #---------------------------------------------------------------------------
  230.     # ● Creating Command Window
  231.     #---------------------------------------------------------------------------
  232.     alias hzm_vxa_audioVol_create_command_window create_command_window
  233.     def create_command_window
  234.       hzm_vxa_audioVol_create_command_window
  235.       @command_window.set_handler(:hzm_vxa_audioVol, method(:hzm_vxa_audioVol_command_config))
  236.     end
  237.     #---------------------------------------------------------------------------
  238.     # ● Command [Volume adjustment]
  239.     #---------------------------------------------------------------------------
  240.     def hzm_vxa_audioVol_command_config
  241.       close_command_window
  242.       SceneManager.call(HZM_VXA::AudioVol::Scene_VolConfig)
  243.     end
  244.   end
  245. end
  246.  
  247. # メニューに追加
  248. if HZM_VXA::AudioVol::MENU_FLAG
  249.   class Window_MenuCommand
  250.     #---------------------------------------------------------------------------
  251.     # ● For adding a custom command
  252.     #---------------------------------------------------------------------------
  253.     alias hzm_vxa_audioVol_add_original_commands add_original_commands
  254.     def add_original_commands
  255.       hzm_vxa_audioVol_add_original_commands
  256.       add_command(HZM_VXA::AudioVol::MENU_NAME, :hzm_vxa_audioVol)
  257.     end
  258.   end
  259.   class Scene_Menu
  260.     #---------------------------------------------------------------------------
  261.     # ● Creating Command Window
  262.     #---------------------------------------------------------------------------
  263.     alias hzm_vxa_audioVol_create_command_window create_command_window
  264.     def create_command_window
  265.       hzm_vxa_audioVol_create_command_window
  266.       @command_window.set_handler(:hzm_vxa_audioVol, method(:hzm_vxa_audioVol_command_config))
  267.     end
  268.     #---------------------------------------------------------------------------
  269.     # ● Call volume from the setting screen
  270.     #---------------------------------------------------------------------------
  271.     def hzm_vxa_audioVol_command_config
  272.       SceneManager.call(HZM_VXA::AudioVol::Scene_VolConfig)
  273.     end
  274.   end
  275. end
  276.  
  277. # Volume Configuration Window
  278. module HZM_VXA
  279.   module AudioVol
  280.     class Window_VolConfig < Window_Command
  281.       #-------------------------------------------------------------------------
  282.       # ● Generate
  283.       #-------------------------------------------------------------------------
  284.       def initialize
  285.         @mode = HZM_VXA::AudioVol::TYPE.to_i
  286.         super(0, 0)
  287.         self.x = (Graphics.width  - self.window_width ) / 2
  288.         self.y = (Graphics.height - self.window_height) / 2
  289.       end
  290.       #-------------------------------------------------------------------------
  291.       # ● Acquire command symbol
  292.       #-------------------------------------------------------------------------
  293.       def command_symbol(index)
  294.         @list[index][:symbol]
  295.       end
  296.       #-------------------------------------------------------------------------
  297.       # ● Command extend data
  298.       #-------------------------------------------------------------------------
  299.       def command_ext(index)
  300.         @list[index][:ext]
  301.       end
  302.       #-------------------------------------------------------------------------
  303.       # ● Window width
  304.       #-------------------------------------------------------------------------
  305.       def window_width
  306.         HZM_VXA::AudioVol::WINDOW_WIDTH
  307.       end
  308.       #--------------------------------------------------------------------------
  309.       # ● Acquire alignment
  310.       #--------------------------------------------------------------------------
  311.       def alignment
  312.         command_symbol(@now_drawing_index) == :cancel ? 1 : 0
  313.       end
  314.       #-------------------------------------------------------------------------
  315.       # ● Command generate
  316.       #-------------------------------------------------------------------------
  317.       def make_command_list
  318.         make_command_list_actions
  319.         make_command_list_exit
  320.       end
  321.       #-------------------------------------------------------------------------
  322.       # ● Command: action
  323.       #-------------------------------------------------------------------------
  324.       def make_command_list_actions
  325.         case @mode
  326.         when 0
  327.           add_command(HZM_VXA::AudioVol::CONFIG_ALL_NAME,  :all)
  328.         when 1
  329.           add_command(HZM_VXA::AudioVol::CONFIG_BGM_NAME,  :bgm)
  330.           add_command(HZM_VXA::AudioVol::CONFIG_SE_NAME,   :se)
  331.         else
  332.           add_command(HZM_VXA::AudioVol::CONFIG_BGM_NAME,  :bgm)
  333.           add_command(HZM_VXA::AudioVol::CONFIG_BGS_NAME,  :bgs)
  334.           add_command(HZM_VXA::AudioVol::CONFIG_SE_NAME,   :se)
  335.           add_command(HZM_VXA::AudioVol::CONFIG_ME_NAME,   :me)
  336.         end
  337.       end
  338.       #-------------------------------------------------------------------------
  339.       # ● Command: cancel
  340.       #-------------------------------------------------------------------------
  341.       def make_command_list_exit
  342.         add_command(HZM_VXA::AudioVol::CONFIG_EXIT_NAME, :cancel)
  343.       end
  344.       #-------------------------------------------------------------------------
  345.       # ● Drawing items
  346.       #-------------------------------------------------------------------------
  347.       def draw_item(index)
  348.         @now_drawing_index = index
  349.         super
  350.         case command_symbol(index)
  351.         when :all, :bgm, :bgs, :se, :me
  352.           draw_item_volume_guage(index)
  353.         end
  354.       end
  355.       #-------------------------------------------------------------------------
  356.       # ● Drawing items: volume gauge
  357.       #-------------------------------------------------------------------------
  358.       def draw_item_volume_guage(index)
  359.         vol =
  360.           case command_symbol(index)
  361.           when :all, :bgm
  362.             Audio.bgm_vol
  363.           when :bgs
  364.             Audio.bgs_vol
  365.           when :se
  366.             Audio.se_vol
  367.           when :me
  368.             Audio.me_vol
  369.           end
  370.         draw_gauge(item_rect_for_text(index).x + 96 - 8, item_rect_for_text(index).y, contents_width - 96, vol/100.0, HZM_VXA::AudioVol::COLOR1, HZM_VXA::AudioVol::COLOR2)
  371.         draw_text(item_rect_for_text(index), vol, 2)
  372.       end
  373.       #-------------------------------------------------------------------------
  374.       # ● Increase volume
  375.       #-------------------------------------------------------------------------
  376.       def vol_add(index, val)
  377.         call_flag = false
  378.  
  379.         case command_symbol(index)
  380.         when :all
  381.           call_flag = add_vol_bgm(val)
  382.           Audio.bgs_vol = Audio.bgm_vol
  383.           Audio.se_vol = Audio.bgm_vol
  384.           Audio.me_vol = Audio.bgm_vol
  385.         when :bgm
  386.           call_flag = add_vol_bgm(val)
  387.           Audio.bgs_vol = Audio.bgm_vol if @mode == 1
  388.         when :bgs
  389.           call_flag = add_vol_bgs(val)
  390.         when :se
  391.           call_flag = add_vol_se(val)
  392.           Audio.me_vol = Audio.se_vol if @mode == 1
  393.         when :me
  394.           call_flag = add_vol_me(val)
  395.         end
  396.  
  397.         if call_flag
  398.           Sound.play_cursor
  399.           redraw_item(index)
  400.         end
  401.       end
  402.       def add_vol_bgm(val)
  403.         old = Audio.bgm_vol
  404.         Audio.bgm_vol += val
  405.         if music = RPG::BGM.last and music.name.size > 0
  406.           Audio.bgm_play("Audio/BGM/#{music.name}", music.volume, music.pitch, music.pos)
  407.         end
  408.         Audio.bgm_vol != old
  409.       end
  410.       def add_vol_bgs(val)
  411.         old = Audio.bgs_vol
  412.         Audio.bgs_vol += val
  413.         Audio.bgs_vol != old
  414.       end
  415.       def add_vol_se(val)
  416.         old = Audio.se_vol
  417.         Audio.se_vol += val
  418.         Audio.se_vol != old
  419.       end
  420.       def add_vol_me(val)
  421.         old = Audio.me_vol
  422.         Audio.me_vol += val
  423.         Audio.me_vol != old
  424.       end
  425.       #--------------------------------------------------------------------------
  426.       # ● Process when the button is pressed
  427.       #    ※Ignore if it's on the volume setting
  428.       #--------------------------------------------------------------------------
  429.       def process_ok
  430.         case current_symbol
  431.         when :bgm, :bgs, :se, :me
  432.           return
  433.         else
  434.           super
  435.         end
  436.       end
  437.       #-------------------------------------------------------------------------
  438.       # ● Key operation
  439.       #-------------------------------------------------------------------------
  440.       def cursor_left(wrap = false)
  441.         vol_add(@index, -HZM_VXA::AudioVol::ADD_VOL_NORMAL)
  442.       end
  443.       def cursor_right(wrap = false)
  444.         vol_add(@index,  HZM_VXA::AudioVol::ADD_VOL_NORMAL)
  445.       end
  446.       def cursor_pageup
  447.         vol_add(@index, -HZM_VXA::AudioVol::ADD_VOL_HIGH)
  448.       end
  449.       def cursor_pagedown
  450.         vol_add(@index,  HZM_VXA::AudioVol::ADD_VOL_HIGH)
  451.       end
  452.     end
  453.     class Scene_VolConfig < Scene_MenuBase
  454.       #-------------------------------------------------------------------------
  455.       # ● Start processing
  456.       #-------------------------------------------------------------------------
  457.       def start
  458.         super
  459.         create_help_window
  460.         @command_window = Window_VolConfig.new
  461.         @command_window.viewport = @viewport
  462.         @command_window.set_handler(:cancel,   method(:return_scene))
  463.         @help_window.set_text("Bạn Có Thể Chỉnh Âm Thanh(0: Im lặng~100: Tối Đa)\n← Vặn Nhỏ / Vặn Lớn →")
  464.       end
  465.       #-------------------------------------------------------------------------
  466.       # ● End processing
  467.       #-------------------------------------------------------------------------
  468.       def terminate
  469.         super
  470.         @command_window.dispose
  471.         if HZM_VXA::AudioVol::USE_INI
  472.           HZM_VXA::Ini.save('AudioVol', 'BGM', Audio.bgm_vol)
  473.           HZM_VXA::Ini.save('AudioVol', 'BGS', Audio.bgs_vol)
  474.           HZM_VXA::Ini.save('AudioVol', 'SE', Audio.se_vol)
  475.           HZM_VXA::Ini.save('AudioVol', 'ME', Audio.me_vol)
  476.         end
  477.       end
  478.     end
  479.   end
  480. end
  481.  
  482. if HZM_VXA::AudioVol::USE_INI
  483.   # If the base script is not installed, it will work with the simplified version
  484.   unless defined?(HZM_VXA::Ini)
  485.     module HZM_VXA
  486.       module Base
  487.         GetPrivateProfileInt = Win32API.new('kernel32', 'GetPrivateProfileInt', %w(p p i p), 'i')
  488.         WritePrivateProfileString = Win32API.new('kernel32', 'WritePrivateProfileString', %w(p p p p), 'i')
  489.       end
  490.       class Ini
  491.         INI_FILENAME = './Game.ini'
  492.         def self.load(section, key)
  493.           HZM_VXA::Base::GetPrivateProfileInt.call(section, key, 100, INI_FILENAME).to_i
  494.         end
  495.         def self.save(section, key, value)
  496.           HZM_VXA::Base::WritePrivateProfileString.call(section, key, value.to_i.to_s, INI_FILENAME) != 0
  497.         end
  498.       end
  499.     end
  500.   end
  501.   # Read volume initial value
  502.   Audio.bgm_vol = (HZM_VXA::Ini.load('AudioVol', 'BGM') or 100)
  503.   Audio.bgs_vol = (HZM_VXA::Ini.load('AudioVol', 'BGS') or 100)
  504.   Audio.se_vol  = (HZM_VXA::Ini.load('AudioVol', 'SE') or 100)
  505.   Audio.me_vol  = (HZM_VXA::Ini.load('AudioVol', 'ME') or 100)
  506. end