#==============================================================================
#  ExCommand_MessageAdjust
#------------------------------------------------------------------------------
# եåʤ [¤αʾ] gФHˡեåΈ
# ͬαʾI{륹ץزĤǤ
#==============================================================================

# ե饰ʹä륹å ID
# ηŤΥå ON ˤȡå`αʾI
# եåΈϤͬ{ޤ
# [xk֫αʾ]  [΄I] BӤ{ޤ
EXCMD_MSGADJUST_SID = 5

# ɥO
# ͨɥʾI˺Ϥ碌{뤫ɤָޤ
# (0:{ʤ 1:{)
EXCMD_MSGADJUST_WINDOW = 1

#------------------------------------------------------------------------------

class Window_NumberInput
  #--------------------------------------------------------------------------
  #  ʾI{٤ɤж
  #--------------------------------------------------------------------------
  def need_adjust?
    return false if $game_temp.in_battle
    if $game_message.face_name.empty? and $game_switches[EXCMD_MSGADJUST_SID]
      return true
    end
    return false
  end
  #--------------------------------------------------------------------------
  #  եå (ٶx)
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = normal_color
    @contents_x = 0
    if need_adjust?
      @contents_x = EXCMD_MSGADJUST_WINDOW == 1 ? 0 : 56
    end
    s = sprintf("%0*d", @digits_max, @number)
    for i in 0...@digits_max
      self.contents.draw_text(@contents_x + 24 + i * 16, 0, 16, WLH, s[i,1], 1)
    end
  end
  #--------------------------------------------------------------------------
  #  `θ (ٶx)
  #--------------------------------------------------------------------------
  def update_cursor
    self.cursor_rect.set(@contents_x + 24 + @index * 16, 0, 16, WLH)
  end
end

class Window_Message
  alias _excmsga_initialize initialize
  alias _excmsga_new_page new_page
  alias _excmsga_new_line new_line
  alias _excmsga_reset_window reset_window
  #--------------------------------------------------------------------------
  #  ֥ȳڻ (׷Ӷx)
  #--------------------------------------------------------------------------
  def initialize
    _excmsga_initialize
    @face_name = ""             # եå
  end
  #--------------------------------------------------------------------------
  #  ʾI{٤ɤж
  #--------------------------------------------------------------------------
  def need_adjust?
    return false if $game_temp.in_battle
    if $game_message.face_name.empty? and $game_switches[EXCMD_MSGADJUST_SID]
      return true
    end
    return false
  end
  #--------------------------------------------------------------------------
  #  ΤΥå`AƱʾ٤ж (ٶx)
  #--------------------------------------------------------------------------
  def continue?
    return true if $game_message.num_input_variable_id > 0
    return false if $game_message.texts.empty?
    if self.openness > 0 and not $game_temp.in_battle
      return false if @background != $game_message.background
      return false if @position != $game_message.position
      if EXCMD_MSGADJUST_WINDOW == 1 and $game_switches[EXCMD_MSGADJUST_SID]
        return false if $game_message.face_name.empty? != @face_name.empty?
      end
    end
    return true
  end
  #--------------------------------------------------------------------------
  #  ĥک`I (׷Ӷx)
  #--------------------------------------------------------------------------
  def new_page
    _excmsga_new_page
    if need_adjust?
      @contents_x = EXCMD_MSGADJUST_WINDOW == 1 ? 0 : 56
    end
  end
  #--------------------------------------------------------------------------
  #  ЄI (׷Ӷx)
  #--------------------------------------------------------------------------
  def new_line
    _excmsga_new_line
    if need_adjust?
      @contents_x = EXCMD_MSGADJUST_WINDOW == 1 ? 0 : 56
    end
  end
  #--------------------------------------------------------------------------
  #  ɥαλäO (׷Ӷx)
  #--------------------------------------------------------------------------
  def reset_window
    _excmsga_reset_window
    @face_name = $game_message.face_name
    if EXCMD_MSGADJUST_WINDOW == 1 and $game_switches[EXCMD_MSGADJUST_SID]
      self.x = $game_message.face_name.empty? ? 56 : 0
      self.width = $game_message.face_name.empty? ? 544 - 112 : 544
      @number_input_window.width = self.width
      @number_input_window.create_contents
      create_contents
    end
  end
  #--------------------------------------------------------------------------
  #  `θ (ٶx)
  #--------------------------------------------------------------------------
  def update_cursor
    if @index >= 0
      x = $game_message.face_name.empty? ? @contents_x : 112
      y = ($game_message.choice_start + @index) * WLH
      w = $game_message.face_name.empty? ? x * 2 : x
      self.cursor_rect.set(x, y, contents.width - w, WLH)
    else
      self.cursor_rect.empty
    end
  end
end
