godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.15k stars 97 forks source link

TextureProgressBar should be able to use a theme like the ProgressBar does #7265

Open dirigonaut opened 1 year ago

dirigonaut commented 1 year ago

Describe the project you are working on

I am working on a 2d isometric game that has is utilizing TextureProgressBars as part of the Hud to display Health/Mana information. I am currently reworking the Hud in the middle of an upgrade to Godot 4.0 from 3.5 since it broke a lot of my .tres files.

Describe the problem or limitation you are having in your project

I have been getting heavily into using themes for skinning the UI since the upgrade to Godot 4.0 broke a lot of resources for me. To avoid this in the future I am looking to use themes more with the plus of being able to reskin. I have setup a pipeline to import spritesheets and build themes with them. Themes with TextureStyleBoxes makes it almost trivial to reskin container elements of the UI. After getting the whole process setup for PanelContainers and Panels I started to move on to getting the themes setup for the TextureProgressBar as I will have a lot of those on my hud.

This is when I found out that per the documentation the TextureProgressBar do not support themes and instead use Texture2Ds. So my issue is that Godot has this amazing feature of themes, that is even used for the base ProgressBar, but if I want to reskin TextureProgressBars I can't use themes.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

So my proposal would be to allow TextureProgressBars to use themes like the ProgressBar.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

  1. Make TextureProgressBars use StyleBoxes like ProgressBar instead of Texture2Ds and just add one more item called "border" under "background" and "fill" image
  2. Make TextureProgressBars have a theme but keep their specific elements(Under/Over/Progress) as Texture2Ds image

I have a feeling proposal one is not viable as I think that the TextureProgressBars are Texture2Ds for their radial fill mode which I do not know how StyleBoxes would handle. If this is not a problem however I do think solution 1 makes things more consistent though might render ProgressBar redundant?

All in all I think proposal 2 is probably the easiest to get off the ground and accomplishes what I am primarily after which is being able to use themes with TextureProgressBars.

If this enhancement will not be used often, can it be worked around with a few lines of script?

How much effort this is to do is going to be based on how the end user builds their control scenes for UI elements. But the code in the end that the user would be writing would be to recreate the cascading nature of Godot Themes or they need to create tooling scripts that reach out to a datastore of whatever type to pull what themed textures they should be using.

As an alternative to recreating themes which is probably what I am going to do is put a PanelContainer over a ProgressBar that way I can bypass using a TextureProgressBar all together since it does not have themes. Though we will see how well this works for me once I get to actually wanting to make a radial ProgressBar but I might just resort to shaders as a hack.

Is there a reason why this should be core and not an add-on in the asset library?

It should be in core because Themes are in core.

dirigonaut commented 1 year ago

Adding this here as I did not want to pollute the request but I have been loving working with Godot and the 4.0 upgrade while a little bumpy has added a ton of wonderful features that I am looking forward to using once I have finished my migration. So thank you all for all of your efforts.

Calinou commented 1 year ago

I'm not sure if this is a good idea for several reasons:

Themes work best when they affect dozens of elements in the project (or more). If they don't, you may end up feeling like you're fighting the theme system by having to override it all the time for every node.

dirigonaut commented 1 year ago
  1. So the only thing about that is I am creating bespoke Panels using the StyleBoxes as is right now via themes, which allows me to swap out a full set of textures/margins used on an PanelContainer and Panel with just a theme update to the root element of the control scene. So I see no reason why the health/mana bar being different would affect the usage of this feature.
  2. I am wanting to use radial ProgressBars for cool down and status effect timers on the elements with it rotating around the border giving an indication of progress while also not taking up more UI space than needed. So I hear your points but they are not relevant to my scenario, though not saying they are not still relevant for others.
  3. After reading through the theme docs I had a feeling this(compatibility breaking) was going to be the case around this request. I have also seen a bunch of conversations around edge cases with radial ProgressBar textures and the like so I get that there is complexity around how to display all the options in a way that makes sense.
  4. One other point I want to make is that one thing I have been toying around with was having separate themes/styles for different screen resolutions so instead of having to mess with scaling making the textures look blurry or borders looking inconsistent between elements I could just swap out a theme to one with higher resolution StyleBox textures.

I do think I will be able to get what I want using Panels and a shader as mentioned above so this is not super critical for me. It just feels weird to me to have a styling system that works for only some of the styled elements.

Hell it might even be that I am misunderstanding what the intent behind themes are, cause to me it has a lot of similarities with CSS. I can go in and create a structured layout on a screen using v/hboxs, grids, margins which are feel a lot like tables and div tags in Html. We even have H/VFlow containers and that is a web convention. I also get that this is not web dev but there are a lot of similar paradigms that have been pulled in. I do think that to create loosely coupled UIs applying these concepts for UI design can be very helpful. Being able to reskin really aids in prototyping solutions.