class Core::GUI::Inventory

Attributes

inv[R]

Public Class Methods

new(x, y, w, h, char, filter=[:all], item_height=24) click to toggle source
Calls superclass method Core::GUI::Container::new
# File lib/gui/inventory.rb, line 6
def initialize(x, y, w, h, char, filter=[:all], item_height=24)
  super(x, y, w, h, item_height)
  @item_height = item_height
  @inv = char.inventory
  @filter = filter
  @item = nil
  assemble_items
end

Public Instance Methods

assemble_items() click to toggle source
# File lib/gui/inventory.rb, line 15
def assemble_items
  @items = []
  items = {}
  y = 0
  @inv.each { |item|
    if @filter.include?(:all) or @filter.include?(item.type)
      if items[item.name] != nil
        items[item.name][1] += 1
      else
        items.store(item.name, [item, 1])
      end
    end
  }
  items.each_value { |ary|
    item = ary[0]
    amount = ary[1]
    @items.push(Button.new(@x, @y+(y*@item_height), @w-24, @item_height, "#{amount}x #{Trans.item(item.name)}", lambda { clicked(item) }, false, :left, 24))
    y += 1
  }
end
inventory=(inv) click to toggle source
# File lib/gui/inventory.rb, line 36
def inventory=(inv)
  @inv = inv
  assemble_items
end