bcp de characters
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
@tool
|
||||
class_name DialogicRichTextTransitionEffect
|
||||
extends RichTextEffect
|
||||
|
||||
## A custom richt text effect class, that allows to easily animate letters when revealed.
|
||||
## The DialogicNode_DialogText node correctly updates the [member visible_characters] and calls the [method reset] and [method skip].
|
||||
## You can simply create a resource of this, edit it in the inspector and add it's path/uid to
|
||||
## dialogics custom bbcode effects setting.
|
||||
|
||||
## Controlled by the DialogText node.
|
||||
var visible_characters := -1
|
||||
|
||||
## The bbcode effect name.
|
||||
@export var bbcode := "animate_in"
|
||||
var _cache := []
|
||||
|
||||
## The length of the transition time.
|
||||
@export_range(0.0, 5.0, 0.01) var time := 0.2
|
||||
@export_group("Color", "color")
|
||||
## A gradient modulating the color of text over the transition time.
|
||||
## Use a transparent to white gradient to fade in the text.
|
||||
@export var color_modulate: Gradient = null
|
||||
## Allows to overwrite the color of the text, with transparency meaning no effect on the text color.
|
||||
@export var color_replace: Gradient = null
|
||||
|
||||
@export_group("Scale", "scale")
|
||||
## Enables the scale curve animation.
|
||||
@export var scale_enabled := false
|
||||
## A curve animating the scale of the character. Should end at 1.
|
||||
@export var scale_curve := Curve.new()
|
||||
## The pivot from which scaling is applied. Vector2(0,0) is a the bottom left of the character, Vector2(1, 1) at the top right.
|
||||
@export var scale_pivot := Vector2()
|
||||
|
||||
@export_group("Position", "position")
|
||||
## Enables the position curve animations.
|
||||
@export var position_enabled := false
|
||||
## A curve animating the x position of the character. Should end at 0.
|
||||
@export var position_x_curve := Curve.new()
|
||||
## A curve animating the y position of the character. Should end at 0.
|
||||
@export var position_y_curve := Curve.new()
|
||||
|
||||
@export_group("Test", "test")
|
||||
## Can be used to preview the animation on all the text at once. Is ignored when less then 0. 1 is the end of the animation independent of its length.
|
||||
@export_range(-0.1, 1.0, 0.1) var test_value := -0.1
|
||||
|
||||
var _was_skipped := false
|
||||
var _was_reset := false
|
||||
|
||||
|
||||
## Called by the DialogText node when the text is cleared/changed.
|
||||
func reset() -> void:
|
||||
_was_reset = true
|
||||
_was_skipped = false
|
||||
_cache.clear()
|
||||
|
||||
|
||||
## Called by the DialogText node when the reveal was skipped, so it also skips the animation.
|
||||
func skip() -> void:
|
||||
_was_skipped = true
|
||||
|
||||
|
||||
## Actually process the animation of the characters.
|
||||
func _process_custom_fx(char_fx: CharFXTransform) -> bool:
|
||||
var char_age :float = 0.0
|
||||
if test_value >= 0:
|
||||
char_age = remap(test_value, 0, 1, 0, time)
|
||||
|
||||
else:
|
||||
if visible_characters == 0:
|
||||
_cache.clear()
|
||||
return false
|
||||
if _was_reset:
|
||||
if visible_characters != -1:
|
||||
_was_reset = false
|
||||
else:
|
||||
return false
|
||||
|
||||
if len(_cache) < visible_characters or visible_characters == -1 or _was_skipped:
|
||||
if char_fx.range.x >= len(_cache):
|
||||
_cache.append(char_fx.elapsed_time)
|
||||
|
||||
if _was_skipped:
|
||||
for i in range(len(_cache)):
|
||||
_cache[i] = char_fx.elapsed_time-time
|
||||
|
||||
if len(_cache) > char_fx.range.x:
|
||||
char_age = char_fx.elapsed_time - _cache[char_fx.range.x]
|
||||
|
||||
var text_server := TextServerManager.get_primary_interface()
|
||||
var trans: float = clamp(char_age, 0.0, time)/time
|
||||
|
||||
if color_replace:
|
||||
var c := color_replace.sample(trans)
|
||||
c.a = 1
|
||||
char_fx.color = char_fx.color.lerp(c, color_replace.sample(trans).a)
|
||||
if color_modulate:
|
||||
char_fx.color *= color_modulate.sample(trans)
|
||||
if char_fx.font.is_valid():
|
||||
var glyph_size := text_server.font_get_glyph_size(char_fx.font, Vector2i(16,1), char_fx.glyph_index)
|
||||
if scale_enabled:
|
||||
char_fx.transform = char_fx.transform.translated_local(scale_pivot*glyph_size*Vector2(1, -1)*(1-scale_curve.sample(trans)))
|
||||
char_fx.transform = char_fx.transform.scaled_local(Vector2.ONE*scale_curve.sample(trans))
|
||||
|
||||
if position_enabled:
|
||||
char_fx.transform = char_fx.transform.translated_local(Vector2(position_x_curve.sample(trans), position_y_curve.sample(trans))*glyph_size)
|
||||
|
||||
return true
|
||||
@@ -0,0 +1 @@
|
||||
uid://wf7hpguw17ex
|
||||
@@ -0,0 +1,21 @@
|
||||
[gd_resource type="RichTextEffect" script_class="DialogicRichTextTransitionEffect" format=3 uid="uid://qegqrr4g2riu"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://wf7hpguw17ex" path="res://addons/dialogic/Example Assets/bbcode_transitions/bbcode_transition_effect.gd" id="1_5w3vn"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_5w3vn"]
|
||||
colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 1)
|
||||
|
||||
[sub_resource type="Curve" id="Curve_5w3vn"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_a27kb"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_2rcd0"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_5w3vn")
|
||||
bbcode = "fade_in"
|
||||
color_modulate = SubResource("Gradient_5w3vn")
|
||||
scale_curve = SubResource("Curve_2rcd0")
|
||||
position_x_curve = SubResource("Curve_5w3vn")
|
||||
position_y_curve = SubResource("Curve_a27kb")
|
||||
metadata/_custom_type_script = "uid://wf7hpguw17ex"
|
||||
@@ -0,0 +1,28 @@
|
||||
[gd_resource type="RichTextEffect" script_class="DialogicRichTextTransitionEffect" format=3 uid="uid://hx8qyt5ry3h0"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://wf7hpguw17ex" path="res://addons/dialogic/Example Assets/bbcode_transitions/bbcode_transition_effect.gd" id="1_rsak6"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_rsak6"]
|
||||
offsets = PackedFloat32Array(0, 0.6351706)
|
||||
colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 1)
|
||||
|
||||
[sub_resource type="Curve" id="Curve_rsak6"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_pa36x"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_oitc5"]
|
||||
_limits = [0.0, 2.0, 0.0, 1.0]
|
||||
_data = [Vector2(0, 2), 0.0, 0.0, 0, 0, Vector2(0.40294844, 1.0066038), -0.13865282, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_rsak6")
|
||||
bbcode = "fade_scale_in"
|
||||
time = 0.30000000000000004
|
||||
color_modulate = SubResource("Gradient_rsak6")
|
||||
scale_enabled = true
|
||||
scale_curve = SubResource("Curve_oitc5")
|
||||
scale_pivot = Vector2(0.5, 0.5)
|
||||
position_x_curve = SubResource("Curve_rsak6")
|
||||
position_y_curve = SubResource("Curve_pa36x")
|
||||
metadata/_custom_type_script = "uid://wf7hpguw17ex"
|
||||
@@ -0,0 +1,37 @@
|
||||
[gd_resource type="RichTextEffect" script_class="DialogicRichTextTransitionEffect" format=3 uid="uid://c8b884puc720d"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://wf7hpguw17ex" path="res://addons/dialogic/Example Assets/bbcode_transitions/bbcode_transition_effect.gd" id="1_n3lqs"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_n3lqs"]
|
||||
offsets = PackedFloat32Array(0, 0.45292622)
|
||||
colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 1)
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_lhhwu"]
|
||||
interpolation_mode = 1
|
||||
offsets = PackedFloat32Array(0, 0.6666667, 0.86513996)
|
||||
colors = PackedColorArray(0.5208, 0.76631993, 0.93, 0, 0.5242275, 0.76595265, 0.93170327, 1, 0.5208, 0.76631993, 0.93, 0)
|
||||
|
||||
[sub_resource type="Curve" id="Curve_lhhwu"]
|
||||
_data = [Vector2(0.002457004, 1), 0.0, -1.993977, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="Curve" id="Curve_n3lqs"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_4i73d"]
|
||||
_limits = [0.0, 1.5, 0.0, 1.0]
|
||||
_data = [Vector2(0, 0.6627359), 0.0, 1.7969435, 0, 0, Vector2(0.4987715, 1.0308962), -1.6188686, -1.6188686, 0, 0, Vector2(0.66093373, 1), -0.34929827, 0.0, 0, 0]
|
||||
point_count = 3
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_n3lqs")
|
||||
bbcode = "fancy_in"
|
||||
time = 0.4
|
||||
color_modulate = SubResource("Gradient_n3lqs")
|
||||
color_replace = SubResource("Gradient_lhhwu")
|
||||
scale_enabled = true
|
||||
scale_curve = SubResource("Curve_4i73d")
|
||||
scale_pivot = Vector2(0.5, 0)
|
||||
position_enabled = true
|
||||
position_x_curve = SubResource("Curve_lhhwu")
|
||||
position_y_curve = SubResource("Curve_n3lqs")
|
||||
metadata/_custom_type_script = "uid://wf7hpguw17ex"
|
||||
@@ -0,0 +1,34 @@
|
||||
[gd_resource type="RichTextEffect" script_class="DialogicRichTextTransitionEffect" format=3 uid="uid://dnxkgwncm1pt5"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://wf7hpguw17ex" path="res://addons/dialogic/Example Assets/bbcode_transitions/bbcode_transition_effect.gd" id="1_ur6c5"]
|
||||
|
||||
[sub_resource type="Gradient" id="Gradient_ur6c5"]
|
||||
offsets = PackedFloat32Array(0, 0.5089058)
|
||||
colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 1)
|
||||
|
||||
[sub_resource type="Curve" id="Curve_5qe3f"]
|
||||
_limits = [-0.5, 0.51556605, 0.0, 1.0]
|
||||
_data = [Vector2(0, 0.0235914), 0.0, 0.0, 0, 0, Vector2(0.019656021, -0.2441923), 0.0, 0.0, 0, 0, Vector2(0.046683047, 0.17305207), 0.0, 0.0, 0, 0, Vector2(0.1081081, -0.23173726), 0.0, 0.0, 0, 0, Vector2(0.16216215, 0.12323183), 0.0, 0.0, 0, 0, Vector2(0.2997543, -0.16946197), 0.0, 0.0, 0, 0, Vector2(0.38329238, 0.042274), 0.0, 0.0, 0, 0, Vector2(0.46928746, -0.107186675), 0.0, 0.0, 0, 0, Vector2(0.5135135, 0.054729044), 0.0, 0.0, 0, 0, Vector2(0.66339064, -0.07604903), 0.0, 0.0, 0, 0, Vector2(0.86240786, 0.054729044), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||
point_count = 12
|
||||
|
||||
[sub_resource type="Curve" id="Curve_ur6c5"]
|
||||
_limits = [-0.5, 0.51556605, 0.0, 1.0]
|
||||
_data = [Vector2(0, 0.042274), 0.0, 0.0, 0, 0, Vector2(0.051597048, -0.13209677), 0.0, 0.0, 0, 0, Vector2(0.09336609, 0.21041724), 0.0, 0.0, 0, 0, Vector2(0.14742014, -0.25664735), 0.0, 0.0, 0, 0, Vector2(0.22850122, 0.098321736), 0.0, 0.0, 0, 0, Vector2(0.31203932, -0.107186675), 0.0, 0.0, 0, 0, Vector2(0.44717443, 0.054729044), 0.0, 0.0, 0, 0, Vector2(0.5995086, -0.08227658), 0.0, 0.0, 0, 0, Vector2(0.8132678, 0.042274), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||
point_count = 10
|
||||
|
||||
[sub_resource type="Curve" id="Curve_qelc7"]
|
||||
_data = [Vector2(0, 0.57688683), 0.0, 0.0, 0, 0, Vector2(0.14250615, 0.77311325), 0.0, 0.0, 0, 0, Vector2(0.2850123, 0.6443397), 0.0, 0.0, 0, 0, Vector2(0.41769046, 0.7976416), 0.0, 0.0, 0, 0, Vector2(0.5503686, 0.74245286), 0.0, 0.0, 0, 0, Vector2(0.6781328, 0.8712265), 0.0, 0.0, 0, 0, Vector2(0.79606885, 0.8528303), 0.0, 0.0, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0]
|
||||
point_count = 8
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_ur6c5")
|
||||
bbcode = "shaky_in"
|
||||
time = 0.4
|
||||
color_modulate = SubResource("Gradient_ur6c5")
|
||||
scale_enabled = true
|
||||
scale_curve = SubResource("Curve_qelc7")
|
||||
scale_pivot = Vector2(0.5, 0.5)
|
||||
position_enabled = true
|
||||
position_x_curve = SubResource("Curve_5qe3f")
|
||||
position_y_curve = SubResource("Curve_ur6c5")
|
||||
metadata/_custom_type_script = "uid://wf7hpguw17ex"
|
||||
Reference in New Issue
Block a user