#===============================================================================
# 
# Yanfly Engine Melody - System Game Options
# Last Date Updated: 2010.06.12
# Level: Normal
# 
# System Game Options replaces the "Game End" scene found in the default RPG
# Maker VX with a system options menu. In this menu, the player can readjust
# sound volumes, automatic dashing, and more. This changes one of the unused
# game end scene into something a whole lot more useful.
# 
#===============================================================================
# Updates
# -----------------------------------------------------------------------------
# o 2010.06.12 - Bugfix for disposing the skins window.
# o 2010.05.14 - Finished Script.
# o 2010.05.12 - Started Script.
#===============================================================================
# Instructions
# -----------------------------------------------------------------------------
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ? Materials but above ? Main. Remember to save.
# 
# 1. Scroll down, adjust the various Switches and Variable values to something
#    empty or predetermined. 
# 2. Make a "Windows" folder in your project's "Graphics" folder. Insert the
#    window skins you want to use there and adjust the WINDOW_HASH accordingly.
# 
#===============================================================================
# Compatibility
# -----------------------------------------------------------------------------
# - Replaces ALL of Scene_End. Expect no functionality with any scripts that
#   will also replace Scene_End.
# - This script is made to be specifically compatible with Battle Engine Melody.
#===============================================================================
 
$imported = {} if $imported == nil
$imported["SystemGameOptions"] = true
 
module YEM
  module SYSTEM
 
    # This replaces the Game End title with the following text. And although
    # script itself doesn't provide the icon, any script that may potentially
    # link towards the System menu will reveal the System icon below.
    TITLE = "系统"
    ICON  = 134
 
    #===========================================================================
    # Game System Commands
    # --------------------------------------------------------------------------
    # The following adjusts the order at which you would like the menu system
    # commands to appear. Here is the reference table to their command ID's.
    #      :blank        - Blank Item.
    #      :volume_bgm   - Adjusts BGM volume.
    #      :volume_bgs   - Adjusts BGS volume.
    #      :volume_sfx   - Adjusts SFX volume.
    #      :animations   - Turns on/off battle animations.
    #      :autocursor   - Requires BEM. Memorized cursor position.
    #      :skill_help   - Requires BEM. Display skill help.
    #      :next_actor   - Requires BEM. Automatic Next Actor.
    #      :atb_active   - Requires BEM. Sets ATB type.
    #      :atb_speed    - Requires BEM. Sets ATB speed.
    #      :auto_dash    - Controls if need to hold down dash button to run.
    #      :instant_text - Whether or not text appears instantly in messages.
    #      :windowskin   - Changes the windowskin.
    #      :return_title - Return back to the title screen.
    #      :return_menu  - Return back to the menu screen.
    #===========================================================================
 
    # This array modifies the order your system menu options appear in from
    # top to bottom. Rearrange them as you see fit or remove them if desired.
    COMMANDS =[
      :windowskin,   # Adjusts window skins.
      :skill_help,   # Requires BEM. Shows skill help.
      :atb_active,   # Requires BEM. Sets ATB type.
      :atb_speeds,   # Requires BEM. Sets ATB speed.
      :animations,   # Turns on/off battle animations.
      :autocursor,   # Requires BEM. Memory cursor.
      :next_actor,   # Requires BEM. Automatic Next Actor.
      :bgm_volume,   # Adjusts BGM volume.
      :bgs_volume,   # Adjusts BGS volume.
      :sfx_volume,   # Adjusts SFX volume.
      :auto_dash,    # Controls need to hold down dash button to run.
      :instant_text, # Makes text appear instantly.
      :blank,        # A blank space.
      :return_title, # Return to the title screen.
      :return_menu,  # Return back to the main menu.
    ] # Do not remove this.
 
    # The following hash determines what variables and switches are used to
    # adjust the system options menu. It's very important that you bind the
    # values to the proper variables and switches in order for your game to
    # run properly. In addition to adjusting the switches, you also apply
    # text descriptions of each of the items here, too.
     OPTIONS ={
    # Option => Value
      :bgm_variable  => 190,  # Variable used to adjust BGM volume.
      :bgm_mute_sw   => 201,  # Switch used to mute/unmute the BGM.
        :bgm_volume  => "BGM 音量",
        :bgm_des     => "设置BGM音量 Z 切换没有和有",
      :bgs_variable  => 191,  # Variable used to adjust BGS volume.
      :bgs_mute_sw   => 202,  # Switch used to mute/unmute the BGS.
        :bgs_volume  => "BGS 音量",
        :bgs_des     => "设置BGS音量 Z 切换没有和有",
      :sfx_variable  => 192,  # Variable used to adjust SFX volume.
      :sfx_mute_sw   => 203,  # Switch used to mute/unmute the SFX.
        :sfx_volume  => "SFX 音量",
        :sfx_des     => "设置SFX音量 Z 切换没有和有",
        :mute        => "静音",
        :audio       => "音量 %d%%",
      :atb_avariable => 193,  # Variable used for ATB Active Type.
        :atb_aname   => "ActiveType",
        :wait_0      => "Full",
        :wait_0_des  => "ATB Gauge does not stop with battle menus open.",
        :wait_1      => "Semi",
        :wait_1_des  => "ATB Gauge stops during target selection.",
        :wait_2      => "Stop",
        :wait_2_des  => "ATB Gauge stops with battle menus open.",
        :wait_3      => "Wait",
        :wait_3_des  => "ATB Gauge stops with any member ready for action.",
      :atb_svariable => 194,  # Variable used for ATB Speeds.
        :atb_sname   => "Turn Speed",
        :atb_s_des   => "Adjusts battle speed. Higher values are faster.",
      :animation_sw  => 295,  # Switch used to display/hide animations.
        :animations  => "动画",
        :ani_des     => "开/关动画",
        :ani_show    => "隐藏",
        :ani_hide    => "显示",
      :autocursor_sw => 205,  # Switch used for autocursors.
        :autocursor  => "AutoCursor",
        :curmem_des  => "Enables/Disables cursor memory for actions.",
        :curmem_on   => "Memory",
        :curmem_off  => "Reset",
      :next_actor_sw => 206,  # Switch used for automatic next actor.
        :next_actor  => "Next Actor",
        :next_des    => "Move to next actor after selecting commands",
        :next_on     => "Auto",
        :next_off    => "Manual",
      :skill_help_sw => 207,  # Switch used to enable skill help.
        :skill_help  => "Skill Help",
        :help_des    => "Display skill descriptions during battle phase.",
        :help_on     => "Enabled",
        :help_off    => "Disable",
      :auto_dash_sw  => 208,  # Switch used to enable auto-dashing.
        :auto_dash   => "自动跑步",
        :dash_des    => "不需要按住Shift,角色会自动跑步",
        :dash_on     => "跑步",
        :dash_off    => "步行",
      :inst_text_sw  => 209,  # Switch used to control instant text.
        :instant_text => "即时文本",
        :inst_des    => "文字会一次出现,而不是一个一个",
        :inst_on     => "即时",
        :inst_off    => "正常",
      :return_title  => "回到标题",
        :retitle_des => "返回到标题菜单,返回前请存档",
      :return_menu   => "返回到主菜单",
        :remenu_des  => "返回到主菜单",
      :window_var    => 195,  # Variable used to change windowskins.
        :windowskin  => "窗口",
        :wind_des    => "更换游戏窗口",
    } # Do not remove this.
 
    # This sets the default fonts used for your windows. Note that in this
    # array, if a player doesn't have the font in front, it'll use the next one
    # onward until the player does have that font installed.
    DEFAULT = ["长城粗圆体"]
    WRITING = [""]
 
 
    # The following adjusts the window skins used for your game. Match the
    # Window skins with the names accordingly. Within the windowskin hash,
    # the following settings are adjusted as such:
    #     Name - File Name
    #     Opac - Back Opacity
    #     Bold - Bold font?
    #   Italic - Italic font?
    #   Shadow - Use shadows?
    #     Size - Font Size
    #     Font - Font Set
    DEFAULT_SKIN_VALUE  = 17
    WINDOW_HASH ={
    # Window ID => [      Name, Opac,      Bold, Italic, Shadow, Size,    Font],
      1 => [  "Advanced Black",     200, false,  false,   true,   20, DEFAULT],
      2 => [  "Advanced Blue",      200, false,  false,   true,   20, DEFAULT],
      3 => [  "Advanced Cyan",      200, false,  false,   true,   20, DEFAULT],
      4 => [  "Advanced Gradiant",  200, false,  false,   true,   20, DEFAULT],
      5 => [  "Advanced Green",     200, false,  false,   true,   20, DEFAULT],
      6 => [  "Advanced Indigo",    200, false,  false,   true,   20, DEFAULT],
      7 => [  "Advanced Red",       200, false,  false,   true,   20, DEFAULT],
      8 => [  "Advanced Rhinestone",200, false,  false,   true,   20, DEFAULT],
      9 => [  "Advanced Tan",       200, false,  false,   true,   20, DEFAULT],
      10 => [  "Advanced White",     200, false,  false,   true,   20, DEFAULT],
      11 => [  "Arcade Red",         200, false,  false,   true,   20, DEFAULT],
      12 => [  "Fade Black",         200, false,  false,   true,   20, DEFAULT],
      13 => [  "Fade Red",           255, false,  false,  false,   20, DEFAULT],
      14 => [  "Gradient Blue",      200, false,  false,   true,   20, DEFAULT],
      15 => [  "Gradient Brown",     200, false,  false,   true,   20, DEFAULT],
      16 => [  "Gradient Black",     200, false,  false,   true,   20, DEFAULT],
      17 => [  "Gradient Cyan",      200, false,  false,   true,   20, DEFAULT],
      18 => [  "Gradient Green",     200, false,  false,   true,   20, DEFAULT],
      19 => [  "Gradient Purple",    200, false,  false,   true,   20, DEFAULT],
      20 => [  "Gradient Red",       200, false,  false,   true,   20, DEFAULT],
      21 => [  "Indigo",             200, false,  false,   true,   20, DEFAULT],
      22 => [  "Onyx Blue",          200, false,  false,   true,   20, DEFAULT],
      23 => [  "Onyx Red",           200, false,  false,   true,   20, DEFAULT],
      24 => [  "Red Gloss",          200, false,  false,   true,   20, DEFAULT],
      25 => [  "Romantic Gold",      200, false,  false,   true,   20, DEFAULT],
      26 => [  "Romantic Silver",    255, false,  false,  false,   20, DEFAULT],
      27 => [  "Wooden",             255, false,  false,  false,   20, DEFAULT],
      28 => [     "Red",             200, false,  false,   true,   20, DEFAULT],
      29 => [  "Orange",             200, false,  false,   true,   20, DEFAULT],
      30 => [  "Yellow",             200, false,  false,   true,   20, DEFAULT],
      31 => [   "Green",             200, false,  false,   true,   20, DEFAULT],
      32 => [    "Cyan",             200, false,  false,   true,   20, DEFAULT],
      33 => [    "Navy",             200, false,  false,   true,   20, DEFAULT],
      34 => [    "Blue",             200, false,  false,   true,   20, DEFAULT],
      35 => [  "Violet",             200, false,  false,   true,   20, DEFAULT],
      36 => [  "Purple",             200, false,  false,   true,   20, DEFAULT],
      37 => [    "Pink",             200, false,  false,   true,   20, DEFAULT],
      38 => [    "Grey",             200, false,  false,   true,   20, DEFAULT],
      39 => [   "Black",             200, false,  false,   true,   20, DEFAULT],
      40 => [   "White",             255, false,  false,  false,   20, DEFAULT],
    } # Do not remove this.
 
  end # SYSTEM
