metro 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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