Class: Lotu::TextBox

Inherits:
Actor
  • Object
show all
Defined in:
lib/lotu/text_box.rb

Instance Attribute Summary

Attributes inherited from Actor

#parent, #systems, #x, #y

Instance Method Summary collapse

Methods inherited from Actor

#activate_system, #die, #dt

Constructor Details

#initialize(opts = {}) ⇒ TextBox

Returns a new instance of TextBox.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/lotu/text_box.rb', line 4

def initialize(opts={})
  default_opts = {
    :font_size => 20
  }
  opts = default_opts.merge!(opts)
  super(opts)
  @watch_list = []
  @subject_opts = {}
  @font_size = opts[:font_size]
  @attached_to = opts[:attach_to]
  # Since we aren't setting an image for this, we need to specify
  # this actor needs to be drawed
  draw_me
end

Instance Method Details

#attach_to(actor) ⇒ Object



24
25
26
# File 'lib/lotu/text_box.rb', line 24

def attach_to(actor)
  @attached_to = actor
end

#drawObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lotu/text_box.rb', line 35

def draw
  pos_y = 0
  @watch_list.each do |watched|
    my_font_size = @subject_opts[watched][:font_size] || @font_size
    my_color = @subject_opts[watched][:color] || @color
    my_text = watched.to_s
    if my_text.is_a?(String)
      $window.fonts[my_font_size].draw(my_text, @x, @y + pos_y, @z, @factor_x, @factor_y, my_color)
      pos_y += my_font_size
    else
      my_text.each do |line|
        $window.fonts[my_font_size].draw(line, @x, @y + pos_y, @z, @factor_x, @factor_y, my_color)
        pos_y += my_font_size
      end
    end
  end
end

#updateObject



28
29
30
31
32
33
# File 'lib/lotu/text_box.rb', line 28

def update
  unless @attached_to.nil?
    @x = @attached_to.x + @attached_to.image.width / 2
    @y = @attached_to.y - @attached_to.image.height / 2
  end
end

#watch(subject, opts = {}) ⇒ Object



19
20
21
22
# File 'lib/lotu/text_box.rb', line 19

def watch(subject, opts={})
  @watch_list << subject
  @subject_opts[subject] = opts
end