Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==========================================================================
- # Description:
- # Allows the creation of additional item categories via notetags. A category
- # can be applied to an item by writing <category ...> in its notebox. The
- # notetag <no default> can be used to exclude an item from the default categories
- # :item, :key_item, :weapon and :armor.
- #--------------------------------------------------------------------------
- # Changelog:
- # - Added the option to hide item quantities for certain categories.
- #==========================================================================
- module IAVRA
- module ITEM_MENU
- #==========================================================================
- # Item categories. The first 4 entries are reserved and include all items,
- # weapons, armors and key items, respectively. The values are built in the
- # following format:
- # - Notetag (nil for reserved categories)
- # - Label in the menu screen
- # - Description in the menu screen
- #==========================================================================
- CATEGORIES = {
- :item => [nil, "Items", "Viewing basic items"],
- :weapon => [nil, "Weapons", "Viewing weapons"],
- :armor => [nil, "Armor", "Viewing armors"],
- :key_item => [nil, "Key Items", "Viewing Key items"],
- :questnote => ["Quests", "Quest", "Viewing Quest items"]
- }
- #==========================================================================
- # Every category in this array will have its item quantities hidden. Useful
- # for key or quest items, where the player will only have 1 at most at any
- # given time anyway.
- #==========================================================================
- HIDE_ITEM_QUANTITY = [:questnote]
- #==========================================================================
- # Set to true if you want all the categories to autofit in the width of the
- # item category window. Set to false if you only want CATEGORY_WINDOW_MAX_COLUMNS
- # number of categories visible in the window width. If there are more categories
- # than CATEGORY_WINDOW_MAX_COLUMNS, the rest will still be accessible to the
- # right of the last category.
- #==========================================================================
- AUTOFIT_CATEGORY_COLUMNS = true
- CATEGORY_WINDOW_MAX_COLUMNS = 5
- #==========================================================================
- # Specify the width of the column to be used for each category. The category's
- # text is auto-squished to fit.
- #==========================================================================
- CATEGORY_WINDOW_COL_WIDTH = 50
- #==========================================================================
- # The amount of space-padding to be used on either end of the column.
- #==========================================================================
- CATEGORY_WINDOW_COL_SPACE = 2
- #==========================================================================
- # Regex used for parsing notetags.
- #==========================================================================
- REGEX_NOTETAG = /^\s*<category\s+(\w+)>/i
- #==========================================================================
- # Notetag used to exclude this item from the default categories.
- #==========================================================================
- REGEX_NO_DEFAULT = /^\s*<no default>/i
- end
- end
- #==========================================================================
- # ▼ IAVRA::ITEM_MENU::Window_ItemCategory
- #==========================================================================
- class Window_ItemCategory < Window_HorzCommand
- def update_help
- keys = IAVRA::ITEM_MENU::CATEGORIES.keys
- @help_window.set_text(IAVRA::ITEM_MENU::CATEGORIES[keys[self.index]][2])
- end
- def make_command_list
- IAVRA::ITEM_MENU::CATEGORIES.each {|symbol, data| add_command(data[1], symbol)}
- end
- def col_max
- IAVRA::ITEM_MENU::AUTOFIT_CATEGORY_COLUMNS ?
- IAVRA::ITEM_MENU::CATEGORIES.length :
- IAVRA::ITEM_MENU::CATEGORY_WINDOW_MAX_COLUMNS
- end
- def window_width
- Graphics.width
- end
- def spacing
- return IAVRA::ITEM_MENU::CATEGORY_WINDOW_COL_SPACE
- end
- end
- #==========================================================================
- # ▼ RPG::BaseItem
- #==========================================================================
- class RPG::BaseItem
- def item_categories
- iavra_item_menu_create_categories if @iavra_item_menu_categories.nil?
- @iavra_item_menu_categories
- end
- def iavra_item_menu_create_categories
- @iavra_item_menu_no_default = false
- @iavra_item_menu_categories = []
- self.note.split(/[\r\n]+/).each do |line|
- if(line[IAVRA::ITEM_MENU::REGEX_NOTETAG])
- cat = IAVRA::ITEM_MENU::CATEGORIES.map{|sym, data| data[0] == $1 ? sym : nil}.compact[0]
- @iavra_item_menu_categories << cat unless cat.nil?
- end
- if(line[IAVRA::ITEM_MENU::REGEX_NO_DEFAULT])
- @iavra_item_menu_no_default = true
- end
- end
- end
- end
- #==========================================================================
- # ▼ RPG::Item
- #==========================================================================
- class RPG::Item < RPG::UsableItem
- def iavra_item_menu_create_categories
- super
- return if @iavra_item_menu_no_default
- @iavra_item_menu_categories << :item unless key_item?
- @iavra_item_menu_categories << :key_item if key_item?
- end
- end
- #==========================================================================
- # ▼ RPG::Weapon
- #==========================================================================
- class RPG::Weapon < RPG::EquipItem
- def iavra_item_menu_create_categories
- super
- return if @iavra_item_menu_no_default
- @iavra_item_menu_categories << :weapon
- end
- end
- #==========================================================================
- # ▼ RPG::Armor
- #==========================================================================
- class RPG::Weapon < RPG::EquipItem
- def iavra_item_menu_create_categories
- super
- return if @iavra_item_menu_no_default
- @iavra_item_menu_categories << :armor
- end
- end
- #==========================================================================
- # ▼ Window_ItemList
- #==========================================================================
- class Window_ItemList < Window_Selectable
- alias :iavra_item_menu_initialize :initialize
- alias :iavra_item_menu_draw_item_number :draw_item_number
- def initialize(*args)
- iavra_item_menu_initialize(*args)
- end
- def include?(item)
- return false if item.nil?
- item.item_categories.include?(@category)
- end
- def draw_item_number(*args)
- return if IAVRA::ITEM_MENU::HIDE_ITEM_QUANTITY.include?(@category)
- iavra_item_menu_draw_item_number(*args)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement