Class: HudText

Inherits:
Object
  • Object
show all
Defined in:
lib/fantasy/hud_text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position:, text: "") ⇒ HudText

Returns a new instance of HudText.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fantasy/hud_text.rb', line 6

def initialize(position:, text: "")
  @position = position
  @text = text
  @size = "medium"
  @color = Color.palette.white
  @background_color = Color.palette.black
  @visible = true
  @layer = 100
  @in_world = false
  @alignment = "top-left"

  Global.hud_texts.push(self)
end

Instance Attribute Details

#alignmentObject

Returns the value of attribute alignment.



4
5
6
# File 'lib/fantasy/hud_text.rb', line 4

def alignment
  @alignment
end

#background_colorObject

Returns the value of attribute background_color.



4
5
6
# File 'lib/fantasy/hud_text.rb', line 4

def background_color
  @background_color
end

#colorObject

Returns the value of attribute color.



4
5
6
# File 'lib/fantasy/hud_text.rb', line 4

def color
  @color
end

#in_worldObject

Returns the value of attribute in_world.



4
5
6
# File 'lib/fantasy/hud_text.rb', line 4

def in_world
  @in_world
end

#layerObject

Returns the value of attribute layer.



4
5
6
# File 'lib/fantasy/hud_text.rb', line 4

def layer
  @layer
end

#positionObject

Returns the value of attribute position.



4
5
6
# File 'lib/fantasy/hud_text.rb', line 4

def position
  @position
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'lib/fantasy/hud_text.rb', line 4

def size
  @size
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/fantasy/hud_text.rb', line 4

def text
  @text
end

#visibleObject

Returns the value of attribute visible.



4
5
6
# File 'lib/fantasy/hud_text.rb', line 4

def visible
  @visible
end

Instance Method Details

#destroyObject



44
45
46
# File 'lib/fantasy/hud_text.rb', line 44

def destroy
  Global.hud_texts.delete(self)
end

#drawObject

rubocop:disable Metrics/AbcSize



23
24
25
26
27
28
29
30
31
32
# File 'lib/fantasy/hud_text.rb', line 23

def draw
  if visible
    unless @background_color.nil?
      font.draw_markup_rel(text, screen_position.x + shadow_offset, screen_position.y + shadow_offset, 1, position_rel.x, position_rel.y, 1, 1, background_color)
    end
    font.draw_markup_rel(text, screen_position.x, screen_position.y, 1, position_rel.x, position_rel.y, 1, 1, color)
  end

  draw_debug if Global.debug
end

#fontObject

rubocop:enable Metrics/AbcSize



35
36
37
38
39
40
41
42
# File 'lib/fantasy/hud_text.rb', line 35

def font
  found_font = Global.pixel_fonts[@size]
  if found_font.nil?
    raise "HudText.size value not valid '#{@size}'. Valid values: 'small, medium, big, huge'"
  end

  found_font
end

#moveObject



20
# File 'lib/fantasy/hud_text.rb', line 20

def move; end

#widthObject



48
49
50
# File 'lib/fantasy/hud_text.rb', line 48

def width
  font.markup_width(text, 1)
end