class Menu

Attributes

current_height[RW]
local_window[RW]
x[RW]
y[RW]

Public Class Methods

new(window, x, y, z = ZOrder::UI, scale = 1) click to toggle source
# File line-em-up/models/menu.rb, line 4
def initialize(window, x, y, z = ZOrder::UI, scale = 1)
    @scale = scale
    @window = window
    @x = x
    @y = y
    @z = z
    @cell_padding = 10 * @scale
    # @offset_y = 0
    @local_window = self
    LUIT.config({window: @window, z: z})
    @items = Array.new
    @current_height = 0
    # Add to it while the buttons are being added, in add_item
    @button_id_mapping = {}
end

Public Instance Methods

add_item(object, x, y, callback, hover_image = nil, options = {}) click to toggle source
# File line-em-up/models/menu.rb, line 25
def add_item(object, x, y, callback, hover_image = nil, options = {})
    if options[:key]
      @button_id_mapping[options[:key]] = callback
    end
    if options[:is_button]

    end
    item = MenuItem.new(@window, object, x, y, @z, callback, hover_image, options)
    if options[:is_button]
      @current_height = @current_height + object.h + @cell_padding
    else
      @current_height = @current_height + object.height + @cell_padding
    end
    @items << item
    self
end
clicked() click to toggle source
# File line-em-up/models/menu.rb, line 54
def clicked
    @items.each do |i|
        i.clicked
    end
end
draw() click to toggle source
# File line-em-up/models/menu.rb, line 42
def draw
    @items.each do |i|
      i.draw
    end
end
increase_y_offset(amount) click to toggle source

For external use

# File line-em-up/models/menu.rb, line 21
def increase_y_offset amount
    @current_height = @current_height + amount
end
onClick(element_id) click to toggle source
# File line-em-up/models/menu.rb, line 60
def onClick element_id
  # puts "LOADOUT WINDOW ONCLICK"
  button_clicked_exists = @button_id_mapping.key?(element_id)
  if button_clicked_exists
    @button_id_mapping[element_id].call(@local_window, element_id)
  else
    puts "Clicked button that is not mapped: #{element_id}"
  end
end
update() click to toggle source
# File line-em-up/models/menu.rb, line 48
def update
    @items.each do |i|
        i.update
    end
end