metro 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gosu_ext/color.rb +24 -0
- data/lib/metro.rb +6 -2
- data/lib/metro/animation/animation.rb +78 -49
- data/lib/metro/animation/easing.rb +22 -19
- data/lib/metro/animation/implicit_animation.rb +84 -25
- data/lib/metro/game.rb +5 -1
- data/lib/metro/game/dsl.rb +4 -0
- data/lib/metro/models/generic.rb +12 -0
- data/lib/metro/models/image.rb +29 -0
- data/lib/metro/models/label.rb +29 -0
- data/lib/metro/models/model.rb +188 -0
- data/lib/metro/models/select.rb +77 -0
- data/lib/metro/scene.rb +106 -6
- data/lib/metro/scene_actor.rb +26 -0
- data/lib/metro/scene_view/scene_view.rb +24 -27
- data/lib/metro/version.rb +1 -1
- data/lib/metro/window.rb +1 -1
- metadata +9 -9
- data/lib/metro/model.rb +0 -12
- data/lib/metro/scene_view/drawers/artists_block.rb +0 -17
- data/lib/metro/scene_view/drawers/composite_drawer.rb +0 -87
- data/lib/metro/scene_view/drawers/drawer.rb +0 -115
- data/lib/metro/scene_view/drawers/image.rb +0 -31
- data/lib/metro/scene_view/drawers/label.rb +0 -28
- data/lib/metro/scene_view/drawers/select.rb +0 -70
@@ -1,28 +0,0 @@
|
|
1
|
-
module Metro
|
2
|
-
module SceneView
|
3
|
-
|
4
|
-
#
|
5
|
-
# Draws a string of text.
|
6
|
-
#
|
7
|
-
class Label < Drawer
|
8
|
-
draws 'label'
|
9
|
-
|
10
|
-
def font
|
11
|
-
@font ||= Gosu::Font.new(window, Gosu::default_font_name, 20)
|
12
|
-
end
|
13
|
-
|
14
|
-
def draw(view)
|
15
|
-
label_text = scene.instance_eval( "\"#{view['text']}\"" )
|
16
|
-
|
17
|
-
label_color = view['color'] || 0xffffffff
|
18
|
-
label_color = label_color.to_i(16) if label_color.is_a? String
|
19
|
-
|
20
|
-
font.draw label_text,
|
21
|
-
view['x'], view['y'], view['z-order'],
|
22
|
-
view['x-factor'] || 1.0, view['y-factor'] || 1.0,
|
23
|
-
label_color
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module Metro
|
2
|
-
module SceneView
|
3
|
-
|
4
|
-
#
|
5
|
-
# Draws a a menu of options. It is called a Select as it is named after the HTML
|
6
|
-
# element select. A select drawer also inserts itself into the scene as an event
|
7
|
-
# target as it needs to maintain the state of the menu. When an option is selected
|
8
|
-
# an event is fired based on the name of the option.
|
9
|
-
#
|
10
|
-
# @note Only one 'select' can be defined for a given scene.
|
11
|
-
#
|
12
|
-
class Select < Drawer
|
13
|
-
draws 'select'
|
14
|
-
|
15
|
-
attr_accessor :selected_index, :options
|
16
|
-
|
17
|
-
def after_initialize
|
18
|
-
name, content = scene.view.find { |name,content| content['type'].to_sym == :select }
|
19
|
-
|
20
|
-
if content
|
21
|
-
@selected_index = 0
|
22
|
-
@options = content['options']
|
23
|
-
events = EventRelay.new(self,window)
|
24
|
-
|
25
|
-
events.on_up Gosu::KbLeft, Gosu::GpLeft, Gosu::KbUp, Gosu::GpUp, do: :previous_option
|
26
|
-
events.on_up Gosu::KbRight, Gosu::GpRight, Gosu::KbDown, Gosu::GpDown, do: :next_option
|
27
|
-
events.on_up Gosu::KbEnter, Gosu::KbReturn, Gosu::GpButton0, do: :selection
|
28
|
-
|
29
|
-
scene.add_event_relay events
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def selection
|
34
|
-
scene_method = options[selected_index].downcase.gsub(/\s/,'_')
|
35
|
-
scene.send scene_method
|
36
|
-
end
|
37
|
-
|
38
|
-
def previous_option
|
39
|
-
@selected_index = @selected_index - 1
|
40
|
-
@selected_index = options.length - 1 if @selected_index <= -1
|
41
|
-
end
|
42
|
-
|
43
|
-
def next_option
|
44
|
-
@selected_index = @selected_index + 1
|
45
|
-
@selected_index = 0 if @selected_index >= options.length
|
46
|
-
end
|
47
|
-
|
48
|
-
def font
|
49
|
-
@font ||= Gosu::Font.new(window, Gosu::default_font_name, 20)
|
50
|
-
end
|
51
|
-
|
52
|
-
def draw(view)
|
53
|
-
view['options'].each_with_index do |option,index|
|
54
|
-
|
55
|
-
color = view["color"] || 0xffffffff
|
56
|
-
|
57
|
-
if index == selected_index
|
58
|
-
color = view["highlight-color"] || 0xffffff00
|
59
|
-
end
|
60
|
-
|
61
|
-
color = color.to_i(16) if color.is_a? String
|
62
|
-
|
63
|
-
y_position = view["y"] + view["padding"] * index
|
64
|
-
font.draw option, view["x"], y_position, Metro::Game::UI, 1.0, 1.0, color
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|