#==============================================================================
# ○サウンドコンフィグ
# for RGSS3
# 巫女瓜 / Space not far
# [url]http://muspell.raindrop.jp/[/url]
# タイトル画面に音量調節機能を追加します。
#==============================================================================
module SoundConfig
FileName = "SoundConfig.rvdata2" # 音量調節の保存先
Span = 5 # 音量調節間隔。100の約数を推奨
Position = 0 # 位置 0:左上 1:右上 2:左下 3:右下
end
module RPG
#==============================================================================
# ■ AudioFile
#==============================================================================
class AudioFile
alias snf_volume_initialize initialize unless $@
def initialize(name = "", volume = 100, pitch = 100)
snf_volume_initialize(name, volume, pitch)
@base_volume = @volume
end
#--------------------------------------------------------------------------
# ● 音量変更
#--------------------------------------------------------------------------
def volume_change
@base_volume = @volume if @base_volume.nil?
@volume = (@base_volume * correction_value / 100)
end
#--------------------------------------------------------------------------
# ● 音量補正値の取得
#--------------------------------------------------------------------------
def correction_value
if self.is_a?(RPG::BGM) or self.is_a?(RPG::ME) or self.is_a?(RPG::BGS)
return SoundConfig.load(0)
elsif self.is_a?(RPG::SE)
return SoundConfig.load(1)
end
return 100
end
end
class BGS < AudioFile
alias snf_volume_play play unless $@
def play(pos = 0)
volume_change
snf_volume_play(pos)
end
end
class BGM < AudioFile
alias snf_volume_play play unless $@
def play(pos = 0)
volume_change
snf_volume_play(pos)
end
end
class SE < AudioFile
alias snf_volume_play play unless $@
def play
volume_change
snf_volume_play
end
end
class ME < AudioFile
alias snf_volume_play play unless $@
def play
volume_change
snf_volume_play
end
end
end
class Scene_Title < Scene_Base
#--------------------------------------------------------------------------
# ● 開始処理
#--------------------------------------------------------------------------
alias snf_140612_start start unless $@
def start
snf_140612_start
create_soundconfig
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
def update
super
if Input.repeat?(:LEFT)
vol = [bgm_vol - volume_span, 0].max
SoundConfig.save(0, vol)
Sound.play_cursor
refresh_soundconfig
RPG::BGM::last.play
end
if Input.repeat?(:RIGHT)
vol = [bgm_vol + volume_span, 100].min
SoundConfig.save(0, vol)
Sound.play_cursor
refresh_soundconfig
RPG::BGM::last.play
end
if Input.repeat?(:L)
vol = [se_vol - volume_span, 0].max
SoundConfig.save(1, vol)
Sound.play_cursor
refresh_soundconfig
end
if Input.repeat?(:R)
vol = [se_vol + volume_span, 100].min
SoundConfig.save(1, vol)
Sound.play_cursor
refresh_soundconfig
end
end
#--------------------------------------------------------------------------
# @ スプライト作成
#--------------------------------------------------------------------------
def create_soundconfig
@sprite_sound = Sprite.new
@sprite_sound.bitmap = Bitmap.new(Graphics.width, Graphics.height)
@sprite_sound.z = 150
refresh_soundconfig
end
def bgm_vol
return SoundConfig.load(0)
end
def se_vol
return SoundConfig.load(1)
end
def volume_span
return SoundConfig::Span
end
def refresh_soundconfig
@sprite_sound.bitmap.clear
@sprite_sound.bitmap.font.size = 12
@sprite_sound.bitmap.font.name = "MS ゴシック"
case SoundConfig::Position
when 0 #左上
align = 0
y = 4
when 1 #右上
align = 2
y = 4
when 2 #左下
align = 0
y = Graphics.height - 28
when 3 #右下
align = 2
y = Graphics.height - 28
end
@sprite_sound.bitmap.draw_text(4, y, Graphics.width - 8, 12, sprintf(" ← BGM %03d% →" , bgm_vol.to_s), align)
@sprite_sound.bitmap.draw_text(4, y + 12, Graphics.width - 8, 12, sprintf(" Q SE %03d% W" , se_vol.to_s), align)
end
end
module SoundConfig
def self.save(index, value)
data = self.loaddata
data[index] = value
file = File.open(FileName, "wb")
Marshal.dump(data, file)
file.close
end
def self.load(index)
data = self.loaddata
value = data[index] if data
if value.nil?
value = 100
self.save(index, value)
end
return value
end
def self.loaddata
if FileTest.exist?(FileName)
file = File.open(FileName, "r")
data = Marshal.load(file)
file.close
else
data = []
end
return data
end
end