class Setting

Constants

NAME
SELECTION

Attributes

font[RW]
max_height[RW]
max_width[RW]
selection[RW]
value[RW]
window[RW]
x[RW]
y[RW]

Public Class Methods

get_id_button_mapping() click to toggle source
# File line-em-up/lib/setting.rb, line 26
def self.get_id_button_mapping
  {
    next: lambda { |setting, id| setting.next_clicked }
  }
end
new(window, fullscreen_height, max_width, max_height, current_height, config_file_path) click to toggle source
# File line-em-up/lib/setting.rb, line 8
def initialize window, fullscreen_height, max_width, max_height, current_height, config_file_path
  @window = window
  @selection = self.class::SELECTION
  # puts "INNITING #{config_file_path}"
  @font = Gosu::Font.new(20)
  # @x = width
  @y = current_height
  @max_width = max_width
  @max_height = max_height
  @next_x = 15
  @prev_x = @max_width - 15 - @font.text_width('>')
  @config_file_path = config_file_path
  @name = self.class::NAME
  @value = ConfigSetting.get_setting(@config_file_path, @name, @selection[0])
  @fullscreen_height = fullscreen_height
  @button_id_mapping = self.class.get_id_button_mapping
end

Public Instance Methods

clicked(mx, my) click to toggle source

Deprecating, using Liut

# File line-em-up/lib/setting.rb, line 86
def clicked mx, my
  if is_mouse_hovering_next(mx, my)
    previous_clicked
  elsif is_mouse_hovering_prev(mx, my)
    next_clicked
  end
end
draw() click to toggle source
# File line-em-up/lib/setting.rb, line 39
def draw
  @font.draw("<", @next_x, @y, 1, 1.0, 1.0, 0xff_ffff00)
  @font.draw(@value, ((@max_width / 2) - @font.text_width(@value) / 2), @y, 1, 1.0, 1.0, 0xff_ffff00)
  @font.draw(">", @prev_x, @y, 1, 1.0, 1.0, 0xff_ffff00)
end
get_values() click to toggle source
# File line-em-up/lib/setting.rb, line 32
def get_values
  # puts "GETTING DIFFICULTY: #{@value}"
  if @value
    @value
  end
end
is_mouse_hovering_next(mx, my) click to toggle source
# File line-em-up/lib/setting.rb, line 94
def is_mouse_hovering_next mx, my
  local_width  = @font.text_width('>')
  local_height = @font.height

  (mx >= @next_x and my >= @y) and (mx <= @next_x + local_width) and (my <= @y + local_height)
end
is_mouse_hovering_prev(mx, my) click to toggle source
# File line-em-up/lib/setting.rb, line 101
def is_mouse_hovering_prev mx, my
  local_width  = @font.text_width('<')
  local_height = @font.height

  (mx >= @prev_x and my >= @y) and (mx <= @prev_x + local_width) and (my <= @y + local_height)
end
next_clicked() click to toggle source
# File line-em-up/lib/setting.rb, line 73
def next_clicked
  index = @selection.index(@value)
  value = @value
  if index == @selection.count - 1
    value = @selection[0]
  else
    value = @selection[index + 1]
  end
  ConfigSetting.set_setting(@config_file_path, @name, value)
  @value = value
end
onClick(element_id) click to toggle source

required for LUIT objects, passes id of element

# File line-em-up/lib/setting.rb, line 50
def onClick element_id
  # puts "ONCLICK mappuing"
  puts @button_id_mapping
  button_clicked_exists = @button_id_mapping.key?(element_id)
  if button_clicked_exists
    @button_id_mapping[element_id].call(self, element_id)
  else
    puts "Clicked button that is not mapped: #{element_id}"
  end
end
previous_clicked() click to toggle source
# File line-em-up/lib/setting.rb, line 61
def previous_clicked
  index = @selection.index(@value)
  value = @value
  if index == 0
    value = @selection[@selection.count - 1]
  else
    value = @selection[index - 1]
  end
  ConfigSetting.set_setting(@config_file_path, @name, value)
  @value = value
end
update(mouse_x, mouse_y) click to toggle source
# File line-em-up/lib/setting.rb, line 45
def update mouse_x, mouse_y
  return @value
end