#==============================================================================
# ■ HIDE_MESSAGE vol.2.52β版(分割定義2)
#------------------------------------------------------------------------------
# ※『Window_digits_number 5.40以上』必須
# 11/09/25
#==============================================================================
module HIDE_MESSAGE
  #…………………………………………………………………………………………………
  # ■点滅文字選択を使用する(Blink_Window 3.00以上必須)
  #…………………………………………………………………………………………………
  BLINK_WINDOW = true
  #…………………………………………………………………………………………………
  # ■メッセージの基本色/基本影色/システム色/選択肢と数値入力時のカーソル色
  #…………………………………………………………………………………………………
  Message_Color = Color.new(255,255,255,255)
  System_Color = Color.new(192, 224, 255, 255)
  Shadow_Color = Color.new(0,0,0,255)
  Blink_Color = Color.new(255,255,0,255)
  #…………………………………………………………………………………………………
  # ■ウィンドウ背景画像(Windowskinsフォルダ内のファイル名を指定)
  #…………………………………………………………………………………………………
  BACK_NAME = "message"
  #…………………………………………………………………………………………………
  # ■テール画像(Windowskinsフォルダ内のファイル名を指定)
  #…………………………………………………………………………………………………
  TAIL_NAME = "window_tail"
  #…………………………………………………………………………………………………
  # ■所持金増減SE(SEフォルダ内のファイル名orRTPのSE名を指定)
  #…………………………………………………………………………………………………
  GOLD_SE = "se_gold"#"006-System06"
  #…………………………………………………………………………………………………
  # ■特殊メッセージ(分割定義1)を使用する[true/false]
  #…………………………………………………………………………………………………
  Word_end = true
  #--------------------------------------------------------------------------
  # ■ メッセージウィンドウのサイズを取得するクラス
  #--------------------------------------------------------------------------
  class Make_Window
    #--------------------------------------------------------------------------
    # ■ 公開インスタンス変数　※イベントスクリプト初期設定不可
    #--------------------------------------------------------------------------
    attr_accessor :id             # 指定されたイベントID
    attr_accessor :event_id       # ※メッセージを表示するイベントIDを格納
    attr_accessor :x              # ウィンドウのX座標
    attr_accessor :y              # ウィンドウのY座標
    attr_accessor :z              # ウィンドウのZ座標
    attr_accessor :width          # ウィンドウの幅
    attr_accessor :height         # ウィンドウの高さ
    attr_accessor :opacity        # ウィンドウの透明度
    attr_accessor :number         # ※描画した順番
    attr_accessor :cx             # ※ウィンドウの補正X
    attr_accessor :cy             # ※ウィンドウの補正Y
    attr_accessor :tail_x         # ※テール画像のパターン切り出し位置(X座標)
    attr_accessor :tail_width     # ※テール画像のパターン切り出し幅
    attr_accessor :sx             # ※基本となるX座標(ウィンドウX座標との差分)
    attr_accessor :sy             # ※基本となるY座標(ウィンドウY座標との差分)
    attr_accessor :skip           # キー入力をスキップするフラグ
    attr_accessor :skip_count     # キー入力をスキップするまでの待ち時間
    attr_accessor :break_count    # コピーウィンドウを解放するまでの待ち時間
    attr_accessor :scroll         # コピーウィンドウのイベント追従フラグ
    attr_accessor :top            # ウィンドウを上に固定するフラグ(下向きテール)
    attr_accessor :under          # ウィンドウを下に固定するフラグ(上向きテール)
    attr_accessor :center         # ウィンドウとテールを中央に固定するフラグ
    attr_accessor :tail           # テールを表示するフラグ
    attr_accessor :copy           # ウィンドウをコピーするフラグ
    attr_accessor :visible        # コピーウィンドウを表示するフラグ
    attr_accessor :text           # ※格納するメッセージ情報
    attr_accessor :digits         # ※格納する数値入力情報
    attr_accessor :dx             # ※数値入力の値を描画するX座標
    attr_accessor :dy             # ※数値入力の値を描画するY座標
    attr_accessor :back_name      # ウィンドウ背景画像
    attr_accessor :tail_name      # テール画像
    attr_accessor :rect_x         # ※ウィンドウ画像を切り取るX座標
    attr_accessor :rect_y         # ※ウィンドウ画像を切り取るY座標
    
    attr_accessor :text_widths    # ※各行の文字幅
    attr_accessor :text_aligns    # ※各行の文字描画X揃え(0=左,1=中央,2=右)
    attr_accessor :pause          # ポーズサインの表示位置(nil=非表示,0=左,1=中央,2=右)
    #--------------------------------------------------------------------------
    # ■ オブジェクト初期化
    #--------------------------------------------------------------------------
    def initialize(id = nil,event_id = nil,x = nil,y = nil,z = 0,w = nil,h = nil,
      opa = 255,number = 0,cx = 0,cy = 0,tail_x = 0,tail_width = 0,sx = nil,sy = 0,
      skip = false,skip_count = nil,break_count = nil,scroll = true,
      top = false,under = false,center = false,tail = true,copy = false,
      visible = true,text = "",digits = [],dx = 0,dy = 0,
      back_name = BACK_NAME,tail_name = TAIL_NAME,rect_x = 0,rect_y = 0,
      text_widths = [],text_aligns = [],pause = 2)
      
      @id = id
      @event_id = event_id
      @x = x
      @y = y
      @z = z
      @width = w
      @height = h
      @opacity = opa
      @number = number
      @cx = cx
      @cy = cy
      @tail_x = tail_x
      @tail_width = tail_width
      @sx = sx
      @sy = sy
      @skip = skip
      @skip_count = skip_count
      @break_count = break_count
      @scroll = scroll
      @top = top
      @under = under
      @center = center
      @tail = tail
      @copy = copy
      @visible = visible
      @text = text
      @digits = digits
      @dx = dx
      @dy = dy
      @back_name = back_name
      @tail_name = tail_name
      @rect_x = rect_x
      @rect_y = rect_y
      @text_widths = text_widths
      @text_aligns = text_aligns
      @pause = pause
    end
  end
  #--------------------------------------------------------------------------
  # ■ メッセージウィンドウの補助ウィンドウを格納するクラス
  #--------------------------------------------------------------------------
  class Make_Other_Window
    #--------------------------------------------------------------------------
    # ■ 公開インスタンス変数　※イベントスクリプト初期設定不可
    #--------------------------------------------------------------------------
    attr_accessor :key            # ※関連付けるコピーウィンドウの配列番号を格納
    attr_accessor :gold           # ※ゴールドウィンドウの関連付け
    attr_accessor :money          # ※所持金を格納
    attr_accessor :digits         # ※所持金の変動Window配列を格納
    def initialize(key = 0,gold = nil,money = 0,money_se = [],digits = nil)
      @key = key
      @gold = gold
      @money = money
      @digits = digits
    end
  end
  #--------------------------------------------------------------------------
  # ■ 全てのコピーウィンドウを解放
  #--------------------------------------------------------------------------
  def all_dispose?(user)
    if user != nil
      user.message_copies.each{ |a| if a != nil ; a.dispose ; end }
      user.message_copies = []
      user.message_viewport = nil
      # □その他のウィンドウを開放
      other_dispose?(user)
    end
  end
  #--------------------------------------------------------------------------
  # ■ (n)番のコピーウィンドウを解放
  #--------------------------------------------------------------------------
  def one_dispose?(message,type,n)
    user = return_event?(type[n].event_id,false)
    # □message_copies[n]を開放
    if message[n] != nil
      message[n].dispose
      message[n] = nil
    end
    # □message_copy_base[n]を初期化
    type[n] = nil
    # □関連付けられた、その他のウィンドウを開放
    if user.message_other.key == n
      other_dispose?(user)
    end
  end
  #--------------------------------------------------------------------------
  # ■ その他のウィンドウを開放
  #--------------------------------------------------------------------------
  def other_dispose?(user)
    if user.message_other.digits != nil
      user.message_other.digits.dispose
      user.message_other.digits = nil
    end
    if user.message_other.gold != nil
      if user.message_other.gold.bitmap != nil
        user.message_other.gold.bitmap.dispose
      end
      user.message_other.gold.dispose
      user.message_other.gold = nil
    end
    user.message_other.key = 0
  end
  #--------------------------------------------------------------------------
  # ■ イベントの種類を返す(eventがバトラーの場合=true)
  #--------------------------------------------------------------------------
  def event_type?(event)
    if event.is_a?(Game_Actor) or event.is_a?(Game_Enemy)
      return true
    else
      return false
    end
  end
  #--------------------------------------------------------------------------
  # ■ イベントを取得
  #--------------------------------------------------------------------------
  def return_event?(id = nil,tail = true)
    # □実行イベントIDを格納
    tail_id = id
    # □戦闘中の場合
    if $game_temp.in_battle
      id.scan(/([pt])([0-9]+)/)
      case $1
      when "p"
        event = $game_party.actors[$2.to_i - 1]
      when "t"
        event = $game_troop.enemies[$2.to_i - 1]
      end
    else
      case id
      when nil
        event = $game_map.events[@event_id]
        tail_id = @event_id
      when 0
        event = $game_player
      else
        event = $game_map.events[id]
      end
    end
    # □テールの位置を取得
    if tail
      $game_map.tail_id = tail_id
    end
    if event.nil?
      p "存在しないイベントIDを指定";error
    end
    return event
  end
  #--------------------------------------------------------------------------
  # ■ イベント画像を取得
  #--------------------------------------------------------------------------
  def image_height?(event)
    if event_type?(event)
      image = RPG::Cache.battler(event.battler_name,event.battler_hue)
      h = image.height - 32
    else
      image = RPG::Cache.character(event.character_name,event.character_hue)
      h = (image.height/4) - 32
    end
    return h
  end
  #--------------------------------------------------------------------------
  # ■ コピーウィンドウの更新
  #--------------------------------------------------------------------------
  def hidesp_message_scroll?(message,type,make = false)
    for i in 0...type.size
      #…………………………………………………………………………………………………
      # ■コピーメッセージの描画位置XYを更新
      #…………………………………………………………………………………………………
      if message[i] != nil && type[i] != nil
        # □表示の更新
        make_copy_window_set?(message[i],type[i])
        message[i].visible = type[i].visible
        #…………………………………………………………………………………………………
        # ■break_countが設定されている場合、カウント後にウィンドウを開放
        #…………………………………………………………………………………………………
        if type[i].break_count != nil
          if type[i].break_count > 0
            if Graphics.frame_count / Graphics.frame_rate != @break_sec
              type[i].break_count -= 1
            end
            @break_sec = Graphics.frame_count / Graphics.frame_rate
          else
            one_dispose?(message,type,i)
          end
        end
      #…………………………………………………………………………………………………
      # ■コピーメッセージの再構築
      #…………………………………………………………………………………………………
      elsif message[i] == nil && type[i] != nil && make
        event = return_event?(type[i].event_id,false)
        # □ウィンドウの再構築
        window = make_window_back?(event,true,type[i])
        copy = Sprite_Copy_Window.new(event.message_viewport,window)
        copy.visible = type[i].visible
        # □テキストの描画
        text = type[i].text.dup
        make_draw_text?(text,copy,nil,type[i])
        # □数値入力の描画
        make_copy_digits?(window,type[i].digits,type[i].dx,type[i].dy)
        event.message_copies[i] = copy
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ コピーウィンドウに数値入力の値を描画
  #--------------------------------------------------------------------------
  def make_copy_digits?(window,digits,x,y)
    if digits != [] or digits != nil
      for d in digits
        window.font.color = HIDE_MESSAGE::Shadow_Color
        window.draw_text(x+1,y+1,window.width,32,d.to_s)
        window.font.color = HIDE_MESSAGE::Message_Color
        window.draw_text(x,y,window.width,32,d.to_s)
        x += window.text_size("0").width + 8
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ 数値を１桁の配列に変換
  #--------------------------------------------------------------------------
  def make_digits?(num,max = nil)
    if max == nil
      if num > 0
        max = (Math.log10(num).to_i) + 1
      else
        return [0]
      end
    end
    digits = []
    for i in 1..max
      digits.push(num/(10**(max-i)))
      num = num%(10**(max-i))
    end
    return digits
  end
  #--------------------------------------------------------------------------
  # ■ コピーウィンドウのXY座標の位置を取得
  #--------------------------------------------------------------------------
  def make_copy_window_set?(window,data)
    event = return_event?(data.event_id,false)
    #…………………………………………………………………………………………………
    # ■所持金の変動(回転ドラム)
    #…………………………………………………………………………………………………
    if event.message_other.digits != nil
      event.message_other.digits.update($game_party.gold,0,RPG::AudioFile.new(HIDE_MESSAGE::GOLD_SE))
    end
    #…………………………………………………………………………………………………
    # ■イベント追従フラグがOFFの場合、座標更新しない
    #…………………………………………………………………………………………………
    unless data.scroll
      window.x = data.x
      window.y = data.y
      window.z = 5000 + data.z + data.number
      return
    end
    #…………………………………………………………………………………………………
    # ■XY座標の基本値を取得
    #…………………………………………………………………………………………………
    x = event.screen_x - data.cx
    y = (event.screen_y - image_height?(event)) - (window.bitmap.height-32)
    #…………………………………………………………………………………………………
    # ■XY座標の手動設定補正
    #…………………………………………………………………………………………………
    # □XY座標を指定している場合
    if data.sx != nil
      x -= (data.sx - data.x)
    end
    if data.sy != nil
      y -= (data.sy - data.y)
    end
    window.x = x
    window.y = y
    window.z = 5000 + data.z + data.number
  end
  #--------------------------------------------------------------------------
  # ■ メッセージウィンドウ背景の作成
  #--------------------------------------------------------------------------
  def make_window_back?(event,make_copy = false,data = nil)
    if data.nil?
      data = event.message
    end
    x = data.x
    y = data.y
    z = 5000 + data.z
    width = data.width
    height = data.height
    #…………………………………………………………………………………………………
    # ■widthが最小値(96)の場合、背景画像の位置を補正
    #…………………………………………………………………………………………………
    @px = 0
    if width == 96
      @px = (96 - width)/2
    end
    #…………………………………………………………………………………………………
    # ■背景ウィンドウの作成
    #…………………………………………………………………………………………………
    @back = Sprite.new
    @back.bitmap = Bitmap.new(width+32,height+64)
    @back.x = x
    @back.y = y
    @back.z = z
    wy = 32
    cx = data.rect_x
    cy = data.rect_y
    #…………………………………………………………………………………………………
    # ■キー入力を待たない場合
    #…………………………………………………………………………………………………
    if data.skip
      @back.visible = false
    end
    #…………………………………………………………………………………………………
    # ■ウィンドウ背景と透明度の取得
    #…………………………………………………………………………………………………
    @back_opa = data.opacity
    pic = RPG::Cache.windowskin(data.back_name)
    tail = RPG::Cache.windowskin(data.tail_name)
    # □[左上]画像の描画
    rect = Rect.new(0,0,cx,height/2)
    @back.bitmap.blt(0,wy + 0, pic, rect,@back_opa)
    # □[右上]画像の描画
    rect = Rect.new(640-width+cx+32, 0,width,height/2)
    @back.bitmap.blt(cx+32,wy + 0, pic, rect,@back_opa)
    # □[左下]画像の描画
    rect = Rect.new(0, 224 - height/2,cx,height)
    @back.bitmap.blt(0,wy + height/2, pic, rect,@back_opa)
    # □[右下]画像の描画
    rect = Rect.new(640-width+cx+32,224 - height/2,width-cx-32,height)
    @back.bitmap.blt(cx+32,wy + height/2, pic, rect,@back_opa)
    #…………………………………………………………………………………………………
    # ■中央固定フラグがOFFの場合
    #…………………………………………………………………………………………………
    tx = 32 ; txw = 640-width+cx
    unless data.center
      # □[テール]位置とパターンの取得
      if event_type?(event)
        if event.screen_x <= 0
          tx = 0 ; txw = 0
        elsif event.screen_x > 640
          tx = 64 ; txw = 640-32
        end
      else
        case event.x
        when 0
          tx = 0 ; txw = 0
        when $game_map.width - 1
          tx = 64 ; txw = 640-32
        end
      end
    end
    #…………………………………………………………………………………………………
    # ■ウィンドウ再構築の場合、テールデータを代入
    #…………………………………………………………………………………………………
    if make_copy
      tx = data.tail_x
      txw = data.tail_width
    else
      $game_map.message_number += 1
      event.message.number = $game_map.message_number
      data.tail_x = tx
      data.tail_width = txw
    end
    #…………………………………………………………………………………………………
    # ■テール表示フラグがONの場合
    #…………………………………………………………………………………………………
    th = 0
    if data.tail
      # □[テール]画像の描画(0=上向きテール 32=下向きテール)
      case data.cy
      when 0,32
        ty = data.cy
      when 64 # □ウィンドウを下に描画(0=上向きテール)
        ty = 0
      when 96 # □ウィンドウを上に描画(32=下向きテール)
        ty = 32
      end
      rect = Rect.new(tx,ty,32,32)
      @back.bitmap.blt(cx,wy + height-8+cy,tail, rect,@back_opa)
      th = 8
    end
    # □[真中]画像の描画
    case data.cy
    when 32,96
      rect = Rect.new(txw,0,32,height/2)
      @back.bitmap.blt(cx,wy + 0, pic, rect,@back_opa)
      rect = Rect.new(txw,224-height/2,32,height/2-th)
      @back.bitmap.blt(cx,wy + height/2, pic, rect,@back_opa)
    when 0,64
      rect = Rect.new(txw,th,32,height/2-th)
      @back.bitmap.blt(cx,wy + th, pic, rect,@back_opa)
      rect = Rect.new(txw,224-height/2,32,height/2)
      @back.bitmap.blt(cx,wy + height/2, pic, rect,@back_opa)
    end
    #…………………………………………………………………………………………………
    # ■ウィンドウ再構築の場合、ウィンドウを返す
    #…………………………………………………………………………………………………
    if make_copy
      bitmap = @back.bitmap.dup
      @back.bitmap.dispose
      @back.dispose
      @back = nil
      return bitmap
    end
    #…………………………………………………………………………………………………
    # ■選択肢ウィンドウの作成
    #…………………………………………………………………………………………………
    if $game_temp.choice_max > 0
      # □点滅文字ウィンドウの作成
      if HIDE_MESSAGE::BLINK_WINDOW
        make_blink_window?(32,x,y,width,width,$game_temp.choice_max*32+32)
      end
      # カーソルの幅を取得
      @cursor_w = width-32
      #…………………………………………………………………………………………………
      # ■キー入力を待たない場合
      #…………………………………………………………………………………………………
      if data.skip && @blink_window != nil
        @blink_window.visible = false
      end
    end
    #…………………………………………………………………………………………………
    # ■数値入力の作成
    #…………………………………………………………………………………………………
    if $game_temp.num_input_variable_id > 0
      i_s = $game_temp.num_input_start
      i_max = $game_temp.num_input_digits_max
      i_num = $game_variables[$game_temp.num_input_variable_id]
      
      @copy_dx = x+22+2
      @copy_dy = y+32+i_s*32
      #…………………………………………………………………………………………………
      # ■数値入力の選択色を作成
      #…………………………………………………………………………………………………
      if BLINK_WINDOW
        @fonts = Copy_Font.new
        @fonts.color = HIDE_MESSAGE::Blink_Color
        @fonts.s_color = HIDE_MESSAGE::Shadow_Color
        @fonts.interval = 8
        @fonts.key = @fonts.cache_key?
        @blink_digits = Window_digits_number.new(x+22+2,y+32+i_s*32,@back.z+2,@digits[@digits.size],1,0,@fonts)
        #…………………………………………………………………………………………………
        # ■キー入力を待たない場合
        #…………………………………………………………………………………………………
        if data.skip
          @blink_digits.visible = false
        end
      end
      #…………………………………………………………………………………………………
      # ■数値入力の作成
      #…………………………………………………………………………………………………
      @fonts = Copy_Font.new
      @fonts.shadow = true
      @fonts.color = HIDE_MESSAGE::Message_Color
      @fonts.s_color = HIDE_MESSAGE::Shadow_Color
      @fonts.interval = 8
      @fonts.key = @fonts.cache_key?
      @digits_window = Window_digits_number.new(x+22+2,y+32+i_s*32,@back.z+1,i_num,i_max,0,@fonts)
    end
    #…………………………………………………………………………………………………
    # ■スキップカウントウィンドウの作成
    #…………………………………………………………………………………………………
    if data.skip_count != nil
      @fonts = Copy_Font.new
      @fonts.size = 14
      @fonts.name = ["Arial","MS Gothic","ＭＳ ゴシック"]
      @fonts.bold = true
      @fonts.shadow = true
      @fonts.color = HIDE_MESSAGE::Message_Color
      @fonts.s_color = HIDE_MESSAGE::Shadow_Color
      ds = data.skip_count.abs > 0 ? (Math.log10(data.skip_count.abs).to_i)+1 : 1
      case data.pause
      when 0 # 左に表示
        skx = data.x + 44
      when 1 # 中央に表示
        skx = data.x + data.width/2 + 12
      when 2 # 右に表示
        skx = data.x + data.width - 40 - ds*7
      end
      sky = y + (data.height)-16
      @count_window = Window_digits_number.new(skx,sky,@back.z+1,data.skip_count,ds,0,@fonts)
    end
  end
  #--------------------------------------------------------------------------
  # ■ テキスト描画X位置を取得(0=左揃え  1=中央揃え  2=右揃え)
  #--------------------------------------------------------------------------
  def text_align?(n,data,align = 0)
    # □コピーでない場合(data=nil)
    if data.nil?
      data = @event.message
    end
    if data.text_aligns[n] != nil
      case data.text_aligns[n]
      when 0
        align = 0
      when 1
        if data.width > data.text_widths.max
          align = (data.width/2) - (data.text_widths[n]/2)
        else
          align = (data.text_widths.max/2) - (data.text_widths[n]/2)
        end
      when 2
        if data.width > data.text_widths.max
          align = data.width - data.text_widths[n]
        else
          align = data.text_widths.max - data.text_widths[n]
        end
      end
    end
    return align
  end
  #--------------------------------------------------------------------------
  # ■ テキストの描画
  #--------------------------------------------------------------------------
  def make_draw_text?(text = "",back = nil,case_back = nil,data = nil)
    unless data.nil?
      @event = return_event?(data.event_id,false)
    end
    @back = back
    @blink_window = case_back
    # □色の設定
    @message_color = HIDE_MESSAGE::Message_Color
    x = text_align?(0,data)
    y = 0
    case_y = 0
    #…………………………………………………………………………………………………
    # ■c に 1 文字を取得 (文字が取得できなくなるまでループ)
    #…………………………………………………………………………………………………
    while ((c = text.slice!(/./m)) != nil)
      # \\ の場合
      if c == "\000"
        # 本来の文字に戻す
        c = "\\"
      end
      #…………………………………………………………………………………………………
      # ■文字色を変更『\C[n]』
      #…………………………………………………………………………………………………
      if c == "\001"
        text.sub!(/\[([0-9]+)\]/, "")
        color = $1.to_i
        if color >= 0 and color <= 7
          @message_color = text_color(color)
        end
        # 次の文字へ
        next
      end
      #…………………………………………………………………………………………………
      # ■ゴールドウィンドウを作成『\G』
      #…………………………………………………………………………………………………
      if c == "\002"
        #…………………………………………………………………………………………………
        # ■ゴールドウィンドウ背景の作成
        #…………………………………………………………………………………………………
        if @back != nil
          make_gold_back?(@event,data)
        end
        # 次の文字へ
        next
      end
      #…………………………………………………………………………………………………
      # ■改行文字の場合『\n』
      #…………………………………………………………………………………………………
      if c == "\n"
        # 選択肢ならカーソルの幅を更新
        if y >= $game_temp.choice_start
          @cursor_width = [@cursor_width, x].max
        end
        # y に 1 を加算
        y += 1
        x = text_align?(y,data)
        # □アイコン位置の補正を初期化
        icons_pos = 0
        case_y += 1
        # 次の文字へ
        next
      end
      #…………………………………………………………………………………………………
      # ■アイコン描画位置の取得
      #…………………………………………………………………………………………………
      draw_icons = false
      case c
      when "\003"
        text.sub!(/\[([0-9]+)\]/,"")
        icon = RPG::Cache.icon($data_items[$1.to_i].icon_name)
        draw_icons = true
      when "\004"
        text.sub!(/\[([0-9]+)\]/,"")
        icon = RPG::Cache.icon($data_weapons[$1.to_i].icon_name)
        draw_icons = true
      when "\005"
        text.sub!(/\[([0-9]+)\]/,"")
        icon = RPG::Cache.icon($data_armors[$1.to_i].icon_name)
        draw_icons = true
      when "\006"
        text.sub!(/\[([0-9]+)\]/,"")
        icon = RPG::Cache.icon($data_skills[$1.to_i].icon_name)
        draw_icons = true
      when "\007"
        text.sub!(/\[(.*?)\]/,"")
        icon = RPG::Cache.icon($1)
        draw_icons = true
      when "\010"
        text.sub!(/\[([0-9]+)\]/,"")
      end
      #…………………………………………………………………………………………………
      # ■メッセージウィンドウ背景に文字を描画
      #…………………………………………………………………………………………………
      if @back != nil
        #…………………………………………………………………………………………………
        # ■アイコンの描画
        #…………………………………………………………………………………………………
        if draw_icons
          @back.bitmap.blt(@px+16+4+x,16+32+32*y+4,icon,Rect.new(0,0,24,24))
          x += 28
        end
        @back.bitmap.font.color = HIDE_MESSAGE::Shadow_Color
        @back.bitmap.draw_text(@px+16+4+x+1,16+32+32*y+1,40,32,c)
        @back.bitmap.font.color = @message_color
        @back.bitmap.draw_text(@px+16+4+x,16+32+32*y,40,32,c)
      end
      #…………………………………………………………………………………………………
      # ■選択肢文字を描画
      #…………………………………………………………………………………………………
      if @blink_window != nil && $game_temp.choice_max > 0 && y >= $game_temp.choice_start
        @blink_window.bitmap.font.color = HIDE_MESSAGE::Blink_Color
        @blink_window.bitmap.draw_text(@px+4+x,32*y,40,32,c)
      end
      #…………………………………………………………………………………………………
      # ■x に描画した文字の幅を加算
      #…………………………………………………………………………………………………
      if @back != nil
        x += @back.bitmap.text_size(c).width
      end
    end
  end
  #--------------------------------------------------------------------------
  # ■ ゴールドウィンドウ背景の作成
  #--------------------------------------------------------------------------
  def make_gold_back?(event,data = nil)
    # □重複起動の禁止
    if event.message_other.gold != nil
      return
    end
    if data.nil?
      data = event.message
    end
    if $game_temp.in_battle
      x = 0
      y = 192
    else
      x = data.x >= 240 ? 32 : 448
      y = data.y >= 128 ? 32 : 384
    end
    @back_gold = Sprite.new
    @back_gold.x = x
    @back_gold.y = y
    @back_gold.z = data.z + data.number
    # □Bitmapを取得
    if (RPG::Cache.digits(cache_gold_key?(event))).nil?
      @back_gold.bitmap = Bitmap.new(160,64)
      make_cache_gold_bitmap?(@back_gold,event,$game_party.gold)
    end
    # □ゴールドの描画
    draw_gold_updata?(@back_gold,event,$game_party.gold)
    #…………………………………………………………………………………………………
    # ■ゴールドウィンドウの関連付け
    #…………………………………………………………………………………………………
    event.message_other.gold = @back_gold
    event.message_other.money = $game_party.gold
  end
  #--------------------------------------------------------------------------
  # ■ ゴールドウィンドウ背景のBitmapをキャッシュ化
  #--------------------------------------------------------------------------
  def make_cache_gold_bitmap?(window,event,money)
    w = window.bitmap.width
    h = window.bitmap.height
    opa = event.message.opacity
    pic = RPG::Cache.windowskin(event.message.back_name)
    # □[左上]画像の描画
    rect = Rect.new(0, 0, w/2, h/2)
    window.bitmap.blt(0, 0, pic, rect, opa)
    # □[右上]画像の描画
    rect = Rect.new(640 - w/2, 0, w, h/2)
    window.bitmap.blt(w/2, 0, pic, rect, opa)
    # □[左下]画像の描画
    rect = Rect.new(0, 224 - h/2, w/2, h)
    window.bitmap.blt(0, h/2, pic, rect, opa)
    # □[右下]画像の描画
    rect = Rect.new(640 - w/2, 224 - h/2, w/2, h)
    window.bitmap.blt(w/2, h/2, pic, rect, opa)
    # □システムの通貨単位を描画
    cx = window.bitmap.text_size($data_system.words.gold).width
    window.bitmap.font.color = HIDE_MESSAGE::Shadow_Color
    window.bitmap.draw_text(124-cx+16+1,0+16+1,cx,32,$data_system.words.gold, 2)
    window.bitmap.font.color = HIDE_MESSAGE::System_Color
    window.bitmap.draw_text(124-cx+16,0+16,cx,32,$data_system.words.gold, 2)
    # □キャッシュ化
    RPG::Cache.digits(cache_gold_key?(event),window.bitmap)
  end
  #--------------------------------------------------------------------------
  # ■ 所持金の描画を更新
  #--------------------------------------------------------------------------
  def draw_gold_updata?(window,event,money)
    # □Bitmapを取得
    if (RPG::Cache.digits(cache_gold_key?(event))).nil?
      window.bitmap = Bitmap.new(160,64)
      make_cache_gold_bitmap?(window,event,$game_party.gold)
    end
    window.bitmap = (RPG::Cache.digits(cache_gold_key?(event))).dup
    #…………………………………………………………………………………………………
    # ■回転数値ウィンドウの作成
    #…………………………………………………………………………………………………
    fonts = Copy_Font.new(22,false,false,true,false,Font.default_name,HIDE_MESSAGE::Message_Color,HIDE_MESSAGE::Shadow_Color)
    event.message_other.digits = Window_digits_number.new(window.x+44,window.y,window.z,money,7,10,fonts)
  end
  #--------------------------------------------------------------------------
  # ■ ゴールドウィンドウBitmapのCacheキーを返す
  #--------------------------------------------------------------------------
  def cache_gold_key?(event)
    key = event.message.back_name + "/gold_bitmap/" + event.message.opacity.to_s
    return key
  end
