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

Enhance or replace drop-down lists (specially in the inspectors) for better filtering and sorting #60

Closed
frigvid opened this issue Jan 16, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@frigvid
Copy link

frigvid commented Jan 16, 2024

The variables tab in the Inspector is sorted alphabetically, but the drop-down menu of the Condition node isn't. I use namespaces in variables to sort them properly in the Inspector variable tab, but when I am to select them in the Condition node's Check for variable it seems to be sorted by when it was created instead.

Code from potential pull request

File modified: nodes/condition/inspector.gd

func refresh_variables_list(select_by_res_id:int = -1) -> void:
	Variables.clear()
	_PROJECT_VARIABLES_CACHE = Main.Mind.clone_dataset_of("variables")

	if _PROJECT_VARIABLES_CACHE.size() > 0:
		var variables_array = []
		for variable_id in _PROJECT_VARIABLES_CACHE:
			var variable = _PROJECT_VARIABLES_CACHE[variable_id]
			variable.id = variable_id  # Ensure each variable has its ID
			variables_array.append(variable)

		variables_array.sort_custom(ConditionVarSorter, "compare_variables")

		for variable in variables_array:
			Variables.add_item(variable.name, variable.id)
			Variables.set_item_metadata(variables_array.find(variable), variable.id)

		if select_by_res_id >= 0:
			var variable_item_index = find_listed_variable_index(select_by_res_id)
			Variables.select(variable_item_index)
		elif a_node_is_open() and _OPEN_NODE.data.has("variable") and _OPEN_NODE.data.variable in _PROJECT_VARIABLES_CACHE:
			var variable_item_index = find_listed_variable_index(_OPEN_NODE.data.variable)
			Variables.select(variable_item_index)
	else:
		Variables.add_item(NO_VARIABLE_TEXT, NO_VARIABLE_ID)
		Variables.set_item_metadata(0, NO_VARIABLE_ID)
	pass

# Crappy sorter
class ConditionVarSorter:
	static func compare_variables(a, b):
		return a.name < b.name

I considered making a pull request for this, but I'm not really sure about the quality of my code, as I am unfamiliar with GDScript and the codebase. For example, I'm pretty sure there's a better solution than making a class for sorting and shoving it into the middle of the file. But it worked, and I have to go in a couple of minutes, so I don't really have time for more. I'd appreciate it if you could at least look over the code, and consider implementing something like it.

I can make a pull request if you'd like, after you've looked over it and point out what abominations are hiding within it, but also feel free to simply yoink things as you'd like.

@mhgolkar
Copy link
Owner

Most of menus including drop-down controls represent underlying data. It is somehow the policy.
Other controls such as lists used in variable and character inspectors, do have the same behavior, but because the alphabetical sorting is active by default, we get them commonly sorted.
Drop-down is not my favorite UI control, and is not ideal choice in many cases, specially when they get too populated!
I think we should replace them completely with a custom filter-able and sort-able menu, but it's going to take time.
For now, I hesitate to change the historic behavior. An overhaul seems necessary in the long-term though.

@mhgolkar mhgolkar changed the title Enhancement: Sort Condition variable drop-down alphabetically Enhance drop-down controls for better filtering and sorting Jan 18, 2024
@mhgolkar mhgolkar added the enhancement New feature or request label Jan 18, 2024
@mhgolkar mhgolkar changed the title Enhance drop-down controls for better filtering and sorting Enhance or replace drop-down lists (specially in the inspectors) for better filtering and sorting Jan 18, 2024
@frigvid
Copy link
Author

frigvid commented Jan 18, 2024

Alright, that's fair enough. I don't know the internals of Godot enough to provide much assistance here, but I'll leave the draft code here. Feel free to close or keep this issue open, if you'd like. Though I don't think I'll be of much help with GDScript.

@mhgolkar
Copy link
Owner

Let's keep this issue open. It's an enhancement that should be done one way or another.
Your suggested code may as well help others who need sorting right now.
Thanks for your attention and the feedback

mhgolkar added a commit that referenced this issue Mar 8, 2024
This commit adds a new button near the main resource pickers
(e.g. variable or character selectors), which if pressed,
filters and/or sorts the options, according to what
is defined in the respective inspector.

This also covers #60.
@mhgolkar
Copy link
Owner

mhgolkar commented Mar 8, 2024

Newly implemented feature allows resource pickers to follow sorting and filtering instructions defined in the respective inspector tabs. For example, if you want your variables to be sorted alphabetically in the Condition node inspector, you can activate the sorting in the Variables inspector tab (by default active) and toggle on the filter button adjacent to the selector. It works for other options such as per-scene, per-type or text filters as well.

@mhgolkar mhgolkar closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants