#==============================================================================
# Music Library
# by momo
#==============================================================================
Â
module MoMo_Sound_Test
 NO_GET_SOUND_SHOW = false
 USE_SWITCH = true
#==============================================================================
# Total music number display
# 0 = don't show
# 1 = total numbers
# 2 = show %
#==============================================================================
 SHOW_COMPLETE_TYPE = 1
 COMMENT_SYSTEM = false
 SYSTEM_DATA_SAVE = false
 SYSTEM_DATA_LOAD = false
 sound = [nil]
#==============================================================================
# sound[ID] = ["Name in Menu", "Archive name", 100, 100, 0]
#
# the musics are added to the menu, when you hear them in game.
#==============================================================================
 sound[1] = ["Overworld", "018-Field01", 100, 100, 0]
 sound[2] = ["Cave", "001-Battle01", 100, 100, 0]
 sound[3] = ["Battle", "035-Dungeon01", 100, 100, 0]
 sound[4] = ["Boss", "005-Boss01", 100, 100, 0]
 ################################################################
 SOUND_DATA = sound
end
Â
module MoMo_Sound_Test
 module_function
 def sound_info_switch_judge(id, form_title=false)
  return true if !USE_SWITCH or form_title
  sw = get_need_switch(id)
  if sw == 0
   return true
  else
   return $game_switches[sw]
  end
 end
 def get_sound_name(id)
  return SOUND_DATA[id][0]
 end
 def get_file_name(id)
  return SOUND_DATA[id][1]
 end
 def get_sound_volume(id)
  return SOUND_DATA[id][2]
 end
 def get_sound_pitch(id)
  return SOUND_DATA[id][3]
 end
 def get_need_switch(id)
  return SOUND_DATA[id][4]
 end
 def get_sound_comment(id)
  return nil if !COMMENT_SYSTEM
  if MoMo_S_Test_Comment::S_TEST_COMMENT[id] == nil
   return MoMo_S_Test_Comment::S_TEST_COMMENT[0]
  else
   return MoMo_S_Test_Comment::S_TEST_COMMENT[id]
  end
 end
 def add_sound_info(file_name)
  sound_info_path(false)[file_name] = 1 if sound_info_path(false) != nil
  if need_system_save? and sound_info_path(false) != nil
   sound_info_path(true)[file_name] = 1
  end
 end
 def del_sound_info(file_name)
  sound_info_path(false)[file_name] = 0
  if need_system_save?
   sound_info_path(true)[file_name] = 0
  end
 end
 def have_sound_info?(id, from_title=false)
  return true if NO_GET_SOUND_SHOW
  return (sound_info_path(from_title)[get_file_name(id)] == 1)
 end
 def need_system_save?
  return (SYSTEM_DATA_SAVE and $system_data != nil)
 end
 def sound_data_max
  return SOUND_DATA.size - 1
 end
 def sound_data_now(from_title=false)
  num = 0
  for i in 1...SOUND_DATA.size
   sound = SOUND_DATA[i]
   if sound != nil and
     (NO_GET_SOUND_SHOW or have_sound_info?(i, from_title)) and
     (from_title or !USE_SWITCH or sound[4] == 0 or $game_switches[sound[4]])
    num += 1
   end
  end
  return num
 end
 def sound_data_complete_percentage(from_title=false)
  s_max = sound_data_max.to_f
  s_now = sound_data_now(from_title).to_f
  comp = s_now / s_max * 100
  return comp.truncate
 end
 def sound_info_path(from_title=false)
  if (!from_title and !SYSTEM_DATA_LOAD)
   return nil if $game_party == nil
   return $game_party.sound_info
  else
   return nil if $system_data == nil
   return $system_data.sound_info
  end
 end
end
Â
class Sound_Test_Data
 attr_reader  :id
 attr_reader  :soundname
 attr_reader  :filename
 attr_reader  :volume
 attr_reader  :pitch
 attr_reader  :need_switch
 def initialize(id)
  @id = id
  @soundname = MoMo_Sound_Test.get_sound_name(id)
  @filename = MoMo_Sound_Test.get_file_name(id)
  @volume = MoMo_Sound_Test.get_sound_volume(id)
  @pitch = MoMo_Sound_Test.get_sound_pitch(id)
  @need_switch = MoMo_Sound_Test.get_need_switch(id)
  @comment = MoMo_Sound_Test.get_sound_comment(id)
 end
end
Â
class Game_System
 alias game_system_sound_test_bgm_play bgm_play
 def bgm_play(bgm)
  if bgm != nil and bgm.name != ""
   MoMo_Sound_Test.add_sound_info(bgm.name)
  end
  game_system_sound_test_bgm_play(bgm)
 end
end
Â
class Game_Party
 include MoMo_Sound_Test
 attr_accessor :sound_info
 alias game_party_sound_test_initialize initialize
 def initialize
  game_party_sound_test_initialize
  @sound_info = {}
 end
