mhgolkar / Arrow

Game Narrative Design Tool
https://mhgolkar.github.io/Arrow/
MIT License
905 stars 42 forks source link

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

Closed frigvid closed 8 months ago

frigvid commented 10 months ago

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` ```gdscript 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 commented 10 months ago

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.

frigvid commented 10 months ago

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 commented 10 months ago

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 commented 8 months ago

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.