# RMVX Script by KGC
# http://f44.aaa.livedoor.jp/~ytomy/tkool/rpgtech/php/tech.php?tool=VX&cat=tech_vx/item&tech=categorize_item
# Ported to RMVXAce by Seiryuki on 2011.12.28
$data_system = load_data("Data/System.rvdata2") if $data_system == nil
module Seiryuki
module CategorizeItem
#Automatically Categorize Items
ENABLE_AUTO_CATEGORIZE = true
#Duplicate Category Entries
#Set to false, items can have multiple categories.
#Set to true, items will be classified under the last tag (In the item
#database "Notes")
NOT_ALLOW_DUPLICATE = false
# ? Coordinates of item category window. [ x, y ]
CATEGORY_WINDOW_POS = [0, 0]
# ? Number of columns in the item category window.
# Column width auto-adjusts to fit amount of columns specified.
CATEGORY_WINDOW_COLUMNS = 6
# ? category window column spacer width.
CATEGORY_WINDOW_COL_SPACE = 2
# ? category window number of lines/rows of text.
#Not working :(
#~ CATEGORY_WINDOW_LINE_NUMBER = 2
# ? help window coordinates.
HELP_WINDOW_POS = [0, 0]
# ? help window number of lines/rows of text.
HELP_WINDOW_LINE_NUMBER = 2
#Set up all item categories here:
CATEGORY_IDENTIFIER = [
"Item",
"Weapons",
"Armor",
"Key-Items",
"HELP",
"All Items",
]
#Choose one from the CATEGORY_IDENTIFIER above,
#but it's text-string must be present in the CATEGORY_NAME below.
ITEM_DEFAULT_CATEGORY = "Item"
#Set up visible item categories here:
CATEGORY_NAME = {
"Item" =>:item,
"Weapons" =>:weapon,
"Armor" =>:armor,
"Key-Items" =>:key_item,
"HELP" =>:helpme,
"All Items" =>:all_items,
}
#Set up item category descriptions here:
CATEGORY_DESCRIPTION = [
"All items in possession.",
"All weapons in possession.",
"All armor in possession.",
"All special and important items in possession.",
"NEED HELP!!!!",
"ALL ITEMS",
]
end
end
$imported = {} if $imported == nil
$imported["CategorizeItem"] = true
module Seiryuki::CategorizeItem
ITEM_DEFAULT_CATEGORY_INDEX = CATEGORY_IDENTIFIER.index(ITEM_DEFAULT_CATEGORY)
RESERVED_CATEGORY_INDEX = {
"All Items" => CATEGORY_IDENTIFIER.index("All Items"),
"Items" => CATEGORY_IDENTIFIER.index("Items"),
"Weapons" => CATEGORY_IDENTIFIER.index("Weapons"),
"Armor" => CATEGORY_IDENTIFIER.index("Armor"),
"Key-Items" => CATEGORY_IDENTIFIER.index("Key-Items"),
}
#Whatever word(s) are after the separator ( | ) in the following lines are
#what are used to determine what is searched for in the "Notes" section.
module Regexp
module BaseItem
# Item Category tag string
CATEGORY = /^<(?:CATEGORY|classification|category?)[ ]*(.*)>/i
end
end
end
class RPG::BaseItem
def create_categorize_item_cache
if @__item_category == nil || !Seiryuki::CategorizeItem::ENABLE_AUTO_CATEGORIZE
@__item_category = []
else
@__item_category.compact!
end
self.note.split(/[\r\n]+/).each { |line|
if line =~ Seiryuki::CategorizeItem::Regexp::BaseItem::CATEGORY
#Category
c = Seiryuki::CategorizeItem::CATEGORY_IDENTIFIER.index($1)
@__item_category << c if c != nil
end
}
if @__item_category.empty?
@__item_category << Seiryuki::CategorizeItem::ITEM_DEFAULT_CATEGORY_INDEX
elsif Seiryuki::CategorizeItem::NOT_ALLOW_DUPLICATE
#Placed in the last specified category
@__item_category = [@__item_category.pop]
end
end
def item_category
create_categorize_item_cache if @__item_category == nil
return @__item_category
end
end
class RPG::UsableItem < RPG::BaseItem
def create_categorize_item_cache
@__item_category = []
if self.price == 0
@__item_category << Seiryuki::CategorizeItem::RESERVED_CATEGORY_INDEX["Key-Items"]
end
super
end
end
class RPG::Weapon < RPG::EquipItem
def create_categorize_item_cache
@__item_category = []
@__item_category << Seiryuki::CategorizeItem::RESERVED_CATEGORY_INDEX["Weapons"]
super
end
end
class RPG::Armor < RPG::EquipItem
def create_categorize_item_cache
@__item_category = []
@__item_category << Seiryuki::CategorizeItem::RESERVED_CATEGORY_INDEX["Armor"]
type = nil
case self.kind
when 0
type = "Shields"
when 1
type = "Head Gear"
when 2
type = "Body Gear"
when 3
type = "Accessories"
end
if type != nil
@__item_category << Seiryuki::CategorizeItem::RESERVED_CATEGORY_INDEX[type]
end
super
end
end
class Window_ItemList < Window_Selectable
attr_reader :category
alias initialize_CategorizeItem initialize
def initialize(x, y, width, height)
@category = 0
initialize_CategorizeItem(x, y, width, height)
end
def category=(value)
@category = value
refresh
end
alias include_CategorizeItem? include?
def include?(item)
return false if item == nil
if @category == Seiryuki::CategorizeItem::RESERVED_CATEGORY_INDEX["All Items"]
return true
end
result = include_CategorizeItem?(item)
unless result
if $imported["UsableEquipment"] && $game_party.item_can_use?(item)
result = true
end
end
#~ unless $game_temp.in_battle
#~ result &= (item.item_category.include?(@category))
#~ end
return result
end
end
##################################################################
#================================================================#
#Window_ItemCategory ============================================#
#================================================================#
##################################################################
class Window_ItemCategory < Window_HorzCommand
#This sets the max columns for the category window.
alias item_category_col_max col_max
def col_max
return Seiryuki::CategorizeItem::CATEGORY_WINDOW_COLUMNS
end
#This sets the coordinates for the category window.
def initialize
super(Seiryuki::CategorizeItem::CATEGORY_WINDOW_POS[0],
Seiryuki::CategorizeItem::CATEGORY_WINDOW_POS[1])
end
def make_command_list
Seiryuki::CategorizeItem::CATEGORY_NAME.each { |name, symb|
add_command(name, symb)
}
end
def update_help
@help_window.set_text(Seiryuki::CategorizeItem::CATEGORY_DESCRIPTION[self.index])
end
end #class
#================================================================#
#================================================================#
#Window_HorzCommand
#================================================================#
class Window_HorzCommand < Window_Command
#This overwrites spacing method
alias item_category_spacing spacing
def spacing
return Seiryuki::CategorizeItem::CATEGORY_WINDOW_COL_SPACE
end
#This overwrites spacing method. Not working.
#~ alias item_category_visible_line_number visible_line_number
#~ def visible_line_number
#~ return Seiryuki::CategorizeItem::CATEGORY_WINDOW_LINE_NUMBER
#~ end
end #class
#================================================================#
#================================================================#
#Scene_Item
#================================================================#
class Scene_Item < Scene_ItemBase
alias item_category_create_item_window create_item_window
def create_item_window
wy = @category_window.y + @category_window.height
wh = Graphics.height - wy
@item_window = Window_ItemList.new(0, wy, Graphics.width, 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))
@category_window.item_window = @item_window
end
alias update_CategorizeItem update
def update
@category_window.update
update_CategorizeItem
if @category_window.active
update_category_selection
end
end
def update_category_selection
unless @category_activated
@category_activated = true
return
end
if @last_category_index != @category_window.index
@item_window.category = @category_window.index
@item_window.refresh
@last_category_index = @category_window.index
end
if Input.trigger?(Input::B)
Sound.play_cancel
return_scene
elsif Input.trigger?(Input::C)
Sound.play_decision
hide_category_window
end
end
end #class
#================================================================#
#================================================================#
#Window_Help
#================================================================#
class Window_Help < Window_Base
alias item_category_help_initialize initialize
def initialize(line_number = Seiryuki::CategorizeItem::HELP_WINDOW_LINE_NUMBER)
super(Seiryuki::CategorizeItem::HELP_WINDOW_POS[0],
Seiryuki::CategorizeItem::HELP_WINDOW_POS[1],
Graphics.width, fitting_height(line_number))
end
end #class
#================================================================#