#=================================================  =============================#
#                [RGSS2] Equipaments in Map Screen                             #
#------------------------------------------------------------------------------#
# $RafiScripts.by = Rafidelis(Rafis)                                           #
# $RafiScripts.version = 1.0                                                   #
# $RafiScripts.release_date = 09/09/09 (legal nй?)  (d/m/y)                    #
# $RafiScripts.email = 
Rafa_Fidelis@hotmail.com or 
Rafa_Fidelis@yahoo.com.br   #
# $RafiScripts.website =  
http://www.ReinoRPG.com/forum                        #
#=================================================  =============================#
#=================================================  =============================#
# [** $RafiScripts.versions **]  // Versхes do Script/ Script Versions         #
#------------------------------------------------------------------------------#
# 22/09/08 - Version 1.0 Released                                              #
# 09/09/09 - Version 2.0 Released                                              #
#=================================================  =============================#
#=================================================  =============================#
# [** $RafiScripts.desc **]  // Sobre o Script / About Script                  #
#------------------------------------------------------------------------------#
# Este script,й uma nova versгo de um velho script que criei,а uns 10 meses    #
# atras.E claro,dessa vez uma versгo aprimorada e melhor,totalmente sem lags.  #
# O que este Script Faz? :Ele mostra na tela os equipamentos atuais do jogador #
#------------------------------------------------------------------------------#
# ** Features :                                                                #
# (*) View the equipment in the Vertical (|) or Horizontal (_)                 #
# (*) Displays the attack or defense of equipment.                             #
# (*) Show / Hide the equipment through a key.                                 #
# (*) Use a background image if desired.                                       #
# (*) Displaying a text, in 'empty' equipment slots                            #
# (*) Compatible with scripts that increase the amount of equipment slots.     #
# (*) Updated only when some equipment is modified, thus totally avoids the    #
#     possible lags т.У                                                        #
#------------------------------------------------------------------------------#
#=================================================  =============================#
# [** $RafiScripts.instr ] // Instruзхes                                       #
#------------------------------------------------------------------------------#
# 1° Paste above the Main                                                      #
# 2° Edit the constants in Module Rafidelis: MapEquip if you want.             #
# 3° If you want to use a background image,it's must be in picture folder      #
#------------------------------------------------------------------------------#
#=================================================  =============================#
#                         [** Module Rafidelis ]                               #
#[**Modulo necessario para rodar os Scripts criados por Rafidelis(RafiScripts)]#
#=================================================  =============================#
module Rafidelis
#=================================================  =============================#
# Rafidelis.add_script - Name : Name of Script - Version : Version of Script   #
#------------------------------------------------------------------------------#
  def self.add_script(name,version)
    $RafiScripts = [] if $RafiScripts.nil?
    $RafiScripts.push("Name : #{name} - Version: #{version}")
  end
#=================================================  =============================#
# Rafidelis.script_exist? - Name : Name of Script - Version : Version of Script#
#------------------------------------------------------------------------------#
  def self.script_exist?(name,version)
    $RafiScripts = [] if $RafiScripts.nil?
    return $RafiScripts.include?("Name : #{name} - Version: #{version}")
  end
#=================================================  =============================#
# Rafidelis.scripts - Return all scripts create by Rafidelis(RafiScripts)      #
#------------------------------------------------------------------------------#
  def self.scripts
    print $RafiScripts
  end
#=================================================  =============================#
# Rafidelis.create_txt - Create a .txt with all Rafidelis(RafiScripts) scripts #
#------------------------------------------------------------------------------#
  def self.create_txt(filename="RafideliScripts")
    file = File.open("#{filename}.txt","wb")
    for i in 0...$RafiScripts.size
      file.write("#{$RafiScripts[i]}\r\n")
    end
  end
  #=================================================  ===========================#
  # (***) Modulo de Opзхes para o Script de Equipamento na Tela.               #
  #=================================================  ===========================#
  module MapEquip
    # Adding the Script at the System. Don't Modify
    name = "Equipaments in Map Screen"
    version = "1.0"
    Rafidelis.add_script(name,version)
    # Script add at the System
    
    # Mode = use "V" -> Vertical or "H" -> Horizontal
    Mode = "V"
    # Background Picture,if you do not use leave the name in ".
    BackGround_Image = "Equip_Back"
    # Show equipaments informations ? -> Attack and Defense.
    Display_Equip_Info = true
    # Terms to be displayed before the attack power and defense power.
    Terms = ["Атк : ","Зщт : "]
    # Text Displayed when the equipament slot is empty.
    No_Equip_Text = "Пусто"
    # Horizontal position of Equipment. Default -> - 10
    Window_X = -10
    # Vertical position of Equipment. Default -> - 10
    Window_Y = 50
    # Opacity of the window,recommended leave 0
    Window_Opacity = 0
    # Use the keyboard to Show / Hide the equipments?
    Use_Input = true
    # If Use_Input = true set down the key to be used.
    # Set according the RPGMaker Default.See down some keys.
    # "Key in RPGMaker" -> the original keyboard key.
    # "A" -> Z : "Y" -> S : "Z" -> D : "X" - A : "L" -> Q : "R" -> W
    Key = "X"
    # If Use_Input = false, set down the ID of a switch to control
    # Display of the Equipment on the screen.
    Control_Switch_ID = 1
  end
