cyberarm_engine 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,8 @@ module CyberarmEngine
36
36
  @style.height = default(:height) || nil
37
37
 
38
38
  @style.background_canvas = Background.new
39
- @style.border_canvas = BorderCanvas.new(element: self)
39
+ @style.background_nine_slice_canvas = BackgroundNineSlice.new
40
+ @style.border_canvas = BorderCanvas.new(element: self)
40
41
 
41
42
  @style_event = :default
42
43
 
@@ -54,6 +55,7 @@ module CyberarmEngine
54
55
  set_margin
55
56
 
56
57
  set_background
58
+ set_background_nine_slice
57
59
 
58
60
  set_border_thickness
59
61
  set_border_color
@@ -74,6 +76,21 @@ module CyberarmEngine
74
76
  @style.background_canvas.background = @style.background
75
77
  end
76
78
 
79
+ def set_background_nine_slice
80
+ @style.background_nine_slice = safe_style_fetch(:background_nine_slice)
81
+
82
+ @style.background_nine_slice_mode = safe_style_fetch(:background_nine_slice_mode) || :stretch
83
+ @style.background_nine_slice_color = safe_style_fetch(:background_nine_slice_color) || Gosu::Color::WHITE
84
+ @style.background_nine_slice_canvas.color = @style.background_nine_slice_color
85
+
86
+ @style.background_nine_slice_from_edge = safe_style_fetch(:background_nine_slice_from_edge)
87
+
88
+ @style.background_nine_slice_left = safe_style_fetch(:background_nine_slice_left) || @style.background_nine_slice_from_edge
89
+ @style.background_nine_slice_top = safe_style_fetch(:background_nine_slice_top) || @style.background_nine_slice_from_edge
90
+ @style.background_nine_slice_right = safe_style_fetch(:background_nine_slice_right) || @style.background_nine_slice_from_edge
91
+ @style.background_nine_slice_bottom = safe_style_fetch(:background_nine_slice_bottom) || @style.background_nine_slice_from_edge
92
+ end
93
+
77
94
  def set_border_thickness
78
95
  @style.border_thickness = safe_style_fetch(:border_thickness)
79
96
 
@@ -118,6 +135,9 @@ module CyberarmEngine
118
135
  end
119
136
 
120
137
  def update_styles(event = :default)
138
+ old_width = width
139
+ old_height = height
140
+
121
141
  _style = @style.send(event)
122
142
  @style_event = event
123
143
 
@@ -126,7 +146,13 @@ module CyberarmEngine
126
146
  @text.swap_font(_style&.dig(:text_size) || @style.default[:text_size], _style&.dig(:font) || @style.default[:font])
127
147
  end
128
148
 
129
- (root&.gui_state || @gui_state).request_recalculate
149
+ return if self.is_a?(ToolTip)
150
+
151
+ if old_width != width || old_height != height
152
+ (root&.gui_state || @gui_state).request_recalculate
153
+ else
154
+ stylize
155
+ end
130
156
  end
131
157
 
132
158
  def default_events
@@ -241,6 +267,7 @@ module CyberarmEngine
241
267
  return unless visible?
242
268
 
243
269
  @style.background_canvas.draw
270
+ @style.background_nine_slice_canvas.draw
244
271
  @style.border_canvas.draw
245
272
 
246
273
  Gosu.clip_to(@x, @y, width, height) do
@@ -343,11 +370,11 @@ module CyberarmEngine
343
370
  end
344
371
 
345
372
  def scroll_width
346
- @children.sum { |c| c.width } + noncontent_width
373
+ @children.sum(&:width) + noncontent_width
347
374
  end
348
375
 
349
376
  def scroll_height
350
- @children.sum { |c| c.height } + noncontent_height
377
+ @children.sum(&:height) + noncontent_height
351
378
  end
352
379
 
353
380
  def max_scroll_width
@@ -361,12 +388,10 @@ module CyberarmEngine
361
388
  def dimensional_size(size, dimension)
362
389
  raise "dimension must be either :width or :height" unless %i[width height].include?(dimension)
363
390
 
364
- if size && size.is_a?(Numeric)
365
- if size.between?(0.0, 1.0)
366
- ((@parent.send(:"content_#{dimension}") - send(:"noncontent_#{dimension}")) * size).round
367
- else
368
- size
369
- end
391
+ if size.is_a?(Numeric) && size.between?(0.0, 1.0)
392
+ (@parent.send(:"content_#{dimension}") * size).round - send(:"noncontent_#{dimension}").round
393
+ else
394
+ size
370
395
  end
371
396
  end
372
397
 
@@ -383,10 +408,34 @@ module CyberarmEngine
383
408
  @style.background_canvas.height = height
384
409
 
385
410
  @style.background_canvas.update
386
-
411
+ update_background_nine_slice
387
412
  @style.border_canvas.update
388
413
  end
389
414
 
415
+ def background_nine_slice=(_image_path)
416
+ @style.background_nine_slice_canvas.image = _image_path
417
+ update_background_nine_slice
418
+ end
419
+
420
+ def update_background_nine_slice
421
+ @style.background_nine_slice_canvas.x = @x
422
+ @style.background_nine_slice_canvas.y = @y
423
+ @style.background_nine_slice_canvas.z = @z
424
+ @style.background_nine_slice_canvas.width = width
425
+ @style.background_nine_slice_canvas.height = height
426
+
427
+ @style.background_nine_slice_canvas.mode = @style.background_nine_slice_mode
428
+
429
+ @style.background_nine_slice_canvas.color = @style.background_nine_slice_color
430
+
431
+ @style.background_nine_slice_canvas.left = @style.background_nine_slice_left
432
+ @style.background_nine_slice_canvas.top = @style.background_nine_slice_top
433
+ @style.background_nine_slice_canvas.right = @style.background_nine_slice_right
434
+ @style.background_nine_slice_canvas.bottom = @style.background_nine_slice_bottom
435
+
436
+ @style.background_nine_slice_canvas.image = @style.background_nine_slice
437
+ end
438
+
390
439
  def root
391
440
  return self if is_root?
392
441
 
@@ -75,6 +75,8 @@ module CyberarmEngine
75
75
  end
76
76
 
77
77
  def hit_element?(x, y)
78
+ return unless hit?(x, y)
79
+
78
80
  @children.reverse_each do |child|
79
81
  next unless child.visible?
80
82
 
@@ -8,7 +8,10 @@ module CyberarmEngine
8
8
  text, font: @options[:font], z: @z, color: @options[:color],
9
9
  size: @options[:text_size], shadow: @options[:text_shadow],
10
10
  shadow_size: @options[:text_shadow_size],
11
- shadow_color: @options[:text_shadow_color]
11
+ shadow_color: @options[:text_shadow_color],
12
+ border: @options[:text_border],
13
+ border_size: @options[:text_border_size],
14
+ border_color: @options[:text_border_color]
12
15
  )
13
16
 
14
17
  @raw_text = text
@@ -19,6 +22,12 @@ module CyberarmEngine
19
22
  end
20
23
 
21
24
  def recalculate
25
+ unless @enabled
26
+ @text.color = @style.disabled[:color]
27
+ else
28
+ @text.color = @style.color
29
+ end
30
+
22
31
  @width = 0
23
32
  @height = 0
24
33
 
@@ -15,12 +15,19 @@ module CyberarmEngine
15
15
 
16
16
  return unless enabled?
17
17
 
18
- return :handled if respond_to?(event) && (send(event, self, *args) == :handled)
18
+ was_handled = false
19
+
20
+ was_handled = true if respond_to?(event) && (send(event, self, *args) == :handled)
19
21
 
20
22
  @event_handler[event].reverse_each do |handler|
21
- return :handled if handler.call(self, *args) == :handled
23
+ if handler.call(self, *args) == :handled
24
+ was_handled = true
25
+ break
26
+ end
22
27
  end
23
28
 
29
+ return :handled if was_handled
30
+
24
31
  parent.publish(event, *args) if parent
25
32
  nil
26
33
  end
@@ -103,7 +103,7 @@ module CyberarmEngine
103
103
  if Vector.new(window.mouse_x, window.mouse_y) == @last_mouse_pos
104
104
  if @mouse_over && (Gosu.milliseconds - @mouse_moved_at) > tool_tip_delay
105
105
  @tip.value = @mouse_over.tip if @mouse_over
106
- @tip.x = window.mouse_x - @tip.width / 2
106
+ @tip.x = window.mouse_x
107
107
  @tip.x = 0 if @tip.x < 0
108
108
  @tip.x = window.width - @tip.width if @tip.x + @tip.width > window.width
109
109
  @tip.y = window.mouse_y - (@tip.height + 5)
@@ -115,10 +115,14 @@ module CyberarmEngine
115
115
  text_size: 28,
116
116
  text_wrap: :word_wrap, # :word_wrap, :break_word, :none
117
117
  text_shadow: false,
118
+ text_border: false,
118
119
  text_align: :left,
119
120
  font: "Arial",
120
121
  margin: 0,
121
- padding: 2
122
+ padding: 2,
123
+ disabled: {
124
+ color: Gosu::Color.rgb(175, 175, 175),
125
+ }
122
126
  },
123
127
 
124
128
  Banner: { # < TextBlock
@@ -1,4 +1,4 @@
1
1
  module CyberarmEngine
2
2
  NAME = "InDev".freeze
3
- VERSION = "0.18.0".freeze
3
+ VERSION = "0.19.0".freeze
4
4
  end
@@ -23,12 +23,18 @@ require_relative "cyberarm_engine/vector"
23
23
  require_relative "cyberarm_engine/transform"
24
24
  require_relative "cyberarm_engine/ray"
25
25
  require_relative "cyberarm_engine/background"
26
+ require_relative "cyberarm_engine/background_nine_slice"
26
27
  require_relative "cyberarm_engine/animator"
27
28
 
28
29
  require_relative "cyberarm_engine/text"
29
30
  require_relative "cyberarm_engine/timer"
30
31
  require_relative "cyberarm_engine/config_file"
31
32
 
33
+ require_relative "cyberarm_engine/console"
34
+ require_relative "cyberarm_engine/console/command"
35
+ require_relative "cyberarm_engine/console/subcommand"
36
+ require_relative "cyberarm_engine/console/commands/help_command"
37
+
32
38
  require_relative "cyberarm_engine/ui/dsl"
33
39
 
34
40
  require_relative "cyberarm_engine/ui/theme"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyberarm_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyberarm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-19 00:00:00.000000000 Z
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -137,6 +137,10 @@ files:
137
137
  - lib/cyberarm_engine/cache/download_manager.rb
138
138
  - lib/cyberarm_engine/common.rb
139
139
  - lib/cyberarm_engine/config_file.rb
140
+ - lib/cyberarm_engine/console.rb
141
+ - lib/cyberarm_engine/console/command.rb
142
+ - lib/cyberarm_engine/console/commands/help_command.rb
143
+ - lib/cyberarm_engine/console/subcommand.rb
140
144
  - lib/cyberarm_engine/game_object.rb
141
145
  - lib/cyberarm_engine/game_state.rb
142
146
  - lib/cyberarm_engine/model.rb