end # YEM
 
#===============================================================================
# Editting anything past this point may potentially result in causing computer
# damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
# Therefore, edit at your own risk.
#===============================================================================
 
#===============================================================================
# Vocab
#===============================================================================
 
module Vocab
 
  #--------------------------------------------------------------------------
  # overwrite method: self.game_end
  #--------------------------------------------------------------------------
  def self.game_end
    return YEM::SYSTEM::TITLE
  end
 
end # Vocab
 
#===============================================================================
# module Icon
#===============================================================================
 
module Icon
 
  #--------------------------------------------------------------------------
  # new method: self.system
  #--------------------------------------------------------------------------
  def self.system
    return YEM::SYSTEM::ICON
  end
 
end # Icon
 
#===============================================================================
# module Cache
#===============================================================================
 
module Cache
 
  #--------------------------------------------------------------------------
  # new method: self.windows
  #--------------------------------------------------------------------------
  def self.windows(filename); load_bitmap("Graphics/Windows/", filename); end
 
end # Cache
YEM::SYSTEM::WINDOWSKIN_VARIABLE = YEM::SYSTEM::OPTIONS[:window_var]
#===============================================================================
# RPG::BGM
#===============================================================================
unless $imported["BattleEngineMelody"]
module RPG
class BGM < AudioFile
 
  #--------------------------------------------------------------------------
  # overwrite method: play
  #--------------------------------------------------------------------------
  def play
    if @name.empty?
      Audio.bgm_stop
      @@last = BGM.new
    else
      vol = @volume
      if $game_variables != nil
        options = YEM::SYSTEM::OPTIONS
        vol = vol * $game_variables[options[:bgm_variable]] / 100
        vol = [[vol, 0].max, 100].min
        vol = 0 if $game_switches[options[:bgm_mute_sw]]
      end
      Audio.bgm_play("Audio/BGM/" + @name, vol, @pitch)
      @@last = self
    end
  end
 
end # BGM
class ME < AudioFile
 
  #--------------------------------------------------------------------------
  # overwrite method: play
  #--------------------------------------------------------------------------
  def play
    if @name.empty?
      Audio.me_stop
    else
      vol = @volume
      if $game_variables != nil
        options = YEM::SYSTEM::OPTIONS
        vol = vol * $game_variables[options[:bgm_variable]] / 100
        vol = [[vol, 0].max, 100].min
        vol = 0 if $game_switches[options[:bgm_mute_sw]]
      end
      Audio.me_play("Audio/ME/" + @name, vol, @pitch)
    end
  end
 
end # ME
class BGS < AudioFile
 
  #--------------------------------------------------------------------------
  # overwrite method: play
  #--------------------------------------------------------------------------
  def play
    if @name.empty?
      Audio.bgs_stop
      @@last = BGS.new
    else
      vol = @volume
      if $game_variables != nil
        options = YEM::SYSTEM::OPTIONS
        vol = vol * $game_variables[options[:bgs_variable]] / 100
        vol = [[vol, 0].max, 100].min
        vol = 0 if $game_switches[options[:bgs_mute_sw]]
      end
      Audio.bgs_play("Audio/BGS/" + @name, vol, @pitch)
      @@last = self
    end
  end
 
end # BGS
class SE < AudioFile
 
  #--------------------------------------------------------------------------
  # overwrite method: play
  #--------------------------------------------------------------------------
  def play
    unless @name.empty?
      vol = @volume
      if $game_variables != nil
        options = YEM::SYSTEM::OPTIONS
        vol = vol * $game_variables[options[:sfx_variable]] / 100
        vol = [[vol, 0].max, 100].min
        vol = 0 if $game_switches[options[:sfx_mute_sw]]
      end
      Audio.se_play("Audio/SE/" + @name, vol, @pitch)
    end
  end
 
end # SE
end # RPG
end # $imported["BattleEngineMelody"]
#===============================================================================
# Game_System
#===============================================================================
 
