Class: RedBird::VerticalMenu
- Defined in:
- lib/red_bird/vertical_menu.rb
Overview
VerticalMenu is an interactive menu that receives input from players. It consists of a vertical list of Option.
Defined Under Namespace
Classes: Option
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#activate ⇒ Object
Executes the action in the selected option.
- #height ⇒ Integer
-
#initialize(style, pos_x, pos_y, options) ⇒ VerticalMenu
constructor
A new instance of VerticalMenu.
-
#next_opt ⇒ Object
Changes the selected Option to the next one.
-
#pred_opt ⇒ Object
Changes the selected Option to the previous one.
-
#render ⇒ Object
Renders to the screen.
- #width ⇒ Integer
Methods inherited from Entity
#cursor_down, #cursor_hover, #cursor_up, #tick
Constructor Details
#initialize(style, pos_x, pos_y, options) ⇒ VerticalMenu
Returns a new instance of VerticalMenu.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/red_bird/vertical_menu.rb', line 36 def initialize(style, pos_x, pos_y, ) @style = style @pos_x = pos_x @pos_y = pos_y @options = @current_option = 0 @option_max_width = 0 @option_max_height = 0 @options.each do |i| if @option_max_width < i.text.width then @option_max_width = i.text.width end if @option_max_height < i.text.height then @option_max_height = i.text.height end end end |
Instance Method Details
#activate ⇒ Object
Executes the action in the selected option.
71 72 73 |
# File 'lib/red_bird/vertical_menu.rb', line 71 def activate @options[@current_option].action.call end |
#height ⇒ Integer
64 65 66 |
# File 'lib/red_bird/vertical_menu.rb', line 64 def height @option_max_height * @options.size end |
#next_opt ⇒ Object
Changes the selected Option to the next one.
78 79 80 81 |
# File 'lib/red_bird/vertical_menu.rb', line 78 def next_opt @current_option += 1 @current_option = 0 if @current_option >= @options.size end |
#pred_opt ⇒ Object
Changes the selected Option to the previous one.
86 87 88 89 90 91 92 |
# File 'lib/red_bird/vertical_menu.rb', line 86 def pred_opt if @current_option <= 0 then @current_option = @options.size - 1 else @current_option -= 1 end end |
#render ⇒ Object
Renders to the screen.
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/red_bird/vertical_menu.rb', line 97 def render # Render texts. @options.each_with_index do |o, i| o.text.render_to_screen( @style.sprite_width * 2 + @pos_x, @style.sprite_height * (i + 1) + @pos_y) end @style.sprites[:arrow_select].render_to_screen( @style.sprite_width + @pos_x, @style.sprite_height * (@current_option + 1) + @pos_y) end |
#width ⇒ Integer
58 59 60 |
# File 'lib/red_bird/vertical_menu.rb', line 58 def width @option_max_width end |