#==============================================================================
# ■ New_Battle_Arrow vol.3.10
#------------------------------------------------------------------------------
# アローの画像/点滅/表示位置/透明度/色調の変更
# 13/06/01
#==============================================================================
module New_Battle_Arrow
  # ■New_Battle_Arrowを使用する[true/false]
  ARROW = true
  # ■ターゲット選択時にブレンドする色
  Y_COLOR = Color.new(0,0,0,0)
  # ■ターゲット非選択時にブレンドする色
  N_COLOR = Color.new(0,0,0,150)
  # ■ターゲット非選択時のターゲット画像透明度
  OPACITY = 200
  # ■アロー画像
  ARROW = "cursor_anim"
  # ■アローのX位置補正
  PX = -32
  # ■アローのY位置補正
  PY = 0
  # ■アローのZ位置補正(カーソルが下位に表示される場合は大きな数値を代入)
  PZ = 3000
  # ■アニメーションループ(配列数=2以上)
  ACT_ANIM = [2,3,4,3,2,1,0,1]
  # ■アニメーション速度(1以上)※大=遅い
  ACT_SPEED = 2
  # ■1アニメ画像の幅
  WIDTH = 32
  # ■1アニメ画像の高さ
  HEIGHT = 32
end
#==============================================================================
# ■ Game_Battler
#==============================================================================
if New_Battle_Arrow::ARROW
class Game_Battler
  #--------------------------------------------------------------------------
  # ■ 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :sprite                   # sprite保管
  attr_accessor :black_bitmap             # 非選択画像保管
  attr_accessor :normal_bitmap            # 通常画像保管
  attr_accessor :arrow_target             # アローカーソル選択中フラグ
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  if !$@;alias new_arrow_target_initialize initialize;end
  def initialize
    @spritet = nil
    @black_bitmap = nil
    @normal_bitmap = nil
    @arrow_target = false
    
    # □元の処理を呼び出し
    new_arrow_target_initialize
  end
  #--------------------------------------------------------------------------
  # ■ バトラー画像幅を取得
  #--------------------------------------------------------------------------
  def g_width
    pic = RPG::Cache.battler(@battler_name,@battler_hue)
    return @pic.width
  end
  #--------------------------------------------------------------------------
  # ■ バトラー画像高さを取得
  #--------------------------------------------------------------------------
  def g_height
    pic = RPG::Cache.battler(@battler_name,@battler_hue)
    return pic.height
  end
end
#==============================================================================
# ■ Sprite_Battler < RPG::Sprite
#==============================================================================
class Sprite_Battler < RPG::Sprite
  #--------------------------------------------------------------------------
  # ■ フレーム更新
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_arrow_target update;end
  def update
    # □バトラー画像を作成
    if @battler.is_a?(Game_Enemy) or @battler.is_a?(Game_Actor)
      if (@battler.battler_name == @battler_name && @battler.battler_name != @battler_arrow_name) or 
        (@battler.battler_hue == @battler_hue && @battler.battler_hue != @battler_arrow_hue)
        @battler_arrow_name = @battler.battler_name
        @battler_arrow_hue = @battler.battler_hue
        make_bitmap?(self.bitmap)
      end
    end
    # □元の処理を呼び出し
    hidesp_arrow_target
  end
  #--------------------------------------------------------------------------
  # ■ バトラー画像を作成
  #--------------------------------------------------------------------------
  def make_bitmap?(bitmap)
    @battler.sprite = self
    @battler.normal_bitmap = bitmap
    if @battler.black_bitmap != nil
      @battler.black_bitmap.dispose
    end
    # □Bitmapを作成
    @battler.black_bitmap = Bitmap.new(bitmap.width,bitmap.height)
    @battler.black_bitmap.blt(0,0,bitmap,Rect.new(0,0,bitmap.width,bitmap.height),New_Battle_Arrow::OPACITY)
    @battler.sprite.bitmap = @battler.normal_bitmap
  end
  #--------------------------------------------------------------------------
  # ■ ウィンドウの削除
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_arrow_dispose dispose;end
  def dispose
    unless @black_bitmap.nil? or @black_bitmap.disposed?
      @black_bitmap.dispose
      @black_bitmap = nil
    end
    unless @normal_bitmap.nil? or @normal_bitmap.disposed?
      @normal_bitmap.dispose
      @normal_bitmap = nil
    end
    if @battler != nil
      @battler.sprite = nil
      @battler.normal_bitmap = nil
      @battler.black_bitmap = nil
    end
    # □セーブバグを修正
    $game_party.actors.each{|a| a.sprite = nil}
    $game_party.actors.each{|a| a.black_bitmap = nil}
    $game_party.actors.each{|a| a.normal_bitmap = nil}
    # □元の処理を呼び出し
    hidesp_arrow_dispose
  end
end
#==============================================================================
# ■ Arrow_Base
#==============================================================================
class Arrow_Base < Sprite
  include New_Battle_Arrow
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化(再定義)
  #--------------------------------------------------------------------------
  def initialize(viewport)
    super(viewport)
    self.z += New_Battle_Arrow::PZ
    #………………………………………………………………………………………………………
    # ■アロー画像を設定
    #………………………………………………………………………………………………………
    self.bitmap = RPG::Cache.windowskin(New_Battle_Arrow::ARROW)
    #………………………………………………………………………………………………………
    # ■アローの基本位置の設定
    #………………………………………………………………………………………………………
    self.src_rect.set(0,0,New_Battle_Arrow::WIDTH,New_Battle_Arrow::HEIGHT)
    @blink_count = 0
    @index = 0
    @help_window = nil
    @bcsr_animas = New_Battle_Arrow::ACT_ANIM
    @bcsr_speed = New_Battle_Arrow::ACT_SPEED
    @bcsr_count = 0
    update
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新(再定義)
  #--------------------------------------------------------------------------
  def update
    @cbp == nil ? @cbp = 0 : 
    # □カーソル移動中は点滅カウントを停止
    if Input.repeat?(Input::RIGHT) or Input.repeat?(Input::LEFT)
      self.opacity = 255
      @blink_count = 100
    # □点滅カウントを更新
    else
      self.src_rect.x = @bcsr_animas[@bcsr_count/@bcsr_speed]*New_Battle_Arrow::WIDTH
      @bcsr_count += 1
      if @bcsr_count == @bcsr_animas.size*@bcsr_speed
        @bcsr_count = 0
      end
    end
    # □ヘルプテキストを更新 (update_help は継承先で定義される)
    if @help_window != nil
      update_help
    end
  end