end
#==============================================================================
# ■ HIDE_MESSAGE_BASE
# [Game_Battler/Game_Character]共通設定
#==============================================================================
module HIDE_MESSAGE_BASE
  attr_accessor :message             # メッセージウィンドウの内容を格納
  attr_accessor :message_copy_base   # コピーウィンドウの補正座標を格納
  attr_accessor :message_copies      # コピーウィンドウを格納
  attr_accessor :message_viewport    # viewporを格納
  attr_accessor :message_other       # その他のウィンドウを格納
  #--------------------------------------------------------------------------
  # ■ メッセージ変数の初期化
  #--------------------------------------------------------------------------
  def base_make?
    @message = HIDE_MESSAGE::Make_Window.new
    @message_copy_base = []
    @message_copies = []
    @message_viewport = nil
    @message_other = HIDE_MESSAGE::Make_Other_Window.new
  end
end
#==============================================================================
# ■ Game_Map
#==============================================================================
class Game_Map
  #--------------------------------------------------------------------------
  # ■ 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :tail_id             # 一時的に保存するイベントID
  attr_accessor :messages            # Map全体のmessageを格納
  attr_accessor :message_number      # 表示中のmessage数を格納
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_message_game_map_initialize initialize;end
  def initialize
    # □元の処理を開始
    hidesp_message_game_map_initialize
    @tail_id = 0
    @messages = {}
    @message_number = 0
  end
  #--------------------------------------------------------------------------
  # ■ セットアップ
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_message_game_map_setup setup;end
  def setup(map_id)
    # □元の処理を開始
    hidesp_message_game_map_setup(map_id)
    numbers = 0
    for i in @map.events.keys
      if @messages[i] != nil
        @events[i].message_copy_base = @messages[i]
        for n in 0...@events[i].message_copy_base.size
          numbers += 1
        end
      end
    end
    if @messages[i] != nil
      $game_player.message_copy_base = @messages[0]
      for n in 0...$game_player.message_copy_base.size
        numbers += 1
      end
    end
    # □表示中のmessage数を格納
    @message_number = numbers
  end
