오디오

볼륨변경 스크립트

by 레기우스州 posted Aug 09, 2020
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

출처:https://torigoya.hatenadiary.jp/entry/20111201/vxace

 

저 링크의 스크립트는 MV버전처럼 볼륨을 변경할 수 있게 해주는 스크립트입니다.

 

 

스크립트 본:

# encoding: utf-8
# 【注意:2011/12/26追記】
# このスクリプトは不具合を含む古いものです.
# 使用する場合はこれではなく,最新版をお使いくださいな.
#===============================================================================
# ■ 音量変更処理スクリプトさん for RGSS3
#-------------------------------------------------------------------------------
# 2011/12/01 Ru/むっくRu
#-------------------------------------------------------------------------------
# 全体の音量変更に関する機能を追加します
#
# ● Audioモジュールに以下のメソッドが追加されます
# Audio.volBGM …… BGMのマスターボリューム取得
# Audio.volBGS …… BGSのマスターボリューム取得
# Audio.volSE  …… SEのマスターボリューム取得
# Audio.volME  …… MEのマスターボリューム取得
# Audio.volBGM=数値 …… BGMのマスターボリューム設定(0〜100)
# Audio.volBGM=数値 …… BGSのマスターボリューム設定(0〜100)
# Audio.volSE=数値  …… SEのマスターボリューム設定(0〜100)
# Audio.volME=数値  …… MEのマスターボリューム設定(0〜100)
#
# ● メニュー画面に音量調整の項目が追加されます
#
#-------------------------------------------------------------------------------
# 【問題点など】
# そもそもVXAce発売前だからちゃんと動くか微妙
#-------------------------------------------------------------------------------

#==============================================================================
# ● 設定項目
#==============================================================================
module HZM_VXA
  module AudioVol
    # メニュー画面に音量調整を表示するか?
    #  true  …… 表示する
    #  false …… 表示しない
    MENU_FLAG = true
    
    # メニュー画面に表示する項目名
    MENU_NAME        = "音量設定"
    
    # 音量設定画面の項目名
    CONFIG_BGM_NAME  = "BGM"
    CONFIG_BGS_NAME  = "BGS"
    CONFIG_SE_NAME   = "SE"
    CONFIG_ME_NAME   = "ME"
    CONFIG_EXIT_NAME = "戻る"
    
    # 音量変更の変動量
    # ADD_VOL_NORMAL …… 左右キーの変動量
    # ADD_VOL_HIGH   …… LRキーの変動量
    ADD_VOL_NORMAL = 5
    ADD_VOL_HIGH   = 25
  end
end

#==============================================================================
# ↑   ここまで設定   ↑
# ↓ 以下、スクリプト部 ↓
#==============================================================================

# 追加メソッド群
module Audio
  def self.volBGM=(vol)
    vol=100 if vol>100
    vol=0 if vol<0
    @hzmVolBGM = vol
  end
  def self.volBGS=(vol)
    vol=100 if vol>100
    vol=0 if vol<0
    @hzmVolBGS = vol
  end
  def self.volSE=(vol)
    vol=100 if vol>100
    vol=0 if vol<0
    @hzmVolSE = vol
  end
  def self.volME=(vol)
    vol=100 if vol>100
    vol=0 if vol<0
    @hzmVolME = vol
  end
  def self.volBGM
    @hzmVolBGM = 100  if @hzmVolBGM == nil
    return @hzmVolBGM
  end
  def self.volBGS
    @hzmVolBGS = 100  if @hzmVolBGS == nil
    return @hzmVolBGS
  end
  def self.volSE
    @hzmVolSE = 100  if @hzmVolSE == nil
    return @hzmVolSE
  end
  def self.volME
    @hzmVolME = 100  if @hzmVolME == nil
    return @hzmVolME
  end
end

# 再生処理
class << Audio
  alias hzm_Vol_Audio_bgm_play bgm_play
  def bgm_play(filename, volume=100, pitch=100, pos=0)
    volume = self.volBGM * volume / 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 / 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 / 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 / 100
    hzm_Vol_Audio_me_play(filename, volume, pitch)
  end
end

# メニューに追加
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

# 音量変更ウィンドウ
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
        draw_text(item_rect_for_text(index), vol, 2)
      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

# セーブ時に保存,読込
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