Class: Core::GUI::CharEquip
Constant Summary
collapse
- @@positions =
{
:head => [144, 72],
:torso => [144, 160],
:rarm => [80, 256],
:larm => [208, 256],
:legs => [144, 320],
:feet => [144, 416],
:back => [208, 96],
}
Instance Attribute Summary collapse
Attributes inherited from Element
#h, #w, #x, #xoff, #y, #yoff, #zoff
Instance Method Summary
collapse
Methods inherited from Element
#remove?
Constructor Details
#initialize(x, y, c) ⇒ CharEquip
Returns a new instance of CharEquip.
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/gui/char_equip.rb', line 15
def initialize(x, y, c)
super(x, y, 320, 512)
@bg = Core.sprite("gui/charequip_background")
@body = Core.sprite("gui/equip_#{c.race}")
@font = Core.font(Core::DEFAULT_FONT, 24)
@equipped = {}
reset_slots
@char = c
@equip = false
@changed = false
setup_equipment
end
|
Instance Attribute Details
Returns the value of attribute slot.
5
6
7
|
# File 'lib/gui/char_equip.rb', line 5
def slot
@slot
end
|
Instance Method Details
#changed? ⇒ Boolean
108
109
110
111
112
113
114
115
|
# File 'lib/gui/char_equip.rb', line 108
def changed?
if @changed
@changed = false
return true
else
return false
end
end
|
27
28
29
30
31
|
# File 'lib/gui/char_equip.rb', line 27
def char=(c)
@char = c
@body = Core.sprite("gui/equip_#{c.race}")
setup_equipment
end
|
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/gui/char_equip.rb', line 97
def draw
super
@bg.draw(@x, @y, Core::GUI_Z + 5, @w/@bg.width.to_f, @h/@bg.height.to_f)
@body.draw(@x+32, @y+32, Core::GUI_Z + 6, (@w-64)/@body.width.to_f, (@h-64)/@body.height.to_f)
@slots.each_value { |but|
but.bg.draw(but.x, but.y, Core::GUI_Z + 10, 1, 1, @colors[but])
}
@equipped.each_value { |el|
el.draw
}
end
|
#equip(location) ⇒ Object
70
71
72
73
|
# File 'lib/gui/char_equip.rb', line 70
def equip(location)
@equip = true
@slot = location
end
|
#equip? ⇒ Boolean
74
75
76
77
78
79
80
81
|
# File 'lib/gui/char_equip.rb', line 74
def equip?
if @equip
@equip = false
return true
else
return false
end
end
|
#highlight_slots(ary) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/gui/char_equip.rb', line 42
def highlight_slots(ary)
@colors = {}
red = @slots
green = {}
ary.each { |loc|
green.store(loc, red[loc])
green[loc].proc = lambda { equip(loc) }
red.delete(loc)
}
red.each_value { |img|
color = Gosu::Color.new(255, 255, 0, 0)
@colors.store(img, color)
}
green.each_value { |img|
color = Gosu::Color.new(255, 0, 255, 0)
@colors.store(img, color)
}
@slots = red.merge(green)
end
|
#reset_slots ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/gui/char_equip.rb', line 32
def reset_slots
@slots = {}
@colors = {}
@@positions.each { |loc, pos|
@slots.store(loc, ImageButton.new(@x+pos[0], @y+pos[1], "gui/equipslot_background", lambda {}))
}
@slots.each { |k, v|
@colors.store(v, Gosu::Color.new(255, 255, 255, 255))
}
end
|
#setup_equipment ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/gui/char_equip.rb', line 61
def setup_equipment
equip = @char.equipment
@equipped = {}
equip.each { |loc, item|
if item
@equipped.store(loc, ImageButton.new(@x+@@positions[loc][0], @y+@@positions[loc][1], "#{item.icon_file}", lambda { unequip(loc) }, 32, 32))
end
}
end
|
#unequip(location) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/gui/char_equip.rb', line 82
def unequip(location)
@char.inventory.add(@char.equipment.remove_at(location))
setup_equipment
@changed = true
end
|
88
89
90
91
92
93
94
95
96
|
# File 'lib/gui/char_equip.rb', line 88
def update
super
@equipped.each_value { |el|
el.update
}
@slots.each_value { |but|
but.update
}
end
|