Class: Chingu::SimpleMenu
Instance Attribute Summary collapse
#options, #parent, #paused
Instance Method Summary
collapse
#add_inputs, #holding?, #holding_all?, #holding_any?, #input, #input=, #on_input
all, create, #destroy, destroy_all, destroy_if, #draw_trait, each, each_with_index, #filename, initialize_trait, #pause!, #paused?, select, #setup, #setup_trait, size, trait, #trait_options, traits, #unpause!, #update, #update_trait
included
Constructor Details
#initialize(options = {}) ⇒ SimpleMenu
Returns a new instance of SimpleMenu.
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/chingu/simple_menu.rb', line 30
def initialize(options = {})
super
@menu_items = options.delete(:menu_items) @x = options.delete(:x) || $window.width/2
@y = options.delete(:y) || 100
@spacing = options.delete(:spacing) || 100
@items = []
@visible = true
y = @spacing
.each do |key, value|
item = if key.is_a? String
Text.new(key, options.dup)
elsif key.is_a? Image
GameObject.new(options.merge!(:image => key))
elsif key.is_a? GameObject
.options.merge!(options.dup)
end
item.options[:on_select] = method(:on_select)
item.options[:on_deselect] = method(:on_deselect)
item.options[:action] = value
item.rotation_center = :center_center
item.x = @x
item.y = y
y += item.height + @spacing
@items << item
end
@selected = options[:selected] || 0
step(0)
self.input = {:up => lambda{step(-1)}, :down => lambda{step(1)}, [:return, :space] => :select}
end
|
Instance Attribute Details
Returns the value of attribute menu_items.
28
29
30
|
# File 'lib/chingu/simple_menu.rb', line 28
def
@menu_items
end
|
#visible ⇒ Object
Returns the value of attribute visible.
28
29
30
|
# File 'lib/chingu/simple_menu.rb', line 28
def visible
@visible
end
|
Instance Method Details
#draw ⇒ Object
91
92
93
|
# File 'lib/chingu/simple_menu.rb', line 91
def draw
@items.each { |item| item.draw }
end
|
#on_deselect(object) ⇒ Object
83
84
85
|
# File 'lib/chingu/simple_menu.rb', line 83
def on_deselect(object)
object.color = Color::WHITE
end
|
#on_select(object) ⇒ Object
87
88
89
|
# File 'lib/chingu/simple_menu.rb', line 87
def on_select(object)
object.color = Color::RED
end
|
#select ⇒ Object
75
76
77
|
# File 'lib/chingu/simple_menu.rb', line 75
def select
dispatch_action(selected.options[:action], self.parent)
end
|
#selected ⇒ Object
79
80
81
|
# File 'lib/chingu/simple_menu.rb', line 79
def selected
@items[@selected]
end
|
#step(value) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/chingu/simple_menu.rb', line 67
def step(value)
selected.options[:on_deselect].call(selected)
@selected += value
@selected = @items.count-1 if @selected < 0
@selected = 0 if @selected == @items.count
selected.options[:on_select].call(selected)
end
|