Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/game_2d/menu.rb
Instance Method Summary collapse
- #draw ⇒ Object
-
#handle_click ⇒ Object
Returns a true value if it handled the click May return a Menu or MenuItem to be set as the new menu to display May return simply ‘true’ if we should redisplay the top-level menu.
-
#initialize(name, window, font, *choices) ⇒ Menu
constructor
A new instance of Menu.
- #to_s ⇒ Object
Constructor Details
#initialize(name, window, font, *choices) ⇒ Menu
Returns a new instance of Menu.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/game_2d/menu.rb', line 5 def initialize(name, window, font, *choices) @name, @window, @font, @choices = name, window, font, choices @main_color, @select_color = Gosu::Color::YELLOW, Gosu::Color::CYAN @right = window.width - 1 @choices.each_with_index do |choice, num| choice.x = @right choice.y = (num + 2) * @font.height end end |
Instance Method Details
#draw ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/game_2d/menu.rb', line 16 def draw str = to_s @font.draw_rel(str, @window.width - 1, 0, ZOrder::Text, 1.0, 0.0, 1.0, 1.0, @main_color) x1, x2, y, c = @right - @font.text_width(str), @right, @font.height, @main_color @window.draw_box_at(x1, y, x2, y+1, @main_color) @choices.each(&:draw) end |
#handle_click ⇒ Object
Returns a true value if it handled the click May return a Menu or MenuItem to be set as the new menu to display May return simply ‘true’ if we should redisplay the top-level menu
28 29 30 |
# File 'lib/game_2d/menu.rb', line 28 def handle_click @choices.collect(&:handle_click).compact.first end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/game_2d/menu.rb', line 32 def to_s @name.respond_to?(:call) ? @name.call(self) : @name.to_s end |