戦闘中のアイテムのカテゴリ分け - 方法2

現在、オーバーワールドのアイテムをカテゴリ分けするスクリプトは作っていますが、戦闘中のアイテムまでは分類されていません。具体的には、「インベントリ」ボタンをクリックすると別のメニューが開き、そこからキーアイテムを含む各カテゴリのメニューを開けるようなボタンを表示させたいのですが、その方法がわかりません。

以下は、戦闘中のアイテムメニューに「アイテム」と「重要アイテム」の分類ウィンドウを追加する小さなスクリプトです。Script Editor (F11) を開き、▼ Materials の下、既存のアイテム分類スクリプトの直下に新しいスロットを作成して貼り付けてください:

class Window_BattleItemCategory < Window_ItemCategory
  def col_max
    return 2
  end

  def make_command_list
    add_command(Vocab::item,     :item)
    add_command(Vocab::key_item, :key_item)
  end
end

class Window_BattleItem < Window_ItemList
  def include?(item)
    super && (@category == :key_item || $game_party.usable?(item))
  end
end

class Scene_Battle < Scene_Base
  alias item_category_create_all_windows create_all_windows
  def create_all_windows
    item_category_create_all_windows
    create_item_category_window
  end

  def create_item_category_window
    @item_category_window = Window_BattleItemCategory.new
    @item_category_window.y = @help_window.height
    @item_category_window.help_window = @help_window
    @item_category_window.hide.deactivate
    @item_category_window.set_handler(:ok,     method(:on_item_category_ok))
    @item_category_window.set_handler(:cancel, method(:on_item_category_cancel))
    @item_category_window.item_window = @item_window
    @item_window.y += @item_category_window.height
    @item_window.height -= @item_category_window.height
  end

  def command_item
    @item_window.refresh
    @item_window.show
    @item_window.unselect
    @item_category_window.show.activate
  end

  def on_item_category_ok
    @item_window.activate
    @item_window.select_last
  end

  def on_item_category_cancel
    @item_category_window.hide
    @item_window.hide
    @actor_command_window.activate
  end

  def on_item_cancel
    @item_window.unselect
    @item_category_window.activate
  end

  alias item_category_next_command next_command
  def next_command
    @item_category_window.hide
    item_category_next_command
  end
end

戦闘中に「インベントリ」を選択すると、まずカテゴリが表示され、移動するたびに下部のリストが切り替わります。通常のアイテムは、戦闘中に使用可能な場合のみ表示されます。重要アイテムは常に表示されますが、使用できない場合はグレー表示になります。

もしオーバーワールドのスクリプトで独自のカテゴリを追加している場合で、それらを戦闘中にも使用したい場合は、どのスクリプトか教えていただければ確認いたします。

バズ、私のガオがまた始めているよ:clap: 愛してる
自分でカテゴリを使いたいんだ。お願い。
このスクリプトを使ってる。セiryukiのアイテムシーン。
[VXA] アイテムシーンの分類
どうやらカテゴリをインデックス(またはそのように呼ばれるもの)に整理し、その後、アイテムにノテタグを使ってカテゴリに割り当てているようだ。

そのスクリプトはすでにノートタグを使ってすべてのものをソートしているので、バトルウィンドウはそのカテゴリリストを借用するだけです。前に提示したスクリプトと入れ替えてください。まだ「アイテムシーンの分類」スクリプトの下に配置してください:

class Window_BattleItemCategory < Window_ItemCategory
  HIDDEN = [:weapon, :armor]

  def col_max
    [item_max, 1].max
  end

  def make_command_list
    ICAT::VISIBLE_CATEGORY_INDEX.each do |symbol, label|
      add_command(label, symbol) unless HIDDEN.include?(symbol)
    end
  end

  def update_help
    i = ICAT::VISIBLE_CATEGORY_INDEX.keys.index(current_symbol)
    @help_window.set_text(i ? ICAT::CATEGORY_DESCRIPTION[i] : "")
  end
end

class Window_BattleItem < Window_ItemList
  def include?(item)
    return false unless super
    (item.is_a?(RPG::Item) && item.key_item?) || $game_party.usable?(item)
  end
end

class Scene_Battle < Scene_Base
  alias item_category_create_all_windows create_all_windows
  def create_all_windows
    item_category_create_all_windows
    create_item_category_window
  end

  def create_item_category_window
    @item_category_window = Window_BattleItemCategory.new
    @item_category_window.y = @help_window.height
    @item_category_window.help_window = @help_window
    @item_category_window.hide.deactivate
    @item_category_window.set_handler(:ok,     method(:on_item_category_ok))
    @item_category_window.set_handler(:cancel, method(:on_item_category_cancel))
    @item_category_window.item_window = @item_window
    @item_window.y += @item_category_window.height
    @item_window.height -= @item_category_window.height
  end

  def command_item
    @item_window.refresh
    @item_window.show
    @item_window.unselect
    @item_category_window.show.activate
  end

  def on_item_category_ok
    @item_window.activate
    @item_window.select_last
  end

  def on_item_category_cancel
    @item_category_window.hide
    @item_window.hide
    @actor_command_window.activate
  end

  def on_item_cancel
    @item_window.unselect
    @item_category_window.activate
  end

  alias item_category_next_command next_command
  def next_command
    @item_category_window.hide
    item_category_next_command
  end
end

バトルでは、武器と防具(これらはバトルで使用できないため)を除いた VISIBLE_CATEGORY_INDEX リストと同じカテゴリを使用します。各カテゴリは、アイテムメニューと同様にヘルプウィンドウに CATEGORY_DESCRIPTION のテキストを表示します。独自の武器や防具のカテゴリを作成した場合は、それらのシンボルを上部の HIDDEN 行に追加して、バトルで空欄として表示されないようにしてください。

あなたがスクリプトをくれるたびに、甘やかされた子供のような気分になります。本当にありがとうございます。

待って、アイテムボックスを大きくするにはどうすればいいの?

ねえ、アイテムメニューを閉じると、すべてのウィンドウが消えてしまって、再度表示するにはボタンを押さなきゃいけないことに気づいたよ。小さなことだけど、ちょっとイライラするよね。アクションを実行している間は、処理中もカテゴリが画面上に残っているのに。
あと、アイテムメニューを閉じると、アイテム画面から抜けるだけでなく、通常の戦闘メニューにも戻っちゃうんだ。これはおそらくYanflyの戦闘エンジンを使っているからだと思われる。
ラップさせる必要があるのかな?

Yanflyの戦闘エンジンには、アイテムメニューが開閉する際の独自のステップ(バトルメニューの非表示と再表示など)があります。私のスクリプトはそれらのステップに追加するのではなく、置き換えてしまっていました。以下のコードに交換してください。これは「カテゴリ別アイテムシーン」スクリプトの下に配置します:

class Window_BattleItemCategory < Window_ItemCategory
  HIDDEN = [:weapon, :armor]

  def col_max
    [item_max, 1].max
  end

  def make_command_list
    ICAT::VISIBLE_CATEGORY_INDEX.each do |symbol, label|
      add_command(label, symbol) unless HIDDEN.include?(symbol)
    end
  end

  def update_help
    i = ICAT::VISIBLE_CATEGORY_INDEX.keys.index(current_symbol)
    @help_window.set_text(i ? ICAT::CATEGORY_DESCRIPTION[i] : "")
  end

  def update
    super
    self.visible = @item_window.visible if @item_window
  end
end

class Window_BattleItem < Window_ItemList
  def include?(item)
    return false unless super
    (item.is_a?(RPG::Item) && item.key_item?) || $game_party.usable?(item)
  end
end

class Scene_Battle < Scene_Base
  alias item_category_create_all_windows create_all_windows
  def create_all_windows
    item_category_create_all_windows
    create_item_category_window
  end

  def create_item_category_window
    @item_category_window = Window_BattleItemCategory.new
    @item_category_window.width = @item_window.width
    @item_category_window.refresh
    @item_category_window.x = @item_window.x
    @item_category_window.y = @item_window.y - @item_category_window.height
    @item_category_window.help_window = @help_window
    @item_category_window.hide.deactivate
    @item_category_window.set_handler(:ok,     method(:on_item_category_ok))
    @item_category_window.set_handler(:cancel, method(:on_item_cancel))
    @item_category_window.item_window = @item_window
    @item_window.set_handler(:cancel, method(:on_item_list_cancel))
  end

  alias item_category_command_item command_item
  def command_item
    item_category_command_item
    @item_window.deactivate
    @item_window.unselect
    @item_category_window.activate
  end

  def on_item_category_ok
    @item_window.activate
    @item_window.select_last
  end

  def on_item_list_cancel
    @item_window.unselect
    @item_category_window.activate
  end
end

アイテムリストから戻る操作を行うとカテゴリ一覧に戻り、カテゴリ一覧から戻る操作を行うと、すべての要素が表示された元のバトルメニューに戻ります。カテゴリバーは現在アイテムリストの直上に位置しており、リストが隠れると同時に自身も隠れるため、アクション実行中に残ったままになることはありません。また、リストはスキルリストと同じサイズに戻っており、スペースを空けるために縮小することはなくなりました。

マジで動いた!ありがとう!

私もゲームのメニュー操作において同様の問題に遭遇したことがあります。特に、異なるプラグインがバトルシステムに影響を与える場合です。アクション実行中にカテゴリウィンドールを表示したままにすれば、プレイがずっとスムーズになり、プレイヤーがメニューを繰り返し開く手間が省けます. また、アイテムメニューを閉じた際に、予期せずメインの戦闘メニューに戻ってしまうのではなく、期待される画面に戻ってくれると親切でしょう。小さなプラグインの調整や互換性修正で対応可能でしょうか?