godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.26k stars 101 forks source link

Control Node (Option Button) - Adding Attribute "Value" To Selectable Items #12609

Open Patrick-VDM opened 3 weeks ago

Patrick-VDM commented 3 weeks ago

Describe the project you are working on

Working on 2D Game. Top Down Pixel Art Simulation type of game. It has heavy interface usage using control nodes to display data, select data e.t.c Using dropdown box aka (Control Node - Option Button) populated data by script from data source and player select drop down and displays results from data source to appropriate labels or textboxes.

Describe the problem or limitation you are having in your project

The problem is the control node (Option Button) it's self.

You can't bind data easily or is limited on what attributes can be assigned to each selectable item.

You don't have a problem if the items will always remain static and doesn't change. But dynamic items that change a lot is the main cause of the issue.

You only have ID, Text, Icon, Disable, and Separator as shown below

Image

For example using primary keys and bind to the ID attribute doesn't work as it get overridden as the main purpose is for display order of items in the dropdown list starting from 0.

Some tutorials I have seen people using text attribute to do comparison which is stupid unless you want your item "apple" displayed as "5238" to the gamer. Gamer wants to know apple not "5238"?

What ever solution I am trying come up will have extra code that is not needed. I'm surprised that I am the only one who has this issue unless someone hasn't added the correct keywords in the title that isn't easy to find.

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

Add a new Attribute called Value or Data that must be string or int and can be accessible by node and script. This new Attribute is optional so it doesn't break backwards compatibility.

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

Some examples below.

My only concern that this might break compatibility if someone used ID in place of data as shown below. Image

Image

I am not 100% sure but it should be easy for someone to implement. I could do it my self but C++ is not my chosen poison and have the setup to do it.

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

I haven't found a work around yet. but I am going try and use an associative array or dictionary to store id's paired with their primary key / data values. Not ideal, just a bunch of extra code that is not needed than accessing the information direct from the node. This work around might not be for everyone depending on their requirements.

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

This is about improving the node and making a bit more friendly and making dynamic data looking up work. I can say that Godot already user friendly, but in the long run this will make it even better with less pain and work for developers.

Tattomoosa commented 3 weeks ago

This is what the metadata field does, it just can't be set in the editor.

https://docs.godotengine.org/en/stable/classes/class_optionbutton.html#class-optionbutton-method-set-item-metadata

Patrick-VDM commented 3 weeks ago

This is what the metadata field does, it just can't be set in the editor.

https://docs.godotengine.org/en/stable/classes/class_optionbutton.html#class-optionbutton-method-set-item-metadata

@Tattomoosa
Thank you for point this out. I will look into this, but I have a feeling this starting become an annoying chore to write the extra code and validation which is wasting my time and this community.

Meorge commented 3 weeks ago

Given that an editor picker for a Variant type exists (used for displaying/editing Dictionaries in the editor), I imagine allowing metadata to be set in the editor couldn't be too hard...?

KoBeWi commented 3 weeks ago

Yes, it's easy to expose now.

Related proposal: #10358