Class: AdventureRL::Menu

Inherits:
Layer show all
Defined in:
lib/AdventureRL/Menu.rb

Constant Summary collapse

[]
DEFAULT_SETTINGS =
Settings.new(
  active:         false,
  auto_update:    false,
  mouse_buttons_event_handler: {
    auto_update:        false,
    only_mouse_buttons: true
  }
)

Constants inherited from Layer

Layer::MASK_ID

Constants included from AdventureRL::Modifiers::Inventory

AdventureRL::Modifiers::Inventory::DEFAULT_INVENTORY_ID

Constants included from Helpers::Error

Helpers::Error::PADDING, Helpers::Error::STACK_TRACE_PADDING, Helpers::Error::STACK_TRACE_SIZE

Constants inherited from Mask

AdventureRL::Mask::MASKS

Constants inherited from Point

Point::POINTS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layer

#get_real_point, #get_real_scale, #get_rotation, #get_scale, #get_solids_manager, #has_solids_manager?, #increase_rotation, #increase_scale, #move_by, #set_rotation, #set_scale

Methods included from AdventureRL::Modifiers::Inventory

#added_object?, #get_object, #get_objects, #remove_object, #remove_objects, #removed

Methods included from Helpers::Error

directory_exists?, error, error_no_directory, error_no_file, file_exists?

Methods inherited from Mask

#assign_to, #assigned_to?, #collides_with?, #collides_with_hash?, #collides_with_mask?, #collides_with_point?, #get_assigned, #get_center, #get_corner, #get_layer, #get_mask, #get_origin, #get_real_center, #get_real_corner, #get_real_side, #get_real_sides, #get_side, #get_sides, #get_size, #has_layer?, #has_mask?, #set_layer, #set_size

Methods inherited from Point

#assign_to, #assigned_to?, #collides_with?, #collides_with_hash?, #collides_with_mask?, #collides_with_point?, #get_assigned, #get_layer, #get_point, #get_position, #get_real_point, #get_real_position, #has_layer?, #has_point?, #keys, #move_by, #set_layer, #set_position, #values, #x, #y

Constructor Details

#initialize(settings = {}) ⇒ Menu

Returns a new instance of Menu.



32
33
34
35
36
37
38
# File 'lib/AdventureRL/Menu.rb', line 32

def initialize settings = {}
  @settings = DEFAULT_SETTINGS.merge settings
  @mouse_buttons_event_handler = EventHandlers::MouseButtons.new @settings.get(:mouse_buttons_event_handler)
  super @settings
  @active = @settings.get :active
  MENUS << self  if (@settings.get(:auto_update))
end

Class Method Details

.button_down(btnid) ⇒ Object



6
7
8
9
10
# File 'lib/AdventureRL/Menu.rb', line 6

def self.button_down btnid
  get_active_menus.each do |menu|
    menu.button_down btnid
  end
end

.button_up(btnid) ⇒ Object



11
12
13
14
15
# File 'lib/AdventureRL/Menu.rb', line 11

def self.button_up btnid
  get_active_menus.each do |menu|
    menu.button_up btnid
  end
end

.get_active_menusObject



19
20
21
# File 'lib/AdventureRL/Menu.rb', line 19

def self.get_active_menus
  return MENUS.select(&:is_active?)
end

.updateObject



16
17
18
# File 'lib/AdventureRL/Menu.rb', line 16

def self.update
  get_active_menus.each(&:update)
end

Instance Method Details

#activateObject



55
56
57
# File 'lib/AdventureRL/Menu.rb', line 55

def activate
  @active = true
end

#add_object(object, id = DEFAULT_INVENTORY_ID) ⇒ Object Also known as: add_button, add_item, add, <<

Overwrite #add_object method, so we can validate, that the given object is a Button.



42
43
44
45
46
47
48
49
# File 'lib/AdventureRL/Menu.rb', line 42

def add_object object, id = DEFAULT_INVENTORY_ID
  #Helpers::Error.error(
  #  "Expected given object to be a Button, but got",
  #  "'#{object.inspect}:#{object.class.name}`."
  #)  unless (object.is_a? Button)
  super
  @mouse_buttons_event_handler.subscribe object  if (object.is_a? Button)
end

#button_down(btnid) ⇒ Object



71
72
73
74
# File 'lib/AdventureRL/Menu.rb', line 71

def button_down btnid
  return  if (is_inactive?)
  @mouse_buttons_event_handler.button_down btnid
end

#button_up(btnid) ⇒ Object



76
77
78
79
# File 'lib/AdventureRL/Menu.rb', line 76

def button_up btnid
  return  if (is_inactive?)
  @mouse_buttons_event_handler.button_up btnid
end

#deactivateObject



59
60
61
# File 'lib/AdventureRL/Menu.rb', line 59

def deactivate
  @active = false
end

#drawObject



87
88
89
90
# File 'lib/AdventureRL/Menu.rb', line 87

def draw
  return  if (is_inactive?)
  super
end

#is_active?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/AdventureRL/Menu.rb', line 63

def is_active?
  return !!@active
end

#is_inactive?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/AdventureRL/Menu.rb', line 67

def is_inactive?
  return !is_active?
end

#updateObject



81
82
83
84
85
# File 'lib/AdventureRL/Menu.rb', line 81

def update
  return  if (is_inactive?)
  @mouse_buttons_event_handler.update
  super
end