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

Expose CreateDialog by adding EditorCreateDialog singleton (accessed via EditorInterface). #99926

Conversation

Lazy-Rabbit-2001
Copy link
Contributor

@Lazy-Rabbit-2001 Lazy-Rabbit-2001 commented Dec 2, 2024

Closes: godotengine/godot-proposals#11238 (Will be done via an addon if this gets merged)

Exposes CreateDialog in another way: By adding a new class EditorCreateDialog as a singleton that can only be accessed via EditorInterface, with some singals and methods.

Signals

created: Emitted when an objects is created from the create dialog.
favourites_updated: Emitted when the content of "favourites" slot gets updated.

Methods

add_type_to_blacklist(type_name: StringName): Adds a type to the blacklist and update the search result of the create dialog. The type in the blacklist will not be displayed in the create dialog.
remove_type_from_blacklist(type_name: StringName): Removes a type from the blacklist. The type removed from the blacklist will get recovery of being displayed in the create dialog.
set_type_custom_suffix(type_name: StringName, custom_suffix: String): Sets the custom suffix of the type in the create dialog. The item will display its suffix with higher priority. If the custom suffix is an empty string, the suffix will be hidden. This is useful for labeling the node by someone, or from some addon, or being used as a "namespace".
get_type_custom_suffix(type_name: StringName): Returns the custom suffix of the type in the create dialog.
clear_all_type_custom_suffixes(): Removes all custom suffixes in the create dialog from all types (If the type is a script type, then it will fall back to showing the file name of the script).
get_search_options: Returns the "result list" (Tree) that is used in the create dialog.
get_dialog_window: Returns the create dialog window. (ConfirmationDialog)

Why not exposing CreateDialog

Exposing CreateDialog seems to be a much more easier and direct way. However, when a user is trying instantiating it with new() by mistake, the whole engine will crash. To make users' engines safe, EditorCreateDialog provides a safer box where users will receive an error if they are trying to instantiate an EditorCreateDialog without passing in a CreateDialog instance, which is not exposed to the engine, and the instance create by mistake will be deleted immediately. A user should never try instantiating EditorCreateDialog, even though it's safe for them.

Getting the instance of EditorCreateDialog

A user can get access to it by calling EditorInterface.get_create_dialog().

WIPs

  • Adding basic interfaces.
  • Basic bug fixes and docs, (done 50%)
  • Further fixes, local and inter-member tests.

@AThousandShips AThousandShips added this to the 4.x milestone Dec 3, 2024
@Lazy-Rabbit-2001 Lazy-Rabbit-2001 changed the title Expose CreateDialog by adding EditorCreateDialog as its interface class. Expose CreateDialog by adding EditorCreateDialog singleton (accessed via EditorInterface). Dec 3, 2024
@Lazy-Rabbit-2001 Lazy-Rabbit-2001 marked this pull request as ready for review December 3, 2024 16:54
@Lazy-Rabbit-2001 Lazy-Rabbit-2001 requested review from a team as code owners December 3, 2024 16:54
@KoBeWi
Copy link
Member

KoBeWi commented Dec 4, 2024

Can't the dialog be exposed via a method, like we did with SceneTreeDialog (popup_node_selector()) etc?

@Lazy-Rabbit-2001
Copy link
Contributor Author

Can't the dialog be exposed via a method, like we did with SceneTreeDialog (popup_node_selector()) etc?

It can, but i forgot to update this in the top post. I'll update it soon.
However, what you get is its base type ConfirmationDialog, not CreateDialog.

@KoBeWi
Copy link
Member

KoBeWi commented Dec 5, 2024

That doesn't really answer my question.
It can be implemented as popup_create_dialog(callback, base_type, type_blacklist, type_custom_suffix) (arguments up to discussion) instead of exposing a whole class. Though looks like you are also adding some new functionality.

@Lazy-Rabbit-2001
Copy link
Contributor Author

Lazy-Rabbit-2001 commented Dec 5, 2024

That doesn't really answer my question. It can be implemented as popup_create_dialog(callback, base_type, type_blacklist, type_custom_suffix) (arguments up to discussion) instead of exposing a whole class. Though looks like you are also adding some new functionality.

This is good for addons that needs a custom create dialog, but for those who needs native changes, I mean, for tweaks on the native create dialogs, singleton is still the best solution from my own perspective of experience.
I'll consider add a popup_create_dialog() for EditorCreateDialog singleton.

@KoBeWi
Copy link
Member

KoBeWi commented Dec 5, 2024

but for those who needs native changes, I mean, for tweaks on the native create dialogs

Like what tweaks? The current properties can be replaced by arguments, like in my example.
I see you have getters for some internal parts of the dialog, but are they useful? (and for what?)

@Lazy-Rabbit-2001
Copy link
Contributor Author

Lazy-Rabbit-2001 commented Dec 5, 2024

but for those who needs native changes, I mean, for tweaks on the native create dialogs

Like what tweaks? The current properties can be replaced by arguments, like in my example. I see you have getters for some internal parts of the dialog, but are they useful? (and for what?)

Or I can say, to "override" the native create dialogs.
E.g. when you click on the "+" at the top left of the scene tree editor to add a node, you want to "override" the native create dialog with your custom one.

@Lazy-Rabbit-2001
Copy link
Contributor Author

Lazy-Rabbit-2001 commented Dec 5, 2024

A fresh idea just hit me. Well, the next push will come soon.

@Lazy-Rabbit-2001
Copy link
Contributor Author

Superseded by #100135

@Lazy-Rabbit-2001 Lazy-Rabbit-2001 deleted the expose-create-dialog branch December 7, 2024 04:15
@YeldhamDev YeldhamDev removed this from the 4.x milestone Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement specific functional metadatas for Script instances that contain custom global classes
4 participants