#========================================================================================
#  Thanks: AcedentProne: for showing location window and using facesets
#  Thanks: Firewords and Axe Man Deke
#  Made by GaveUpTomorrow - January 8th, 2007
#  Version 1.13 Final
#========================================================================================
#----------------------------------------------------------------
# Window_Base (New Functions)
#----------------------------------------------------------------
class Window_Base < Window
def draw_item_name(item, x, y)
    if item == nil; return; end
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    self.contents.font.color = normal_color
    self.contents.draw_text(x + 28, y, 90, 32, item.name)
end
def draw_actor_battler(actor, x, y)
   bitmap = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
   cw = bitmap.width; ch = bitmap.height; src_rect = Rect.new(0, 0, cw, ch)
   self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
end
def draw_actor_face(actor, x, y)
     face = RPG::Cache.character("Faces/" + actor.character_name, actor.character_hue)
     fw = face.width; fh = face.height
     src_rect = Rect.new(0, 0, fw, fh)
     self.contents.blt(x - fw / 23, y - fh, face, src_rect)
end
def draw_actor_level2(actor, x, y)
      self.contents.font.color = system_color
      self.contents.draw_text(x, y, 32, 32, "Level")
      self.contents.font.color = normal_color
      self.contents.draw_text(x + 26, y, 24, 32, actor.level.to_s, 2)
end
def draw_actor_exp2(actor, x, y)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 24, 32, "Exp")
    self.contents.font.color = normal_color
    self.contents.draw_text(x + -5, y, 84, 32, actor.exp_s, 2)
    self.contents.draw_text(x + 79, y, 12, 32, "/", 1)
    self.contents.draw_text(x + 91, y, 84, 32, actor.next_exp_s)
end
def draw_actor_hp2(actor, x, y, width = 144)
      self.contents.font.color = system_color
      self.contents.draw_text(x, y, 32, 32, $data_system.words.hp)
      if width - 32 >= 108; hp_x = x + width - 108; flag = true
      elsif width - 32 >= 48; hp_x = x + width - 48; flag = false; end
      self.contents.font.color = actor.hp == 0 ? knockout_color :
          actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
      self.contents.draw_text(hp_x - 15, y, 48, 32, actor.hp.to_s, 2)
      if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(hp_x + 33, y, 12, 32, "/", 1)
      self.contents.draw_text(hp_x + 45, y, 48, 32, actor.maxhp.to_s)
    end
  end
def draw_actor_sp2(actor, x, y, width = 144)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.sp)
    if width - 32 >= 108; sp_x = x + width - 108; flag = true
    elsif width - 32 >= 48; sp_x = x + width - 48; flag = false; end
    self.contents.font.color = actor.sp == 0 ? knockout_color :
      actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
    self.contents.draw_text(sp_x - 15, y, 48, 32, actor.sp.to_s, 2)
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(sp_x + 33, y, 12, 32, "/", 1)
      self.contents.draw_text(sp_x + 45, y, 48, 32, actor.maxsp.to_s)
    end
  end  
end
#==============================================================================
class Game_Map; def name; $map_infos[@map_id]; end; end
#==============================================================================
class Scene_Title; $map_infos = load_data("Data/MapInfos.rxdata")
for key in $map_infos.keys; $map_infos[key] = $map_infos[key].name; end; end
#==============================================================================
class Window_Selectable < Window_Selectable
def update_cursor_rect
    if @index < 0; self.cursor_rect.empty; return; end
    row = @index / @column_max
    if row < self.top_row; self.top_row = row; end
    if row > self.top_row + (self.page_row_max - 1); self.top_row = row - (self.page_row_max - 1); end
    cursor_width = self.width / @column_max - 32
    x = @index % @column_max * (cursor_width + 32)
    y = @index / @column_max * 32 - self.oy
    self.cursor_rect.set(x, y, cursor_width + 5, 32)
  end
end  
#==============================================================================
class Window_Location < Window_Base
  def initialize
    super(475, 234, 160, 172)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = 18
    self.opacity = 175
    self.contents.font.color = system_color     
    self.contents.draw_text(0, 0, 120, 32, "Location:")
    self.contents.draw_text(0, 50 , 120, 32, "Distance Traveled:")
    self.contents.draw_text(0, 100, 120, 32, "Shards:")
    self.contents.font.color = normal_color
    if $game_map.name.include?("*")
      self.contents.draw_text(0, 25, 120, 32, $game_map.name.delete!("*"))
    else
      self.contents.draw_text(0, 25, 120, 32, $game_map.name)
    end
    self.contents.draw_text(4, 75, 120, 32, $game_party.steps.to_s, 2)
    self.contents.draw_text(116, 100, 120, 32, $game_system.shard_count.to_s)
  end  
end
#==============================================================================
class Window_MenuStatus2 < Window_Base
  def initialize
    super(170, 355, 300, 120)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = 18
    refresh
    self.opacity = 175
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
      i = $game_system.character_select.to_s
      actor = $game_party.actors[i.to_i]
      x = -50
      if $game_system.face_support == 1
      draw_actor_face(actor, 0, 85)
      x = 0
      end
      draw_actor_level(actor, x + 85, 0)
      draw_actor_exp(actor, x + 85, 20)
      draw_actor_hp(actor, x + 85, 40)
      draw_actor_sp(actor, x + 85, 60)
    end
end
#==============================================================================
class Window_MapHud < Window_Base
  def initialize
    
    if $game_system.map_hud == 1
    super(5, 355, 260, 120) 
    elsif $game_system.map_hud == 2
    super(5, 335, 630, 140)   
    end
    
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = 18
    refresh
    self.opacity = 100
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    
    if $game_system.map_hud == 1
      i = $game_system.map_hudcharselect
      actor = $game_party.actors[i.to_i]
      draw_actor_face(actor, 0, 85)
      x = 0
      #end
      self.contents.font.size = 14
      draw_actor_level2(actor, x + 85, 0)
      draw_actor_exp2(actor, x + 85, 20)
      draw_actor_hp2(actor, x + 85, 40)
      draw_actor_sp2(actor, x + 85, 60)
    end    
      
      
    
    if $game_system.map_hud == 2
      for i in 0..3
        actor = $game_party.actors[i.to_i]
        draw_actor_face(actor, 5 + 165*i, 80)
        self.contents.font.size = 12
 
        if i == 0
          draw_actor_level2(actor, 0 + 85, 10)
        elsif i == 1
          draw_actor_level2(actor, 165 - 50, 50)
        elsif i == 2
          draw_actor_level2(actor, 2 * 165 + 85, 10)
        elsif i == 3
          draw_actor_level2(actor, 3 * 165 - 50, 50)
        end
    
        draw_actor_hp2(actor, 165 * i, 75)
        draw_actor_sp2(actor, 165 * i, 85)
      end
    end
    
  end
end
#==============================================================================
class Window_PlayTime2 < Window_Base
  def initialize
    super(5, 234, 160, 172)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = $defaultfontsize
    self.opacity = 175
    refresh
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 120, 32, "Play Time:")
    @total_sec = Graphics.frame_count / Graphics.frame_rate
    hour = @total_sec / 60 / 60; min = @total_sec / 60 % 60; sec = @total_sec % 60
    text = sprintf("%02d:%02d:%02d", hour, min, sec)
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 32, 120, 32, text, 2)
    @total_sec = Graphics.frame_count / Graphics.frame_rate
    @minute=$game_time.get_minute.floor
    hour = $game_time.get_hour
    pm_flag= hour >=12 ? true : false
    hour= hour >= 12 ? hour-12 : hour
    day=$game_time.get_day; month=$game_time.get_month; year=$game_time.get_year
    if hour.floor==0; text=sprintf("%02d:%02d",12,@minute)
    else; text=sprintf("%02d:%02d",hour,@minute); end
    if pm_flag; text += " PM"; else; text += " AM"; end
    self.contents.font.color = normal_color
    self.contents.draw_text(4,114,120, 32, text, 2)
    text = sprintf("%02d-%02d-%02d", month, day, year)
    self.contents.draw_text(30,94,120,32,text)
    self.contents.font.color = system_color
    self.contents.draw_text(4,64,140,32,"Date and Time:")
  end
  #--------------------------------------------------------------------------
  def update; super
    if Graphics.frame_count / Graphics.frame_rate != @total_sec; refresh; end
    if $game_time.get_minute.floor != @minute; refresh; end; end; end
#==============================================================================
class Window_Status2 < Window_Base
  def initialize(actor)
    super(170, 5, 300, 345)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 175
    refresh
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = 18
    i = $game_system.character_select.to_s
    @actor = $game_party.actors[i.to_i]
    draw_actor_name(@actor, 4, 0)
    draw_actor_class(@actor, 178, 0)
    draw_actor_state(@actor, 86, 0)
    @holder = ["[No Weapon]","[No Helmet]","[No Accessory]","[No Sheild]","[No Armor]"] 
    for i in 0..6
    draw_actor_parameter(@actor, 4, 50 + 17*i, i)
    end
    self.contents.font.color = normal_color
    self.contents.draw_text(76, 25, 84, 32, @actor.next_rest_exp_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(4, 25, 80, 32, "Next Level:")
    self.contents.draw_text(4, 182, 96, 32, "Equipment:")
    self.contents.font.size = 13
    self.contents.font.color = normal_color
    s1 = [$data_weapons[@actor.weapon_id], $data_armors[@actor.armor2_id], $data_armors[@actor.armor4_id], $data_armors[@actor.armor1_id], $data_armors[@actor.armor3_id]]
    s2 = [0, 30, 215, 30, 247, 30, 279, 180, 215, 180, 246, 4, 4, 4, 149, 149] 
    for i in 0..4
      if s1[i] == nil 
        self.contents.draw_text(s2[2*i + 1], s2[2*i+2] , 120, 32, @holder[i])
      end
    end
    draw_item_name($data_weapons[@actor.weapon_id], 4, 215)
    draw_item_name($data_armors[@actor.armor2_id], 4, 247)
    draw_item_name($data_armors[@actor.armor4_id], 4, 279)
    draw_item_name($data_armors[@actor.armor1_id], 149, 215) 
    draw_item_name($data_armors[@actor.armor3_id], 149, 247)       
  end
end
#==============================================================================
class Window_Battler < Window_Base
  def initialize
    super(475, 5, 160, 224)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 175    
    refresh
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    i = $game_system.character_select.to_s
    actor = $game_party.actors[i.to_i]
    draw_actor_battler(actor, 60, 180)
  end
end
#==============================================================================
class Window_Gold < Window_Base
  def initialize
    super(5, 411, 160, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 175
    cx = contents.text_size($data_system.words.gold).width
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(124-cx, 0, cx, 32, $data_system.words.gold, 2)
  end
end
#==============================================================================
class Window_RightCorner < Window_Base
  def initialize
    super(475, 411 , 160 , 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 175
    self.contents.font.size = 18
    refresh
    end
    def refresh
      self.contents.clear
    if $game_system.help_mode == 1
      if $scene.is_a?(Scene_Equip)
           self.contents.draw_text(7, 0, 135, 32, "[Shift] Toggles Text Box")
      elsif $scene.is_a?(Scene_Menu)
        if $game_system.debug == false
           self.contents.draw_text(7, 0, 135, 32, "Press [Shift] for Options ")
        end
      elsif $scene.is_a?(Scene_Options)
        self.contents.draw_text(3, 0, 135, 32, "Help Mode Window")
      end
    end
  end
end
#==============================================================================
class Window_Empty < Window_Base
  def initialize
    super(475, 5, 160, 48)     
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = 20
    self.opacity = 175; refresh
  end
#----------------------------------------------------------------------------- 
  def refresh
    self.contents.clear
    s1 = ["Weapons:", "Sheilds:", "Helmets:", "Armors:", "Accessories:"]
    s2 = [0, 30, 80, 35, 80, 35, 80, 35, 80, 22, 90]
    for i in 0..4
      if $game_system.equip_name == i
        self.contents.draw_text(s2[2*i + 1], -11, s2[2*i+2], 32, s1[i])
      end
    end
  end
end
#==============================================================================
class Window_Command < Window_Selectable
  def initialize(width, commands)
    super(0, 0, width, commands.size * 32 + 32)
    @item_max = commands.size
    @commands = commands
    self.contents = Bitmap.new(width - 32, @item_max * 32)
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = $defaultfontsize
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i, normal_color)
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index])
  end
  #--------------------------------------------------------------------------
  def disable_item(index)
    draw_item(index, disabled_color)
  end
