Advertisement
roninator2

Seiryuki Categorize Item scene mod

Dec 5th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 17.34 KB | None | 0 0
  1. #===============================================================
  2. #==================== CATEGORIZE ITEM SCENE v1.0 ===============
  3. #===============================================================
  4. #= Ported from RMVX to RMVXAce
  5. #= Author: Seiryuki
  6. #= Date: 2019-Aug-15
  7. #= Type: VXA/RGSS3
  8. #= Additions: a few more customisation options
  9. #= Mod by Roninator2
  10. #---------------------------------------------------------------
  11. #= RMVX Title: KGC's Categorize Item Script
  12. #= Author: KGC
  13. #= Date: 2008-Apr-10
  14. #= Translated by: Mr. Anonymous
  15. #= The original untranslated version of the VX script can be found here:
  16. #= http://f44.aaa.livedoor.jp/~ytomy/tkool/rpgtech/php/tech.php?tool=VX&cat=tech_vx/item&tech=categorize_item
  17. #===============================================================
  18. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. # DESCRIPTION:
  20. # While RMVXAce already categorises the items in the items scene
  21. # into Items, Weapons, Armor, and Key Items this script allows
  22. # you to create your own categories and assign items, weapons,
  23. # and armor to any of them using notebox tags.
  24. #
  25. # This script also allows you to customise the size and location
  26. # of the help, category, and item windows.
  27. # See the Custom Layout Section for more information.
  28. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. # COMPATIBILITY:
  30. # May not be compatible with scripts that redo the item scene.
  31. # May be compatible with scripts that modify the item categories
  32. # for shops.
  33. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. # INSTRUCTIONS:
  35. # Place this script above Main and below Materials.
  36. #
  37. # To assign an item to a category, place <category IDENTIFIER> tag
  38. # in the item's (or weapon, or armor) notebox where IDENTIFIER
  39. # is the label listed in the CATEGORY_IDENTIFIER array in the
  40. # Customisation Section below.
  41. # You can add to or remove from the CATEGORY_IDENTIFIER list.
  42. #
  43. # NOTE: The following symbols are reserved and MUST NOT be used in
  44. #   the CATEGORY_IDENTIFIER list:
  45. #      :item, :weapon, :armor, :key_item, :all_item
  46. #
  47. # You can assign an item to multiple categories by simply placing
  48. # more <category IDENTIFIER> tags in the item's notebox.
  49. # NOTE: When doing that, make sure that ALLOW_DUPLICATE is set to
  50. # true (see Customisation Section) or else only the last tag in
  51. # the notebox will be used as the category for the item.
  52. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. #===============================================================
  54.  
  55.  
  56.  
  57. $data_system = load_data("Data/System.rvdata2") if $data_system == nil
  58.  
  59. module ICAT
  60. #=============================================================================#
  61. # CUSTOMISATION SECTION - Do not make changes unless you understand completely
  62. # what you are doing. Read and follow the below instructions very carefully.
  63. #=============================================================================#
  64. #-----------------------------------------------------------------------------#
  65. #>> HIDECATEGORIES - When true it will hide categories
  66. #   when no items are present for that category.
  67.  HIDECATEGORIES = true
  68.  
  69. #>> CATEGORY_IDENTIFIER - Create your categories here.
  70. #   You can add or remove categories from this list.
  71. #   On the left is the symbol used to identify the category.
  72. #   On the right is the category label that will be used when setting
  73. #   the e.g. <category Potions> tag in the notebox, where Potions is
  74. #   the label.
  75. #
  76. #   IMPORTANT - You cannot use the following as symbols as they are
  77. #   reserved:
  78. #      :item, :weapon, :armor, :key_item, :all_item
  79.  CATEGORY_IDENTIFIER = {
  80. :potion => "Potions", #example tag: <category Potions>
  81. :ammunition => "Ammunition", #example tag: <category Ammunition>
  82. }
  83.  
  84. #>> VISIBLE_CATEGORY_INDEX - Set the categories that would be visible
  85. #    in the item category window.
  86. #   On the left is identifying symbol from the CATEGORY_IDENTIFIER list
  87. #   above. It must be a symbol present in that list above, OR, one of the
  88. #   reserved symbols stated above. Make sure spelling is correct!
  89. #   On the right is the text to display, and can be any text desired.
  90. #   (see below customisation section for RESERVED_CATEGORY_INDEX list).
  91. #
  92. #   Only what is present in the VISIBLE_CATEGORY_INDEX will be shown in the
  93. #   item category window (so you can remove any from the list).
  94. #   This list can be arranged in any order desired.
  95.  VISIBLE_CATEGORY_INDEX = {
  96.   :item => "Common", #reserved symbol, but can be removed.
  97.   :weapon => "Weapons", #reserved symbol, but can be removed.
  98.   :armor => "Armor", #reserved symbol, but can be removed.
  99.   :key_item => "Special", #reserved symbol, but can be removed.
  100.   :all_item => "*ALL*", #reserved symbol, but can be removed.
  101.   :potion => "Potions",
  102.   :ammunition => "Ammo",
  103.  }
  104.  
  105. # NEW
  106. #>> CategoryConditions - Specifies if a category is to be shown
  107. #   On the left is identifying symbol from the CATEGORY_IDENTIFIER list
  108. #   above and VISIBLE_CATEGORY_INDEX list.
  109. #   It must be a symbol present in that list above, OR, one of the
  110. #   reserved symbols stated above. Make sure spelling is correct!
  111. #   On the right the conditions used to determine if the category is displayed.
  112. #   The CATEGORY_IDENTIFIER list must have the identifying symbol
  113. #   on the left and on the right and they must be the same.
  114.  CategoryConditions = {
  115.   :item => lambda { !$game_party.items.empty? && $game_party.items.any? {|item| !item.key_item? }},
  116.   :weapon => lambda { !$game_party.weapons.empty? },
  117.   :armor => lambda { !$game_party.armors.empty? },
  118.   :key_item => lambda { !$game_party.items.empty? && $game_party.items.any? {|item| item.key_item? }},
  119.   :all_item => lambda { !$game_party.all_items.empty? },
  120.  
  121.   # CATEGORY_IDENTIFIER
  122.   :potion => lambda { $game_party.all_items.any? {|item| item.find_category == :potion} },
  123.   :ammunition => lambda { $game_party.all_items.any? {|item| item.find_category == :ammunition} },
  124.  }
  125.  
  126. # UPDATED
  127. #>> CATEGORY_DESCRIPTION - Simple. The list below creates descriptions
  128. #    that will be shown in the help window.
  129.  CATEGORY_DESCRIPTION = {
  130.   :item => "Viewing basic items.",
  131.   :weapon => "Viewing attack-type items for use in battles.",
  132.   :armor => "Viewing head, body, arm and leg equipment.",
  133.   :key_item => "Viewing important items.",
  134.   :all_item => "Viewing all items.",
  135.   :potion => "Viewing potions.",
  136.   :ammunition => "Viewing ammunition.",
  137.  }
  138.  
  139. #>> I'm not sure how important setting this is.
  140.  ITEM_DEFAULT_CATEGORY = :item #default= :item
  141.  ITEM_DEFAULT_CATEGORY_INDEX = CATEGORY_IDENTIFIER.index(ITEM_DEFAULT_CATEGORY)
  142.  
  143. #>> AUTOFIT_CATEGORY_COLUMNS - Set to true if you want all the
  144. #    categories to autofit in the width of the item category window.
  145. #    Set to false if you only want CATEGORY_WINDOW_MAX_COLUMNS number
  146. #    of categories visible in the window width. If there are more
  147. #    categories than CATEGORY_WINDOW_MAX_COLUMNS, the rest will still be
  148. #    accessible to the right of the last category.
  149.  AUTOFIT_CATEGORY_COLUMNS = true #default=true
  150.  CATEGORY_WINDOW_MAX_COLUMNS = 5 #If autofit=false, this number is used.
  151.  
  152. #>> ALLOW_DUPLICATE - This is for when items have multiple tags
  153. #    in the notebox.
  154. #   Set to true if you want to allow an item in other categories.
  155. #   Setting to false will only choose the last category tag from the
  156. #   item's notebox as the item's category.
  157.  ALLOW_DUPLICATE = true #default=true
  158.  
  159. #>> CATEGORY_WINDOW_COL_WIDTH - Specify the width of the column to
  160. #    be used for each category. The category's text is auto-squished
  161. #    to fit.
  162.  CATEGORY_WINDOW_COL_WIDTH = 50 #default=50
  163.  
  164. #>> CATEGORY_WINDOW_COL_SPACE - The amount of space-padding to be
  165. #    used on either end of the column.
  166.  CATEGORY_WINDOW_COL_SPACE = 2 #default=2
  167.  
  168. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  169. #>> DEFAULT_SCENE_ITEM_LAYOUT - If you want the normal item scene
  170. #    layout where the help window is on top, categories in the
  171. #    middle, and item list below set this to TRUE.
  172. #    If you wish to move and resize the windows yourself, set to
  173. #    FALSE and modify the CUSTOM LAYOUT SECTION below.
  174.  DEFAULT_SCENE_ITEM_LAYOUT = true #default=true
  175.  
  176. #>> CUSTOM LAYOUT SECTION:
  177. #    The default settings below recreate the layout as if
  178. #    DEFAULT_SCENE_ITEM_LAYOUT was set to true above.
  179. #-----------
  180. # DEFAULTS:
  181. #-----------
  182. #  HELP_WINDOW_POSITION   = [0, 0]
  183. #  HELP_WINDOW_WIDTH         = Graphics.width #or enter your own number
  184. #  HELP_WINDOW_NUM_OF_LINES  = 2
  185. #  CATEGORY_WINDOW_POSITION  = [0, 72]
  186. #  CATEGORY_WINDOW_WIDTH     = Graphics.width #or enter your own number
  187. #  ITEMLIST_WINDOW_POSITION  = [0, 120]
  188. #  ITEMLIST_WINDOW_HEIGHT   = 296
  189.  
  190.  HELP_WINDOW_POSITION     = [0, 0]
  191.  HELP_WINDOW_WIDTH       = Graphics.width #or enter your own number
  192.  HELP_WINDOW_NUM_OF_LINES  = 2
  193.  CATEGORY_WINDOW_POSITION  = [0, 72]
  194.  CATEGORY_WINDOW_WIDTH   = Graphics.width #or enter your own number
  195.  ITEMLIST_WINDOW_POSITION  = [0, 120]
  196.  ITEMLIST_WINDOW_HEIGHT = 296
  197. #>> END OF LAYOUT SECTION
  198. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  199.  
  200. #-----------------------------------------------------------------------------#
  201. #=============================================================================#
  202. # END OF CUSTOMISATION SECTION
  203. #=============================================================================#
  204. #-----------------------------------------------------------------------------#
  205. # DO NOT MODIFY ANYTHING BELOW HERE UNLESS YOU ARE SURE OF WHAT YOU'RE DOING! #
  206. #-----------------------------------------------------------------------------#
  207. #=============================================================================#
  208. #=============================================================================#
  209.  
  210.  RESERVED_CATEGORY_INDEX = {
  211. "All Items" => CATEGORY_IDENTIFIER.index(:all_item),
  212. "Key Items" => CATEGORY_IDENTIFIER.index(:key_item),
  213. "Weapons" => CATEGORY_IDENTIFIER.index(:weapon),
  214. "Armor" => CATEGORY_IDENTIFIER.index(:armor),
  215. "Items" => CATEGORY_IDENTIFIER.index(:item),
  216.  }
  217.  
  218.  module Regexp
  219. module BaseItem
  220.   # Category tag string
  221.   CATEGORY = /^<(?:CATEGORY|classification|category?)[ ]*(.*)>/i
  222. end
  223.  end
  224.  
  225. end # END OF module: ICAT
  226.  
  227. #=============================================================================#
  228. # Creates the item category window from VISIBLE_CATEGORY_INDEX hash above.
  229. #=============================================================================#
  230. class ICAT_WindowItemCategory < Window_ItemCategory
  231.  
  232.  def initialize
  233.   @category_list = []
  234.   super
  235.   self.z = 1000
  236.   self.index = 0
  237.  end
  238.  
  239.  #updated
  240.  def update_help
  241.   @help_window.set_text(ICAT::CATEGORY_DESCRIPTION[@category_list[self.index]])
  242.  end
  243.  
  244.  # updated
  245. if ICAT::HIDECATEGORIES
  246.  
  247.  alias icat_make_command_list make_command_list
  248.  def make_command_list
  249.     ICAT::VISIBLE_CATEGORY_INDEX.each do |symbol, label|
  250.     add_command(label, symbol) if ICAT::CategoryConditions[symbol].call
  251.     @category_list << symbol if ICAT::CategoryConditions[symbol].call
  252.     end
  253.  end
  254.  
  255. else
  256.  
  257.  alias icat_make_command_list make_command_list
  258.  def make_command_list
  259.   ICAT::VISIBLE_CATEGORY_INDEX.each { |symbol, label|
  260.     add_command(label, symbol)
  261.     @category_list << symbol
  262.   }
  263.  end
  264.  
  265. end
  266.  
  267.  def col_max
  268.   if ICAT::AUTOFIT_CATEGORY_COLUMNS
  269.     cols = @category_list.length / 2
  270.   else
  271.     cols = ICAT::CATEGORY_WINDOW_MAX_COLUMNS
  272.   end
  273.   return cols == 0 ? 1 : cols
  274.  end
  275.  
  276.  def window_width
  277.   if ICAT::CATEGORY_WINDOW_WIDTH == nil
  278.     return Graphics.width
  279.   else
  280.     return ICAT::CATEGORY_WINDOW_WIDTH
  281.   end
  282.  end
  283.  
  284.  def spacing
  285.   return ICAT::CATEGORY_WINDOW_COL_SPACE
  286.  end
  287.  
  288. end #class
  289.  
  290.  
  291.  
  292. #=============================================================================#
  293. # Creates category array from BASEITEM database.
  294. #=============================================================================#
  295. class RPG::BaseItem
  296.  attr_reader :icat
  297.  
  298.  def create_categorize_item_cache
  299.   if @icat == nil
  300.     @icat = []
  301.   else
  302.     @icat.compact!
  303.   end
  304.   self.note.split(/[\r\n]+/).each { |line|
  305.     if line =~ ICAT::Regexp::BaseItem::CATEGORY
  306.     c = ICAT::CATEGORY_IDENTIFIER.key($1)
  307.     @icat << c if c != nil
  308.     end
  309.   }
  310.   if @icat.empty?
  311.     @icat << ICAT::ITEM_DEFAULT_CATEGORY_INDEX
  312.   elsif !ICAT::ALLOW_DUPLICATE
  313.     @icat = [@icat.pop]
  314.   end
  315.  end
  316.  
  317.  def item_category
  318.   create_categorize_item_cache if @icat == nil
  319.   return @icat
  320.  end
  321.  
  322.  # new
  323.  def find_category
  324.   self.note.split(/[\r\n]+/).each { |line|
  325.     if line =~ ICAT::Regexp::BaseItem::CATEGORY
  326.     c = ICAT::CATEGORY_IDENTIFIER.key($1)
  327.     return c if c != nil
  328.     end
  329.   }
  330.  end
  331.  
  332. end #class
  333.  
  334.  
  335.  
  336. #=============================================================================#
  337. # Creates category array from USABLEITEM database.
  338. #=============================================================================#
  339. class RPG::UsableItem < RPG::BaseItem
  340.  
  341.  def create_categorize_item_cache
  342.   @icat = []
  343.   if key_item?
  344.     @icat << ICAT::RESERVED_CATEGORY_INDEX.key("Key Items")
  345.   elsif !key_item?
  346.     @icat << ICAT::RESERVED_CATEGORY_INDEX.key("Items")
  347.   end
  348.   super
  349.  end
  350.  
  351. end #class
  352.  
  353.  
  354.  
  355. #=============================================================================#
  356. # Creates category array from WEAPON database.
  357. #=============================================================================#
  358. class RPG::Weapon < RPG::EquipItem
  359.  
  360.  def create_categorize_item_cache
  361.   @icat = []
  362.   @icat << ICAT::RESERVED_CATEGORY_INDEX.key("Weapons")
  363.   super
  364.  end
  365.  
  366. end #class
  367.  
  368.  
  369.  
  370. #=============================================================================#
  371. # Creates category array from ARMOR database.
  372. #=============================================================================#
  373. class RPG::Armor < RPG::EquipItem
  374.  
  375.  def create_categorize_item_cache
  376.   @icat = []
  377.   @icat << ICAT::RESERVED_CATEGORY_INDEX.key("Armor")
  378.   super
  379.  end
  380.  
  381. end #class
  382.  
  383.  
  384.  
  385. #=============================================================================#
  386. # Creates item window, categorised by RESERVED_CATEGORY_INDEX and by your own
  387. # custom VISIBLE_CATEGORY_INDEX hash above.
  388. #=============================================================================#
  389. class Window_ItemList < Window_Selectable
  390.  
  391.  alias icat_initialize initialize
  392.  def initialize(x, y, width, height)
  393.   icat_initialize(x, y, width, height)
  394.   @category = ICAT::VISIBLE_CATEGORY_INDEX
  395.  end
  396.  
  397.  def include?(item)
  398.   return false if item == nil
  399.   case @category
  400.   when :item
  401.     item.is_a?(RPG::Item) && !item.key_item?
  402.   when :weapon
  403.     item.is_a?(RPG::Weapon)
  404.   when :armor
  405.     item.is_a?(RPG::Armor)
  406.   when :key_item
  407.     item.is_a?(RPG::Item) && item.key_item?
  408.   when :all_item
  409.     item.is_a?(RPG::Item) || item.is_a?(RPG::Armor) || item.is_a?(RPG::Weapon)
  410.   else
  411.     ###### NEED TO CHECK FOR CUSTOM CATEGORIES HERE AND
  412.     ###### DECIDE IF TO INCLUDE THE ITEM TO IT
  413.     @icategory = item.item_category
  414.     for i in @icategory do
  415.     if @category == i
  416.       return item.item_category.include?(@category)
  417.     end
  418.     end
  419.     return false
  420.   end #when
  421.  end #def
  422.  
  423. end #class
  424.  
  425.  
  426.  
  427. #=============================================================================#
  428. # Allows for the customisation of the help window.
  429. #=============================================================================#
  430. class Window_Help < Window_Base
  431.  
  432.  alias icat_help_initialize initialize
  433.  def initialize(line_number = 2)
  434.   if ICAT::DEFAULT_SCENE_ITEM_LAYOUT
  435.     super(0, 0, Graphics.width, fitting_height(line_number))
  436.   else
  437.     super(
  438.     ICAT::HELP_WINDOW_POSITION[0],
  439.     ICAT::HELP_WINDOW_POSITION[1],
  440.     ICAT::HELP_WINDOW_WIDTH,
  441.     fitting_height(ICAT::HELP_WINDOW_NUM_OF_LINES))
  442.   end
  443.  end
  444.  
  445. end #class
  446.  
  447.  
  448.  
  449. #=============================================================================#
  450. # Creates the entire item scene: item window, item categories, help window.
  451. #=============================================================================#
  452. class Scene_Item < Scene_ItemBase
  453.  
  454.  alias icat_create_category_window create_category_window
  455.  #Create the item category window.
  456.  def create_category_window
  457. @category_window = ICAT_WindowItemCategory.new
  458. @category_window.viewport = @viewport
  459. @category_window.help_window = @help_window
  460. @category_window.x = ICAT::CATEGORY_WINDOW_POSITION[0]
  461. if ICAT::DEFAULT_SCENE_ITEM_LAYOUT #customise check
  462.   @category_window.y = @help_window.height
  463. else
  464.   @category_window.y = ICAT::CATEGORY_WINDOW_POSITION[1]
  465. end
  466. @category_window.set_handler(:ok,    method(:on_category_ok))
  467. @category_window.set_handler(:cancel, method(:return_scene))
  468. @category_window.opacity = 255 #255=totally opaque
  469. @category_window.back_opacity = 255 #255=totally opaque
  470. @category_window.contents_opacity = 255 #255=totally opaque
  471.  end
  472.  
  473.  #Create the item list window.
  474.  alias icat_create_item_window create_item_window
  475.  def create_item_window
  476. if ICAT::DEFAULT_SCENE_ITEM_LAYOUT #customise check
  477.   wy = @category_window.y + @category_window.height
  478.   wh = Graphics.height - wy
  479. else
  480.   wy = ICAT::ITEMLIST_WINDOW_POSITION[1]
  481.   wh = ICAT::ITEMLIST_WINDOW_HEIGHT
  482. end
  483. @item_window = Window_ItemList.new(0, wy, Graphics.width, wh)
  484. @item_window.viewport = @viewport
  485. @item_window.help_window = @help_window
  486. @item_window.set_handler(:ok,    method(:on_item_ok))
  487. @item_window.set_handler(:cancel, method(:on_item_cancel))
  488. @category_window.item_window = @item_window
  489.  end
  490.  
  491. end #class
  492.  
  493. #=============================================================================#
  494. # -------------------------------END OF SCRIPT------------------------------- #
  495. #=============================================================================#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement