#==============================================================================
#                   「お一人様メニュー」(ACE) Ver.1.4
#   製作者:奈々(なな)
#   へぷたなすくろーる http://heptanas.mamagoto.com/
#
#   ◇使用規約
#   使用される場合はスクリプト作成者として「奈々」を明記して下さい。
#   このスクリプトを改変したり、改変したものを配布するなどは自由ですが
#   その場合も元のスクリプトの作成者として名前は載せて下さい。
#   その他、詳しい利用規約はブログを参照して下さい。
#
#------------------------------------------------------------------------------
#
#   パーティメンバーが1人の場合に使いやすいメニューです。
#   1人なのにいちいちアクターを選択する無駄な手間を省きます。
#   
#   導入すると、パーティメンバーが1人の場合
#   メニュー画面の「スキル」「装備」「ステータス」及び
#   スキル・アイテムの使用対象で、アクター選択が行われません。
#   
#   更に初期設定の各項目をtrueにすることで
#   より1人パーティに適したメニュー画面にすることができます。
#
#==============================================================================
#◇初期設定
module Nana

  #複数メンバー時の設定
  LONELY_ONLY = true
  # true   パーティメンバーが複数でも、自動で先頭メンバーを選ぶ
  # false  パーティメンバーが複数なら、アクター選択を行う
  
  #並び替えの設定
  LONELY_FORMATION = true
  # true   並び替えをメニューから削除
  
  #ステータス画面の設定
  LONELY_STATUS = false
  # true   ステータス画面がメニュー画面と一体化する  
  
  #アイテム画面の設定
  LONELY_ITEM = true
  # true   アイテム画面をスキル画面と同じ構成にする
  
  #戦闘画面の設定
  LONELY_BATTLE = true
  # true   戦闘画面のスキル・アイテム選択にも適用する
  
end
#==============================================================================

#==============================================================================
# ■ Scene_Menu
#------------------------------------------------------------------------------
#  メニュー画面の処理を行うクラスです。
#==============================================================================

class Scene_Menu < Scene_MenuBase
  
  #--------------------------------------------------------------------------
  # ● コマンド[アイテム]
  #--------------------------------------------------------------------------
  def command_item
    if Nana::LONELY_ITEM
      SceneManager.call(Scene_Item_Skill)
    else
      SceneManager.call(Scene_Item)
    end
  end
  #--------------------------------------------------------------------------
  # ● コマンド[スキル][装備][ステータス]
  #--------------------------------------------------------------------------
  alias n7_lonely_command_personal command_personal
  def command_personal
    if Nana::LONELY_ONLY || ($game_party && $game_party.members.size == 1)
      on_personal_ok
    else
      n7_lonely_command_personal
    end
  end

if Nana::LONELY_STATUS
  #--------------------------------------------------------------------------
  # ● 開始処理
  #--------------------------------------------------------------------------
  def start
    super
    @status_window = Window_Status.new($game_party.leader)
    create_command_window
    create_gold_window
  end
  #--------------------------------------------------------------------------
  # ● ゴールドウィンドウの作成
  #--------------------------------------------------------------------------
  def create_gold_window
    @gold_window = Window_Gold.new
    @gold_window.x = Graphics.width - @gold_window.width
    @gold_window.y = Graphics.height - @gold_window.height
  end
end
end

#==============================================================================
# ■ Scene_MenuBase
#------------------------------------------------------------------------------
#  メニュー画面系の基本処理を行うクラスです。
#==============================================================================

class Scene_MenuBase < Scene_Base

if Nana::LONELY_ONLY || ($game_party && $game_party.members.size == 1)
  #--------------------------------------------------------------------------
  # ● 次のアクターに切り替え
  #--------------------------------------------------------------------------
  def next_actor
    on_actor_change
  end
  #--------------------------------------------------------------------------
  # ● 前のアクターに切り替え
  #--------------------------------------------------------------------------
  def prev_actor
    on_actor_change
  end
end
end

#==============================================================================
# ■ Window_MenuCommand
#------------------------------------------------------------------------------
#  メニュー画面で表示するコマンドウィンドウです。
#==============================================================================

class Window_MenuCommand < Window_Command

if Nana::LONELY_FORMATION
  #--------------------------------------------------------------------------
  # ● 並び替えをコマンドリストに追加
  #--------------------------------------------------------------------------
  def add_formation_command
  end
end

if Nana::LONELY_STATUS
  #--------------------------------------------------------------------------
  # ● ウィンドウ幅の取得
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width 
  end
  #--------------------------------------------------------------------------
  # ● 桁数の取得
  #--------------------------------------------------------------------------
  def col_max
    return 5
  end
  #--------------------------------------------------------------------------
  # ● 表示行数の取得
  #--------------------------------------------------------------------------
  def visible_line_number
    return 1
  end
  #--------------------------------------------------------------------------
  # ● 主要コマンドをリストに追加
  #--------------------------------------------------------------------------
  def add_main_commands
    add_command(Vocab::item,   :item,   main_commands_enabled)
    add_command(Vocab::skill,  :skill,  main_commands_enabled)
    add_command(Vocab::equip,  :equip,  main_commands_enabled)
  end
