class Core::GUI::CharEquip
Attributes
slot[R]
Public Class Methods
new(x, y, c)
click to toggle source
Calls superclass method
Core::GUI::Element::new
# 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
Public Instance Methods
changed?()
click to toggle source
# File lib/gui/char_equip.rb, line 108 def changed? if @changed @changed = false return true else return false end end
char=(c)
click to toggle source
# File lib/gui/char_equip.rb, line 27 def char=(c) @char = c @body = Core.sprite("gui/equip_#{c.race}") setup_equipment end
draw()
click to toggle source
Calls superclass method
Core::GUI::Element#draw
# 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)
click to toggle source
# File lib/gui/char_equip.rb, line 70 def equip(location) @equip = true @slot = location end
equip?()
click to toggle source
# File lib/gui/char_equip.rb, line 74 def equip? if @equip @equip = false return true else return false end end
highlight_slots(ary)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/gui/char_equip.rb, line 82 def unequip(location) # TODO weight/capacity check @char.inventory.add(@char.equipment.remove_at(location)) setup_equipment @changed = true end
update()
click to toggle source
Calls superclass method
Core::GUI::Element#update
# File lib/gui/char_equip.rb, line 88 def update super @equipped.each_value { |el| el.update } @slots.each_value { |but| but.update } end