Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # encoding: utf-8
- #===============================================================================
- # �¡ Volume Control For RGSS3
- #-------------------------------------------------------------------------------
- #�@2011/12/01�@Ru/‚Þ‚Á‚R
- #-------------------------------------------------------------------------------
- # English Translation By: Elemental Crisis (http://RPGMakerVXAce.com)
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # Bug fixes and menu bars added by Kal.
- #-------------------------------------------------------------------------------
- #
- #�@Adds the ability to change volume control.
- #
- #�@�œ The following methods are added to the Audio Module
- #�@Audio.volBGM �c�c Maximum BGM volume setting.
- #�@Audio.volBGS �c�c Maximum BGS volume setting.
- #�@Audio.volSE �c�c Maximum SE volume setting.
- #�@Audio.volME �c�c Maximum ME volume setting.
- #�@Audio.volBGM=�”’l �c�cSet BGM maximum volume (0-100)
- #�@Audio.volBGM=�”’l �c�c Set BGS maximum volume (0-100)
- #�@Audio.volSE=�”’l �c�c Set SE maximum volume (0-100)
- #�@Audio.volME=�”’l �c�c Set ME maximum volume (0-100)
- #
- #�@�œ Volume control is added to the main menu.
- #
- #-------------------------------------------------------------------------------
- # �yKnown Issues�z
- #�@Created before VXAce's official release so unable to properly test.
- #-------------------------------------------------------------------------------
- #==============================================================================
- # �œ Settings
- #==============================================================================
- module HZM_VXA
- module AudioVol
- # Display Volume Control on Main Menu?
- # �@true �c�c Display.
- # �@false �c�c Don't Display.
- MENU_FLAG = false
- # Volume Control Name in Main Menu.
- MENU_NAME = "Volume Settings"
- # Volume Control Settings Name.
- CONFIG_BGM_NAME = "BGM"
- CONFIG_BGS_NAME = "BGS"
- CONFIG_SE_NAME = "SE"
- CONFIG_ME_NAME = "ME"
- CONFIG_EXIT_NAME = "Exit"
- # Volume Change Variation.
- # ADD_VOL_NORMAL �c�c Variation of Left/Right Keys.
- # ADD_VOL_HIGH �c�c Variation of LR Key.
- ADD_VOL_NORMAL = 5
- ADD_VOL_HIGH = 25
- # Use bars or numbers.
- # :bars => use bars
- # :numbers => use numbers
- DISPLAY = :bars
- # Bar display options.
- # The higher BAR_X the more to the right the bar is drawn.
- # BAR_WIDTH sets the width of the bar.
- # Y_ADJUST allows you to precisely adjust the y value (how high or low
- # the bar is rendered).
- BAR_X = 55
- BAR_WIDTH = 70
- Y_ADJUST = -3
- end
- end
- #==============================================================================
- # �ª �@ Settings Above �@ �ª
- # �« Script Below �«
- #==============================================================================
- # Additonal Methods.
- # class << Audio means we open up the Audio module and all methods defined
- # get defined on self (that is, the Audio module itself)
- class << Audio
- def volBGM=(vol)
- @hzmVolBGM = normalize_volume(vol)
- end
- def volBGS=(vol)
- @hzmVolBGS = normalize_volume(vol)
- end
- def volSE=(vol)
- @hzmVolSE = normalize_volume(vol)
- end
- def volME=(vol)
- @hzmVolME = normalize_volume(vol)
- end
- def volBGM
- @hzmVolBGM.nil? ? @hzmVolBGM = 100 : @hzmVolBGM
- end
- def volBGS
- @hzmVolBGS.nil? ? @hzmVolBGS = 100 : @hzmVolBGS
- end
- def volSE
- @hzmVolSE.nil? ? @hzmVolSE = 100 : @hzmVolSE
- end
- def volME
- @hzmVolME.nil? ? @hzmVolME = 100 : @hzmVolME
- end
- # Make sure volume does not go over 100 or under 0.
- def normalize_volume(vol)
- vol = 100 if vol > 100
- vol = 0 if vol < 0
- vol
- end
- # Playback
- alias hzm_Vol_Audio_bgm_play bgm_play
- def bgm_play(filename, volume=100, pitch=100, pos=0)
- volume = self.volBGM * volume.to_f / 100
- hzm_Vol_Audio_bgm_play(filename, volume, pitch, pos)
- end
- alias hzm_Vol_Audio_bgs_play bgs_play
- def bgs_play(filename, volume=100, pitch=100)
- volume = self.volBGS * volume.to_f / 100
- hzm_Vol_Audio_bgs_play(filename, volume, pitch)
- end
- alias hzm_Vol_Audio_se_play se_play
- def se_play(filename, volume=100, pitch=100)
- volume = self.volSE * volume.to_f / 100
- hzm_Vol_Audio_se_play(filename, volume, pitch)
- end
- alias hzm_Vol_Audio_me_play me_play
- def me_play(filename, volume=100, pitch=100)
- volume = self.volME * volume.to_f / 100
- hzm_Vol_Audio_me_play(filename, volume, pitch)
- end
- end
- # Add To Menu.
- if HZM_VXA::AudioVol::MENU_FLAG
- class Window_MenuCommand
- alias hzm_Vol_Window_MenuCommand_add_original_commands add_original_commands
- def add_original_commands
- hzm_Vol_Window_MenuCommand_add_original_commands
- add_command(HZM_VXA::AudioVol::MENU_NAME, :hzm_vxa_vol)
- end
- end
- class Scene_Menu
- alias hzm_Vol_create_command_window create_command_window
- def create_command_window
- hzm_Vol_create_command_window
- @command_window.set_handler(:hzm_vxa_vol, method(:hzm_vxa_vol))
- end
- def hzm_vxa_vol
- SceneManager.call(HZM_VXA::AudioVol::Scene_VolConfig)
- end
- end
- end
- # Volume Change Window
- module HZM_VXA
- module AudioVol
- class Window_VolConfig < Window_Command
- def initialize
- super(0, 0)
- self.x = (Graphics.width - self.window_width)/2
- self.y = (Graphics.height - self.window_height)/2
- end
- def make_command_list
- add_command(HZM_VXA::AudioVol::CONFIG_BGM_NAME, :bgm)
- add_command(HZM_VXA::AudioVol::CONFIG_BGS_NAME, :bgs)
- add_command(HZM_VXA::AudioVol::CONFIG_SE_NAME, :se)
- add_command(HZM_VXA::AudioVol::CONFIG_ME_NAME, :me)
- add_command(HZM_VXA::AudioVol::CONFIG_EXIT_NAME, :cancel)
- end
- def draw_item(index)
- super
- return unless index < 4
- case index
- when 0
- vol = Audio.volBGM
- when 1
- vol = Audio.volBGS
- when 2
- vol = Audio.volSE
- when 3
- vol = Audio.volME
- end
- # Draws vol as a number or as a bar.
- if DISPLAY == :bars
- y = (index * line_height) + Y_ADJUST
- draw_gauge(BAR_X, y, BAR_WIDTH, vol / 100.0, normal_color, normal_color)
- else
- draw_text(item_rect_for_text(index), vol, 2)
- end
- end
- def volAdd(index, val)
- case index
- when 0
- Audio.volBGM += val
- now = RPG::BGM.last
- Audio.bgm_play('Audio/BGM/' + now.name, now.volume, now.pitch, now.pos) if now
- when 1
- Audio.volBGS += val
- when 2
- Audio.volSE += val
- when 3
- Audio.volME += val
- end
- Sound.play_cursor
- redraw_item(index)
- end
- def cursor_left(wrap = false)
- volAdd(@index, -HZM_VXA::AudioVol::ADD_VOL_NORMAL)
- end
- def cursor_right(wrap = false)
- volAdd(@index, HZM_VXA::AudioVol::ADD_VOL_NORMAL)
- end
- def cursor_pageup
- volAdd(@index, -HZM_VXA::AudioVol::ADD_VOL_HIGH)
- end
- def cursor_pagedown
- volAdd(@index, HZM_VXA::AudioVol::ADD_VOL_HIGH)
- end
- end
- class Scene_VolConfig < Scene_MenuBase
- def start
- super
- @command_window = Window_VolConfig.new
- @command_window.viewport = @viewport
- @command_window.set_handler(:cancel, method(:return_scene))
- end
- def terminate
- super
- @command_window.dispose
- end
- end
- end
- end
- # Reading/Saving
- class << DataManager
- alias hzm_Vol_make_save_contents make_save_contents
- def make_save_contents
- contents = hzm_Vol_make_save_contents
- contents[:hzm_vxa_vol] = {
- :bgm => Audio.volBGM,
- :bgs => Audio.volBGS,
- :se => Audio.volSE,
- :me => Audio.volME
- }
- contents
- end
- alias hzm_Vol_extract_save_contents extract_save_contents
- def extract_save_contents(contents)
- hzm_Vol_extract_save_contents(contents)
- Audio.volBGM = contents[:hzm_vxa_vol][:bgm]
- Audio.volBGS = contents[:hzm_vxa_vol][:bgs]
- Audio.volSE = contents[:hzm_vxa_vol][:se]
- Audio.volME = contents[:hzm_vxa_vol][:me]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement