cyberarm_engine 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/Gemfile +1 -1
  4. data/Rakefile +1 -1
  5. data/assets/textures/default.png +0 -0
  6. data/cyberarm_engine.gemspec +10 -8
  7. data/lib/cyberarm_engine.rb +13 -2
  8. data/lib/cyberarm_engine/animator.rb +6 -4
  9. data/lib/cyberarm_engine/background.rb +19 -15
  10. data/lib/cyberarm_engine/background_nine_slice.rb +125 -0
  11. data/lib/cyberarm_engine/bounding_box.rb +18 -18
  12. data/lib/cyberarm_engine/cache.rb +4 -0
  13. data/lib/cyberarm_engine/cache/download_manager.rb +121 -0
  14. data/lib/cyberarm_engine/common.rb +13 -13
  15. data/lib/cyberarm_engine/config_file.rb +2 -2
  16. data/lib/cyberarm_engine/game_object.rb +63 -72
  17. data/lib/cyberarm_engine/game_state.rb +6 -3
  18. data/lib/cyberarm_engine/model.rb +207 -0
  19. data/lib/cyberarm_engine/model/material.rb +21 -0
  20. data/lib/cyberarm_engine/model/model_object.rb +131 -0
  21. data/lib/cyberarm_engine/model/parser.rb +74 -0
  22. data/lib/cyberarm_engine/model/parsers/collada_parser.rb +138 -0
  23. data/lib/cyberarm_engine/model/parsers/wavefront_parser.rb +154 -0
  24. data/lib/cyberarm_engine/model_cache.rb +31 -0
  25. data/lib/cyberarm_engine/opengl.rb +28 -0
  26. data/lib/cyberarm_engine/opengl/light.rb +50 -0
  27. data/lib/cyberarm_engine/opengl/orthographic_camera.rb +46 -0
  28. data/lib/cyberarm_engine/opengl/perspective_camera.rb +38 -0
  29. data/lib/cyberarm_engine/opengl/renderer/bounding_box_renderer.rb +249 -0
  30. data/lib/cyberarm_engine/opengl/renderer/g_buffer.rb +164 -0
  31. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +289 -0
  32. data/lib/cyberarm_engine/opengl/renderer/renderer.rb +22 -0
  33. data/lib/cyberarm_engine/{shader.rb → opengl/shader.rb} +51 -43
  34. data/lib/cyberarm_engine/opengl/texture.rb +69 -0
  35. data/lib/cyberarm_engine/ray.rb +5 -5
  36. data/lib/cyberarm_engine/stats.rb +2 -2
  37. data/lib/cyberarm_engine/text.rb +41 -27
  38. data/lib/cyberarm_engine/timer.rb +1 -1
  39. data/lib/cyberarm_engine/transform.rb +43 -20
  40. data/lib/cyberarm_engine/ui/border_canvas.rb +4 -3
  41. data/lib/cyberarm_engine/ui/dsl.rb +25 -11
  42. data/lib/cyberarm_engine/ui/element.rb +30 -20
  43. data/lib/cyberarm_engine/ui/elements/button.rb +86 -16
  44. data/lib/cyberarm_engine/ui/elements/check_box.rb +1 -1
  45. data/lib/cyberarm_engine/ui/elements/container.rb +44 -20
  46. data/lib/cyberarm_engine/ui/elements/edit_box.rb +175 -2
  47. data/lib/cyberarm_engine/ui/elements/edit_line.rb +121 -37
  48. data/lib/cyberarm_engine/ui/elements/flow.rb +1 -1
  49. data/lib/cyberarm_engine/ui/elements/image.rb +12 -9
  50. data/lib/cyberarm_engine/ui/elements/label.rb +93 -14
  51. data/lib/cyberarm_engine/ui/elements/list_box.rb +64 -2
  52. data/lib/cyberarm_engine/ui/elements/progress.rb +5 -5
  53. data/lib/cyberarm_engine/ui/elements/radio.rb +1 -1
  54. data/lib/cyberarm_engine/ui/elements/slider.rb +13 -16
  55. data/lib/cyberarm_engine/ui/elements/stack.rb +1 -1
  56. data/lib/cyberarm_engine/ui/elements/toggle_button.rb +27 -19
  57. data/lib/cyberarm_engine/ui/event.rb +7 -7
  58. data/lib/cyberarm_engine/ui/gui_state.rb +44 -10
  59. data/lib/cyberarm_engine/ui/style.rb +10 -9
  60. data/lib/cyberarm_engine/ui/theme.rb +28 -20
  61. data/lib/cyberarm_engine/vector.rb +33 -30
  62. data/lib/cyberarm_engine/version.rb +2 -2
  63. data/lib/cyberarm_engine/window.rb +27 -18
  64. metadata +65 -15
@@ -12,56 +12,70 @@ module CyberarmEngine
12
12
  options[:parent] = element_parent
13
13
  options[:theme] = current_theme
14
14
 
15
- add_element( Element::Label.new(text, options, block) )
15
+ add_element(Element::Label.new(text, options, block))
16
16
  end
17
17
 
18
18
  def button(text, options = {}, &block)
19
19
  options[:parent] = element_parent
20
20
  options[:theme] = current_theme
21
21
 
22
- add_element( Element::Button.new(text, options, block) { if block.is_a?(Proc); block.call; end } )
22
+ add_element(Element::Button.new(text, options, block) { block.call if block.is_a?(Proc) })
23
+ end
24
+
25
+ def list_box(options = {}, &block)
26
+ options[:parent] = element_parent
27
+ options[:theme] = current_theme
28
+
29
+ add_element(Element::ListBox.new(options, block) { block.call if block.is_a?(Proc) })
23
30
  end
24
31
 
25
32
  def edit_line(text, options = {}, &block)
26
33
  options[:parent] = element_parent
27
34
  options[:theme] = current_theme
28
35
 
29
- add_element( Element::EditLine.new(text, options, block) )
36
+ add_element(Element::EditLine.new(text, options, block))
37
+ end
38
+
39
+ def edit_box(text, options = {}, &block)
40
+ options[:parent] = element_parent
41
+ options[:theme] = current_theme
42
+
43
+ add_element(Element::EditBox.new(text, options, block))
30
44
  end
31
45
 
32
46
  def toggle_button(options = {}, &block)
33
47
  options[:parent] = element_parent
34
48
  options[:theme] = current_theme
35
49
 
36
- add_element( Element::ToggleButton.new(options, block) )
50
+ add_element(Element::ToggleButton.new(options, block))
37
51
  end
38
52
 
39
53
  def check_box(text, options = {}, &block)
40
54
  options[:parent] = element_parent
41
55
  options[:theme] = current_theme
42
56
 
43
- add_element( Element::CheckBox.new(text, options, block) )
57
+ add_element(Element::CheckBox.new(text, options, block))
44
58
  end
45
59
 
46
60
  def image(path, options = {}, &block)
47
61
  options[:parent] = element_parent
48
62
  options[:theme] = current_theme
49
63
 
50
- add_element( Element::Image.new(path, options, block) )
64
+ add_element(Element::Image.new(path, options, block))
51
65
  end
52
66
 
53
67
  def progress(options = {}, &block)
54
68
  options[:parent] = element_parent
55
69
  options[:theme] = current_theme
56
70
 
57
- add_element( Element::Progress.new(options, block) )
71
+ add_element(Element::Progress.new(options, block))
58
72
  end
59
73
 
60
74
  def slider(options = {}, &block)
61
75
  options[:parent] = element_parent
62
76
  options[:theme] = current_theme
63
77
 
64
- add_element( Element::Slider.new(options, block) )
78
+ add_element(Element::Slider.new(options, block))
65
79
  end
66
80
 
67
81
  def background(color = Gosu::Color::NONE)