class Game_System
 
  #--------------------------------------------------------------------------
  # new method: create_system_options
  #--------------------------------------------------------------------------
  def create_system_options
    return if @created_system_options
    @created_system_options = true
    options = YEM::SYSTEM::OPTIONS
    $game_variables[options[:bgm_variable]] = 100
    $game_variables[options[:bgs_variable]] = 100
    $game_variables[options[:sfx_variable]] = 100
    $game_switches[options[:bgm_mute_sw]] = false
    $game_switches[options[:bgs_mute_sw]] = false
    $game_switches[options[:sfx_mute_sw]] = false
    $game_switches[options[:animation_sw]] = true
    $game_switches[options[:autocursor_sw]] = true
    $game_switches[options[:next_actor_sw]] = true
    $game_switches[options[:skill_help_sw]] = false
    $game_switches[options[:auto_dash_sw]] = false
    $game_switches[options[:inst_text_sw]] = false
    $game_variables[YEM::SYSTEM::WINDOWSKIN_VARIABLE] = 
      YEM::SYSTEM::DEFAULT_SKIN_VALUE
  end
 
end # Game_System
 
#===============================================================================
# Game_Player
#===============================================================================
 
class Game_Player < Game_Character
 
  #--------------------------------------------------------------------------
  # alias method: dash?
  #--------------------------------------------------------------------------
  alias dash_sgo dash? unless $@
  def dash?
    if $game_switches[YEM::SYSTEM::OPTIONS[:auto_dash_sw]]
      return false if @move_route_forcing
      return false if $game_map.disable_dash?
      return false if in_vehicle?
      return false if Input.press?(Input::A)
      return true
    else
      return dash_sgo
    end
  end
 
end # Game_Player
 
#===============================================================================
# Window
#===============================================================================
 
class Window
 
  #--------------------------------------------------------------------------
  # update windowskin
  #--------------------------------------------------------------------------
  def update_windowskin
    return if $game_variables == nil
    variable = YEM::SYSTEM::WINDOWSKIN_VARIABLE
    if $game_variables[variable] == 0
      $game_variables[variable] = YEM::SYSTEM::DEFAULT_SKIN_VALUE
    elsif !YEM::SYSTEM::WINDOW_HASH.include?($game_variables[variable])
      $game_variables[variable] = YEM::SYSTEM::DEFAULT_SKIN_VALUE
    end
    skin = YEM::SYSTEM::WINDOW_HASH[$game_variables[variable]]
    change_settings(skin)
  end
 
  #--------------------------------------------------------------------------
  # change_settings
  #--------------------------------------------------------------------------
  def change_settings(skin)
    self.windowskin = Cache.windows(skin[0])
    self.back_opacity = skin[1]
    self.contents.font.bold = Font.default_bold = skin[2]
    self.contents.font.italic = Font.default_italic = skin[3]
    self.contents.font.shadow = Font.default_shadow = skin[4]
    self.contents.font.size = Font.default_size = skin[5]
    self.contents.font.name = Font.default_name = skin[6]
    self.contents.font.color = normal_color
  end
 
end # Window
 
#===============================================================================
# Window_Base
#===============================================================================
 
class Window_Base < Window
 
  #--------------------------------------------------------------------------
  # alias method: initialize
  #--------------------------------------------------------------------------
  alias initialize_window_sgo initialize unless $@
  def initialize(x, y, width, height)
    initialize_window_sgo(x, y, width, height)
    self.update_windowskin
  end
 
  #--------------------------------------------------------------------------
  # alias method: create_contents
  #--------------------------------------------------------------------------
  alias create_contents_base_sgo create_contents unless $@
  def create_contents
    create_contents_base_sgo
    self.contents.font.color = normal_color
  end
 
end # Window_Base
 
#===============================================================================
# Window_Selectable
#===============================================================================
 
class Window_Selectable < Window_Base
 
  #--------------------------------------------------------------------------
  # alias method: create_contents
  #--------------------------------------------------------------------------
  alias create_contents_selectable_sgo create_contents unless $@
  def create_contents
    create_contents_selectable_sgo
    self.contents.font.color = normal_color
  end
 
end # Window_Selectable
 
#===============================================================================
# Window_SaveFile
#===============================================================================
 
class Window_SaveFile < Window_Base
 
  #--------------------------------------------------------------------------
  # alias method: refresh
  #--------------------------------------------------------------------------
  alias refresh_savefile_mso refresh unless $@
  def refresh
    if @file_exist
      n = @game_variables[YEM::SYSTEM::WINDOWSKIN_VARIABLE]
      if n == 0 or !YEM::SYSTEM::WINDOW_HASH.include?(n)
        n = YEM::SYSTEM::DEFAULT_SKIN_VALUE
      end
      skin = YEM::SYSTEM::WINDOW_HASH[n]
      change_settings(skin)
    end
    refresh_savefile_mso
  end
 
end # Window_SaveFile
 
#===============================================================================
# Window_Message
#===============================================================================
 
