Skip to content

Commit

Permalink
Merge pull request #44143 from KoBeWi/callable_multiplayer
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Sep 18, 2022
2 parents 7a0a3fe + 882a4f8 commit e5594c2
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 93 deletions.
4 changes: 2 additions & 2 deletions editor/animation_bezier_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,8 @@ void AnimationBezierTrackEdit::set_timeline(AnimationTimelineEdit *p_timeline) {

void AnimationBezierTrackEdit::set_editor(AnimationTrackEditor *p_editor) {
editor = p_editor;
connect("clear_selection", Callable(editor, "_clear_selection").bind(false));
connect("select_key", Callable(editor, "_key_selected"), CONNECT_DEFERRED);
connect("clear_selection", callable_mp(editor, &AnimationTrackEditor::_clear_selection).bind(false));
connect("select_key", callable_mp(editor, &AnimationTrackEditor::_key_selected), CONNECT_DEFERRED);
}

void AnimationBezierTrackEdit::_play_position_draw() {
Expand Down
18 changes: 5 additions & 13 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3424,9 +3424,6 @@ void AnimationTrackEditGroup::_zoom_changed() {
queue_redraw();
}

void AnimationTrackEditGroup::_bind_methods() {
}

AnimationTrackEditGroup::AnimationTrackEditGroup() {
set_mouse_filter(MOUSE_FILTER_PASS);
}
Expand Down Expand Up @@ -6461,16 +6458,11 @@ void AnimationTrackEditor::_select_all_tracks_for_copy() {
}

void AnimationTrackEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_animation_update"), &AnimationTrackEditor::_animation_update);
ClassDB::bind_method(D_METHOD("_track_grab_focus"), &AnimationTrackEditor::_track_grab_focus);
ClassDB::bind_method(D_METHOD("_update_tracks"), &AnimationTrackEditor::_update_tracks);
ClassDB::bind_method(D_METHOD("_redraw_tracks"), &AnimationTrackEditor::_redraw_tracks);
ClassDB::bind_method(D_METHOD("_clear_selection_for_anim"), &AnimationTrackEditor::_clear_selection_for_anim);
ClassDB::bind_method(D_METHOD("_select_at_anim"), &AnimationTrackEditor::_select_at_anim);

ClassDB::bind_method(D_METHOD("_key_selected"), &AnimationTrackEditor::_key_selected); // Still used by some connect_compat.
ClassDB::bind_method(D_METHOD("_key_deselected"), &AnimationTrackEditor::_key_deselected); // Still used by some connect_compat.
ClassDB::bind_method(D_METHOD("_clear_selection"), &AnimationTrackEditor::_clear_selection); // Still used by some connect_compat.
ClassDB::bind_method("_animation_update", &AnimationTrackEditor::_animation_update);
ClassDB::bind_method("_track_grab_focus", &AnimationTrackEditor::_track_grab_focus);
ClassDB::bind_method("_clear_selection_for_anim", &AnimationTrackEditor::_clear_selection_for_anim);
ClassDB::bind_method("_select_at_anim", &AnimationTrackEditor::_select_at_anim);
ClassDB::bind_method("_clear_selection", &AnimationTrackEditor::_clear_selection);

ClassDB::bind_method(D_METHOD("_bezier_track_set_key_handle_mode", "animation", "track_idx", "key_idx", "key_handle_mode", "key_handle_set_mode"), &AnimationTrackEditor::_bezier_track_set_key_handle_mode, DEFVAL(Animation::HANDLE_SET_MODE_NONE));

Expand Down
10 changes: 5 additions & 5 deletions editor/animation_track_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ class AnimationTrackEditGroup : public Control {
void _zoom_changed();

protected:
static void _bind_methods();
void _notification(int p_what);

public:
Expand Down Expand Up @@ -407,7 +406,6 @@ class AnimationTrackEditor : public VBoxContainer {
void _insert_key_from_track(float p_ofs, int p_track);
void _add_method_key(const String &p_method);

void _clear_selection(bool p_update = false);
void _clear_selection_for_anim(const Ref<Animation> &p_anim);
void _select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos);

Expand All @@ -425,9 +423,6 @@ class AnimationTrackEditor : public VBoxContainer {

RBMap<SelectedKey, KeyInfo> selection;

void _key_selected(int p_key, bool p_single, int p_track);
void _key_deselected(int p_key, int p_track);

bool moving_selection = false;
float moving_selection_offset = 0.0f;
void _move_selection_begin();
Expand Down Expand Up @@ -531,6 +526,11 @@ class AnimationTrackEditor : public VBoxContainer {
void _notification(int p_what);

public:
// Public for use with callable_mp.
void _clear_selection(bool p_update = false);
void _key_selected(int p_key, bool p_single, int p_track);
void _key_deselected(int p_key, int p_track);

enum {
EDIT_COPY_TRACKS,
EDIT_COPY_TRACKS_CONFIRM,
Expand Down
2 changes: 1 addition & 1 deletion editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ void ConnectionsDock::_go_to_script(TreeItem &p_item) {
}

if (script.is_valid() && ScriptEditor::get_singleton()->script_goto_method(script, cd.method)) {
EditorNode::get_singleton()->call("_editor_select", EditorNode::EDITOR_SCRIPT);
EditorNode::get_singleton()->editor_select(EditorNode::EDITOR_SCRIPT);
}
}

Expand Down
4 changes: 3 additions & 1 deletion editor/editor_file_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ class EditorFileDialog : public ConfirmationDialog {

void _select_drive(int p_idx);
void _dir_submitted(String p_dir);
void _file_submitted(const String &p_file);
void _action_pressed();
void _save_confirm_pressed();
void _cancel_pressed();
Expand Down Expand Up @@ -240,6 +239,9 @@ class EditorFileDialog : public ConfirmationDialog {
static void _bind_methods();

public:
// Public for use with callable_mp.
void _file_submitted(const String &p_file);

void popup_file_dialog();
void clear_filters();
void add_filter(const String &p_filter, const String &p_description = "");
Expand Down
48 changes: 18 additions & 30 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,15 @@ void EditorNode::shortcut_input(const Ref<InputEvent> &p_event) {
}

if (ED_IS_SHORTCUT("editor/editor_2d", p_event)) {
_editor_select(EDITOR_2D);
editor_select(EDITOR_2D);
} else if (ED_IS_SHORTCUT("editor/editor_3d", p_event)) {
_editor_select(EDITOR_3D);
editor_select(EDITOR_3D);
} else if (ED_IS_SHORTCUT("editor/editor_script", p_event)) {
_editor_select(EDITOR_SCRIPT);
editor_select(EDITOR_SCRIPT);
} else if (ED_IS_SHORTCUT("editor/editor_help", p_event)) {
emit_signal(SNAME("request_help_search"), "");
} else if (ED_IS_SHORTCUT("editor/editor_assetlib", p_event) && AssetLibraryEditorPlugin::is_available()) {
_editor_select(EDITOR_ASSETLIB);
editor_select(EDITOR_ASSETLIB);
} else if (ED_IS_SHORTCUT("editor/editor_next", p_event)) {
_editor_select_next();
} else if (ED_IS_SHORTCUT("editor/editor_prev", p_event)) {
Expand Down Expand Up @@ -584,7 +584,7 @@ void EditorNode::_update_from_settings() {
void EditorNode::_select_default_main_screen_plugin() {
if (EDITOR_3D < main_editor_buttons.size() && main_editor_buttons[EDITOR_3D]->is_visible()) {
// If the 3D editor is enabled, use this as the default.
_editor_select(EDITOR_3D);
editor_select(EDITOR_3D);
return;
}

Expand All @@ -593,12 +593,12 @@ void EditorNode::_select_default_main_screen_plugin() {
for (int i = 0; i < main_editor_buttons.size(); i++) {
Button *editor_button = main_editor_buttons[i];
if (editor_button->is_visible()) {
_editor_select(i);
editor_select(i);
return;
}
}

_editor_select(-1);
editor_select(-1);
}

void EditorNode::_notification(int p_what) {
Expand Down Expand Up @@ -1190,7 +1190,7 @@ void EditorNode::_editor_select_next() {
}
} while (!main_editor_buttons[editor]->is_visible());

_editor_select(editor);
editor_select(editor);
}

void EditorNode::_open_command_palette() {
Expand All @@ -1208,7 +1208,7 @@ void EditorNode::_editor_select_prev() {
}
} while (!main_editor_buttons[editor]->is_visible());

_editor_select(editor);
editor_select(editor);
}

Error EditorNode::load_resource(const String &p_resource, bool p_ignore_broken_deps) {
Expand Down Expand Up @@ -2390,7 +2390,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) {

else if (main_plugin != editor_plugin_screen && (!ScriptEditor::get_singleton() || !ScriptEditor::get_singleton()->is_visible_in_tree() || ScriptEditor::get_singleton()->can_take_away_focus())) {
// Update screen main_plugin.
_editor_select(plugin_index);
editor_select(plugin_index);
main_plugin->edit(current_obj);
} else {
editor_plugin_screen->edit(current_obj);
Expand Down Expand Up @@ -3305,7 +3305,7 @@ VBoxContainer *EditorNode::get_main_screen_control() {
return main_screen_vbox;
}

void EditorNode::_editor_select(int p_which) {
void EditorNode::editor_select(int p_which) {
static bool selecting = false;
if (selecting || changing_scene) {
return;
Expand Down Expand Up @@ -3359,7 +3359,7 @@ void EditorNode::select_editor_by_name(const String &p_name) {

for (int i = 0; i < main_editor_buttons.size(); i++) {
if (main_editor_buttons[i]->get_text() == p_name) {
_editor_select(i);
editor_select(i);
return;
}
}
Expand All @@ -3372,7 +3372,7 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed
Button *tb = memnew(Button);
tb->set_flat(true);
tb->set_toggle_mode(true);
tb->connect("pressed", callable_mp(singleton, &EditorNode::_editor_select).bind(singleton->main_editor_buttons.size()));
tb->connect("pressed", callable_mp(singleton, &EditorNode::editor_select).bind(singleton->main_editor_buttons.size()));
tb->set_name(p_editor->get_name());
tb->set_text(p_editor->get_name());

Expand Down Expand Up @@ -3406,7 +3406,7 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan
for (int i = 0; i < singleton->main_editor_buttons.size(); i++) {
if (p_editor->get_name() == singleton->main_editor_buttons[i]->get_text()) {
if (singleton->main_editor_buttons[i]->is_pressed()) {
singleton->_editor_select(EDITOR_SCRIPT);
singleton->editor_select(EDITOR_SCRIPT);
}

memdelete(singleton->main_editor_buttons[i]);
Expand Down Expand Up @@ -3630,7 +3630,7 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) {
int index = p_state["editor_index"];
if (current < 2) { // If currently in spatial/2d, only switch to spatial/2d. If currently in script, stay there.
if (index < 2 || !get_edited_scene()) {
_editor_select(index);
editor_select(index);
}
}
}
Expand All @@ -3641,9 +3641,9 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) {
int n2d = 0, n3d = 0;
_find_node_types(get_edited_scene(), n2d, n3d);
if (n2d > n3d) {
_editor_select(EDITOR_2D);
editor_select(EDITOR_2D);
} else if (n3d > n2d) {
_editor_select(EDITOR_3D);
editor_select(EDITOR_3D);
}
}
}
Expand Down Expand Up @@ -5935,7 +5935,7 @@ void EditorNode::_feature_profile_changed() {
if ((profile->is_feature_disabled(EditorFeatureProfile::FEATURE_3D) && singleton->main_editor_buttons[EDITOR_3D]->is_pressed()) ||
(profile->is_feature_disabled(EditorFeatureProfile::FEATURE_SCRIPT) && singleton->main_editor_buttons[EDITOR_SCRIPT]->is_pressed()) ||
(AssetLibraryEditorPlugin::is_available() && profile->is_feature_disabled(EditorFeatureProfile::FEATURE_ASSET_LIB) && singleton->main_editor_buttons[EDITOR_ASSETLIB]->is_pressed())) {
_editor_select(EDITOR_2D);
editor_select(EDITOR_2D);
}
} else {
import_tabs->set_tab_hidden(import_tabs->get_tab_idx_from_control(ImportDock::get_singleton()), false);
Expand All @@ -5958,19 +5958,14 @@ void EditorNode::_bind_methods() {
GLOBAL_DEF("editor/scene/scene_naming", SCENE_NAME_CASING_SNAKE_CASE);
ProjectSettings::get_singleton()->set_custom_property_info("editor/scene/scene_naming", PropertyInfo(Variant::INT, "editor/scene/scene_naming", PROPERTY_HINT_ENUM, "Auto,PascalCase,snake_case"));
ClassDB::bind_method("edit_current", &EditorNode::edit_current);
ClassDB::bind_method("_editor_select", &EditorNode::_editor_select);
ClassDB::bind_method("_node_renamed", &EditorNode::_node_renamed);
ClassDB::bind_method("edit_node", &EditorNode::edit_node);

ClassDB::bind_method(D_METHOD("push_item", "object", "property", "inspector_only"), &EditorNode::push_item, DEFVAL(""), DEFVAL(false));

ClassDB::bind_method("_get_scene_metadata", &EditorNode::_get_scene_metadata);
ClassDB::bind_method("set_edited_scene", &EditorNode::set_edited_scene);
ClassDB::bind_method("open_request", &EditorNode::open_request);
ClassDB::bind_method("edit_foreign_resource", &EditorNode::edit_foreign_resource);
ClassDB::bind_method("is_resource_read_only", &EditorNode::is_resource_read_only);
ClassDB::bind_method("_close_messages", &EditorNode::_close_messages);
ClassDB::bind_method("_show_messages", &EditorNode::_show_messages);

ClassDB::bind_method("stop_child_process", &EditorNode::stop_child_process);

Expand All @@ -5983,13 +5978,6 @@ void EditorNode::_bind_methods() {

ClassDB::bind_method(D_METHOD("get_gui_base"), &EditorNode::get_gui_base);

ClassDB::bind_method(D_METHOD("_on_plugin_ready"), &EditorNode::_on_plugin_ready); // Still used by some connect_compat.

ClassDB::bind_method("_screenshot", &EditorNode::_screenshot);
ClassDB::bind_method("_save_screenshot", &EditorNode::_save_screenshot);

ClassDB::bind_method("_version_button_pressed", &EditorNode::_version_button_pressed);

ADD_SIGNAL(MethodInfo("play_pressed"));
ADD_SIGNAL(MethodInfo("pause_pressed"));
ADD_SIGNAL(MethodInfo("stop_pressed"));
Expand Down
8 changes: 5 additions & 3 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ class EditorNode : public Node {
void _update_file_menu_opened();
void _update_file_menu_closed();

void _on_plugin_ready(Object *p_script, const String &p_activate_name);
void _remove_plugin_from_enabled(const String &p_name);

void _fs_changed();
Expand All @@ -553,7 +552,6 @@ class EditorNode : public Node {
void _node_renamed();
void _editor_select_next();
void _editor_select_prev();
void _editor_select(int p_which);
void _set_scene_metadata(const String &p_file, int p_idx = -1);
void _get_scene_metadata(const String &p_file);
void _update_title();
Expand Down Expand Up @@ -701,7 +699,11 @@ class EditorNode : public Node {
void set_current_tab(int p_tab);

public:
void set_visible_editor(EditorTable p_table) { _editor_select(p_table); }
// Public for use with callable_mp.
void _on_plugin_ready(Object *p_script, const String &p_activate_name);

void editor_select(int p_which);
void set_visible_editor(EditorTable p_table) { editor_select(p_table); }

bool call_build();

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_plugin_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void EditorPluginSettings::_notification(int p_what) {
} break;

case Node::NOTIFICATION_READY: {
plugin_config_dialog->connect("plugin_ready", Callable(EditorNode::get_singleton(), "_on_plugin_ready"));
plugin_config_dialog->connect("plugin_ready", callable_mp(EditorNode::get_singleton(), &EditorNode::_on_plugin_ready));
plugin_list->connect("button_clicked", callable_mp(this, &EditorPluginSettings::_cell_button_pressed));
} break;
}
Expand Down
8 changes: 4 additions & 4 deletions editor/export/project_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,10 +865,10 @@ void ProjectExportDialog::_validate_export_path(const String &p_path) {

if (invalid_path) {
export_project->get_ok_button()->set_disabled(true);
export_project->get_line_edit()->disconnect("text_submitted", Callable(export_project, "_file_submitted"));
export_project->get_line_edit()->disconnect("text_submitted", callable_mp(export_project, &EditorFileDialog::_file_submitted));
} else {
export_project->get_ok_button()->set_disabled(false);
export_project->get_line_edit()->connect("text_submitted", Callable(export_project, "_file_submitted"));
export_project->get_line_edit()->connect("text_submitted", callable_mp(export_project, &EditorFileDialog::_file_submitted));
}
}

Expand Down Expand Up @@ -901,9 +901,9 @@ void ProjectExportDialog::_export_project() {
// with _validate_export_path.
// FIXME: This is a hack, we should instead change EditorFileDialog to allow
// disabling validation by the "text_submitted" signal.
if (!export_project->get_line_edit()->is_connected("text_submitted", Callable(export_project, "_file_submitted"))) {
if (!export_project->get_line_edit()->is_connected("text_submitted", callable_mp(export_project, &EditorFileDialog::_file_submitted))) {
export_project->get_ok_button()->set_disabled(false);
export_project->get_line_edit()->connect("text_submitted", Callable(export_project, "_file_submitted"));
export_project->get_line_edit()->connect("text_submitted", callable_mp(export_project, &EditorFileDialog::_file_submitted));
}

export_project->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
Expand Down
9 changes: 2 additions & 7 deletions editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4715,12 +4715,10 @@ void CanvasItemEditor::_reset_drag() {
}

void CanvasItemEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_update_override_camera_button", "game_running"), &CanvasItemEditor::_update_override_camera_button);
ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data);

ClassDB::bind_method(D_METHOD("set_state"), &CanvasItemEditor::set_state);
ClassDB::bind_method(D_METHOD("update_viewport"), &CanvasItemEditor::update_viewport);
ClassDB::bind_method(D_METHOD("_zoom_on_position"), &CanvasItemEditor::_zoom_on_position);

ClassDB::bind_method("_set_owner_for_node_and_children", &CanvasItemEditor::_set_owner_for_node_and_children);

Expand Down Expand Up @@ -4984,8 +4982,8 @@ CanvasItemEditor::CanvasItemEditor() {
SceneTreeDock::get_singleton()->connect("node_created", callable_mp(this, &CanvasItemEditor::_node_created));
SceneTreeDock::get_singleton()->connect("add_node_used", callable_mp(this, &CanvasItemEditor::_reset_create_position));

EditorNode::get_singleton()->call_deferred(SNAME("connect"), "play_pressed", Callable(this, "_update_override_camera_button").bind(true));
EditorNode::get_singleton()->call_deferred(SNAME("connect"), "stop_pressed", Callable(this, "_update_override_camera_button").bind(false));
EditorNode::get_singleton()->call_deferred(SNAME("connect"), callable_mp(this, &CanvasItemEditor::_update_override_camera_button).bind(true));
EditorNode::get_singleton()->call_deferred(SNAME("connect"), "stop_pressed", callable_mp(this, &CanvasItemEditor::_update_override_camera_button).bind(false));

// A fluid container for all toolbars.
HFlowContainer *main_flow = memnew(HFlowContainer);
Expand Down Expand Up @@ -5883,9 +5881,6 @@ void CanvasItemEditorViewport::_notification(int p_what) {
}
}

void CanvasItemEditorViewport::_bind_methods() {
}

CanvasItemEditorViewport::CanvasItemEditorViewport(CanvasItemEditor *p_canvas_item_editor) {
default_texture_node_type = "Sprite2D";
// Node2D
Expand Down
2 changes: 0 additions & 2 deletions editor/plugins/canvas_item_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,6 @@ class CanvasItemEditorViewport : public Control {
void _show_resource_type_selector();
void _update_theme();

static void _bind_methods();

protected:
void _notification(int p_what);

Expand Down
Loading

0 comments on commit e5594c2

Please sign in to comment.