@@ -79,7 +93,7 @@ module CyberarmEngine
79
93
  private def add_element(element)
80
94
  element_parent.add(element)
81
95
 
82
- return element
96
+ element
83
97
  end
84
98
 
85
99
  private def element_parent
@@ -100,7 +114,7 @@ module CyberarmEngine
100
114
 
101
115
  $__current_container__ = old_parent
102
116
 
103
- return _container
117
+ _container
104
118
  end
105
119
  end
106
- end
120
+ end
@@ -16,10 +16,13 @@ module CyberarmEngine
16
16
  @focus = false
17
17
  @enabled = true
18
18
  @visible = true
19
- @tip = @options[:tip] ? @options[:tip] : ""
19
+ @tip = @options[:tip] || ""
20
20
 
21
21
  @style = Style.new(options)
22
22
 
23
+ @root ||= nil
24
+ @gui_state ||= nil
25
+
23
26
  @x = @style.x
24
27
  @y = @style.y
25
28
  @z = @style.z
@@ -27,9 +30,6 @@ module CyberarmEngine
27
30
  @width = 0
28
31
  @height = 0
29
32
 
30
- @fixed_x = @x if @x != 0
31
- @fixed_y = @y if @y != 0
32
-
33
33
  @style.width = default(:width) || nil
34
34
  @style.height = default(:height) || nil
35
35
 
@@ -42,6 +42,7 @@ module CyberarmEngine
42
42
  end
43
43
 
44
44
  def stylize
45
+ set_static_position
45
46
  set_border_thickness(@style.border_thickness)
46
47
 
47
48
  set_padding(@style.padding)
@@ -52,6 +53,11 @@ module CyberarmEngine
52
53
  set_border_color(@style.border_color)
53
54
  end
54
55
 
56
+ def set_static_position
57
+ @x = @style.x if @style.x != 0
58
+ @y = @style.y if @style.y != 0
59
+ end
60
+
55
61
  def set_background(background)
56
62
  @style.background = background
57
63
  @style.background_canvas.background = background
@@ -96,7 +102,7 @@ module CyberarmEngine
96
102
  end
97
103
 
98
104
  def default_events
99
- [:left, :middle, :right].each do |button|
105
+ %i[left middle right].each do |button|
100
106
  event(:"#{button}_mouse_button")
101
107
  event(:"released_#{button}_mouse_button")
102
108
  event(:"clicked_#{button}_mouse_button")
@@ -129,21 +135,26 @@ module CyberarmEngine
129
135
  end
130
136
 
131
137
  def show
138
+ bool = visible?
132
139
  @visible = true
133
- root.gui_state.request_recalculate
140
+ root.gui_state.request_recalculate unless bool
134
141
  end
135
142
 
136
143
  def hide
144
+ bool = visible?
137
145
  @visible = false
138
- root.gui_state.request_recalculate
146
+ root.gui_state.request_recalculate if bool
139
147
  end
140
148
 
141
149
  def draw
142
- return unless @visible
150
+ return unless visible?
143
151
 
144
152
  @style.background_canvas.draw
145
153
  @style.border_canvas.draw
146
- render
154
+
155
+ Gosu.clip_to(@x, @y, width, height) do
156
+ render
157
+ end
147
158
  end
148
159
 
149
160
  def update
@@ -155,7 +166,7 @@ module CyberarmEngine
155
166
  def button_up(id)
156
167
  end
157
168
 
158
- def draggable?(button)
169
+ def draggable?(_button)
159
170
  false
160
171
  end
161
172
 
@@ -164,7 +175,7 @@ module CyberarmEngine
164
175
 
165
176
  def hit?(x, y)
166
177
  x.between?(@x, @x + width) &&
167
- y.between?(@y, @y + height)
178
+ y.between?(@y, @y + height)
168
179
  end
169
180
 
170
181
  def width
@@ -215,21 +226,20 @@ module CyberarmEngine
215
226
  (@style.border_thickness_top + @style.padding_top) + (@style.padding_bottom + @style.border_thickness_bottom)
216
227
  end
217
228
 
218
- private def dimensional_size(size, dimension)
219
- raise "dimension must be either :width or :height" unless dimension == :width || dimension == :height
229
+ def dimensional_size(size, dimension)
230
+ raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
231
+
220
232
  if size && size.is_a?(Numeric)
221
233
  if size.between?(0.0, 1.0)
222
- ((@parent.send(:"content_#{dimension}") - self.send(:"noncontent_#{dimension}")) * size).round
234
+ ((@parent.send(:"content_#{dimension}") - send(:"noncontent_#{dimension}")) * size).round
223
235
  else
224
236
  size
225
237
  end
226
- else
227
- nil
228
238
  end
229
239
  end
230
240
 
231
241
  def background=(_background)
232
- @style.background_canvas.background=(_background)
242
+ @style.background_canvas.background = (_background)
233
243
  update_background
234
244
  end
235
245
 
@@ -278,12 +288,12 @@ module CyberarmEngine
278
288
  raise "#{self.class}#value was not overridden!"
279
289
  end
280
290
 
281
- def value=(value)
291
+ def value=(_value)
282
292
  raise "#{self.class}#value= was not overridden!"
283
293
  end
284
294
 
285
295
  def to_s
286
- "#{self.class} x=#{x} y=#{y} width=#{width} height=#{height} value=#{ value.is_a?(String) ? "\"#{value}\"" : value }"
296
+ "#{self.class} x=#{x} y=#{y} width=#{width} height=#{height} value=#{value.is_a?(String) ? "\"#{value}\"" : value}"
287
297
  end
288
298
  end
289
- end
299
+ end
@@ -1,21 +1,40 @@
1
1
  module CyberarmEngine
2
2
  class Element
3
3
  class Button < Label
4
- def initialize(text, options = {}, block = nil)
5
- super(text, options, block)
4
+ def initialize(text_or_image, options = {}, block = nil)
5
+ @image = nil
6
+ @scale_x = 1
7
+ @scale_y = 1
8
+
9
+ @image = text_or_image if text_or_image.is_a?(Gosu::Image)
10
+
11
+ super(text_or_image, options, block)
6
12
 
7
13
  @style.background_canvas.background = default(:background)
8
14
  end
9
15
 
10
16
  def render
11
- draw_text
17
+ if @image
18
+ draw_image
19
+ else
20
+ draw_text
21
+ end
22
+ end
23
+
24
+ def draw_image
25
+ @image.draw(
26
+ @style.border_thickness_left + @style.padding_left + @x,
27
+ @style.border_thickness_top + @style.padding_top + @y,
28
+ @z + 2,
29
+ @scale_x, @scale_y, @text.color
30
+ )
12
31
  end
13
32
 
14
33
  def draw_text
15
34
  @text.draw
16
35
  end
17
36
 
18
- def enter(sender)
37
+ def enter(_sender)
19
38
  @focus = false unless window.button_down?(Gosu::MsLeft)
20
39
 
21
40
  if @focus
@@ -26,42 +45,93 @@ module CyberarmEngine
26
45
  @text.color = default(:hover, :color)
27
46
  end
28
47
 
29
- return :handled
48
+ :handled
30
49
  end
31
50
 
32
- def left_mouse_button(sender, x, y)
51
+ def left_mouse_button(_sender, _x, _y)
33
52
  @focus = true
34
53
  @style.background_canvas.background = default(:active, :background)
35
54
  window.current_state.focus = self
36
55
  @text.color = default(:active, :color)
37
56
 
38
- return :handled
57
+ :handled
39
58
  end
40
59
 
41
- def released_left_mouse_button(sender,x, y)
60
+ def released_left_mouse_button(sender, _x, _y)
42
61
  enter(sender)
43
62
 
44
- return :handled
63
+ :handled
45
64
  end
46
65
 