end
#=================================================  =============================#
# [** $RafiScripts.conf_start ] \\ Inicio das Configuraзхes                    #
#------------------------------------------------------------------------------#
# Verificando se o script esta incluso no sistema                              #
#=================================================  =============================#
name = "Equipaments in Map Screen"
version = "1.0"
if Rafidelis.script_exist?(name,version)
#=================================================  =============================#
# [** Window_Equipment **]                                                     #
#------------------------------------------------------------------------------#
#  (*) Esta Janela exibe os equipamentos do personagem principal no Mapa.      #
#=================================================  =============================#
class Window_Equipament < Window_Base
  include Rafidelis::MapEquip
  #=================================================  ===========================#
  # (*) -> Inicializaзгo do objeto                                             #
  #----------------------------------------------------------------------------#
  def initialize
    dim = get_dimensions
    super(Window_X,Window_Y,dim[0],dim[1])
    self.opacity = Window_Opacity
    self.contents.font.bold = true
    refresh
  end
  #=================================================  ===========================#
  # (*) -> Pegar as Dimensхes de Altura e Largura da Janela.                   #
  #----------------------------------------------------------------------------#
  def get_dimensions
    @mode = Mode
    @bitmap = Cache.picture(BackGround_Image)
    @equips = $game_party.members[0].equips
    case @mode
    when "H"
      width = (@equips.size * @bitmap.width) + 32
      height = @bitmap.height + 32
    when "V"
      width = @bitmap.width + 32
      height = (@equips.size * @bitmap.height) + 32
    end
    return [width,height]
  end
  #=================================================  ===========================#
  # (*) Refresh                                                                #
  #----------------------------------------------------------------------------#
  def refresh
    self.contents.clear
    bw = @bitmap.width; bh = @bitmap.height
    for i in 0...@equips.size
      if @mode == "H"
        x = i * bw
        y = 0
        tx = 5 + x
      else
        x = 0
        y = i * bh
        tx = 5 + x
      end
      self.contents.blt(x,y,@bitmap,@bitmap.rect)
      if @equips[i].nil?
        tw = contents.text_size(No_Equip_Text).width
        self.contents.font.size = 15
        self.contents.draw_text(tx,y,self.width,32,No_Equi  p_Text)
      else
        draw_equip_icon(@equips[i],x + 8,y + 5,Display_Equip_Info)
      end
    end
  end
  #=================================================  ===========================#
  # (*) Mostrar os Icones dos Equipamentos                                     #
  # item  :equipamento a ser exibido,pode ser tanto uma Arma ou Armadura.      #
  # x : Posiзгo x do Icone | y : Posiзгo Y do Icone                            #
  # show_text : Exibir as Informaзхes de Ataque e Defesa do Equipamento.       #
  #----------------------------------------------------------------------------#
  def draw_equip_icon(item, x, y,show_text=false)
    draw_icon(item.icon_index,x,y)
    if item != nil
      self.contents.font.size = 11
      atk = Terms[0]
      defense = Terms[1]
      tw = contents.text_size(atk).width
      tw2 = contents.text_size(defense).width
      x = x - 6
      y = y + 12
      if show_text
        if item.is_a?(RPG::Armor)
          self.contents.font.color = text_color(2)
          self.contents.draw_text(x, y,@bitmap.width,32,defense)
          self.contents.font.color = normal_color
          self.contents.draw_text(tw2 + x, y,@bitmap.width,32,"#{item.def}")
        elsif item.is_a?(RPG::Weapon)
          self.contents.font.color = text_color(2)
          self.contents.draw_text(x, y,@bitmap.width, 32,atk)
          self.contents.font.color = normal_color
          self.contents.draw_text(tw + x, y,@bitmap.width, 32,"#{item.atk}")
        end
      end
    end
  end
  #=================================================  ===========================#
  # (*) Atualizaзгo | (*) Update                                               #
  #----------------------------------------------------------------------------#
  def update
    if Use_Input
      if Input.trigger?(eval("Input::#{Key}"))
        if self.visible
          self.visible = false
        else
          self.visible = true
        end
      end
    elsif not Use_Input
      self.visible = $game_switches[Control_Switch_ID]
    end
    actor = $game_party.members[0]
    for i in 0...@equips.size
      if @equips[i] != actor.equips[i]
        @equips = $game_party.members[0].equips
        refresh if self.visible
      end
    end
  end
end
#=================================================  =============================#
# Scene_Map                                                                    #
#------------------------------------------------------------------------------#
# Classe das operaзхes nos mapas.                                              #
#=================================================  =============================#
class Scene_Map < Scene_Base
  include Rafidelis::MapEquip
  #=================================================  ===========================#
  # (*) -> Aliase                                                              #
  #----------------------------------------------------------------------------#
  alias :rafidelis_mapequip_start      :start
  alias :rafidelis_mapequip_update     :update
  alias :rafidelis_mapequip_terminate  :terminate
  #=================================================  ===========================#
  # (*) -> Inicializaзгo do processo                                           #
  #----------------------------------------------------------------------------#
  def start
    @equip_window = Window_Equipament.new
    $game_switches[Rafidelis::MapEquip::Control_Switch_ID] = true
    rafidelis_mapequip_start
  end
  #=================================================  ===========================#
  # (*) -> Atualizaзгo do processo                                             #
  #----------------------------------------------------------------------------#  
  def update
    @equip_window.update
    rafidelis_mapequip_update
  end
  #=================================================  ===========================#
  # (*) -> Termininaзгo do processo                                            #
  #----------------------------------------------------------------------------#
  def terminate
     @equip_window.dispose
     rafidelis_mapequip_terminate
   end
end
# Fim da Verificaзгo do Script no Sistema
end
#=================================================  =============================#
# [** $RafiScripts.script_end] // Fim do Script - Script End                   #
#------------------------------------------------------------------------------#
# Vocк pode encontrar mais scripts meus em 
http://www.ReinoRPG.com             #
# You can find more scripts create for me at 
http://www.ReinoRPG.com           #
#=================================================  =============================#