Advertisement
Iavra

[Ace] Item Menu

May 30th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.83 KB | None | 0 0
  1. #==========================================================================
  2. # Description:
  3. # Allows the creation of additional item categories via notetags. A category
  4. # can be applied to an item by writing <category ...> in its notebox. The
  5. # notetag <no default> can be used to exclude an item from the default categories
  6. # :item, :key_item, :weapon and :armor.
  7. #--------------------------------------------------------------------------
  8. # Changelog:
  9. # - Added the option to hide item quantities for certain categories.
  10. #==========================================================================
  11.  
  12. module IAVRA
  13.     module ITEM_MENU
  14.    
  15.         #==========================================================================
  16.         # Item categories. The first 4 entries are reserved and include all items,
  17.         # weapons, armors and key items, respectively. The values are built in the
  18.         # following format:
  19.         # - Notetag (nil for reserved categories)
  20.         # - Label in the menu screen
  21.         # - Description in the menu screen
  22.         #==========================================================================
  23.        
  24.         CATEGORIES = {
  25.             :item => [nil, "Items", "Viewing basic items"],
  26.             :weapon => [nil, "Weapons", "Viewing weapons"],
  27.             :armor => [nil, "Armor", "Viewing armors"],
  28.             :key_item => [nil, "Key Items", "Viewing Key items"],
  29.              
  30.             :questnote => ["Quests", "Quest", "Viewing Quest items"]
  31.         }
  32.        
  33.         #==========================================================================
  34.         # Every category in this array will have its item quantities hidden. Useful
  35.         # for key or quest items, where the player will only have 1 at most at any
  36.         # given time anyway.
  37.         #==========================================================================
  38.        
  39.         HIDE_ITEM_QUANTITY = [:questnote]
  40.        
  41.         #==========================================================================
  42.         # Set to true if you want all the categories to autofit in the width of the
  43.         # item category window. Set to false if you only want CATEGORY_WINDOW_MAX_COLUMNS
  44.         # number of categories visible in the window width. If there are more categories
  45.         # than CATEGORY_WINDOW_MAX_COLUMNS, the rest will still be accessible to the
  46.         # right of the last category.
  47.         #==========================================================================
  48.        
  49.         AUTOFIT_CATEGORY_COLUMNS = true
  50.         CATEGORY_WINDOW_MAX_COLUMNS = 5
  51.        
  52.         #==========================================================================
  53.         # Specify the width of the column to be used for each category. The category's
  54.         # text is auto-squished to fit.
  55.         #==========================================================================
  56.        
  57.         CATEGORY_WINDOW_COL_WIDTH = 50
  58.        
  59.         #==========================================================================
  60.         # The amount of space-padding to be used on either end of the column.
  61.         #==========================================================================
  62.        
  63.         CATEGORY_WINDOW_COL_SPACE = 2
  64.        
  65.         #==========================================================================
  66.         # Regex used for parsing notetags.
  67.         #==========================================================================
  68.        
  69.         REGEX_NOTETAG = /^\s*<category\s+(\w+)>/i
  70.        
  71.         #==========================================================================
  72.         # Notetag used to exclude this item from the default categories.
  73.         #==========================================================================
  74.        
  75.         REGEX_NO_DEFAULT = /^\s*<no default>/i
  76.        
  77.     end
  78. end
  79.  
  80. #==========================================================================
  81. # ▼ IAVRA::ITEM_MENU::Window_ItemCategory
  82. #==========================================================================
  83.  
  84. class Window_ItemCategory < Window_HorzCommand
  85.  
  86.   def update_help
  87.         keys = IAVRA::ITEM_MENU::CATEGORIES.keys
  88.         @help_window.set_text(IAVRA::ITEM_MENU::CATEGORIES[keys[self.index]][2])
  89.   end
  90.  
  91.   def make_command_list
  92.     IAVRA::ITEM_MENU::CATEGORIES.each {|symbol, data| add_command(data[1], symbol)}
  93.   end
  94.  
  95.   def col_max
  96.         IAVRA::ITEM_MENU::AUTOFIT_CATEGORY_COLUMNS ?
  97.             IAVRA::ITEM_MENU::CATEGORIES.length :
  98.             IAVRA::ITEM_MENU::CATEGORY_WINDOW_MAX_COLUMNS
  99.   end
  100.  
  101.   def window_width
  102.     Graphics.width
  103.   end
  104.  
  105.   def spacing
  106.     return IAVRA::ITEM_MENU::CATEGORY_WINDOW_COL_SPACE
  107.   end
  108.  
  109. end
  110.  
  111. #==========================================================================
  112. # ▼ RPG::BaseItem
  113. #==========================================================================
  114.  
  115. class RPG::BaseItem
  116.    
  117.     def item_categories
  118.         iavra_item_menu_create_categories if @iavra_item_menu_categories.nil?
  119.         @iavra_item_menu_categories
  120.     end
  121.    
  122.     def iavra_item_menu_create_categories
  123.         @iavra_item_menu_no_default = false
  124.         @iavra_item_menu_categories = []
  125.         self.note.split(/[\r\n]+/).each do |line|
  126.             if(line[IAVRA::ITEM_MENU::REGEX_NOTETAG])
  127.                 cat = IAVRA::ITEM_MENU::CATEGORIES.map{|sym, data| data[0] == $1 ? sym : nil}.compact[0]
  128.                 @iavra_item_menu_categories << cat unless cat.nil?
  129.             end
  130.             if(line[IAVRA::ITEM_MENU::REGEX_NO_DEFAULT])
  131.                 @iavra_item_menu_no_default = true
  132.             end
  133.         end
  134.     end
  135.    
  136. end
  137.  
  138. #==========================================================================
  139. # ▼ RPG::Item
  140. #==========================================================================
  141.  
  142. class RPG::Item < RPG::UsableItem
  143.    
  144.     def iavra_item_menu_create_categories
  145.         super
  146.         return if @iavra_item_menu_no_default
  147.         @iavra_item_menu_categories << :item unless key_item?
  148.         @iavra_item_menu_categories << :key_item if key_item?
  149.     end
  150.    
  151. end
  152.  
  153. #==========================================================================
  154. # ▼ RPG::Weapon
  155. #==========================================================================
  156.  
  157. class RPG::Weapon < RPG::EquipItem
  158.    
  159.     def iavra_item_menu_create_categories
  160.         super
  161.         return if @iavra_item_menu_no_default
  162.         @iavra_item_menu_categories << :weapon
  163.     end
  164.    
  165. end
  166.  
  167. #==========================================================================
  168. # ▼ RPG::Armor
  169. #==========================================================================
  170.  
  171. class RPG::Weapon < RPG::EquipItem
  172.    
  173.     def iavra_item_menu_create_categories
  174.         super
  175.         return if @iavra_item_menu_no_default
  176.         @iavra_item_menu_categories << :armor
  177.     end
  178.    
  179. end
  180.  
  181. #==========================================================================
  182. # ▼ Window_ItemList
  183. #==========================================================================
  184.  
  185. class Window_ItemList < Window_Selectable
  186.    
  187.     alias :iavra_item_menu_initialize :initialize
  188.     alias :iavra_item_menu_draw_item_number :draw_item_number
  189.    
  190.     def initialize(*args)
  191.         iavra_item_menu_initialize(*args)
  192.     end
  193.    
  194.     def include?(item)
  195.         return false if item.nil?
  196.         item.item_categories.include?(@category)
  197.     end
  198.    
  199.     def draw_item_number(*args)
  200.         return if IAVRA::ITEM_MENU::HIDE_ITEM_QUANTITY.include?(@category)
  201.         iavra_item_menu_draw_item_number(*args)
  202.     end
  203.    
  204. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement