@@ -911,8 +911,9 @@ Here are some examples of custom effects:
911
911
Ghost
912
912
~~~~~
913
913
914
- ::
915
-
914
+ .. tabs ::
915
+ .. code-tab :: gdscript GDScript
916
+
916
917
@tool
917
918
extends RichTextEffect
918
919
class_name RichTextGhost
@@ -931,10 +932,35 @@ Ghost
931
932
char_fx.color.a = alpha
932
933
return true
933
934
935
+ .. code-tab :: csharp
936
+
937
+ using Godot;
938
+
939
+ [Tool]
940
+ public class RichTextGhost : RichTextEffect
941
+ {
942
+ // Syntax: [ghost freq=5.0 span=10.0][/ghost]
943
+
944
+ // Define the tag name.
945
+ private const string Bbcode = "ghost";
946
+
947
+ public override bool _ProcessCustomFx(CharFXTransform charFX)
948
+ {
949
+ // Get parameters, or use the provided default value if missing.
950
+ var speed = charFx.Env.Get("freq", 5.0f);
951
+ var span = charFx.Env.Get("span", 10.0f);
952
+
953
+ var alpha = Mathf.Sin(charFx.ElapsedTime * speed + (charFx.Range.X / span)) * 0.5f + 0.5f;
954
+ charFx.Color.A = alpha;
955
+ return true;
956
+ }
957
+ }
958
+
934
959
Matrix
935
960
~~~~~~
936
961
937
- ::
962
+ .. tabs ::
963
+ .. code-tab :: gdscript GDScript
938
964
939
965
@tool
940
966
extends RichTextEffect
@@ -970,6 +996,48 @@ Matrix
970
996
char_fx.glyph_index = get_text_server().font_get_glyph_index(char_fx.font, 1, value, 0)
971
997
return true
972
998
999
+ .. code-tab :: csharp
1000
+
1001
+ using Godot;
1002
+
1003
+ [Tool]
1004
+ public class RichTextMatrix : RichTextEffect
1005
+ {
1006
+ // Syntax: [matrix clean=2.0 dirty=1.0 span=50][/matrix]
1007
+
1008
+ // Define the tag name.
1009
+ private const string Bbcode = "matrix";
1010
+
1011
+ // Gets TextServer for retrieving font information.
1012
+ private TextServer GetTextServer()
1013
+ {
1014
+ return TextServerManager.GetPrimaryInterface();
1015
+ }
1016
+
1017
+ public override bool _ProcessCustomFx(CharFXTransform charFX)
1018
+ {
1019
+ // Get parameters, or use the provided default value if missing.
1020
+ var clearTime = charFx.Env.Get("clean", 2.0f);
1021
+ var dirtyTime = charFx.Env.Get("dirty", 1.0f);
1022
+ var textSpan = charFx.Env.Get("span", 50);
1023
+
1024
+ var value = charFx.GlyphIndex;
1025
+
1026
+ var matrixTime = Mathf.Fmod(charFx.ElapsedTime + (charFx.Range.X / textSpan), clearTime + dirtyTime);
1027
+
1028
+ matrixTime = matrixTime < clearTime ? 0.0f : (matrixTime - clearTime) / dirtyTime;
1029
+
1030
+ if (matrixTime > 0.0f)
1031
+ {
1032
+ value = (int)(1 * matrixTime * (126 - 65));
1033
+ value %= (126 - 65);
1034
+ value += 65;
1035
+ }
1036
+ charFx.GlyphIndex = GetTextServer().FontGetGlyphIndex(charFx.Font, 1, value, 0);
1037
+ return true;
1038
+ }
1039
+ }
1040
+
973
1041
This will add a few new BBCode commands, which can be used like so:
974
1042
975
1043
.. code-block :: none
0 commit comments