Advertisement
LiTTleDRAgo

[RGSS2] Window Item Edit

Apr 4th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.50 KB | None | 0 0
  1. #==============================================================================
  2. # ** Window_Item
  3. #------------------------------------------------------------------------------
  4. #  This window displays a list of inventory items for the item screen, etc.
  5. #==============================================================================
  6.  
  7. class Window_Item < Window_Selectable
  8.   #--------------------------------------------------------------------------
  9.   # * Object Initialization
  10.   #     x      : window x-coordinate
  11.   #     y      : window y-coordinate
  12.   #     width  : window width
  13.   #     height : window height
  14.   #--------------------------------------------------------------------------
  15.   def initialize(x, y, width, height)
  16.     super(x, y, width, height)
  17.     @column_max = (width-32)/WLH
  18.     self.index = 0
  19.     refresh
  20.   end
  21.   #--------------------------------------------------------------------------
  22.   # * Refresh
  23.   #--------------------------------------------------------------------------
  24.   def refresh
  25.     @data = []
  26.     $game_party.items.each {|item|
  27.       next unless include?(item)
  28.       $game_party.item_number(item).times {@data << item}
  29.       if item.is_a?(RPG::Item) && item.id == $game_party.last_item_id
  30.         self.index = @data.size - 1
  31.       end}
  32.     @data.push(nil) if include?(nil)
  33.     @item_max = @data.size
  34.     create_contents
  35.     @data.each_index{|i| draw_item(i)}
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # * Draw Item
  39.   #     index : item number
  40.   #--------------------------------------------------------------------------
  41.   def draw_item(index)
  42.     rect = item_rect(index)
  43.     self.contents.clear_rect(rect)    
  44.     item = @data[index]
  45.     draw_icon(item.icon_index, rect.x, rect.y, enable?(item))
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # * Get rectangle for displaying items
  49.   #     index : item number
  50.   #--------------------------------------------------------------------------
  51.   def item_rect(index)
  52.     rect = Rect.new(0, 0, 0, 0)
  53.     rect.width = WLH
  54.     rect.height = WLH
  55.     rect.x = index % @column_max * WLH
  56.     rect.y = index / @column_max * WLH
  57.     return rect
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # * Update Help Text
  61.   #--------------------------------------------------------------------------
  62.   def update_help
  63.     @help_window.set_text(item == nil ? "" : item.name+' : '+item.description)
  64.   end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement