godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.13k stars 93 forks source link

Support procedural images for the `[img]` tag on RichTextLabel #89

Open Bethleem opened 5 years ago

Bethleem commented 5 years ago

Describe the project you are working on: A interactive ficition engine. Is text based with ilustrations created in runtime and added between the text. RichTextLabel is critical because the engine relies on the meta_clicked feature.

Describe how this feature / enhancement will help your project: Images showed in the games are created in runtime. They are not file disk images because may change a lot with player choices and that would end in thousands of png files just to use one of them. Even if I save that procedural image into a png file in runtime, it can´t be used by godot because the .import file would be missing and img tag don´t work with Sprite or Image variables. RichTextLabel show only image files from disk previosusly imported via the editor, so no way procedural ones woul be used.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work: Well, it´s the same output that the actual img tag but reading it from variable instead of disk file. Or, It would work too if a png file could be saved with the needed .import file, but I think it would be a mayor headhache to add to the engine.

Describe implementation detail for your proposal (in code), if possible: I have not the level to touch Godot´s internal code. But the img tag should read a Image/Sprite variable reference instead a disk path for file.

If this enhancement will not be used often, can it be worked around with a few lines of script?: Nope. It´s a hardoded feature. A entire new RichTextLabel must be written from scratch in order to acomplish procedural images showed if Godot´s one doesn´t provide that feature.

Is there a reason why this should be core and not an add-on in the asset library?: Not really. Any way it can work, would be wellcomed.

girng commented 5 years ago

I actually ran into this as well (I was writing a client side forum using Godot's UI paired with FluxBB). I remember trying to get dynamically loaded images to work inside [img]. I remember getting it to work and loading the image data into a Sprite's texture, but not inside an RTL's [img] tags.

Nope. It´s a hardoded feature. A entire new RichTextLabel must be written from scratch in order to acomplish procedural images showed if Godot´s one doesn´t provide that feature.

I don't think an entire new RTL must be created. I would propose a new BBCode tag that would enable this functionality.

I also think this might be a unique use case that is not common. However, I think it could be argued it's an improvement to RTL, which can make it even more powerful. It may also be appropriate for https://github.com/godot-community/godot-next,

Bethleem commented 5 years ago

I don't think an entire new RTL must be created. I would propose a new BBCode tag that would enable this functionality.

Good idea! :smiley:

I also think this might be a unique use case that is not common. However, I think it could be argued it's an improvement to RTL, which can make it even more powerful.

It´s always about cost & return. The cost of add the feature vs the potential it shows. Most engine users are about 2D & 3D graphics, not just text interfaces, so it might not be a shiny feature for them. But for movile text interfaces, for instance, will make godot a killing machine.

Hope it will be a go. :pray:

girng commented 5 years ago

I don't think an entire new RTL must be created. I would propose a new BBCode tag that would enable this functionality.

Good idea! 😃

I also think this might be a unique use case that is not common. However, I think it could be argued it's an improvement to RTL, which can make it even more powerful.

It´s always about cost & return. The cost of add the feature vs the potential it shows. Most engine users are about 2D & 3D graphics, not just text interfaces, so it might not be a shiny feature for them. But for movile text interfaces, for instance, will make godot a killing machine.

Hope it will be a go. 🙏

I think a sprite tag would be an appropriate solution. The sprite's texture can be modified at runtime, and allow for its texture to be updated dynamically (even if you download an image from external url, then use that image data). Problem is, if that node is free'd, it'll need to update the tag and implementing this is unfortunately beyond my knowledge. Will need someone like willnations or above.

I'm just shooting out ideas though, feel free to chime in.. Or, a [node=ref] (more powerful, but would have to accommodate for sizes and everything, would be a PITA). No idea.

Calinou commented 4 years ago

Reading the image's contents from a variable sounds very difficult to implement, especially if you factor in cross-language functionality (Godot supports more than just GDScript).

It might be easier to implement data URI support so you can specify the image contents encoded in Base64 as an img tag's value. This also plays well with Web standards that are generally expected when working with BBCode.

fahrstuhl commented 4 years ago

Hi, I hope it's okay to post this here, but I got RichTextLabels to work with images loaded from the filesystem.

To me the key steps seem to be:

  1. load the image as an ImageTexture (and store it in a persistent variable so it doesn't get cleaned up)
  2. run the texture's take_over_path method on the path that's used in the [img]-tag in the bbcode_text
  3. set bbcode_text to make the ResourceLoader called on the image paths find the already loaded textures

I didn't try with generated textures, yet, but I think it should work the same way. You just need to come up with a dynamic path.

grayhaze commented 2 years ago

I just ran across this too. Unfortunately @fahrstuhl's suggestion doesn't work for generated images which exist only in memory, but rather only for images loaded from disk. I agree this would be a really useful feature to have, as the current [img] functionality is severely restricted.

Yazir commented 4 months ago

I see two workarounds to this issue:

  1. Use add_image and update_image of RichTextLabel - not necessarily easy to do if someone relies on just strings as sole RichTextLabel inputs.
  2. Save the image to disk (eg. Image.save_png or just generic ResourceSaver.Save), preferably under "user://" path - the RichTextLabel by default chooses res:// paths, but if you provide user:// explicitly, it will use that one.

Second is the option I had chosen and it works so far so good.