end
end

#==============================================================================
# ■ Window_Status
#------------------------------------------------------------------------------
#  ステータス画面で表示する、フル仕様のステータスウィンドウです。
#==============================================================================

class Window_Status < Window_Selectable

if Nana::LONELY_STATUS
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(actor)
    super(0, line_height * 2, Graphics.width, Graphics.height - line_height * 2)
    @actor = actor
    refresh
    activate
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_block1   (line_height * 0)
    draw_horz_line(line_height * 1)
    draw_block2   (line_height * 2)
    draw_horz_line(line_height * 6)
    draw_block3   (line_height * 7)
  end
end

end
#==============================================================================
# ■ Scene_Skill
#------------------------------------------------------------------------------
#  スキル画面の処理を行うクラスです。処理共通化の便宜上、スキルも「アイテム」
# として扱っています。
#==============================================================================

class Scene_Skill < Scene_ItemBase
  #--------------------------------------------------------------------------
  # ● アイテムの決定
  #--------------------------------------------------------------------------
  alias lonely_determine_item determine_item
  def determine_item
    if item.for_friend? && (Nana::LONELY_ONLY || ($game_party && $game_party.members.size == 1))
      on_actor_ok
      activate_item_window
    else
      lonely_determine_item
    end
  end
  #--------------------------------------------------------------------------
  # ● アイテムの使用対象となるアクターを配列で取得
  #--------------------------------------------------------------------------
  def item_target_actors
    if !item.for_friend?
      []
    elsif item.for_all?
      $game_party.members
    elsif (Nana::LONELY_ONLY || ($game_party && $game_party.members.size == 1))
      [$game_party.members[0]]
    else
      [$game_party.members[@actor_window.index]]
    end
  end
end

#==============================================================================
# ■ Scene_Item_Skill
#------------------------------------------------------------------------------
#  スキル画面を元にしたアイテム画面。
#==============================================================================

class Scene_Item_Skill < Scene_Skill
  #--------------------------------------------------------------------------
  # ● コマンドウィンドウの作成
  #--------------------------------------------------------------------------
  def create_command_window
    wy = @help_window.height
    @command_window = Window_ItemCategory_SkillCommand.new(0, wy)
    @command_window.viewport = @viewport
    @command_window.help_window = @help_window
    @command_window.actor = @actor
    @command_window.set_handler(:ok,    method(:command_skill))
    @command_window.set_handler(:cancel,   method(:return_scene))
    @command_window.set_handler(:pagedown, method(:next_actor))
    @command_window.set_handler(:pageup,   method(:prev_actor))
  end
  #--------------------------------------------------------------------------
  # ● アイテムウィンドウの作成
  #--------------------------------------------------------------------------
  def create_item_window
    wx = 0
    wy = @status_window.y + @status_window.height
    ww = Graphics.width
    wh = Graphics.height - wy
    @item_window = Window_ItemList.new(wx, wy, ww, wh)
    @item_window.viewport = @viewport
    @item_window.help_window = @help_window
    @item_window.set_handler(:ok,     method(:on_item_ok))
    @item_window.set_handler(:cancel, method(:on_item_cancel))
    @command_window.item_window = @item_window
  end
  #--------------------------------------------------------------------------
  # ● アイテム[決定]
  #--------------------------------------------------------------------------
  def on_item_ok
    $game_party.last_item.object = item
    determine_item
  end
  #--------------------------------------------------------------------------
  # ● アクターの切り替え
  #--------------------------------------------------------------------------
  def on_actor_change
    @command_window.actor = @actor
    @status_window.actor = @actor
    @command_window.activate
  end
end

#==============================================================================
# ■ Window_ItemCategory_SkillCommand
#------------------------------------------------------------------------------
#  スキルコマンドを元にしたアイテムカテゴリー。
#==============================================================================

class Window_ItemCategory_SkillCommand < Window_SkillCommand
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    @item_window.category = current_symbol if @item_window
  end
  #--------------------------------------------------------------------------
  # ● コマンドリストの作成
  #--------------------------------------------------------------------------
  def make_command_list
    add_command(Vocab::item,     :item)
    add_command(Vocab::weapon,   :weapon)
    add_command(Vocab::armor,    :armor)
    add_command(Vocab::key_item, :key_item)
  end
  #--------------------------------------------------------------------------
  # ● アイテムウィンドウの設定
  #--------------------------------------------------------------------------
  def item_window=(item_window)
    @item_window = item_window
    update
  end
end

#==============================================================================
# ■ Scene_Battle
#------------------------------------------------------------------------------
#  バトル画面の処理を行うクラスです。
#==============================================================================

class Scene_Battle < Scene_Base

if Nana::LONELY_BATTLE
  #--------------------------------------------------------------------------
  # ● アクター選択の開始
  #--------------------------------------------------------------------------
  alias n7_lonely_select_actor_selection select_actor_selection
  def select_actor_selection
    if Nana::LONELY_ONLY || ($game_party && $game_party.members.size == 1)
      BattleManager.actor.input.target_index = 0
      @skill_window.hide
      @item_window.hide
      next_command
    else
      n7_lonely_select_actor_selection
    end
  end
end
end