end
Â
class Interpreter
 def sound_data_max
  return MoMo_Sound_Test.sound_data_max
 end
 def sound_data_now
  return MoMo_Sound_Test.sound_data_now
 end
 def sound_data_comp
  return MoMo_Sound_Test.sound_data_complete_percentage
 end
end
Â
class Window_Sound_Test < Window_Selectable
 def initialize(index=0, from_title=false)
  @from_title = from_title
  if MoMo_Sound_Test::COMMENT_SYSTEM
   super(0, 64, 640, 416 - 128)
  else
   super(0, 64, 640, 416)
  end
  @column_max = 2
  self.index = index
  refresh
 end
 def set_data
  for i in 1...MoMo_Sound_Test::SOUND_DATA.size
   @data.push(Sound_Test_Data.new(i))
  end
 end
 def show?(id)
  bool = (MoMo_Sound_Test.have_sound_info?(id, @from_title) and
      MoMo_Sound_Test.sound_info_switch_judge(id, @from_title))
  return bool
 end
 def item
  return @data[self.index]
 end
 def refresh
  if self.contents != nil
   self.contents.dispose
   self.contents = nil
  end
  @data = []
  set_data
  @item_max = @data.size
  self.contents = Bitmap.new(width - 32, row_max * 32)
  if @item_max > 0
   for i in 0...@item_max
    draw_item(i)
   end
  end
 end
 def draw_item(index)
  sound = @data[index]
  x = 4 + index % 2 * (288 + 32)
  y = index / 2 * 32
  rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  self.contents.font.color = normal_color
  self.contents.draw_text(x, y, 32, 32, sound.id.to_s)
  if show?(sound.id)
   self.contents.draw_text(x + 28+16, y, 212, 32, sound.soundname, 0)
  else
   self.contents.draw_text(x + 28+16, y, 212, 32, "------", 0)
   return
  end
 end
end
Â
class Scene_Sound_Test
 def initialize(from_title=false)
  @from_title = from_title
 end
 #--------------------------------------------------------------------------
 def main
  @map_bgm = $game_system.playing_bgm
  @title_window = Window_Base.new(0, 0, 640, 64)
  @title_window.contents = Bitmap.new(640 - 32, 64 - 32)
  @title_window.contents.draw_text(4, 0, 320, 32, "Livro de Música", 0)
  if MoMo_Sound_Test::SHOW_COMPLETE_TYPE != 0
   case MoMo_Sound_Test::SHOW_COMPLETE_TYPE
   when 1
    s_now = MoMo_Sound_Test.sound_data_now(@from_title)
    s_max = MoMo_Sound_Test.sound_data_max
    text = s_now.to_s + "/" + s_max.to_s
   when 2
    comp = MoMo_Sound_Test.sound_data_complete_percentage(@from_title)
    text = comp.to_s + "%"
   when 3
    s_now = MoMo_Sound_Test.sound_data_now(@from_title)
    s_max = MoMo_Sound_Test.sound_data_max
    comp = MoMo_Sound_Test.sound_data_complete_percentage(@from_title)
    text = s_now.to_s + "/" + s_max.to_s + " " + comp.to_s + "%"
   end
   if text != nil
    @title_window.contents.draw_text(320, 0, 288, 32,  text, 2)
   end
  end
  @main_window = Window_Sound_Test.new(0, @from_title)
  @main_window.active = true
  if MoMo_Sound_Test::COMMENT_SYSTEM
   @comment_window = Window_Sound_Test_Comment.new
   @comment_window.z = 120
   draw_comment
  end
  Graphics.transition
  loop do
   Graphics.update
   Input.update
   update
   if $scene != self
    break
   end
  end
  Graphics.freeze
  @main_window.x -= 10
  @main_window.dispose
  @title_window.dispose
  @comment_window.dispose if @comment_window != nil
 end
 def update
  @main_window.update
  if @main_window.active
   update_main
   return
  end
 end
 def update_main
  if MoMo_Sound_Test::COMMENT_SYSTEM and @last_index != @main_window.index
   @last_index = @main_window.index
   draw_comment
  end
  if Input.trigger?(Input::B)
   $game_system.se_play($data_system.cancel_se)
   $game_system.bgm_play(@map_bgm)
   if @from_title
    $scene = Scene_Title.new
   else
    $scene = Scene_Map.new
   end
   return
  end
  if Input.trigger?(Input::C)
   if @main_window.item == nil or @main_window.show?(@main_window.item.id) == false
    $game_system.se_play($data_system.buzzer_se)
    return
   end
   $game_system.se_play($data_system.decision_se)
   filename = @main_window.item.filename
   volume = @main_window.item.volume
   pitch = @main_window.item.pitch
   Audio.bgm_play("Audio/BGM/" + filename, volume, pitch)
   return
  end
 end
 def draw_comment
  if @main_window.show?(@main_window.item.id)
   @comment_window.draw_comment(@main_window.item.id)
  else
   @comment_window.clear_comment
  end
 end
end