end
#==============================================================================
# ■ Arrow_Actor
#==============================================================================
class Arrow_Actor < Arrow_Base
  #--------------------------------------------------------------------------
  # ■ フレーム更新(再定義)
  #--------------------------------------------------------------------------
  def update
    super
    # カーソル右
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      @index += 1
      @index %= $game_party.actors.size
    end
    # カーソル左
    if Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      @index += $game_party.actors.size - 1
      @index %= $game_party.actors.size
    end
    #………………………………………………………………………………………………………
    # ■スプライトの座標を設定(処理の軽量化)
    #………………………………………………………………………………………………………
    if self.actor != nil
      x = self.x
      y = self.y
      # □アクター画像のサイズを取得(アロー中心表示の補正)
      x = self.actor.screen_x + New_Battle_Arrow::PX - (self.src_rect.width/2)
      y = self.actor.screen_y + New_Battle_Arrow::PY - (self.actor.g_height/2) - (self.src_rect.height/2)
      if x != self.x or y != self.y
        self.x = x
        self.y = y
        Graphics.update
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ カーソルが指しているアクターの取得
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_arrow_target_actor actor;end
  def actor
    # □アクターを取得
    actor = $game_party.actors[@index]
    if actor != nil
      $game_party.actors.each{|a| a.arrow_target = false}
      actor.arrow_target = true
      if actor.arrow_target
        if @a_ndex != @index
          $game_party.actors.each{|a| a.sprite.bitmap = a.black_bitmap}
          actor.sprite.bitmap = actor.normal_bitmap
          $game_party.actors.each{|a| a.sprite.color = New_Battle_Arrow::N_COLOR}
          actor.sprite.color = New_Battle_Arrow::Y_COLOR
        end
      end
    end
    @a_ndex = @index
    # □元の処理を呼び出し
    hidesp_arrow_target_actor
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの削除
  #--------------------------------------------------------------------------
  def dispose
    $game_party.actors.each{|a| a.arrow_target = false}
    $game_party.actors.each{|a| a.sprite.bitmap = a.normal_bitmap}
    $game_party.actors.each{|a| a.sprite.color = Color.new(0,0,0,0)}
    # □元の処理を呼び出し
    super
  end
end
#==============================================================================
# ■ Arrow_Enemy
#==============================================================================
class Arrow_Enemy < Arrow_Base
  #--------------------------------------------------------------------------
  # ■ フレーム更新(再定義)
  #--------------------------------------------------------------------------
  def update
    super
    # 存在しないエネミーを指していたら飛ばす
    $game_troop.enemies.size.times do
      break if self.enemy.exist?
      @index += 1
      @index %= $game_troop.enemies.size
    end
    # カーソル右
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      $game_troop.enemies.size.times do
        @index += 1
        @index %= $game_troop.enemies.size
        break if self.enemy.exist?
      end
    end
    # カーソル左
    if Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      $game_troop.enemies.size.times do
        @index += $game_troop.enemies.size - 1
        @index %= $game_troop.enemies.size
        break if self.enemy.exist?
      end
    end
    #………………………………………………………………………………………………………
    # ■スプライトの座標を設定(処理の軽量化)
    #………………………………………………………………………………………………………
    if self.enemy != nil
      x = self.x
      y = self.y
      # □エネミー画像のサイズを取得(アロー中心表示の補正)
      x = self.enemy.screen_x + New_Battle_Arrow::PX - (self.src_rect.width/2)
      y = self.enemy.screen_y + New_Battle_Arrow::PY - (self.enemy.g_height/2) - (self.src_rect.height/2)
      if x != self.x or y != self.y
        self.x = x
        self.y = y
        Graphics.update
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ カーソルが指しているエネミーの取得
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_arrow_target_enemy enemy;end
  def enemy
    # □エネミーを取得
    enemy = $game_troop.enemies[@index]
    if enemy != nil
      $game_troop.enemies.each{|a| a.arrow_target = false}
      enemy.arrow_target = true
      if enemy.arrow_target
        if @e_ndex != @index
          $game_troop.enemies.each{|a| a.sprite.bitmap = a.black_bitmap}
          enemy.sprite.bitmap = enemy.normal_bitmap
          $game_troop.enemies.each{|a| a.sprite.color = New_Battle_Arrow::N_COLOR}
          enemy.sprite.color = New_Battle_Arrow::Y_COLOR
        end
      end
    end
    @e_ndex = @index
    # □元の処理を呼び出し
    hidesp_arrow_target_enemy
  end
  #--------------------------------------------------------------------------
  # ■ ウィンドウの削除
  #--------------------------------------------------------------------------
  def dispose
    $game_troop.enemies.each{|a| a.arrow_target = false}
    $game_troop.enemies.each{|a| a.sprite.bitmap = a.normal_bitmap}
    $game_troop.enemies.each{|a| a.sprite.color = Color.new(0,0,0,0)}
    # □元の処理を呼び出し
    super
  end
end
#
end