Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #==============================================================================
  2. # ■ RGSS3 Nút Vặn Âm Thanh F6
  3. #------------------------------------------------------------------------------
  4. # ゲーム内でBGM・BGS・ME・SEの音量を
  5. # プレイヤーの手で変更する事が出来るようになります。
  6. #
  7. # プレイ中、F6キーを押す事で音量調節用画面を呼び出せます。
  8. # 呼び出しに使用するキーは変更する事が出来ます。
  9. #
  10. # Ver1.01  BGS・SEの音量処理が不適切だった不具合を修正しました。
  11. #
  12. # Ver1.02  bitmapの解放し忘れを修正しました。
  13. #
  14. # Ver1.02X 新たに音量データを格納したVolumeファイルを生成するようになります。
  15. #          タイトル画面を含むゲーム中のあらゆる場面で呼び出せるようになると共に
  16. #          全てのセーブデータの音量調節を一元管理するようになりました。
  17. #
  18. # Ver1.03  データ一元管理版と統合し、いくつかの処理を見直しました。
  19. #==============================================================================
  20. module Sound_Control
  21.  
  22.   #音量調節タイプを設定して下さい。
  23.   #0の場合、全セーブデータ共通。
  24.   #1の場合、セーブデータ個別。
  25.  
  26.   TYPE    = 0
  27.  
  28.   #全セーブデータ共通とする場合の音量保存用ファイル名を指定します。
  29.  
  30.   NAME    = "Volume.rvdata2"
  31.  
  32.   #空の配列を作成。
  33.  
  34.   SNAME   = []
  35.  
  36.   #BGMの表示名称を指定します。
  37.  
  38.   SNAME[0]   = "BGM"
  39.  
  40.   #BGSの表示名称を指定します。
  41.  
  42.   SNAME[1]   = "BGS"
  43.  
  44.   #MEの表示名称を指定します。
  45.  
  46.   SNAME[2]   = "ME"
  47.  
  48.   #SEの表示名称を指定します。
  49.  
  50.   SNAME[3]   = "SE"
  51.  
  52.   #空の配列を作成。
  53.  
  54.   DEF_VOL = []
  55.  
  56.   #各初期音量を指定します。
  57.   #音量調節タイプがセーブデータ個別の場合
  58.   #タイトル画面とテスト戦闘の音量は毎回初期化されます。
  59.  
  60.   #BGMの初期音量を指定。
  61.  
  62.   DEF_VOL[0] = 40
  63.  
  64.   #BGSの初期音量を指定。
  65.  
  66.   DEF_VOL[1] = 40
  67.  
  68.   #MEの初期音量を指定。
  69.  
  70.   DEF_VOL[2] = 40
  71.  
  72.   #SEの初期音量を指定。
  73.  
  74.   DEF_VOL[3] = 40
  75.  
  76.   #音量調節画面呼び出し用キーを指定して下さい。
  77.   #なお、本来は変更する必要はありません。
  78.  
  79.   KEY = :F6
  80.  
  81.   #カーソルの飾り文字を指定します。
  82.   #デフォルトでは全角二文字もしくは半角四文字までが推奨文字数です。
  83.   #なお、変更する必要はありません。
  84.   #不要な場合はそれぞれ""に変えて下さい
  85.  
  86.   #前
  87.  
  88.   CURSOR_1 = "★☆"
  89.  
  90.   #後
  91.  
  92.   CURSOR_2 = "☆★"
  93.  
  94.   #説明文の内容を設定します。
  95.   #デフォルトでは音量調節画面の使用方法が記載されています。
  96.  
  97.   #見出しとして表示するテキスト。(大きく表示されます)
  98.  
  99.   TITLE = "- Điều Chỉnh Âm Thanh -"
  100.  
  101.   #左下・右下に表示するテキストを数値に応じて更に下の方に移動させます。
  102.   #解像度を640×480に拡張している場合は、この値を32に設定すると
  103.   #ちょうどいいかもしれません。
  104.  
  105.   Y_PLUS = 0
  106.  
  107.   #左下に表示するテキスト用配列を用意します。
  108.  
  109.   LTEXT = []
  110.  
  111.   #左下に表示するテキストを指定順に記述します。
  112.  
  113.   LTEXT[0] = "♪Nhấn Phím ▲ : Duy Chuyển Lên"
  114.   LTEXT[1] = "♪Nhấn Phím ▼ : Duy Chuyển Xuống"
  115.   LTEXT[2] = "♪Nhấn Phím ► : Âm Lượng +1"
  116.   LTEXT[3] = "♪Nhấn Phím ◄ : Âm Lượng -1"
  117.   LTEXT[4] = "♪Shift + ► : Âm Lượng +5"
  118.   LTEXT[5] = "♪Shift + ◄ : Âm Lượng -5"
  119.   LTEXT[6] = "♪Ctrl: Trở Về Mặc Định"
  120.  
  121.   #右下に表示するテキスト用配列を用意します。
  122.  
  123.   RTEXT = []
  124.  
  125.   #左下に表示するテキストを指定順に記述します。
  126.  
  127.   RTEXT[0] = "♪Xác nhận Nút (Z): Thoát"
  128.   RTEXT[1] = "♪Bỏ Chọn Nút (X): Thoát"
  129.   RTEXT[2] = ""
  130.   RTEXT[3] = "♪F6: Tắt Tiếng"
  131.   RTEXT[4] = "♪F7: Bật Tối Đa"
  132.   RTEXT[5] = "♪F8: Tắt Tiếng Hết"
  133.   RTEXT[6] = "♪F9: Bật Tối Đa Hết"
  134.  
  135. end
  136. class Scene_Base
  137.   #--------------------------------------------------------------------------
  138.   # 更新
  139.   #--------------------------------------------------------------------------
  140.   alias update_sound_control update
  141.   def update
  142.     update_sound_control
  143.     sound_control_execute if Input.trigger?(Sound_Control::KEY)
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # 音量調節画面の背景を作成
  147.   #--------------------------------------------------------------------------
  148.   def create_sound_control_back_sprite(color)
  149.     @back_sprite = Sprite.new
  150.     @back_sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  151.     @back_sprite.x = (Graphics.width - @back_sprite.width) / 2
  152.     @back_sprite.y = (Graphics.height - @back_sprite.height) / 2
  153.     @back_sprite.z = 10000
  154.     @back_sprite.bitmap.fill_rect(@back_sprite.bitmap.rect, color)
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # 音量調節カーソルを作成
  158.   #--------------------------------------------------------------------------
  159.   def create_sound_control_cursor(h)
  160.     @big_cursor = Sprite.new
  161.     @big_cursor.bitmap = Bitmap.new(350, 24)
  162.     color = Color.new(255, 255, 255, 50)
  163.     @big_cursor.bitmap.fill_rect(@big_cursor.bitmap.rect, color)
  164.     @big_cursor.bitmap.draw_text(@big_cursor.bitmap.rect,
  165.     Sound_Control::CURSOR_1, 0)
  166.     @big_cursor.bitmap.draw_text(@big_cursor.bitmap.rect,
  167.     Sound_Control::CURSOR_2, 2)
  168.     @big_cursor.x = (@back_sprite.width - @big_cursor.width) / 2
  169.     @big_cursor.y = @back_sprite.y + h * 3
  170.     @big_cursor.z = @back_sprite.z + 1
  171.   end
  172.   #--------------------------------------------------------------------------
  173.   # 音量調節用テキストを作成
  174.   #--------------------------------------------------------------------------
  175.   def create_sound_control_text(h)
  176.     @back_sprite.bitmap.font.size = 32
  177.     @back_sprite.bitmap.draw_text(0, 24,
  178.     @back_sprite.width, @back_sprite.bitmap.font.size, Sound_Control::TITLE, 1)
  179.     @back_sprite.bitmap.font.size = 20
  180.     Sound_Control::LTEXT.each_with_index {|text, i|
  181.     @back_sprite.bitmap.draw_text(12,   h * (i + 10) + Sound_Control::Y_PLUS,
  182.     @back_sprite.width, 24, text, 0)
  183.     }
  184.     Sound_Control::RTEXT.each_with_index {|text, i|
  185.     @back_sprite.bitmap.draw_text(@back_sprite.bitmap.width / 2 + 12,
  186.     h * (i + 10) + Sound_Control::Y_PLUS, @back_sprite.width, 24, text, 0)
  187.     }
  188.     @back_sprite.bitmap.font.size = 24
  189.     4.times {|i| @back_sprite.bitmap.draw_text(
  190.     @big_cursor.x + 48, h * (i * 2 + 3), 40, 24, Sound_Control::SNAME[i], 2)}
  191.   end
  192.   #--------------------------------------------------------------------------
  193.   # 音量調節ゲージを作成
  194.   #--------------------------------------------------------------------------
  195.   def create_sound_control_gauge(h)
  196.     @gauge_sprite = []
  197.     color = []
  198.     color.push(Color.new(128, 0, 0))
  199.     color.push(Color.new(255, 128, 128))
  200.     color.push(Color.new(0, 0, 128))
  201.     color.push(Color.new(128, 128, 255))
  202.     color.push(Color.new(128, 128, 0))
  203.     color.push(Color.new(255, 255, 128))
  204.     color.push(Color.new(0, 128, 0))
  205.     color.push(Color.new(128, 255, 128))
  206.     color.push(Color.new(32, 0, 0))
  207.     color.push(Color.new(0, 0, 32))
  208.     color.push(Color.new(32, 32, 0))
  209.     color.push(Color.new(0, 32, 0))
  210.     color.push(Color.new(64, 0, 0))
  211.     color.push(Color.new(0, 0, 64))
  212.     color.push(Color.new(64, 64, 0))
  213.     color.push(Color.new(0, 64, 0))
  214.     color.push(Color.new(128, 64, 64))
  215.     color.push(Color.new(64, 64, 128))
  216.     color.push(Color.new(128, 128, 64))
  217.     color.push(Color.new(64, 128, 64))
  218.     4.times {|i|
  219.     @gauge_sprite.push(Sprite.new)
  220.     @gauge_sprite[i].bitmap = Bitmap.new(120, 12)
  221.     @gauge_sprite[i].bitmap.gradient_fill_rect(
  222.     @gauge_sprite[i].bitmap.rect, color[i * 2], color[i * 2 + 1])
  223.     @gauge_sprite[i].x = (@back_sprite.x + @back_sprite.width - @gauge_sprite[i].bitmap.width) / 2
  224.     @gauge_sprite[i].y = @back_sprite.y + h * (i * 2 + 3) + 6
  225.     @gauge_sprite[i].z = @back_sprite.z + 2
  226.     }
  227.     4.times {|i|
  228.     @gauge_sprite.push(Sprite.new)
  229.     @gauge_sprite[i + 4].bitmap = Bitmap.new(120, 12)
  230.     @gauge_sprite[i + 4].bitmap.fill_rect(@gauge_sprite[i + 4].bitmap.rect, color[i + 8])
  231.     @gauge_sprite[i + 4].x = @gauge_sprite[i].x + @gauge_sprite[i].width - (@gauge_sprite[i].width * (100 - $game_system.m_v[i]) / 100.0).truncate
  232.     @gauge_sprite[i + 4].y = @back_sprite.y + h * (i * 2 + 3) + 6
  233.     @gauge_sprite[i + 4].z = @back_sprite.z + 3
  234.     @gauge_sprite[i + 4].zoom_x = (100 - $game_system.m_v[i]) / 100.0
  235.     }
  236.     4.times {|i|
  237.     @gauge_sprite.push(Sprite.new)
  238.     @gauge_sprite[i + 8].bitmap = Bitmap.new(124, 16)
  239.     @gauge_sprite[i + 8].bitmap.gradient_fill_rect(
  240.     @gauge_sprite[i + 8].bitmap.rect, color[i + 12], color[i + 16])
  241.     @gauge_sprite[i + 8].x = @gauge_sprite[i].x - 2
  242.     @gauge_sprite[i + 8].y = @back_sprite.y + h * (i * 2 + 3) + 4
  243.     @gauge_sprite[i + 8].z = @back_sprite.z + 1
  244.     }
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # 音量調節ゲージの更新
  248.   #--------------------------------------------------------------------------
  249.   def sound_control_gauge_text_update(number, h, color)
  250.     @back_sprite.bitmap.clear_rect(
  251.     @big_cursor.x + @big_cursor.width - 116, h * (number * 2 + 3), 64, 24)
  252.     @back_sprite.bitmap.fill_rect(
  253.     @big_cursor.x + @big_cursor.width - 116, h * (number * 2 + 3), 64, 24, color)
  254.     @back_sprite.bitmap.draw_text(
  255.     @big_cursor.x + @big_cursor.width - 116, h * (number * 2 + 3), 64, 24, $game_system.m_v[number], 2)
  256.     @gauge_sprite[number + 4].x = @gauge_sprite[number].x + @gauge_sprite[number].width - (@gauge_sprite[number].width * (100 - $game_system.m_v[number]) / 100.0).truncate
  257.     @gauge_sprite[number + 4].zoom_x = (100 - $game_system.m_v[number]) / 100.0
  258.     case number
  259.     when 0;RPG::BGM::last.play
  260.     when 1;RPG::BGS::last.play
  261.     end
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # 音量調節の実行
  265.   #--------------------------------------------------------------------------
  266.   def sound_control_execute
  267.     Sound.play_ok
  268.     color = Color.new(0, 0, 10, 200)
  269.     create_sound_control_back_sprite(color)
  270.     h = 24
  271.     create_sound_control_cursor(h)
  272.     create_sound_control_text(h)
  273.     create_sound_control_gauge(h)
  274.     4.times {|i| @back_sprite.bitmap.draw_text(@big_cursor.x + @big_cursor.width - 116, h * (i * 2 + 3), 64, 24, $game_system.m_v[i], 2)}
  275.     data_index = 0
  276.     loop do
  277.       Graphics.update
  278.       Input.update
  279.       Graphics.frame_count -= 1
  280.       if Input.trigger?(Input::UP)
  281.         Sound.play_cursor
  282.         data_index -= 1
  283.         data_index = 3 if data_index < 0
  284.         @big_cursor.y = @back_sprite.y + h * (data_index * 2 + 3)
  285.       elsif Input.trigger?(Input::DOWN)
  286.         Sound.play_cursor
  287.         data_index += 1
  288.         data_index = 0 if data_index > 3
  289.         @big_cursor.y = @back_sprite.y + h * (data_index * 2 + 3)
  290.       elsif Input.trigger?(Input::LEFT) or Input.repeat?(Input::LEFT)
  291.         predata = $game_system.m_v[data_index]
  292.         data = 1 * (Input.press?(Input::A) ? 5 : 1)
  293.         $game_system.m_v[data_index] = [[$game_system.m_v[data_index] - data, 100].min, 0].max
  294.         sound_control_gauge_text_update(data_index, h, color)
  295.         Sound.play_cursor if predata != $game_system.m_v[data_index]
  296.       elsif Input.trigger?(Input::RIGHT) or Input.repeat?(Input::RIGHT)
  297.         predata = $game_system.m_v[data_index]
  298.         data = 1 * (Input.press?(Input::A) ? 5 : 1)
  299.         $game_system.m_v[data_index] = [[$game_system.m_v[data_index] + data, 100].min, 0].max
  300.         sound_control_gauge_text_update(data_index, h, color)
  301.         Sound.play_cursor if predata != $game_system.m_v[data_index]
  302.       elsif Input.trigger?(:CTRL)
  303.         predata = $game_system.m_v
  304.         $game_system.m_v = Sound_Control::DEF_VOL.clone
  305.         4.times {|i| sound_control_gauge_text_update(i, h, color)}
  306.         Sound.play_cursor if predata != $game_system.m_v
  307.       elsif Input.trigger?(Input::F6)
  308.         predata = $game_system.m_v[data_index]
  309.         $game_system.m_v[data_index] = 0
  310.         sound_control_gauge_text_update(data_index, h, color)
  311.         Sound.play_cursor if predata != $game_system.m_v[data_index]
  312.       elsif Input.trigger?(Input::F7)
  313.         predata = $game_system.m_v[data_index]
  314.         $game_system.m_v[data_index] = 100
  315.         sound_control_gauge_text_update(data_index, h, color)
  316.         Sound.play_cursor if predata != $game_system.m_v[data_index]
  317.       elsif Input.trigger?(Input::F8)
  318.         predata = $game_system.m_v
  319.         4.times {|i|
  320.         $game_system.m_v[i] = 0
  321.         sound_control_gauge_text_update(i, h, color)
  322.         }
  323.         Sound.play_cursor if predata != $game_system.m_v
  324.       elsif Input.trigger?(Input::F9)
  325.         predata = $game_system.m_v
  326.         4.times {|i|
  327.         $game_system.m_v[i] = 100
  328.         sound_control_gauge_text_update(i, h, color)
  329.         }
  330.         Sound.play_cursor if predata != $game_system.m_v
  331.       elsif Input.trigger?(Input::B) or Input.trigger?(Input::C)
  332.         $game_system.vd_save
  333.         break
  334.       end
  335.       @big_cursor.update
  336.       @back_sprite.update
  337.       12.times {|i| @gauge_sprite[i].update}
  338.     end
  339.     Sound.play_cancel
  340.     @back_sprite.bitmap.dispose;@back_sprite.dispose
  341.     @big_cursor.bitmap.dispose;@big_cursor.dispose
  342.     12.times {|i| @gauge_sprite[i].bitmap.dispose;@gauge_sprite[i].dispose}
  343.   end
  344. end
  345. class << DataManager
  346.   #--------------------------------------------------------------------------
  347.   # セーブデータの展開
  348.   #--------------------------------------------------------------------------
  349.   alias extract_save_contents_first_volume extract_save_contents
  350.   def extract_save_contents(contents)
  351.     extract_save_contents_first_volume(contents)
  352.     $game_system.m_v = $game_system.m_v_make if Sound_Control::TYPE == 0
  353.   end
  354. end
  355. class Game_System
  356.   attr_accessor :m_v
  357.   #--------------------------------------------------------------------------
  358.   # 音量データの作成
  359.   #--------------------------------------------------------------------------
  360.   def m_v_make
  361.     case Sound_Control::TYPE
  362.     when 0;Dir.glob(Sound_Control::NAME).empty? ? vd_save : vd_load
  363.     when 1;@m_v = Sound_Control::DEF_VOL.clone
  364.     end
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # 音量データのセーブ
  368.   #--------------------------------------------------------------------------
  369.   def vd_save
  370.     @m_v = Sound_Control::DEF_VOL.clone if @m_v == nil
  371.     save_data(@m_v,Sound_Control::NAME) if Sound_Control::TYPE == 0
  372.   end
  373.   #--------------------------------------------------------------------------
  374.   # 音量データのロード
  375.   #--------------------------------------------------------------------------
  376.   def vd_load
  377.     @m_v = load_data(Sound_Control::NAME)
  378.   end
  379. end
  380. class RPG::AudioFile
  381.   #--------------------------------------------------------------------------
  382.   # BGMの初期化
  383.   #--------------------------------------------------------------------------
  384.   alias initialize_sound_control initialize unless $!
  385.   def initialize(name = '', volume = 100, pitch = 100)
  386.     initialize_sound_control(name, volume, pitch)
  387.     @true_volume = @volume
  388.     sound_control
  389.   end
  390.   def true_volume
  391.     @true_volume = @volume unless @true_volume
  392.     return @true_volume
  393.   end
  394.   def sound_control
  395.     @volume = true_volume * master_volume * 1.00 / 100
  396.   end
  397.   def master_volume
  398.     $game_system.m_v_make unless $game_system.m_v
  399.     return $game_system.m_v[0] if self.is_a?(RPG::BGM)
  400.     return $game_system.m_v[1] if self.is_a?(RPG::BGS)
  401.     return $game_system.m_v[2] if self.is_a?(RPG::ME)
  402.     return $game_system.m_v[3] if self.is_a?(RPG::SE)
  403.   end
  404. end
  405. class RPG::BGM < RPG::AudioFile
  406.   alias play_sc play unless $!
  407.   def play(pos = 0)
  408.     sound_control
  409.     play_sc(pos)
  410.   end
  411. end
  412. class RPG::BGS < RPG::AudioFile
  413.   alias play_sc play unless $!
  414.   def play(pos = 0)
  415.     sound_control
  416.     play_sc(pos)
  417.   end
  418. end
  419. class RPG::ME < RPG::AudioFile
  420.   alias play_sc play unless $!
  421.   def play
  422.     sound_control
  423.     play_sc
  424.   end
  425. end
  426. class RPG::SE < RPG::AudioFile
  427.   alias play_sc play unless $!
  428.   def play
  429.     sound_control
  430.     play_sc
  431.   end
  432. end