end
#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler
  include HIDE_MESSAGE
  include HIDE_MESSAGE_BASE
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_battler_message initialize;end
  def initialize
    # □元の処理を開始
    hidesp_battler_message
    # □メッセージ変数の初期化
    base_make?
  end
end
#==============================================================================
# ■ Game_Character
#==============================================================================
class Game_Character
  include HIDE_MESSAGE
  include HIDE_MESSAGE_BASE
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_message_move_initialize initialize;end
  def initialize
    # □元の処理を開始
    hidesp_message_move_initialize
    # □メッセージ変数の初期化
    base_make?
  end
end
#==============================================================================
# ■ Sprite_Copy_Window
#==============================================================================
class Sprite_Copy_Window < RPG::Sprite
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(viewport,bitmap = nil)
    super(viewport)
    self.bitmap = bitmap
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  def dispose
    if self.bitmap != nil
      self.bitmap.dispose
      self.bitmap = nil
    end
    super
  end
end
#==============================================================================
# ■ Sprite_Character
#==============================================================================
class Sprite_Character < RPG::Sprite
  include HIDE_MESSAGE
  #--------------------------------------------------------------------------
  # ■ オブジェクト初期化(再定義)
  #--------------------------------------------------------------------------
  def initialize(viewport, character = nil)
    super(viewport)
    @viewpor = viewport
    @character = character
    @character.message_viewport = viewport
    update
    # □コピーメッセージの再構築
    hidesp_message_scroll?(@character.message_copies,@character.message_copy_base,true)
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_sprite_message_update update;end
  def update
    # □元の処理を開始
    hidesp_sprite_message_update
    # □Mapデータを格納
    $game_map.messages[@character.id] = @character.message_copy_base
    # □コピーメッセージの描画位置XYを更新
    @character.hidesp_message_scroll?(@character.message_copies,@character.message_copy_base,false)
  end
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_sprite_message_dispose dispose;end
  def dispose
    # □全て初期化
    all_dispose?(@character)
    # □元の処理を開始
    hidesp_sprite_message_dispose
  end
end
#==============================================================================
# ■ Sprite_Battler
#==============================================================================
class Sprite_Battler < RPG::Sprite
  include HIDE_MESSAGE
  #--------------------------------------------------------------------------
  # ■ 解放
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_sprite_battler_dispose dispose;end
  def dispose
    # □全て初期化
    if @battler != nil
      all_dispose?(@battler)
      @battler.message_copy_base = []
    end
    # □元の処理を開始
    hidesp_sprite_battler_dispose
  end
  #--------------------------------------------------------------------------
  # ■ フレーム更新
  #--------------------------------------------------------------------------
  if !$@;alias hidesp_sprite_battler_update update;end
  def update
    # □元の処理を開始
    hidesp_sprite_battler_update
    if @battler != nil
      # □viewporを格納
      if @battler.message_viewport == nil
        @battler.message_viewport = Viewport.new(0, 0, 640, 480)
        @battler.message_viewport.z = 5000
      end
      # □コピーメッセージの描画位置XYを更新
      @battler.hidesp_message_scroll?(@battler.message_copies,@battler.message_copy_base,false)
    end
  end
end