47
- def clicked_left_mouse_button(sender, x, y)
66
+ def clicked_left_mouse_button(_sender, _x, _y)
48
67
  @block.call(self) if @block
49
68
 
50
- return :handled
69
+ :handled
51
70
  end
52
71
 
53
- def leave(sender)
72
+ def leave(_sender)
54
73
  @style.background_canvas.background = default(:background)
55
74
  @text.color = default(:color)
56
75
 
57
- return :handled
76
+ :handled
58
77
  end
59
78
 
60
- def blur(sender)
79
+ def blur(_sender)
61
80
  @focus = false
62
81
 
63
- return :handled
82
+ :handled
83
+ end
84
+
85
+ def recalculate
86
+ if @image
87
+ @width = 0
88
+ @height = 0
89
+
90
+ _width = dimensional_size(@style.image_width, :width)
91
+ _height = dimensional_size(@style.image_height, :height)
92
+
93
+ if _width && _height
94
+ @scale_x = _width.to_f / @image.width
95
+ @scale_y = _height.to_f / @image.height
96
+ elsif _width
97
+ @scale_x = _width.to_f / @image.width
98
+ @scale_y = @scale_x
99
+ elsif _height
100
+ @scale_y = _height.to_f / @image.height
101
+ @scale_x = @scale_y
102
+ else
103
+ @scale_x = 1
104
+ @scale_y = 1
105
+ end
106
+
107
+ @width = _width || @image.width.round * @scale_x
108
+ @height = _height || @image.height.round * @scale_y
109
+
110
+ update_background
111
+ else
112
+ super
113
+ end
114
+ end
115
+
116
+ def value
117
+ @image || super
118
+ end
119
+
120
+ def value=(value)
121
+ if value.is_a?(Gosu::Image)
122
+ @image = value
123
+ else
124
+ super
125
+ end
126
+
127
+ old_width = width
128
+ old_height = height
129
+ recalculate
130
+
131
+ root.gui_state.request_recalculate if old_width != width || old_height != height
132
+
133
+ publish(:changed, self.value)
64
134
  end
65
135
  end
66
136
  end
67
- end
137
+ end
@@ -48,4 +48,4 @@ module CyberarmEngine
48
48
  end
49
49
  end
50
50
  end
51
- end
51
+ end
@@ -4,14 +4,14 @@ module CyberarmEngine
4
4
  include Common
5
5
 
6
6
  attr_accessor :stroke_color, :fill_color
7
- attr_reader :children, :gui_state
8
- attr_reader :scroll_x, :scroll_y
7
+ attr_reader :children, :gui_state, :scroll_x, :scroll_y
9
8
 
10
9
  def initialize(options = {}, block = nil)
11
10
  @gui_state = options.delete(:gui_state)
12
11
  super
13
12
 
14
- @scroll_x, @scroll_y = 0, 0
13
+ @scroll_x = 0
14
+ @scroll_y = 0
15
15
  @scroll_speed = 10
16
16
 
17
17
  @text_color = options[:color]
@@ -48,6 +48,31 @@ module CyberarmEngine
48
48
  Gosu.clip_to(@x, @y, width, height) do
49
49
  @children.each(&:draw)
50
50
  end
51
+
52
+ if false # DEBUG
53
+ Gosu.flush
54
+
55
+ Gosu.draw_line(
56
+ x, y, Gosu::Color::RED,
57
+ x + outer_width, y, Gosu::Color::RED,
58
+ Float::INFINITY
59
+ )
60
+ Gosu.draw_line(
61
+ x + outer_width, y, Gosu::Color::RED,
62
+ x + outer_width, y + outer_height, Gosu::Color::RED,
63
+ Float::INFINITY
64
+ )
65
+ Gosu.draw_line(
66
+ x + outer_width, y + outer_height, Gosu::Color::RED,
67
+ x, y + outer_height, Gosu::Color::RED,
68
+ Float::INFINITY
69
+ )
70
+ Gosu.draw_line(
71
+ x, outer_height, Gosu::Color::RED,
72
+ x, y, Gosu::Color::RED,
73
+ Float::INFINITY
74
+ )
75
+ end
51
76
  end
