Skip to content

Add C# version for examples of custom BBCode tags and text effects #9420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mateuseap
Copy link
Contributor

@mateuseap mateuseap commented May 26, 2024

What I did

  • Added C# version of the examples for creating custom BBCode tags and text effects.

Closes: #9334

@AThousandShips AThousandShips requested a review from a team May 26, 2024 12:59
@AThousandShips AThousandShips added topic:dotnet area:manual Issues and PRs related to the Manual/Tutorials section of the documentation topic:gui labels May 26, 2024
// Syntax: [ghost freq=5.0 span=10.0][/ghost]

// Define the tag name.
public string bbcode = "ghost";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this a constant, and it probably doesn't need to be public. Although I don't see this being used at all.

Suggested change
public string bbcode = "ghost";
private const string Bbcode = "ghost";

Copy link
Contributor

@RedMser RedMser May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be magic - not sure how it exactly needs to be defined to be read in C# but in GDScript it just is a variable named bbcode:

https://docs.godotengine.org/en/stable/classes/class_richtexteffect.html

This has to be tested / check RichTextEffect source code in godot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. It looks like this only works with scripts that have a property named exactly bbcode:

https://github.com/godotengine/godot/blob/be56cab58c056c074d1e02cd0b38641204e39f41/scene/gui/rich_text_effect.cpp#L49

That's a weird pattern, I don't think we usually do that. For example, in editor plugins there are virtual methods for doing this kind of thing (e.g.: EditorPlugin::_get_plugin_name).

So to make this work the member would have to be named bbcode even though that goes against our C# naming conventions. And it can't be a constant.

@mateuseap
Copy link
Contributor Author

Thank you, @raulsntos, for the code corrections you've provided! I've applied all of them to the examples.

Include C# implementations for custom BBCode tags and text effects examples in "BBCode in RichTextLabel" tutorial.
@mateuseap
Copy link
Contributor Author

Thanks once again for the providing all these adjustments, @raulsntos! I've applied them all.

@mateuseap mateuseap requested review from raulsntos and RedMser May 28, 2024 02:46
Copy link
Contributor

@RedMser RedMser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably try following the tutorial here and see if the effect actually works as expected, especially for things like the bbcode string since it seems to be a very weirdly handled thing.

@mateuseap
Copy link
Contributor Author

mateuseap commented May 29, 2024

I've created a C# script to test out the matrix effect code provided in this PR, but I wasn't able to load this custom effect — it didn't show up in the inspector. On the other hand, I created a script called RichTextGhost.gd using the GDScript code provided in the tutorial, and it worked properly. I was able to load and use it.

The effect in action:
2024-05-29-01-23-33

Do you guys have any idea of what could be the problem?

@raulsntos
Copy link
Member

You have to use the [GlobalClass] attribute to get C# classes to show up in the inspector, it's somewhat equivalent to GDScript's class_name.

@mateuseap
Copy link
Contributor Author

mateuseap commented May 29, 2024

I've added [GlobalClass], but it still didn't show up as expected:

image

I've tested many things but still haven't figured out the problem.

@paulloz
Copy link
Member

paulloz commented May 29, 2024

After a very quick test, I don't seem to have an issue seeing the effect in editor once it is marked with [GlobalClass].
godot windows editor dev x86_64 mono_01mCxiLfXw

@mateuseap
Copy link
Contributor Author

Then it's probably a misconfiguration with my Godot. I've tried it on two different devices (both with the .NET 6.0 SDK (v6.0.423) - Windows x64 installed) but still I wasn't able to use the C# version of these custom effects, not even was able to load them in the inspector using the [GlobalClass].

image

I've used v4.3.dev5.mono.official [89f70e98d] and v4.2.2.stable.mono.official [15073afe3].

@paulloz
Copy link
Member

paulloz commented May 29, 2024

Did you compile the C# solution?


.. tabs::
.. code-tab:: gdscript GDScript

Copy link
Member

@AThousandShips AThousandShips May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

No space, rather than deleting the line, GitHub doesn't allow that clearly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it, you suggested to delete the line between the code-tab and the code itself?

@@ -931,10 +932,35 @@ Ghost
char_fx.color.a = alpha
return true

.. code-tab:: csharp

Copy link
Member

@AThousandShips AThousandShips May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:manual Issues and PRs related to the Manual/Tutorials section of the documentation topic:dotnet topic:gui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add C# examples for custom BBCode
5 participants