Class: Core::GUI::Inventory

Inherits:
Container show all
Includes:
Core
Defined in:
lib/gui/inventory.rb

Constant Summary

Constants included from Core

CURSOR_Z, DEFAULT_CONFIG, DEFAULT_FONT, FOG_Z, Core::GUI_Z, HOME_PATH, LIBRARY_PATH, MAPOBJECT_Z, MAP_Z, PARTICLE_Z, RELEASE, SAVE_DIR, VERSION

Instance Attribute Summary collapse

Attributes inherited from Container

#ch

Attributes inherited from Element

#h, #w, #x, #xoff, #y, #yoff, #zoff

Instance Method Summary collapse

Methods included from Core

anim, animations, animations=, between?, config, exit, font, inside?, load_game, mouse_inside?, multiline, particles, particles=, save_game, silently, sprite, tiles, window, window=

Methods inherited from Container

#add, #changed?, #draw, #hovered, #selected, #update

Methods inherited from Element

#draw, #remove?, #update

Constructor Details

#initialize(x, y, w, h, char, filter = [:all], item_height = 24) ⇒ Inventory

Returns a new instance of Inventory.



6
7
8
9
10
11
12
13
# 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

Instance Attribute Details

#invObject (readonly)

Returns the value of attribute inv.



5
6
7
# File 'lib/gui/inventory.rb', line 5

def inv
  @inv
end

Instance Method Details

#assemble_itemsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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) ⇒ Object



36
37
38
39
# File 'lib/gui/inventory.rb', line 36

def inventory=(inv)
  @inv = inv
  assemble_items
end