52
77
 
53
78
  def update
@@ -85,13 +110,14 @@ module CyberarmEngine
85
110
  @width = @style.width = window.width
86
111
  @height = @style.height = window.height
87
112
  else
88
- @width, @height = 0, 0
113
+ @width = 0
114
+ @height = 0
89
115
 
90
116
  _width = dimensional_size(@style.width, :width)
91
- _height= dimensional_size(@style.height,:height)
117
+ _height = dimensional_size(@style.height, :height)
92
118
 
93
- @width = _width ? _width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
94
- @height = _height ? _height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
119
+ @width = _width || (@children.map { |c| c.x + c.outer_width }.max || 0).round
120
+ @height = _height || (@children.map { |c| c.y + c.outer_height }.max || 0).round
95
121
  end
96
122
 
97
123
  # Move child to parent after positioning
@@ -115,33 +141,35 @@ module CyberarmEngine
115
141
 
116
142
  def max_width
117
143
  _width = dimensional_size(@style.width, :width)
118
- _width ? outer_width : window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
144
+ if _width
145
+ outer_width
146
+ else
147
+ window.width - (@parent ? @parent.style.margin_right + @style.margin_right : @style.margin_right)
148
+ end
119
149
  end
120
150
 
121
151
  def fits_on_line?(element) # Flow
122
152
  p [@options[:id], @width] if @options[:id]
123
153
  @current_position.x + element.outer_width <= max_width &&
124
- @current_position.x + element.outer_width <= window.width
154
+ @current_position.x + element.outer_width <= window.width
125
155
  end
126
156
 
127
157
  def position_on_current_line(element) # Flow
128
158
  element.x = element.style.margin_left + @current_position.x
129
159
  element.y = element.style.margin_top + @current_position.y
130
160
 
131
- element.recalculate
132
-
133
161
  @current_position.x += element.outer_width
134
162
  @current_position.x = @style.margin_left if @current_position.x >= max_width
135
163
  end
136
164
 
137
- def tallest_neighbor(querier, y_position) # Flow
165
+ def tallest_neighbor(querier, _y_position) # Flow
138
166
  response = querier
139
167
  @children.each do |child|
140
168
  response = child if child.outer_height > response.outer_height
141
169
  break if child == querier
142
170
  end
143
171
 
144
- return response
172
+ response
145
173
  end
146
174
 
147
175
  def position_on_next_line(child) # Flow
@@ -151,8 +179,6 @@ module CyberarmEngine
151
179
  child.x = child.style.margin_left + @current_position.x
152
180
  child.y = child.style.margin_top + @current_position.y
153
181
 
154
- child.recalculate
155
-
156
182
  @current_position.x += child.outer_width
157
183
  end
158
184
 
@@ -160,8 +186,6 @@ module CyberarmEngine
160
186
  element.x = element.style.margin_left + @current_position.x
161
187
  element.y = element.style.margin_top + @current_position.y
162
188
 
163
- element.recalculate
164
-
165
189
  @current_position.y += element.outer_height
166
190
  end
167
191
 
@@ -176,17 +200,17 @@ module CyberarmEngine
176
200
  # end
177
201
 
178
202
  def value
179
- @children.map {|c| c.class}.join(", ")
203
+ @children.map { |c| c.class }.join(", ")
180
204
  end
181
205
 
182
206
  def to_s
183
207
  "#{self.class} x=#{x} y=#{y} width=#{width} height=#{height} children=#{@children.size}"
184
208
  end
185
209
 
186
- def write_tree(indent = "", index = 0)
210
+ def write_tree(indent = "", _index = 0)
187
211
  puts self
188
212
 
189
- indent = indent + " "
213
+ indent += " "
190
214
  @children.each_with_index do |child, i|
191
215
  print "#{indent}#{i}: "
192
216