This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm ussing BBCode RichTextEffects to hide text. The text only turns invisable but doesn't behave as it would in 3.5 or as the 4.10 documentation states it should.

@tool
extends RichTextEffect
class_name HideText

var bbcode := "hide"

func _process_custom_fx( char_fx : CharFXTransform) -> bool :
    if Settings.hide == true :
        char_fx.set_visibility( false )
    return true  

Unparsed text:
"Integer vitae justo eget magna fermentum iaculis eu non diam.[no_hide]

This should show. [/no_hide][hide]

This should be hidden..[/hide]

Convallis a cras semper auctor neque vitae tempus quam. Integer vitae justo eget magna fermentum iaculis eu non diam."


output looks like this :
"Integer vitae justo eget magna fermentum iaculis eu non diam.

This should show.

invisible, selectable, space-consuming characters be here!!!!!

Convallis a cras semper auctor neque vitae tempus quam. Integer vitae justo eget magna fermentum iaculis eu non diam."

The [hide] tag "works", in that it hides the text. The issue is that you can still select, copy and paste this "hidden" text and it still takes up space. The documentation says that the text should move to take up this space and that if I didn't want this, I should set the Alpha to 0 instead. But it seems like setting the Alpha to 0 is exactly what this char_fx is actually doing, rather than hiding the text and shifting the visible characters as the documentation implies.

I switched to 4.10 because 3.5 would hide the text but the control would still size itself as if the text was still there. I just can't seem win... sigh.

Godot version 4.10 Beta
in Engine by (63 points)

1 Answer

0 votes
Best answer

Incase anyone is interested I got feedback from the Godot peeps. Turns out that it's borkt and rather than fixing it, they're changing the documentation to show that this is now a "feature".

So I created a content parser that nukes the tags before BB Code can do it's thing. In your string you'd enter something like "<male>this text will show if the player is male</male> and <female>this text will show if the the player is female</female> " if they are male it will only nuke the <male></male> tags and if they are female it will nuke everything, to include the tags.

extends Node
class_name ContentParser

func parse_content( _text : String ) -> String :
    ##### Player Stuff #####
    if Player.is_male :
        _text = _hide_tag_only( _text, "male" )
        _text = _hide_content( _text, "female" )
    else : 
        _text = _hide_tag_only( _text, "female" )
        _text = _hide_content( _text, "male" )


func _hide_tag_only( _text : String,   _tag : String ) -> String :
    var pattern = RegEx.new()
    var results : Array 
    var reg_ex : String = (
        "<" + 
        _tag +
        ">|</" +
        _tag +
        ">"
    )  
    pattern.compile( reg_ex )
    #check if regex is valid
    if pattern.is_valid() :
        results = pattern.search_all( _text )

    #check if tags need to be scrubbed.
    if results.size() > 0 :
        _text =  pattern.sub( _text, "", true)

    return _text

func _hide_content( _text : String,   _tag : String ) -> String :
    var pattern = RegEx.new()
    var results : Array 
    var reg_ex : String = (
        "<" + 
        _tag +
        ">[.\\s\\S]*?</" +
        _tag +
        ">"
    )  
    pattern.compile( reg_ex )
    #check if regex is valid
    if pattern.is_valid() :
        results = pattern.search_all( _text )

    #check if tags need to be scrubbed.
    if results.size() > 0 :
        _text =  pattern.sub( _text, "", true)

    return _text
by (63 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.