cyberarm_engine 0.16.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -4
  3. data/assets/textures/logo.png +0 -0
  4. data/cyberarm_engine.gemspec +2 -2
  5. data/lib/cyberarm_engine/animator.rb +172 -9
  6. data/lib/cyberarm_engine/background_nine_slice.rb +51 -34
  7. data/lib/cyberarm_engine/builtin/intro_state.rb +131 -0
  8. data/lib/cyberarm_engine/common.rb +19 -2
  9. data/lib/cyberarm_engine/console/command.rb +158 -0
  10. data/lib/cyberarm_engine/console/commands/help_command.rb +43 -0
  11. data/lib/cyberarm_engine/console/subcommand.rb +100 -0
  12. data/lib/cyberarm_engine/console.rb +248 -0
  13. data/lib/cyberarm_engine/game_state.rb +5 -0
  14. data/lib/cyberarm_engine/model.rb +6 -1
  15. data/lib/cyberarm_engine/opengl/perspective_camera.rb +2 -2
  16. data/lib/cyberarm_engine/opengl/renderer/opengl_renderer.rb +9 -0
  17. data/lib/cyberarm_engine/opengl/texture.rb +1 -1
  18. data/lib/cyberarm_engine/text.rb +82 -45
  19. data/lib/cyberarm_engine/ui/dsl.rb +3 -2
  20. data/lib/cyberarm_engine/ui/element.rb +236 -47
  21. data/lib/cyberarm_engine/ui/elements/button.rb +0 -63
  22. data/lib/cyberarm_engine/ui/elements/check_box.rb +4 -1
  23. data/lib/cyberarm_engine/ui/elements/container.rb +65 -35
  24. data/lib/cyberarm_engine/ui/elements/edit_line.rb +20 -13
  25. data/lib/cyberarm_engine/ui/elements/text_block.rb +13 -7
  26. data/lib/cyberarm_engine/ui/event.rb +9 -2
  27. data/lib/cyberarm_engine/ui/gui_state.rb +37 -4
  28. data/lib/cyberarm_engine/ui/style.rb +14 -3
  29. data/lib/cyberarm_engine/ui/theme.rb +26 -1
  30. data/lib/cyberarm_engine/version.rb +1 -1
  31. data/lib/cyberarm_engine/window.rb +7 -1
  32. data/lib/cyberarm_engine.rb +11 -4
  33. metadata +12 -7
  34. data/lib/cyberarm_engine/ui/elements/label.rb +0 -156
@@ -1,156 +0,0 @@
1
- module CyberarmEngine
2
- class Element
3
- class TextBlock < Element
4
- def initialize(text, options = {}, block = nil)
5
- super(options, block)
6
-
7
- @text = Text.new(
8
- text, font: @options[:font], z: @z, color: @options[:color],
9
- size: @options[:text_size], shadow: @options[:text_shadow],
10
- shadow_size: @options[:text_shadow_size],
11
- shadow_color: @options[:text_shadow_color]
12
- )
13
-
14
- @raw_text = text
15
- end
16
-
17
- def render
18
- @text.draw
19
- end
20
-
21
- def clicked_left_mouse_button(_sender, _x, _y)
22
- @block&.call(self) if @enabled
23
-
24
- # return :handled
25
- end
26
-
27
- def recalculate
28
- @width = 0
29
- @height = 0
30
-
31
- _width = dimensional_size(@style.width, :width)
32
- _height = dimensional_size(@style.height, :height)
33
-
34
- handle_text_wrapping(_width)
35
-
36
- @width = _width || @text.width.round
37
- @height = _height || @text.height.round
38
-
39
- @text.y = @style.border_thickness_top + @style.padding_top + @y
40
- @text.z = @z + 3
41
-
42
- if (text_alignment = @options[:text_align])
43
- case text_alignment
44
- when :left
45
- @text.x = @style.border_thickness_left + @style.padding_left + @x
46
- when :center
47
- @text.x = if @text.width <= outer_width
48
- @x + outer_width / 2 - @text.width / 2
49
- else # Act as left aligned
50
- @style.border_thickness_left + @style.padding_left + @x
51
- end
52
- when :right
53
- @text.x = @x + outer_width - (@text.width + @style.border_thickness_right + @style.padding_right)
54
- end
55
- end
56
-
57
- update_background
58
- end
59
-
60
- def handle_text_wrapping(max_width)
61
- max_width ||= @parent&.width
62
- max_width ||= @x - (window.width + noncontent_width)
63
- wrap_behavior = style.text_wrap
64
- copy = @raw_text.to_s.dup
65
-
66
- if max_width >= line_width(copy[0]) && line_width(copy) > max_width && wrap_behavior != :none
67
- breaks = []
68
- line_start = 0
69
- line_end = copy.length
70
-
71
- while line_start != copy.length
72
- if line_width(copy[line_start...line_end]) > max_width
73
- line_end = ((line_end - line_start) / 2.0)
74
- elsif line_end < copy.length && line_width(copy[line_start...line_end + 1]) < max_width
75
- # To small, grow!
76
- # TODO: find a more efficient way
77
- line_end += 1
78
-
79
- else # FOUND IT!
80
- entering_line_end = line_end.floor
81
- max_reach = line_end.floor - line_start < 63 ? line_end.floor - line_start : 63
82
- reach = 0
83
-
84
- if wrap_behavior == :word_wrap
85
- max_reach.times do |i|
86
- reach = i
87
- break if copy[line_end.floor - i].to_s.match(/[[:punct:]]| /)
88
- end
89
-
90
- puts "Max width: #{max_width}/#{line_width(@raw_text)} Reach: {#{reach}/#{max_reach}} Line Start: #{line_start}/#{line_end.floor} (#{copy.length}|#{@raw_text.length}) [#{entering_line_end}] '#{copy}' {#{copy[line_start...line_end]}}"
91
- line_end = line_end.floor - reach + 1 if reach != max_reach # Add +1 to walk in front of punctuation
92
- end
93
-
94
- breaks << line_end.floor
95
- line_start = line_end.floor
96
- line_end = copy.length
97
-
98
- break if entering_line_end == copy.length || reach == max_reach
99
- end
100
- end
101
-
102
- breaks.each_with_index do |pos, index|
103
- copy.insert(pos + index, "\n") if pos + index >= 0 && pos + index < copy.length
104
- end
105
- end
106
-
107
- @text.text = copy
108
- end
109
-
110
- def line_width(text)
111
- (@x + @text.textobject.markup_width(text) + noncontent_width)
112
- end
113
-
114
- def value
115
- @raw_text
116
- end
117
-
118
- def value=(value)
119
- @raw_text = value.to_s.chomp
120
-
121
- old_width = width
122
- old_height = height
123
- recalculate
124
-
125
- root.gui_state.request_recalculate if old_width != width || old_height != height
126
-
127
- publish(:changed, self.value)
128
- end
129
- end
130
-
131
- class Banner < TextBlock
132
- end
133
-
134
- class Title < TextBlock
135
- end
136
-
137
- class Subtitle < TextBlock
138
- end
139
-
140
- class Tagline < TextBlock
141
- end
142
-
143
- class Caption < TextBlock
144
- end
145
-
146
- class Para < TextBlock
147
- end
148
-
149
- class Inscription < TextBlock
150
- end
151
-
152
- # TODO: Remove in version 0.16.0+
153
- class Label < TextBlock
154
- end
155
- end
156
- end