class Menu

Public Class Methods

new(name, window, font, *choices) click to toggle source
# 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

Public Instance Methods

draw() click to toggle source
# 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() click to toggle source

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

# File lib/game_2d/menu.rb, line 28
def handle_click
  @choices.collect(&:handle_click).compact.first
end
to_s() click to toggle source
# File lib/game_2d/menu.rb, line 32
def to_s
  @name.respond_to?(:call) ? @name.call(self) : @name.to_s
end