#==============================================================================
# ■2nd_Cursor_Icon_plus vol.3.00
#------------------------------------------------------------------------------
# ※include HIDESP_CSR2ND を追加したウィンドウのみ
# 07/9/07
#==============================================================================
module HIDESP_CSR2ND
  # ■デフォルトカーソルを使う[true/false]
  DEFAULT_CURSOR = true
  # ■『Cursor_Icon_type2』を使う[true/false]
  CURSOR_ICON2 = false
  # ■『Cursor_Icon_type3』を使う[true/false]
  CURSOR_ICON3 = false
  # ※CURSOR_ICON2/CURSOR_ICON3はどちらか１つ
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @csr2nd_set = false
    @index2 = -1
  end
  #--------------------------------------------------------------------------
  # ■ ウィンドウの更新
  #--------------------------------------------------------------------------
  def update
    if self.contents != nil && @csr2nd == nil
      if self.index2 >= 0
        #…………………………………………………………………………………………………
        # ■第2カーソルウィンドウを作成
        #…………………………………………………………………………………………………
        @csr2nd = Sprite.new(Viewport.new(self.x+16,self.y+16,self.width-32,self.height-32))
        @csr2nd.viewport.z = self.z
        @csr2nd.bitmap = Bitmap.new(self.contents.width,self.contents.height)
        #…………………………………………………………………………………………………
        # ■第2カーソルアイコンを作成(CURSOR_ICON2)
        #…………………………………………………………………………………………………
        if HIDESP_CSR2ND::CURSOR_ICON2
          @csr2nd_icon = Sprite.new(Viewport.new(self.x,self.y+16,self.width-16,self.height-32))
          @csr2nd_icon.viewport.z = self.z + 2
          @csr2nd_icon.bitmap = Bitmap.new(self.contents.width,self.contents.height)
        end
        #…………………………………………………………………………………………………
        # ■第2カーソルアイコンを作成(CURSOR_ICON3)
        #…………………………………………………………………………………………………
        if HIDESP_CSR2ND::CURSOR_ICON3
          vx = self.x + self.cursor_rect.x + self.ox
          vy = self.y + 16 + self.cursor_rect.y + self.oy
          @csr2nd_icon = Sprite.new(Viewport.new(vx,vy,32,32))
          @csr2nd_icon.viewport.z = self.z + 2
          @csr2nd_icon.viewport.oy = 32
          # XY座標を格納
          @csr2nd_icon3y = @csr2nd_icon.viewport.rect.y
          @csr2nd_icon3x = @csr2nd_icon.viewport.rect.x
          ##@csr2nd_icon.viewport.color = Color.new(255,255,255,50)
          @csr2nd_icon.bitmap = @csr3_icon.bitmap
        end
      end
    elsif self.contents != nil
      if @csr2nd.bitmap != nil
        #…………………………………………………………………………………………………
        # ■カーソルindex2で分岐
        #…………………………………………………………………………………………………
        if self.index2 < 0 && @csr2nd_set
          # □カーソルの開放
          @csr2nd_set = false
          dispose_csr2nd
          return
        elsif self.index2 >= 0 && @csr2nd_set == false
          # □途中でzを変更している場合の不具合を解消
          @csr2nd.viewport.z = self.z
          x = self.cursor_rect.x + self.ox
          y = self.cursor_rect.y + self.oy
          w = self.cursor_rect.width
          h = self.cursor_rect.height
          #…………………………………………………………………………………………………
          # ■第2カーソルアイコンを描画(CURSOR_ICON2)
          #…………………………………………………………………………………………………
          if HIDESP_CSR2ND::DEFAULT_CURSOR
            # □カーソル画像の切り出し(x,y,(w&h),opacity)
            skin = RPG::Cache.windowskin($game_system.windowskin_name)
            wsx,wsy,wwh,opa = 128,64,32,160
            # □カーソル画像の引き伸ばし描画（真中、左、右、上、下）
            @csr2nd.bitmap.stretch_blt(Rect.new(x+2,y+2,w-4,h-4),skin,Rect.new(wsx+2,wsy+2,wwh-4,wwh-4),opa)
            @csr2nd.bitmap.stretch_blt(Rect.new(x,y+2,2,h-4),skin,Rect.new(wsx,wsy+2,2,wwh-4),opa)
            @csr2nd.bitmap.stretch_blt(Rect.new(x+w-2,y+2,2,h-4),skin,Rect.new(wsx+wwh-2,wsy+2,2,wwh-4),opa)
            @csr2nd.bitmap.stretch_blt(Rect.new(x+2,y,w-4,2),skin,Rect.new(wsx+2,wsy,wwh-4,2),opa)
            @csr2nd.bitmap.stretch_blt(Rect.new(x+2,y+h-2,w-4,2),skin,Rect.new(wsx+2,wsy+wwh-2,wwh-4,2),opa)
            # □カーソル画像の描画（左上、右上、左下、右下）
            @csr2nd.bitmap.blt(x,y,skin,Rect.new(wsx,wsy,2,2),opa)
            @csr2nd.bitmap.blt(x+w-2,y,skin,Rect.new(wsx+wwh-2,wsy,2,2),opa)
            @csr2nd.bitmap.blt(x,y+h-2,skin,Rect.new(wsx,wsy+wwh-2,2,2),opa)
            @csr2nd.bitmap.blt(x+w-2,y+h-2,skin,Rect.new(wsx+wwh-2,wsy+wwh-2,2,2),opa)
          end
          #…………………………………………………………………………………………………
          # ■第2カーソルアイコンを描画(CURSOR_ICON2)
          #…………………………………………………………………………………………………
          if HIDESP_CSR2ND::CURSOR_ICON2
            @csr2nd_icon.viewport.z = self.z + 2
            @csr2nd_icon.bitmap.blt(x,y,@csr2pic,Rect.new(0,0,@csr2pic.width,@csr2pic.height))
            @csr2nd_icon.color = @csr2_negcolor
          end
          @csr2nd_set = true
        end
      end
    end
    super
    #…………………………………………………………………………………………………
    # ■カーソル位置の更新
    #…………………………………………………………………………………………………
    if @csr2nd != nil
      @csr2nd.oy = self.oy
      if HIDESP_CSR2ND::CURSOR_ICON2
        @csr2nd_icon.oy = self.oy
        @csr2nd_icon.ox = self.ox
      end
    end
    #…………………………………………………………………………………………………
    # ■カーソルアニメの開始(CURSOR_ICON3)
    #…………………………………………………………………………………………………
    if HIDESP_CSR2ND::CURSOR_ICON3
      if @csr2nd_icon != nil
        # □アニメーションの更新
        @csr2nd_icon.viewport.ox = @csr3_animas[@csr3_count/@csr3_speed]*32
        # □カーソル位置の更新
        @csr2nd_icon.viewport.rect.x = @csr2nd_icon3x - self.ox
        @csr2nd_icon.viewport.rect.y = @csr2nd_icon3y - self.oy
        # □カーソル位置がウィンドウ外の場合は、非表示
        @csr2nd_icon.viewport.visible = @csr2nd_icon.viewport.rect.x > self.x && 
        @csr2nd_icon.viewport.visible = @csr2nd_icon.viewport.rect.x < self.x + self.width-32
        @csr2nd_icon.viewport.visible = @csr2nd_icon.viewport.rect.y > self.y && 
        @csr2nd_icon.viewport.visible = @csr2nd_icon.viewport.rect.y < self.y + self.height-32
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ ウィンドウの可視状態
  #--------------------------------------------------------------------------
  def visible=(visible)
    super
    if @csr2nd != nil
      @csr2nd.visible = visible
      if HIDESP_CSR2ND::CURSOR_ICON2 or HIDESP_CSR2ND::CURSOR_ICON3
        @csr2nd_icon.visible = visible
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ カーソルの開放
  #--------------------------------------------------------------------------
  def dispose_csr2nd
    if @csr2nd != nil
      if @csr2nd.bitmap != nil
        @csr2nd.bitmap.dispose
        @csr2nd.bitmap = nil
      end
      @csr2nd.viewport.dispose
      @csr2nd.dispose
      @csr2nd = nil
      if HIDESP_CSR2ND::CURSOR_ICON2 or HIDESP_CSR2ND::CURSOR_ICON3
        if HIDESP_CSR2ND::CURSOR_ICON2 && @csr2nd_icon.bitmap != nil
          @csr2nd_icon.bitmap.dispose
          @csr2nd_icon.bitmap = nil
        end
        @csr2nd_icon.viewport.dispose
        @csr2nd_icon.dispose
        @csr2nd_icon = nil
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ ウィンドウの削除
  #--------------------------------------------------------------------------
  def dispose
    super
    dispose_csr2nd
  end
end
#==============================================================================
# ■ Window_Selectable < Window_Base
#==============================================================================
class Window_Selectable < Window_Base
  #--------------------------------------------------------------------------
  # ■ index2を追加
  #--------------------------------------------------------------------------
  attr_reader   :index2
  def index2=(index2)
    @index2 = index2
  end
end