class Window_Message < Window_Selectable
 
  #--------------------------------------------------------------------------
  # alias method: update_show_fast
  #--------------------------------------------------------------------------
  alias update_show_fast_sgo update_show_fast unless $@
  def update_show_fast
    if $game_switches[YEM::SYSTEM::OPTIONS[:inst_text_sw]]
      if self.pause or self.openness < 255
        @show_fast = false
      else
        @show_fast = true
      end
      if @show_fast and @wait_count > 0
        @wait_count -= 1
      end
    else
      update_show_fast_sgo
    end
  end
 
  #--------------------------------------------------------------------------
  # alias method: new_page
  #--------------------------------------------------------------------------
  alias new_page_sgo new_page unless $@
  def new_page
    self.update_windowskin
    new_page_sgo
  end
 
end # Window_Message
 
#===============================================================================
# Window_SystemOptions
#===============================================================================
 
class Window_SystemOptions < Window_Selectable
 
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize(help_window)
    dy = help_window.height
    dh = Graphics.height - dy
    super(0, dy, Graphics.width, dh)
    self.index = 0
    refresh
    @help_window = help_window
    update_help
  end
 
  #--------------------------------------------------------------------------
  # item
  #--------------------------------------------------------------------------
  def item; return @data[self.index]; end
 
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    @data = []
    for command in YEM::SYSTEM::COMMANDS
      case command
      when :windowskin, :animations, :bgm_volume, :sfx_volume, :bgs_volume,
      :auto_dash, :instant_text, :blank, :return_title, :return_menu
      when :skill_help, :atb_active, :atb_speeds, :autocursor, :next_actor
        next unless $imported["BattleEngineMelody"]
        if [:atb_active, :atb_speeds].include?(command)
          type = $game_variables[YEM::BATTLE_ENGINE::BATTLE_TYPE_VARIABLE]
          next unless type == 2
        end
      else; next
      end
      @data.push(command)
    end
    @item_max = @data.size
    create_contents
    for i in 0...@item_max; draw_item(i); end
  end
 
  #--------------------------------------------------------------------------
  # draw_item
  #--------------------------------------------------------------------------
  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    obj = @data[index]
    return if obj == nil
    case obj
    when :windowskin
      draw_window_item(obj, rect.clone)
    when :bgm_volume, :sfx_volume, :bgs_volume
      draw_volume_item(obj, rect.clone)
    when :animations, :autocursor, :next_actor, :skill_help,
    :auto_dash, :instant_text
      draw_switch_item(obj, rect.clone)
    when :atb_active, :atb_speeds
      draw_atb_item(obj, rect.clone)
    when :return_title, :return_menu
      draw_solo_item(obj, rect.clone)
    end
  end
 
  #--------------------------------------------------------------------------
  # draw_window_item
  #--------------------------------------------------------------------------
  def draw_window_item(obj, rect)
    title = YEM::SYSTEM::OPTIONS[:windowskin]
    self.contents.font.color = normal_color
    self.contents.draw_text(rect.x, rect.y, rect.width/2, WLH, title, 1)
    dx = rect.x + rect.width/2
    skin_id = $game_variables[YEM::SYSTEM::WINDOWSKIN_VARIABLE]
    skin_name = YEM::SYSTEM::WINDOW_HASH[skin_id][0]
    dx = rect.x + rect.width/2
    self.contents.draw_text(dx, rect.y, rect.width/2, WLH, skin_name, 1)
  end
 
  #--------------------------------------------------------------------------
  # draw_volume_item
  #--------------------------------------------------------------------------
  def draw_volume_item(obj, rect)
    options = YEM::SYSTEM::OPTIONS
    case obj
    when :bgm_volume
      title = options[:bgm_volume]
      value = $game_variables[options[:bgm_variable]]
      mute  = $game_switches[options[:bgm_mute_sw]]
    when :bgs_volume
      title = options[:bgs_volume]
      value = $game_variables[options[:bgs_variable]]
      mute  = $game_switches[options[:bgs_mute_sw]]
    when :sfx_volume
      title = options[:sfx_volume]
      value = $game_variables[options[:sfx_variable]]
      mute  = $game_switches[options[:sfx_mute_sw]]
    else; return
    end
    value = sprintf(options[:audio], value)
    self.contents.font.color = normal_color
    self.contents.draw_text(rect.x, rect.y, rect.width/2, WLH, title, 1)
    self.contents.font.color.alpha = mute ? 128 : 255
    dx = rect.x + rect.width/2
    self.contents.draw_text(dx, rect.y, rect.width/4, WLH, value, 1)
    self.contents.font.color.alpha = mute ? 255 : 128
    dx = rect.x + rect.width*3/4
    self.contents.draw_text(dx, rect.y, rect.width/4, WLH, options[:mute], 1)
  end
 
  #--------------------------------------------------------------------------
  # draw_switch_item
  #--------------------------------------------------------------------------
  def draw_switch_item(obj, rect)
    options = YEM::SYSTEM::OPTIONS
    title = options[obj]
    case obj
    when :animations
      name1 = options[:ani_show]
      name2 = options[:ani_hide]
      toggle = $game_switches[options[:animation_sw]]
    when :autocursor
      name1 = options[:curmem_on]
      name2 = options[:curmem_off]
      toggle = $game_switches[options[:autocursor_sw]]
    when :next_actor
      name1 = options[:next_on]
      name2 = options[:next_off]
      toggle = $game_switches[options[:next_actor_sw]]
    when :skill_help
      name1 = options[:help_on]
      name2 = options[:help_off]
      toggle = $game_switches[options[:skill_help_sw]]
    when :cinematics
      name1 = options[:cinem_on]
      name2 = options[:cinem_off]
      toggle = $game_switches[options[:cinematics_sw]]
    when :auto_dash
      name1 = options[:dash_on]
      name2 = options[:dash_off]
      toggle = $game_switches[options[:auto_dash_sw]]
    when :instant_text
      name1 = options[:inst_on]
      name2 = options[:inst_off]
      toggle = $game_switches[options[:inst_text_sw]]
    else; return
    end
    self.contents.font.color = normal_color
    self.contents.draw_text(rect.x, rect.y, rect.width/2, WLH, title, 1)
    self.contents.font.color.alpha = toggle ? 255 : 128
    dx = rect.x + rect.width/2
    self.contents.draw_text(dx, rect.y, rect.width/4, WLH, name1, 1)
    self.contents.font.color.alpha = toggle ? 128 : 255
    dx = rect.x + rect.width*3/4
    self.contents.draw_text(dx, rect.y, rect.width/4, WLH, name2, 1)
  end
 
  #--------------------------------------------------------------------------
  # draw_atb_item
  #--------------------------------------------------------------------------
  def draw_atb_item(obj, rect)
    options = YEM::SYSTEM::OPTIONS
    case obj
    when :atb_active
      title = options[:atb_aname]
      value = $game_variables[options[:atb_avariable]]
      #---
      self.contents.font.color = normal_color
      name1 = options[:wait_0]
      dx = rect.x + rect.width/2
      self.contents.font.color.alpha = (value == 0) ? 255 : 128
      self.contents.draw_text(dx, rect.y, rect.width/8, WLH, name1, 1)
      name2 = options[:wait_1]
      dx = rect.x + rect.width*5/8
      self.contents.font.color.alpha = (value == 1) ? 255 : 128
      self.contents.draw_text(dx, rect.y, rect.width/8, WLH, name2, 1)
      name3 = options[:wait_2]
      dx = rect.x + rect.width*6/8
      self.contents.font.color.alpha = (value == 2) ? 255 : 128
      self.contents.draw_text(dx, rect.y, rect.width/8, WLH, name3, 1)
      name4 = options[:wait_3]
      dx = rect.x + rect.width*7/8
      self.contents.font.color.alpha = (value == 3) ? 255 : 128
      self.contents.draw_text(dx, rect.y, rect.width/8, WLH, name4, 1)
      #---
    when :atb_speeds
      title = options[:atb_sname]
      value = $game_variables[options[:atb_svariable]] - 1
      #---
      for i in 0...10
        self.contents.font.color = normal_color
        name = (i + 1).to_s
        dx = rect.x + rect.width * (10 + i)/20
        self.contents.font.color.alpha = (value == i) ? 255 : 128
        self.contents.draw_text(dx, rect.y, rect.width/20, WLH, name, 1)
      end
      #---
    else; return
    end
    self.contents.font.color = normal_color
    self.contents.draw_text(rect.x, rect.y, rect.width/2, WLH, title, 1)
  end
 
  #--------------------------------------------------------------------------
  # draw_solo_item
  #--------------------------------------------------------------------------
  def draw_solo_item(obj, rect)
    options = YEM::SYSTEM::OPTIONS
    case obj
    when :return_title, :return_menu
      text = options[obj]
    else; return
    end
    self.contents.font.color = normal_color
    self.contents.draw_text(rect.x, rect.y, rect.width, WLH, text, 1)
  end
 
  #--------------------------------------------------------------------------
  # update
  #--------------------------------------------------------------------------
  def update
    super
    if Input.trigger?(Input::C)
      input_case_c
    elsif Input.repeat?(Input::LEFT)
      input_case_left
    elsif Input.repeat?(Input::RIGHT)
      input_case_right
    end
  end
 
  #--------------------------------------------------------------------------
  # input_case_c
  #--------------------------------------------------------------------------
  def input_case_c
    options = YEM::SYSTEM::OPTIONS
    case item
    when :windowskin
      Sound.play_decision
      $scene.open_skins_window
      return
    when :bgm_volume; switch = options[:bgm_mute_sw]
    when :bgs_volume; switch = options[:bgs_mute_sw]
    when :sfx_volume; switch = options[:sfx_mute_sw]
    when :animations; switch = options[:animation_sw]
    when :autocursor; switch = options[:autocursor_sw]
    when :next_actor; switch = options[:next_actor_sw]
    when :skill_help; switch = options[:skill_help_sw]
    when :cinematics; switch = options[:cinematics_sw]
    when :auto_dash;  switch = options[:auto_dash_sw]
    when :instant_text; switch = options[:inst_text_sw]
    when :return_title
      $scene.command_to_title
      return
    when :return_menu
      Sound.play_decision
      $scene.return_scene
      return
    else; return
    end
    $game_switches[switch] = !$game_switches[switch]
    Sound.play_decision
    RPG::BGM::last.play if item == :bgm_volume
    RPG::BGS::last.play if item == :bgs_volume
    draw_item(self.index)
  end
 
  #--------------------------------------------------------------------------
  # input_case_left
  #--------------------------------------------------------------------------
  def input_case_left
    options = YEM::SYSTEM::OPTIONS
    ignore = false
    case item
    when :bgm_volume, :bgs_volume, :sfx_volume
      value = Input.press?(Input::SHIFT) ? 10 : 1
      case item
      when :bgm_volume; variable = options[:bgm_variable]
      when :bgs_volume; variable = options[:bgs_variable]
      when :sfx_volume; variable = options[:sfx_variable]
      end
      return if $game_variables[variable] == 0
      $game_variables[variable] -= value
      $game_variables[variable] = [$game_variables[variable], 0].max
      ignore = true
    when :atb_active
      variable = options[:atb_avariable]
      return if $game_variables[variable] == 0
      $game_variables[variable] -= 1
      $game_variables[variable] = [$game_variables[variable], 0].max
      ignore = true
    when :atb_speeds
      variable = options[:atb_svariable]
      return if $game_variables[variable] == 1
      $game_variables[variable] -= 1
      $game_variables[variable] = [$game_variables[variable], 1].max
      ignore = true
    when :animations; switch = options[:animation_sw]
    when :autocursor; switch = options[:autocursor_sw]
    when :next_actor; switch = options[:next_actor_sw]
    when :skill_help; switch = options[:skill_help_sw]
    when :cinematics; switch = options[:cinematics_sw]
    when :auto_dash;  switch = options[:auto_dash_sw]
    when :instant_text; switch = options[:inst_text_sw]
    else; return
    end
    unless ignore
      return if $game_switches[switch]
      $game_switches[switch] = true
    end
    Sound.play_cursor
    RPG::BGM::last.play if item == :bgm_volume
    RPG::BGS::last.play if item == :bgs_volume
    draw_item(self.index)
  end
 
  #--------------------------------------------------------------------------
  # input_case_right
  #--------------------------------------------------------------------------
  def input_case_right
    options = YEM::SYSTEM::OPTIONS
    ignore = false
    case item
    when :bgm_volume, :bgs_volume, :sfx_volume
      value = Input.press?(Input::SHIFT) ? 10 : 1
      case item
      when :bgm_volume; variable = options[:bgm_variable]
      when :bgs_volume; variable = options[:bgs_variable]
      when :sfx_volume; variable = options[:sfx_variable]
      end
      return if $game_variables[variable] == 100
      $game_variables[variable] += value
      $game_variables[variable] = [$game_variables[variable], 100].min
      ignore = true
    when :atb_active
      variable = options[:atb_avariable]
      return if $game_variables[variable] == 3
      $game_variables[variable] += 1
      $game_variables[variable] = [$game_variables[variable], 3].min
      ignore = true
    when :atb_speeds
      variable = options[:atb_svariable]
      return if $game_variables[variable] == 10
      $game_variables[variable] += 1
      $game_variables[variable] = [$game_variables[variable], 10].min
      ignore = true
    when :animations; switch = options[:animation_sw]
    when :autocursor; switch = options[:autocursor_sw]
    when :next_actor; switch = options[:next_actor_sw]
    when :skill_help; switch = options[:skill_help_sw]
    when :cinematics; switch = options[:cinematics_sw]
    when :auto_dash;  switch = options[:auto_dash_sw]
    when :instant_text; switch = options[:inst_text_sw]
    else; return
    end
    unless ignore
      return if !$game_switches[switch]
      $game_switches[switch] = false
    end
    Sound.play_cursor
    RPG::BGM::last.play if item == :bgm_volume
    RPG::BGS::last.play if item == :bgs_volume
    draw_item(self.index)
  end
 
  #--------------------------------------------------------------------------
  # update_help
  #--------------------------------------------------------------------------
  def update_help
    case item
    when :bgm_volume; type = :bgm_des
    when :bgs_volume; type = :bgs_des
    when :sfx_volume; type = :sfx_des
    when :animations; type = :ani_des
    when :autocursor; type = :curmem_des
    when :next_actor; type = :next_des
    when :skill_help; type = :help_des
    when :cinematics; type = :cinem_des
    when :windowskin; type = :wind_des
    when :auto_dash;  type = :dash_des
    when :instant_text; type = :inst_des
    when :return_title; type = :retitle_des
    when :return_menu;  type = :remenu_des
    when :atb_active
      case $game_variables[YEM::SYSTEM::OPTIONS[:atb_avariable]]
      when 0; type = :wait_0_des
      when 1; type = :wait_1_des
      when 2; type = :wait_2_des
      when 3: type = :wait_3_des
      end
    when :atb_speeds; type = :atb_s_des
    else; type = nil
    end
    text = YEM::SYSTEM::OPTIONS[type].to_s
    @help_window.set_text(text, 1)
  end
 