end
#==============================================================================
class Window_Help < Window_Base
  def initialize
    if  $game_system.help_switch == 0
      super(170, 5, 300, 65)
    elsif $game_system.help_switch == 1
      super(0, 0, 640, 64)
    elsif $game_system.help_switch == 2
      if $game_system.version_104 == 0
        super(645, 411, 630, 64)
      else
        super(5, 411, 630, 64)      
      end
    end
    self.contents = Bitmap.new(width - 32, height - 32)
  end
  def set_text(text, align = 0)
    if text != @text or align != @align
      self.contents.clear
      self.contents.font.color = normal_color
      self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
      @text = text
      @align = align
      @actor = nil
    end
    self.visible = true
  end
  def set_actor(actor)
    if actor != @actor
      self.contents.clear
      draw_actor_name(actor, 4, 0)
      draw_actor_state(actor, 140, 0)
      draw_actor_hp(actor, 284, 0)
      draw_actor_sp(actor, 460, 0)
      @actor = actor
      @text = nil
      self.visible = true
    end
  end
  def set_enemy(enemy)
    text = enemy.name
    state_text = make_battler_state_text(enemy, 112, false)
    if state_text != ""
      text += "  " + state_text
    end
    set_text(text, 1)
  end
end
#==============================================================================
class Window_Item < Window_Selectable
  def initialize
    super(170, 74, 300, 276)
    @column_max = 1
    refresh
    self.index = 0
    self.opacity = 175
    if $game_temp.in_battle
      self.y = 64
      self.height = 256
      self.back_opacity = 160
    end
  end
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 1...$data_items.size
      if $game_party.item_number(i) > 0
        @data.push($data_items[i])
      end
    end
    unless $game_temp.in_battle
      for i in 1...$data_weapons.size
        if $game_party.weapon_number(i) > 0
          @data.push($data_weapons[i])
        end
      end
      for i in 1...$data_armors.size
        if $game_party.armor_number(i) > 0
          @data.push($data_armors[i])
        end
      end
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      self.contents.font.name = $defaultfonttype  # "Items" window font
      self.contents.font.size = $defaultfontsize
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x =  4 + index % 2 * (288 + 32)
    y = index / 1 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(19, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(43, y, 212, 32, item.name, 0) #x+28 #212
    self.contents.draw_text(225, y, 16, 32, ":", 1)
    self.contents.draw_text(235, y, 24, 32, number.to_s, 2)
  end
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end
#==============================================================================
class Window_Skill < Window_Selectable
  def initialize(actor)
    super(170, 74, 300, 276)
    @actor = actor
    @column_max = 1
    refresh
    self.index = 0
    self.opacity = 175
    if $game_temp.in_battle
      self.y = 64
      self.height = 256
      self.back_opacity = 160
    end
  end
  #--------------------------------------------------------------------------
  def skill
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 0...@actor.skills.size
      skill = $data_skills[@actor.skills[i]]
      if skill != nil
        @data.push(skill)
      end
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = $defaultfontsize
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  def draw_item(index)
    skill = @data[index]
    if @actor.skill_can_use?(skill.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 2 * (288 + 32)
    y = index / 1 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(skill.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(4, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(28, y, 204, 32, skill.name, 0)
    self.contents.draw_text(200, y, 48, 32, skill.sp_cost.to_s, 2)
  end
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.skill == nil ? "" : self.skill.description)
  end
end
#==============================================================================
class Window_EquipLeft < Window_Base
  def initialize(actor)
    super(125, -9, 300 + 100, 192 + 150)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype  # "Equip" left side (Status) window font
    self.contents.font.size = 18
    @actor = actor
    refresh
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    s1 = [@new_atk, @new_pdef, @new_mdef, @new_str, @new_dex, @new_agi, @new_int] 
    s2 = [@actor.atk, @actor.pdef, @actor.mdef, @actor.str, @actor.dex, @actor.agi, @actor.int]
    for i in 0..6
      if s1[i] != nil
        @a = (s1[i] - s2[i]).to_s
        @y = 64 + 17 * i
        text_check; plus_minus
        self.contents.draw_text(210, @y, 36, 32, s1[i].to_s, 2)
        self.contents.font.color = system_color
        self.contents.draw_text(208, @y, 40, 32, ">")
      end
    end
  end
  #--------------------------------------------------------------------------
  def set_new_parameters(new_atk, new_pdef, new_mdef, new_str, new_dex, new_agi, new_int)
    if @new_atk != new_atk or @new_pdef != new_pdef or @new_mdef != new_mdef or @new_str != new_str or @new_dex != new_dex or @new_agi != new_agi or @new_int != new_int
      @new_atk = new_atk
      @new_pdef = new_pdef
      @new_mdef = new_mdef
      @new_str = new_str
      @new_dex = new_dex
      @new_agi = new_agi
      @new_int = new_int
      refresh
    end
  end
  #--------------------------------------------------------------------------  
  def text_check
    if @a == 0.to_s
      self.contents.font.color = normal_color      
      elsif @a >= 0.to_s
      self.contents.font.color = text_color(3)        
      elsif @a <= 0.to_s
      self.contents.font.color = text_color(2)
    end
    return
  end
  #--------------------------------------------------------------------------    
  def plus_minus
      if @a >= 0.to_s
      self.contents.draw_text(260, @y.to_i, 92, 32, "(+"+@a+")")
      else
      self.contents.draw_text(260, @y.to_i, 92, 32, "("+@a+")")      
    end    
  end
end
#==============================================================================
class Window_EquipRight < Window_Selectable
  def initialize(actor)
    super(272, 64, 293, 192)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype  # "Equip" right side (Equiped Items) window font
    self.contents.font.size = $defaultfontsize
    @actor = actor
    @column_max = 2
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.size = 13
    @data = []
    @data.push($data_weapons[@actor.weapon_id])
    @data.push($data_armors[@actor.armor1_id])
    @data.push($data_armors[@actor.armor2_id])    
    @data.push($data_armors[@actor.armor3_id])   
    @data.push($data_armors[@actor.armor4_id])
    @item_max = @data.size
  end
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end
#==============================================================================
class Window_EquipItem < Window_Selectable
  def initialize(actor, equip_type)
    super(475, 53, 160, 176)
    @actor = actor
    @equip_type = equip_type
    @column_max = 1
    refresh
    self.active = false
    self.index = -1
  end
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    if @equip_type == 0
      weapon_set = $data_classes[@actor.class_id].weapon_set
      for i in 1...$data_weapons.size
        if $game_party.weapon_number(i) > 0 and weapon_set.include?(i)
          @data.push($data_weapons[i])
        end
      end
    end
    if @equip_type != 0
      armor_set = $data_classes[@actor.class_id].armor_set
      for i in 1...$data_armors.size
        if $game_party.armor_number(i) > 0 and armor_set.include?(i)
          if $data_armors[i].kind == @equip_type-1
            @data.push($data_armors[i])
          end
        end
      end
    end
    @data.push(nil)
    @item_max = @data.size
    self.contents = Bitmap.new(width - 32, row_max * 32)
    self.contents.font.name = $defaultfonttype
    self.contents.font.size = $defaultfontsize
    for i in 0...@item_max-1
      draw_item(i)
    end
   i = @data.size-1
   self.contents.font.size = 12
   self.contents.draw_text(4, i*32, 100, 32, "[None]")
  end
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    x = 4 + index % 1 * (288 + 32)
    y = index / 1 * 32
    case item
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    self.contents.font.color = normal_color
    self.contents.font.size = 12
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.font.size = 10
    self.contents.draw_text(x + 99, y, 24, 32, "x" + number.to_s, 2)
  end
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end
#==============================================================================
class Window_Status < Window_Base
  def initialize(actor)
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype  # "Status" window font
    self.contents.font.size = $defaultfontsize
    @actor = actor
    refresh
  end
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_actor_graphic(@actor, 40, 112)
    draw_actor_name(@actor, 4, 0)
    draw_actor_class(@actor, 148, 0)
    draw_actor_level(@actor, 96, 32)
    draw_actor_state(@actor, 96, 64)
    draw_actor_hp(@actor, 96, 112, 172)
    draw_actor_sp(@actor, 96, 144, 172)
    for i in 0..6
    draw_actor_parameter(@actor, 96, 192 + 32*i, i)
    end
    self.contents.font.color = system_color
    self.contents.draw_text(320, 48, 80, 32, "Exp")
    self.contents.draw_text(320, 80, 80, 32, "Next Level")
    self.contents.font.color = normal_color
    self.contents.draw_text(320 + 80, 48, 84, 32, @actor.exp_s, 2)
    self.contents.draw_text(320 + 80, 80, 84, 32, @actor.next_rest_exp_s, 2)
    self.contents.font.color = system_color
    self.contents.draw_text(320, 160, 96, 32, "Equipment")
  end
end
#==============================================================================
class Scene_Menu
  def initialize(menu_index = 0)
    @menu_index = menu_index
    $game_system.help_switch = 1
  end
  #--------------------------------------------------------------------------
  def main
      @command_window = Window_Command.new(160,["Item", "Abilities", "Equipment", "Change Party", "Save Game", "End Game"])
      @command_window.index = @menu_index
      @command_window.opacity = 175; @command_window.x = 5; @command_window.y = 5
      @battler = Window_Battler.new        
      @gold_window = Window_Gold.new      
      @location_window = Window_Location.new
      @playtime_window = Window_PlayTime2.new
      @status_window = Window_MenuStatus2.new
      @status2_window = Window_Status2.new(@actor)
      @sprite = Spriteset_Map.new
      @right_window = Window_RightCorner.new
    if $game_system.save_disabled
      @command_window.disable_item(4)
    end
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @command_window.dispose; @status_window.dispose; @gold_window.dispose
    @playtime_window.dispose; @status2_window.dispose; @battler.dispose
    @location_window.dispose; @sprite.dispose; @right_window.dispose
  end
  #--------------------------------------------------------------------------
  def update
    @command_window.update; @playtime_window.update; $game_system.update
    $game_system.char_max = $game_party.actors.size
    if Input.repeat?(Input::RIGHT)
        $game_system.character_select += 1
        $game_system.se_play($data_system.decision_se)        
      if $game_system.character_select == $game_system.char_max
         $game_system.character_select = 0
      end
        @battler.refresh; @status2_window.refresh; @status_window.refresh
    end
    if Input.repeat?(Input::LEFT)
      $game_system.character_select -= 1
      $game_system.se_play($data_system.decision_se)
      if $game_system.character_select == -1
         $game_system.character_select = $game_system.char_max - 1
      end
        @battler.refresh; @status2_window.refresh; @status_window.refresh
    end                   
    if @command_window.active
      update_command
      return
    end
  end
 #---------------------------------------------------------------------------
   def delay(seconds)
    for i in 0...(seconds * 1)
      sleep 0.01
      Graphics.update
     end
   end
  #--------------------------------------------------------------------------
  def update_command
    i = $game_system.character_select.to_s
    if Input.trigger?(Input::A)
      if $game_system.debug == false
         $game_system.se_play($data_system.decision_se)
         $scene = Scene_Options.new(0)
      end
    end    
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      $game_system.character_select = 0
      return
    end
    if Input.trigger?(Input::C)
      case @command_window.index
      when 0
        $scene = Scene_Item.new
      when 1
        $scene = Scene_Skill.new(i.to_i)
      when 2
        $scene = Scene_Equip.new(i.to_i)
      when 3        
        $scene = Scene_Change.new
        $game_system.character_select = 0
      when 4
        if $game_system.save_disabled
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        $scene = Scene_Save.new
      when 5
        $scene = Scene_End.new
      end
        $game_system.se_play($data_system.decision_se)      
      return
    end
  end
end
#==============================================================================
class Scene_Item
  def main
    @command_window = Window_Command.new(160,["Item", "Abilities", "Equipment", "Change Party", "Save Game", "End Game"])
    @command_window.x = 5; @command_window.y = 5; @command_window.opacity = 175
    @command_window.index = 0
    @command_window.active = false
    $game_system.help_switch = 0    
    @help_window = Window_Help.new
    @help_window.opacity = 175
    @item_window = Window_Item.new 
    @item_window.help_window = @help_window; 
    @item_window.x = 170; @item_window.y = 74
    @target_window = Window_Target.new
    @target_window.visible = false
    @target_window.active = false
    @playtime_window = Window_PlayTime2.new
    @gold_window = Window_Gold.new
    @status_window = Window_MenuStatus2.new
    @location_window = Window_Location.new
    @battler = Window_Battler.new
    @sprite = Spriteset_Map.new
    @right_window = Window_RightCorner.new
    if $game_system.save_disabled
      @command_window.disable_item(4)
    end
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose; @item_window.dispose; @target_window.dispose
    @gold_window.dispose; @playtime_window.dispose; @battler.dispose
    @location_window.dispose; @status_window.dispose; @command_window.dispose
    @sprite.dispose; @right_window.dispose
  end
  #--------------------------------------------------------------------------
  def update
    @help_window.update; @item_window.update; @target_window.update
    @playtime_window.update; $game_system.update
    if @item_window.active
      update_item
      return
    end
    if @target_window.active
      update_target
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(0)
      return
    end
    if Input.trigger?(Input::C)
      @item = @item_window.item
      unless @item.is_a?(RPG::Item)
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      unless $game_party.item_can_use?(@item.id)
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      if @item.scope >= 3
        @item_window.active = false
        @target_window.x = 304 #(@item_window.index + 1) % 2 * 304
        @target_window.visible = true
        @target_window.active = true
        if @item.scope == 4 || @item.scope == 6
          @target_window.index = -1
        else
          @target_window.index = 0
        end
      else
        if @item.common_event_id > 0
          $game_temp.common_event_id = @item.common_event_id
          $game_system.se_play(@item.menu_se)
          if @item.consumable
            $game_party.lose_item(@item.id, 1)
            @item_window.draw_item(@item_window.index)
          end
          $scene = Scene_Map.new
          return
        end
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_target
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      unless $game_party.item_can_use?(@item.id)
        @item_window.refresh
      end
      @item_window.active = true
      @target_window.visible = false
      @target_window.active = false
      return
    end
    if Input.trigger?(Input::C)
      if $game_party.item_number(@item.id) == 0
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      if @target_window.index == -1
        used = false
        for i in $game_party.actors
          used |= i.item_effect(@item)
        end
      end
      if @target_window.index >= 0
        target = $game_party.actors[@target_window.index]
        used = target.item_effect(@item)
      end
      if used
        $game_system.se_play(@item.menu_se)
        if @item.consumable
          $game_party.lose_item(@item.id, 1)
          @item_window.draw_item(@item_window.index)
        end
        @target_window.refresh
        if $game_party.all_dead?
          $scene = Scene_Gameover.new
          return
        end
        if @item.common_event_id > 0
          $game_temp.common_event_id = @item.common_event_id
          $scene = Scene_Map.new
          return
        end
      end
      unless used
        $game_system.se_play($data_system.buzzer_se)
      end
      return
    end
  end
end
#==============================================================================
class Scene_Skill
  def initialize(actor_index = 0, equip_index = 0)
    @actor_index = actor_index
  end
  #--------------------------------------------------------------------------
  def main        
    @command_window = Window_Command.new(160,["Item", "Abilities", "Equipment", "Change Party", "Save Game", "End Game"])
    @command_window.x = 5; @command_window.y = 5
    @command_window.opacity = 175; @command_window.index = 1  
    @command_window.active = false
    @actor = $game_party.actors[@actor_index]
    $game_system.help_switch = 0
    @help_window = Window_Help.new; @help_window.opacity = 175
    @skill_window = Window_Skill.new(@actor)
    @skill_window.help_window = @help_window
    @target_window = Window_Target.new
    @target_window.visible = false; @target_window.active = false
    @playtime_window = Window_PlayTime2.new
    @gold_window = Window_Gold.new
    @status_window = Window_MenuStatus2.new
    @location_window = Window_Location.new
    @battler = Window_Battler.new
    @sprite = Spriteset_Map.new
    @right_window = Window_RightCorner.new
    if $game_system.save_disabled
      @command_window.disable_item(4)
    end
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose; @skill_window.dispose; @target_window.dispose
    @gold_window.dispose; @playtime_window.dispose; @battler.dispose
    @location_window.dispose; @status_window.dispose; @command_window.dispose
    @sprite.dispose; @right_window.dispose
  end
  #--------------------------------------------------------------------------
  def update
    @help_window.update; @status_window.update; @skill_window.update
    @target_window.update; @playtime_window.update; $game_system.update   
    if @skill_window.active
      update_skill
      return
    end
    if @target_window.active
      update_target
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_skill
    $game_system.char_max = $game_party.actors.size
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(1)
      return
    end
    if Input.trigger?(Input::C)
      @skill = @skill_window.skill
      if @skill == nil or not @actor.skill_can_use?(@skill.id)
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      if @skill.scope >= 3
        @skill_window.active = false
        @target_window.x = 304 #(@skill_window.index + 1) % 2 * 304
        @target_window.visible = true
        @target_window.active = true
        if @skill.scope == 4 || @skill.scope == 6
          @target_window.index = -1
        elsif @skill.scope == 7
          @target_window.index = @actor_index - 10
        else
          @target_window.index = 0
        end
      else
        if @skill.common_event_id > 0
          $game_temp.common_event_id = @skill.common_event_id
          $game_system.se_play(@skill.menu_se)
          @actor.sp -= @skill.sp_cost
          @status_window.refresh; @skill_window.refresh; @target_window.refresh
          $scene = Scene_Map.new
          return
        end
      end
      return
    end
    if Input.trigger?(Input::R)
      $game_system.se_play($data_system.cursor_se)
      @actor_index += 1
      @actor_index %= $game_party.actors.size
      $scene = Scene_Skill.new(@actor_index)
      $game_system.character_select += 1
      if $game_system.character_select == $game_system.char_max
         $game_system.character_select = 0
       end
      @battler.refresh; @status_window.refresh      
      return
    end
    if Input.trigger?(Input::L)
      $game_system.se_play($data_system.cursor_se)
      @actor_index += $game_party.actors.size - 1
      @actor_index %= $game_party.actors.size
      $scene = Scene_Skill.new(@actor_index)
      $game_system.character_select -= 1
      if $game_system.character_select == -1
         $game_system.character_select = $game_system.char_max - 1
      end
      @status_window.refresh; @battler.refresh
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_target
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @skill_window.active = true
      @target_window.visible = false
      @target_window.active = false
      return
    end
    if Input.trigger?(Input::C)
      unless @actor.skill_can_use?(@skill.id)
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      if @target_window.index == -1
        used = false
        for i in $game_party.actors
          used |= i.skill_effect(@actor, @skill)
        end
      end
      if @target_window.index <= -2
        target = $game_party.actors[@target_window.index + 10]
        used = target.skill_effect(@actor, @skill)
      end
      if @target_window.index >= 0
        target = $game_party.actors[@target_window.index]
        used = target.skill_effect(@actor, @skill)
      end
      if used
        $game_system.se_play(@skill.menu_se)
        @actor.sp -= @skill.sp_cost
        @status_window.refresh; @skill_window.refresh; @target_window.refresh
        if $game_party.all_dead?
          $scene = Scene_Gameover.new
          return
        end
        if @skill.common_event_id > 0
          $game_temp.common_event_id = @skill.common_event_id
          $scene = Scene_Map.new
          return
        end
      end
      unless used
        $game_system.se_play($data_system.buzzer_se)
      end
      return
    end
  end
end
#==============================================================================
class Scene_Equip
  def initialize(actor_index = 0, equip_index = 0)
    @actor_index = actor_index
    @equip_index = equip_index
  end
  #--------------------------------------------------------------------------
  def main
    @command_window = Window_Command.new(160,["Item", "Abilities", "Equipment", "Change Party", "Save Game", "End Game"])
    @command_window.x = 5; @command_window.y = 5
    @command_window.opacity = 175; @command_window.index = 2
    @command_window.active = false
    @actor = $game_party.actors[@actor_index]
    $game_system.help_switch = 2
    @help_window = Window_Help.new
    @left_window = Window_EquipLeft.new(@actor); @left_window.opacity = 0
    @right_window = Window_EquipRight.new(@actor); @right_window.opacity = 0
    @right_window.x = 170; @right_window.y = 220
    @right_window.index = @equip_index
    @item_window1 = Window_EquipItem.new(@actor, 0)
    @item_window1.opacity = 175
    @item_window2 = Window_EquipItem.new(@actor, 1)
    @item_window2.opacity = 175    
    @item_window3 = Window_EquipItem.new(@actor, 2)
    @item_window3.opacity = 175    
    @item_window4 = Window_EquipItem.new(@actor, 3)
    @item_window4.opacity = 175    
    @item_window5 = Window_EquipItem.new(@actor, 4)
    @item_window5.opacity = 175
    @right_window.help_window = @help_window
    @help_window.z = 1000
    @help_window.width = 630
    @help_window.opacity = 255
    @item_window1.help_window = @help_window
    @item_window2.help_window = @help_window
    @item_window3.help_window = @help_window
    @item_window4.help_window = @help_window
    @item_window5.help_window = @help_window
    @playtime_window = Window_PlayTime2.new
    @gold_window = Window_Gold.new
    @status_window = Window_MenuStatus2.new
    @location_window = Window_Location.new
    @status2_window = Window_Status2.new(@actor)
    @status_window.y = @status_window.y
    @empty = Window_Empty.new
    @sprite = Spriteset_Map.new
    @right_window2 = Window_RightCorner.new
    if $game_system.save_disabled
      @command_window.disable_item(4)
    end
    refresh
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose; @left_window.dispose; @right_window.dispose
    @item_window1.dispose; @item_window2.dispose; @item_window3.dispose
    @item_window4.dispose; @item_window5.dispose; @gold_window.dispose
    @playtime_window.dispose; @location_window.dispose; @status_window.dispose; 
    @command_window.dispose; @status2_window.dispose; @empty.dispose
    @sprite.dispose; @right_window2.dispose
  end
  #--------------------------------------------------------------------------
  def refresh
    $game_system.equip_name = @right_window.index
    @item_window1.visible = (@right_window.index == 0)
    @item_window2.visible = (@right_window.index == 1)
    @item_window3.visible = (@right_window.index == 2)
    @item_window4.visible = (@right_window.index == 3)
    @item_window5.visible = (@right_window.index == 4)
    item1 = @right_window.item
    case @right_window.index
    when 0
      @item_window = @item_window1
    when 1
      @item_window = @item_window2
    when 2
      @item_window = @item_window3
    when 3
      @item_window = @item_window4
    when 4
      @item_window = @item_window5
    end
    if @right_window.active
         @left_window.set_new_parameters(nil, nil, nil, nil, nil, nil, nil)
    end
    if @item_window.active
      item2 = @item_window.item
      last_hp = @actor.hp
      last_sp = @actor.sp
      @actor.equip(@right_window.index, item2 == nil ? 0 : item2.id)
      new_atk = @actor.atk
      new_pdef = @actor.pdef
      new_mdef = @actor.mdef
      new_str = @actor.str
      new_dex = @actor.dex
      new_agi = @actor.agi
      new_int = @actor.int
      @actor.equip(@right_window.index, item1 == nil ? 0 : item1.id)
      @actor.hp = last_hp
      @actor.sp = last_sp
      @left_window.set_new_parameters(new_atk, new_pdef, new_mdef, new_str, new_dex, new_agi, new_int)
    end
  end
  #--------------------------------------------------------------------------
  def update
    @left_window.update; @right_window.update; @item_window.update
    @playtime_window.update; @status2_window.update; $game_system.update
    @empty.refresh
    refresh
    if @right_window.active
      update_right
      return
    end
    if @item_window.active
      update_item
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_right
    $game_system.char_max = $game_party.actors.size
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(2)
      return
    end
    if Input.trigger?(Input::A)
    if @help_window.x == 645
       @help_window.x = 5
    elsif @help_window.x == 5
       @help_window.x = 645
    end
    end
    if Input.trigger?(Input::C)
      if @actor.equip_fix?(@right_window.index)
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      @right_window.active = false
      @item_window.active = true
      @item_window.index = 0
      return
    end
    if Input.trigger?(Input::R)
      $game_system.se_play($data_system.cursor_se)
      @actor_index += 1
      @actor_index %= $game_party.actors.size
      $scene = Scene_Equip.new(@actor_index, @right_window.index)
      $game_system.character_select += 1
      if $game_system.character_select == $game_system.char_max
         $game_system.character_select = 0
      end
      @status_window.refresh; @status2_window.refresh
      return
    end
    if Input.trigger?(Input::L)
      $game_system.se_play($data_system.cursor_se)
      @actor_index += $game_party.actors.size - 1
      @actor_index %= $game_party.actors.size
      $scene = Scene_Equip.new(@actor_index, @right_window.index)
      $game_system.character_select -= 1
      if $game_system.character_select == -1
         $game_system.character_select = $game_system.char_max - 1
      end
      @status_window.refresh; @status2_window.refresh
      return
    end
  end
  #--------------------------------------------------------------------------
  def update_item
    if Input.trigger?(Input::A)
    if @help_window.x == 645
       @help_window.x = 5
    elsif @help_window.x == 5
       @help_window.x = 645
    end
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.equip_se)
      item = @item_window.item
      @actor.equip(@right_window.index, item == nil ? 0 : item.id)
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      @right_window.refresh; @item_window.refresh; @status2_window.dispose
      @status2_window = Window_Status2.new(@actor); @status2_window.opacity = 175
      return
    end
  end
end
#==============================================================================
class Scene_Save < Scene_File
  def initialize
    super("Save to which file?")
  end
  #--------------------------------------------------------------------------
  def on_decision(filename)
    $game_system.se_play($data_system.save_se)
    file = File.open(filename, "wb")
    write_save_data(file)
    file.close
    if $game_temp.save_calling
      $game_temp.save_calling = false
      $scene = Scene_Map.new
      return
    end
      $scene = Scene_Menu.new(4)
  end
  #--------------------------------------------------------------------------
  def on_cancel
    $game_system.se_play($data_system.cancel_se)
    if $game_temp.save_calling
      $game_temp.save_calling = false
      $scene = Scene_Map.new
      return
    end
    $scene = Scene_Menu.new(4)   
  end
  #--------------------------------------------------------------------------
  def write_save_data(file)
    characters = []
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      characters.push([actor.character_name, actor.character_hue])
    end
    Marshal.dump(characters, file)
    Marshal.dump(Graphics.frame_count, file)
    $game_system.save_count += 1
    $game_system.magic_number = $data_system.magic_number
    Marshal.dump($game_system, file)
    Marshal.dump($game_switches, file)
    Marshal.dump($game_variables, file)
    Marshal.dump($game_self_switches, file)
    Marshal.dump($game_screen, file)
    Marshal.dump($game_actors, file)
    Marshal.dump($game_party, file)
    Marshal.dump($game_troop, file)
    Marshal.dump($game_map, file)
    Marshal.dump($game_player, file)
    Marshal.dump($party_variables, file)
    Marshal.dump($game_time, file)
  end
end
#==============================================================================
class Scene_End
  def main
    @command_window = Window_Command.new(192, ["Return to Title", "Exit to Windows", "Cancel"])
    @command_window.x = 320 - @command_window.width / 2
    @command_window.y = 240 - @command_window.height / 2
    @command_window.opacity = 175
    @sprite = Spriteset_Map.new
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @command_window.dispose
    @sprite.dispose
    if $scene.is_a?(Scene_Title)
      Graphics.transition
      Graphics.freeze
    end
  end
  #--------------------------------------------------------------------------
  def update
    $game_system.update; @command_window.update
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(5)
      return
    end
    if Input.trigger?(Input::C)
        $game_system.se_play($data_system.decision_se)
      case @command_window.index
      when 0
        Audio.bgm_fade(800); Audio.bgs_fade(800); Audio.me_fade(800)
        $scene = Scene_Title.new
        if $game_system.full_screen == 1
           $game_system.screen_size
        end
      when 1
        Audio.bgm_fade(800); Audio.bgs_fade(800); Audio.me_fade(800)
        $scene = nil
      when 2
        $scene = Scene_Menu.new(5)
      end
      return
    end
  end
end

#--------------------------------------------------------------------------
class Window_OptionsClear< Window_Base
  def initialize
    super(170, 5, 300, 345)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    self.contents.font.size = 24
    self.contents.draw_text(70, 0, 120, 32, "Options Menu")
    self.contents.draw_text(0, 20, 300, 32, "--------------------------------------------")
    self.contents.font.size = 16
    self.contents.draw_text(40, 40, 250, 32, "Keep on Equip Description Window")
    self.contents.draw_text(40, 60, 250, 32, "Toggle Face Support")
    self.contents.draw_text(40, 80, 250, 32, "Full Screen/Window Toggle")
    self.contents.draw_text(40, 100, 250, 32, "Help Mode") 
    self.contents.draw_text(20, 135, 250, 32, "Volumes")
    self.contents.draw_text(50, 155, 250, 32, "Music Level")
    self.contents.draw_text(50, 170, 300, 32, "--------------------------------------")
    self.contents.draw_text(50, 185, 250, 32, "Sound Level")
    self.contents.draw_text(50, 200, 300, 32, "--------------------------------------")      
    self.contents.draw_text(20, 220, 250, 32, "Menu Background Skin")
    self.contents.draw_text(50, 240, 250, 32, "Default   1   2   3   4   5   6   7   8   9")
    self.contents.draw_text(20, 262, 250, 32, "Map HUD")
    self.contents.draw_text(50, 282, 280, 32, "Off        Normal Mode        Full Mode")

  end    
end
#--------------------------------------------------------------------------

class Window_Options < Window_Base
  
  def initialize
    super(170, 5, 300, 345)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 175
    refresh
  end
  #-------------------------------------------------------------------------- 
  
    def refresh
     
    self.contents.clear
    self.contents.font.size = 16
    self.contents.draw_text(215, 170, 250, 32, "(" + $game_system.music_level.to_s + "%)")
    self.contents.draw_text(215, 200, 250, 32, "(" + $game_system.sound_level.to_s + "%)")    
    y_spot = [40,60,80,100,155,185,220,262]
    
    i = $game_system.option_decision   
    self.contents.draw_text(2, y_spot[i], 250, 32, "->")
    
    i = $game_system.music_level
    self.contents.draw_text(50 + 1.5*i, 170, 250, 32, "|")
    i = $game_system.sound_level
    self.contents.draw_text(50 + 1.5*i, 200, 250, 32, "|")  

    end
    end
  #--------------------------------------------------------------------------
class Scene_Options
  
  def initialize(menu_index)
    $game_system.sound_music = 0
    $game_system.option_decision = menu_index
  end
  
  #--------------------------------------------------------------------------
  def main
    @command_window = Window_Command.new(160,["Item", "Abilities", "Equipment", "Change Party", "Save Game", "End Game"])
    @command_window.opacity = 175; @command_window.x = 5; @command_window.y = 5
    @command_window.active = false
    @battler = Window_Battler.new        
    @gold_window = Window_Gold.new      
    @location_window = Window_Location.new
    @playtime_window = Window_PlayTime2.new
    @status_window = Window_MenuStatus2.new
    @sprite = Spriteset_Map.new
    @right_window = Window_RightCorner.new
    @options_window = Window_Options.new 
    @options_window2=Window_OptionsClear.new
    s1 = [@checkmark1, @checkmark2, @checkmark3, @checkmark4, @checkmark5, @checkmark6, @checkmark7] 
    s2 = [$game_system.version_104, $game_system.face_support, $game_system.full_screen, $game_system.help_mode]
    s3 = [40,60,80,100]
    
    for i in 0..3
        s1[i] = Sprite.new
      if s2[i] == 1
            s1[i].bitmap = RPG::Cache.picture("checked1.PNG")
      else
            s1[i].bitmap = RPG::Cache.picture("Unchecked.PNG")
      end
        s1[i].x = 205
        s1[i].y = s3[i] + 30
        s1[i].z = 1000
    end 

    s2= [146, 194, 303]
    for i in 0..2
        s1[i+5] = Sprite.new
        s1[i+5].bitmap = RPG::Cache.picture("Unchecked.PNG")
        if  i == $game_system.map_hud
            s1[i+5].bitmap = RPG::Cache.picture("checked1.PNG")
        end
        s1[i+5].x = 70 + s2[i]
        s1[i+5].y = 312
        s1[i+5].z = 1000  
    end

    j = $game_system.windowskin_name.to_i
    s4 = Sprite.new
    if j == 0
    s4.bitmap = RPG::Cache.picture("Uncheckedlong.PNG")
    s4.x = 230
    elsif 0 < j  and j <= 9
    s4.bitmap = RPG::Cache.picture("Unchecked.PNG")
    s4.x = 265 + j*19
   end
    s4.y = 270
    s4.z = 5  
    
    if $game_system.save_disabled
        @command_window.disable_item(4)
    end
    
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      update_options
     
      if $scene != self
        break
      end

    end
    Graphics.freeze
    @command_window.dispose; @status_window.dispose; @gold_window.dispose
    @playtime_window.dispose; @battler.dispose; @options_window.dispose
    @location_window.dispose; @sprite.dispose; @right_window.dispose #;@back1.dispose
    @options_window2.dispose; s4.dispose
    
    for i in 0..3
        s1[i].bitmap.dispose    
    end
    for i in 5..7
        s1[1].bitmap.dispose
      end

  
  end
  #--------------------------------------------------------------------------
  def update
    @playtime_window.update; $game_system.update
    $game_system.char_max = $game_party.actors.size
    
    if Input.repeat?(Input::RIGHT)
       if $game_system.option_decision == 4
             $game_system.music_level += 5    
             $game_system.bgm_memorize
             $game_system.bgm_restore
              if $game_system.music_level >= 100
                 $game_system.music_level = 100
              end
       elsif $game_system.option_decision == 5
             $game_system.sound_level += 5
             $game_system.bgs_memorize
             $game_system.bgs_restore
             if $game_system.sound_level >= 100
                $game_system.sound_level = 100
             end
       elsif $game_system.option_decision == 6
       i = $game_system.windowskin_name.to_i
       i = i+1
       if i == 10
          i = 0
       end         
       $game_system.windowskin_name = i.to_s
       $scene = Scene_Options.new(6)
       elsif $game_system.option_decision == 7
                $game_system.map_hud += 1
            if $game_system.map_hud == 3
               $game_system.map_hud = 2
            end
       end
        @options_window.refresh
        $game_system.se_play($data_system.decision_se)    
    end
    
    if Input.repeat?(Input::LEFT)
      if $game_system.option_decision == 4
             $game_system.music_level -= 5
             $game_system.bgm_memorize
             $game_system.bgm_restore
                if $game_system.music_level <= 0
                   $game_system.music_level = 0
                end
      elsif $game_system.option_decision == 5
            $game_system.sound_level -= 5
            $game_system.bgs_memorize
            $game_system.bgs_restore
                if $game_system.sound_level <= 0
                   $game_system.sound_level = 0
                 end
      elsif $game_system.option_decision == 6
       i = $game_system.windowskin_name.to_i
       i = i - 1
             if i == -1
                 i = 9
             end           
       $game_system.windowskin_name = i.to_s
       $scene = Scene_Options.new(6)
        elsif $game_system.option_decision == 7
                $game_system.map_hud -= 1
            if $game_system.map_hud == -1
               $game_system.map_hud = 0
            end
        end   
              
        @options_window.refresh
        $game_system.se_play($data_system.decision_se)    
    end
    
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new
      return
    end
 
  end
 #---------------------------------------------------------------------------
 def update_options
    
  if Input.trigger?(Input::C)
    $game_system.se_play($data_system.decision_se)
    
    if $game_system.sound_music == 0
 
      if $game_system.option_decision == 0
           if $game_system.version_104 == 1
               $game_system.version_104 = 0
           else
               $game_system.version_104 = 1
           end
       end
       if $game_system.option_decision == 1
            if $game_system.face_support == 1
               $game_system.face_support = 0
            else
               $game_system.face_support = 1
            end
        end
        if $game_system.option_decision == 2
            if $game_system.full_screen == 1
               $game_system.full_screen = 0
               $game_system.screen_size
            Graphics.update
            sleep 1.0
            else
               $game_system.full_screen = 1
               $game_system.screen_size
               Graphics.update
               sleep 1.0     
            end
        end
        if $game_system.option_decision == 3
            if $game_system.help_mode == 1
               $game_system.help_mode = 0
            else
               $game_system.help_mode = 1
            end
          @right_window.refresh
        end
        @status_window.refresh
        @options_window.refresh
  
  end
end

      s1 = [@checkmark1, @checkmark2, @checkmark3, @checkmark4, @checkmark5, @checkmark6, @checkmark7] 
      s2 = [$game_system.version_104, $game_system.face_support, $game_system.full_screen, $game_system.help_mode]
      s3 = [40,60,80,100]
       
     for i in 0..3
       s1[i] = Sprite.new
         if s2[i] == 1
             s1[i].bitmap = RPG::Cache.picture("checked1.PNG")
         else
             s1[i].bitmap = RPG::Cache.picture("Unchecked.PNG")
         end
       s1[i].x = 205
       s1[i].y = s3[i] + 30
       s1[i].z = 1000
     end

    s2= [146, 194, 303]
    for i in 0..2
        s1[i+5] = Sprite.new
        s1[i+5].bitmap = RPG::Cache.picture("Unchecked.PNG")
        if  i == $game_system.map_hud
            s1[i+5].bitmap = RPG::Cache.picture("checked1.PNG")
        end
        s1[i+5].x = 70 + s2[i]
        s1[i+5].y = 312
        s1[i+5].z = 1000  
    end
      
     if Input.repeat?(Input::DOWN)
       $game_system.option_decision += 1
        if  $game_system.sound_music == 0
                if  $game_system.option_decision == 8
                    $game_system.option_decision = 0
                end
        elsif $game_system.sound_music == 1
                if  $game_system.option_decision == 2
                    $game_system.option_decision = 0
                end
        end
        $game_system.se_play($data_system.decision_se)
        @options_window.refresh
     end
     
     if Input.repeat?(Input::UP)
        $game_system.option_decision -= 1
        if $game_system.sound_music == 0
                if $game_system.option_decision == -1
                   $game_system.option_decision = 7
                end
        elsif $game_system.sound_music == 1
                if  $game_system.option_decision == -1
                    $game_system.option_decision = 1
                end         
        end
        $game_system.se_play($data_system.decision_se)
        @options_window.refresh
    end
      
end
 #--------------------------------------------------------------------------- 
  def delay(seconds)
    
     for i in 0...(seconds * 1)
      sleep 0.01
      Graphics.update
     end
   
  end
  #--------------------------------------------------------------------------
end

    Source: geocities.com/relientk99