Skip to content
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

Add get_item_at_index(int idx) to ItemList #11764

Open
elvisish opened this issue Feb 13, 2025 · 6 comments
Open

Add get_item_at_index(int idx) to ItemList #11764

elvisish opened this issue Feb 13, 2025 · 6 comments

Comments

@elvisish
Copy link

elvisish commented Feb 13, 2025

Describe the project you are working on

Puzzle game with level select.

Describe the problem or limitation you are having in your project

Currently ItemList has:

  • get_item_metadata ( idx )
  • get_item_text ( idx )
  • get_item_tooltip ( idx )
  • get_item_icon_region ( idx )
  • get_item_custom_bg_color ( idx )
  • get_item_custom_fg_color ( idx )
  • get_item_icon ( idx )
  • get_item_icon_modulate ( idx )

But it does not have:

  • get_item_at_index ( idx )

It only has:

  • get_item_at_position ( [Vector2] position, [bool] exact=false ) const

So the only choice to get an index in an ItemList is to loop through every item, if not using the selected signal.

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

Add get_item_at_index ( idx ) to ItemList.

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

It would be exactly the same as the other ways of getting the other information from ItemList items at indexes.

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

The workaround is current to loop through the entire ItemList.

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

It is an engine related feature.

@bruvzg
Copy link
Member

bruvzg commented Feb 13, 2025

What it supposed to return? get_item_at_position returns index, so why do you need get_item_at_index(idx) if you already have idx?

@elvisish
Copy link
Author

elvisish commented Feb 13, 2025

What it supposed to return? get_item_at_position returns index, so why do you need get_item_at_index(idx) if you already have idx?

get_item_at_position needs a position. get_item_at_index(idx) would allow you to return the item reference at the index (the actual item for removing, or modifying).

@bruvzg
Copy link
Member

bruvzg commented Feb 13, 2025

Item as a single object? There's no such thing as ItemList item object in the current implementation. So it's not just adding a function, but completely changing the way it's working. It makes sense for Tree, since it has non-linear structure, but I'm not sure what's the benefits of doing so for ItemList.

@Calinou Calinou changed the title Add get_item_at_index ( int idx ) to ItemList Add get_item_at_index(int idx) to ItemList Feb 13, 2025
@KoBeWi
Copy link
Member

KoBeWi commented Feb 13, 2025

It could return a Dictionary with item's data.

@nielsvaes
Copy link

What would be the key(s) of that return Dictionary then?

@theraot
Copy link

theraot commented Feb 16, 2025

There are already functions to get the different values associated with an index, so coming up with names for the keys of the dictionary is easy: keep it consistent with the function names, in camel case, since that would be consistent with other APIs (e.g. you get the value form get_item_tooltip in the "tooltip" key).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants