Class: Core::States::EquipMenu

Inherits:
State show all
Includes:
Core, GUI
Defined in:
lib/states/menus/equip.rb

Constant Summary

Constants included from Core

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

Instance Attribute Summary

Attributes inherited from State

#window, #x, #y

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 State

#draw_cursor, #finish, #update_cursor

Constructor Details

#initialize(window, previous, party) ⇒ EquipMenu

Returns a new instance of EquipMenu.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/states/menus/equip.rb', line 7

def initialize(window, previous, party)
  super(window)
  @previous = previous
  @party = party
  @background = Core.sprite("menu/ingame_background")
  @w = Core::GUI::Window.new(0, 0, 1024, 768, Trans.menu(:equipment))
  @w.add(:charselect, CharSelector.new(32, 32, party))
  @w.add(:inventory, Inventory.new(32, 96, 256, 360, @party.members[@w.get(:charselect).index], [:pants, :melee, :armor, :cloth, :ranged, :boots, :ammo]))
  @w.add(:iteminfo, ItemInfo.new(320, 32))
  @w.add(:itemdrop, ImageButton.new(32, 464, "gui/drop_item", lambda { drop_item }, 96, 96))
  @w.get(:itemdrop).disable
  @w.add(:equip, CharEquip.new(320, 224, @party.members[0]))
end

Instance Method Details

#drawObject



63
64
65
66
67
# File 'lib/states/menus/equip.rb', line 63

def draw
  @background.draw(0, 0, 0)
  @w.draw
  draw_cursor
end

#drop_itemObject

TODO ask for amount, right now it drops only one



69
70
71
72
73
74
75
76
# File 'lib/states/menus/equip.rb', line 69

def drop_item
  @party.members[@w.get(:charselect).index].inventory.remove(@w.get(:inventory).selected)
  @w.get(:inventory).assemble_items
  @w.get(:iteminfo).item = nil
  @cursor.clear
  @w.get(:equip).reset_slots
  @w.get(:itemdrop).disable
end

#updateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/states/menus/equip.rb', line 20

def update
  super
  if @window.pressed?(Gosu::KbEscape) or @w.remove?
    @window.advance(@previous)
  end
  @w.update
  if @w.get(:charselect).changed?
    @w.get(:inventory).inventory = @party.members[@w.get(:charselect).index].inventory
    @w.get(:iteminfo).item = nil
    @w.get(:itemdrop).disable
    @w.get(:equip).char = @party.members[@w.get(:charselect).index]
    @w.get(:equip).reset_slots
    @cursor.clear
  end
  if @w.get(:inventory).changed?
    @w.get(:iteminfo).item = @w.get(:inventory).selected
    @w.get(:itemdrop).enable
    ary = Core::Game.itemtype_to_locations(@w.get(:inventory).selected.type, @party.members[@w.get(:charselect).index].equipment)
    @w.get(:equip).highlight_slots(ary)
    @cursor.attach(@w.get(:inventory).selected.icon)
  end
  if @w.get(:equip).changed?
    @w.get(:inventory).assemble_items
    ary = Core::Game.itemtype_to_locations(@w.get(:inventory).selected.type, @party.members[@w.get(:charselect).index].equipment)
    @w.get(:equip).reset_slots
    if !@cursor.empty?
      @w.get(:equip).highlight_slots(ary)
    end
    @w.get(:equip).setup_equipment
  end
  if @w.get(:equip).equip?
    loc = @w.get(:equip).slot
    inv = @party.members[@w.get(:charselect).index].inventory
    equip = @party.members[@w.get(:charselect).index].equipment
    equip.equip(@w.get(:inventory).selected, loc, inv)
    @w.get(:iteminfo).item = nil
    @w.get(:itemdrop).disable
    @w.get(:equip).reset_slots
    @w.get(:equip).setup_equipment
    @w.get(:inventory).assemble_items
    @cursor.clear
  end
end