Class: HudText
- Inherits:
-
Object
- Object
- HudText
- Defined in:
- lib/fantasy/hud_text.rb
Instance Attribute Summary collapse
-
#alignment ⇒ Object
Returns the value of attribute alignment.
-
#background_color ⇒ Object
Returns the value of attribute background_color.
-
#color ⇒ Object
Returns the value of attribute color.
-
#in_world ⇒ Object
Returns the value of attribute in_world.
-
#layer ⇒ Object
Returns the value of attribute layer.
-
#position ⇒ Object
Returns the value of attribute position.
-
#size ⇒ Object
Returns the value of attribute size.
-
#text ⇒ Object
Returns the value of attribute text.
-
#visible ⇒ Object
Returns the value of attribute visible.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#draw ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#font ⇒ Object
rubocop:enable Metrics/AbcSize.
-
#initialize(position:, text: "") ⇒ HudText
constructor
A new instance of HudText.
- #move ⇒ Object
- #width ⇒ Object
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
#alignment ⇒ Object
Returns the value of attribute alignment.
4 5 6 |
# File 'lib/fantasy/hud_text.rb', line 4 def alignment @alignment end |
#background_color ⇒ Object
Returns the value of attribute background_color.
4 5 6 |
# File 'lib/fantasy/hud_text.rb', line 4 def background_color @background_color end |
#color ⇒ Object
Returns the value of attribute color.
4 5 6 |
# File 'lib/fantasy/hud_text.rb', line 4 def color @color end |
#in_world ⇒ Object
Returns the value of attribute in_world.
4 5 6 |
# File 'lib/fantasy/hud_text.rb', line 4 def in_world @in_world end |
#layer ⇒ Object
Returns the value of attribute layer.
4 5 6 |
# File 'lib/fantasy/hud_text.rb', line 4 def layer @layer end |
#position ⇒ Object
Returns the value of attribute position.
4 5 6 |
# File 'lib/fantasy/hud_text.rb', line 4 def position @position end |
#size ⇒ Object
Returns the value of attribute size.
4 5 6 |
# File 'lib/fantasy/hud_text.rb', line 4 def size @size end |
#text ⇒ Object
Returns the value of attribute text.
4 5 6 |
# File 'lib/fantasy/hud_text.rb', line 4 def text @text end |
#visible ⇒ Object
Returns the value of attribute visible.
4 5 6 |
# File 'lib/fantasy/hud_text.rb', line 4 def visible @visible end |
Instance Method Details
#destroy ⇒ Object
44 45 46 |
# File 'lib/fantasy/hud_text.rb', line 44 def destroy Global.hud_texts.delete(self) end |
#draw ⇒ Object
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 |
#font ⇒ Object
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 |
#move ⇒ Object
20 |
# File 'lib/fantasy/hud_text.rb', line 20 def move; end |
#width ⇒ Object
48 49 50 |
# File 'lib/fantasy/hud_text.rb', line 48 def width font.markup_width(text, 1) end |