end # Window_SystemOptions
 
#===============================================================================
# Window_Skins
#===============================================================================
 
class Window_Skins < Window_Selectable
 
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  def initialize
    dx = Graphics.width/4
    dw = Graphics.width/2
    dh = Graphics.height - 112
    super(dx, 56, dw, dh)
    @column_max = 1
    self.index = 0
    self.back_opacity = 255
    self.openness = 0
    self.active = false
    refresh
  end
 
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    @data = []
    variable = $game_variables[YEM::SYSTEM::WINDOWSKIN_VARIABLE]
    hash = YEM::SYSTEM::WINDOW_HASH.sort{ |a,b| a[0] <=> b[0] }
    for key in hash
      @data.push(key[0])
      self.index = key[0] - 1 if key[0] == $game_variables[variable]
    end
    @item_max = @data.size
    create_contents
    for i in 0...@item_max
      draw_item(i)
    end
  end
 
  #--------------------------------------------------------------------------
  # draw_item
  #--------------------------------------------------------------------------
  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    rect.width -= 4
    text = YEM::SYSTEM::WINDOW_HASH[@data[index]][0]
    self.contents.draw_text(rect, text, 1)
  end
 
end # Window_Skins
 
#===============================================================================
# Scene_Title
#===============================================================================
 
class Scene_Title < Scene_Base
 
  #--------------------------------------------------------------------------
  # alias method: create_game_objects
  #--------------------------------------------------------------------------
  alias create_game_objects_sgo create_game_objects unless $@
  def create_game_objects
    create_game_objects_sgo
    $game_system.create_system_options
  end
 
end # Scene_Title
 
#===============================================================================
# Scene_Map
#===============================================================================
 
class Scene_Map < Scene_Base
 
  #--------------------------------------------------------------------------
  # alias method: start
  #--------------------------------------------------------------------------
  alias start_sgo start unless $@
  def start
    $game_system.create_system_options
    start_sgo
  end
 
end # Scene_Map
 
#===============================================================================
# Scene_Battle
#===============================================================================
 
class Scene_Battle < Scene_Base
 
  #--------------------------------------------------------------------------
  # alias method: display_normal_animation
  #--------------------------------------------------------------------------
  unless $imported["BattleEngineMelody"]
  alias display_normal_animation_sgo display_normal_animation unless $@
  def display_normal_animation(targets, animation_id, mirror = false)
    return if $game_switches[YEM::SYSTEM::OPTIONS[:animation_sw]]
    display_normal_animation_sgo(targets, animation_id, mirror)
  end
  end # $imported["BattleEngineMelody"]
 
end # Scene_Battle
 
#===============================================================================
# Scene_End
#===============================================================================
 
class Scene_End < Scene_Base
 
  #--------------------------------------------------------------------------
  # public instance variables
  #--------------------------------------------------------------------------
  attr_accessor :window_var
 
  #--------------------------------------------------------------------------
  # overwrite method: start
  #--------------------------------------------------------------------------
  def start
    super
    create_menu_background
    @window_var = YEM::SYSTEM::WINDOWSKIN_VARIABLE
    @help_window = Window_Help.new
    @options_window = Window_SystemOptions.new(@help_window)
    @skins_window = Window_Skins.new
  end
 
  #--------------------------------------------------------------------------
  # overwrite method: post_start
  #--------------------------------------------------------------------------
  def post_start; super; end
 
  #--------------------------------------------------------------------------
  # overwrite method: pre_terminate
  #--------------------------------------------------------------------------
  def pre_terminate; super; end
 
  #--------------------------------------------------------------------------
  # overwrite method: close_command_window
  #--------------------------------------------------------------------------
  def close_command_window; end
 
  #--------------------------------------------------------------------------
  # overwrite method: terminate
  #--------------------------------------------------------------------------
  def terminate
    super
    @help_window.dispose
    @options_window.dispose
    @skins_window.dispose
    dispose_menu_background
  end
 
  #--------------------------------------------------------------------------
  # overwrite method: update
  #--------------------------------------------------------------------------
  def update
    super
    @help_window.update
    @skins_window.update
    update_menu_background
    if @options_window.active
      update_options_window
    elsif @skins_window.active
      update_skins_window
    end
  end
 
  #--------------------------------------------------------------------------
  # new method: update_options_window
  #--------------------------------------------------------------------------
  def update_options_window
    @options_window.update
    if Input.trigger?(Input::B)
      Sound.play_cancel
      return_scene
    end
  end
 
  #--------------------------------------------------------------------------
  # new method: open_skins_window
  #--------------------------------------------------------------------------
  def open_skins_window
    @skins_window.open
    @skins_window.index = $game_variables[YEM::SYSTEM::WINDOWSKIN_VARIABLE] - 1
    @skins_window.active = true
    @options_window.active = false
  end
 
  #--------------------------------------------------------------------------
  # new method: update_skins_window
  #--------------------------------------------------------------------------
  def update_skins_window
    if @last_index != @skins_window.index
      @last_index = @skins_window.index
      update_skins
    end
    if Input.trigger?(Input::B)
      Sound.play_cancel
      @skins_window.close
      @skins_window.active = false
      @options_window.active = true
    elsif Input.trigger?(Input::C)
      Sound.play_decision
      @skins_window.close
      @skins_window.active = false
      @options_window.active = true
    end
  end
 
  #--------------------------------------------------------------------------
  # new method: update_skins
  #--------------------------------------------------------------------------
  def update_skins
    $game_variables[@window_var] = @skins_window.index + 1
    @options_window.update_windowskin
    @options_window.refresh
    @help_window.update_windowskin
    @help_window.set_text("")
    @options_window.update_help
    @skins_window.update_windowskin
    @skins_window.back_opacity = 255
    @skins_window.refresh
    @options_window.draw_item(@options_window.index)
  end
 
end # Scene_End
 
#===============================================================================
# 
# END OF FILE
# 
#===============================================================================