From 5406b001ca8dd0b22cece26ebf4c15884d03add2 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 29 Dec 2022 11:21:39 +0200 Subject: [PATCH] Move remote debug buttons to a single menu. --- .../debug_adapter/debug_adapter_parser.cpp | 2 +- editor/editor_node.cpp | 4 +- editor/editor_node.h | 2 +- editor/editor_run_native.cpp | 94 +++++++------------ editor/editor_run_native.h | 7 +- editor/icons/PlayRemote.svg | 1 + 6 files changed, 43 insertions(+), 67 deletions(-) create mode 100644 editor/icons/PlayRemote.svg diff --git a/editor/debugger/debug_adapter/debug_adapter_parser.cpp b/editor/debugger/debug_adapter/debug_adapter_parser.cpp index d685db40d94..fc806ded5ec 100644 --- a/editor/debugger/debug_adapter/debug_adapter_parser.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_parser.cpp @@ -213,7 +213,7 @@ Dictionary DebugAdapterParser::req_launch(const Dictionary &p_params) const { } EditorNode *editor = EditorNode::get_singleton(); - Error err = platform_string == "android" ? editor->run_play_native(device, idx) : editor->run_play_native(-1, idx); + Error err = platform_string == "android" ? editor->run_play_native(device * 10000 + idx) : editor->run_play_native(idx); if (err) { if (err == ERR_INVALID_PARAMETER && platform_string == "android") { return prepare_error_response(p_params, DAP::ErrorType::MISSING_DEVICE); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index b1b40eb52a7..d1af28f8cf1 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5067,8 +5067,8 @@ bool EditorNode::ensure_main_scene(bool p_from_native) { return true; } -Error EditorNode::run_play_native(int p_idx, int p_platform) { - return run_native->run_native(p_idx, p_platform); +Error EditorNode::run_play_native(int p_id) { + return run_native->run_native(p_id); } void EditorNode::run_play() { diff --git a/editor/editor_node.h b/editor/editor_node.h index ae951808d5a..c1090bf6805 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -914,7 +914,7 @@ public: bool ensure_main_scene(bool p_from_native); - Error run_play_native(int p_idx, int p_platform); + Error run_play_native(int p_id); void run_play(); void run_play_current(); void run_play_custom(const String &p_custom); diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp index eab4e08cec2..49723aa169e 100644 --- a/editor/editor_run_native.cpp +++ b/editor/editor_run_native.cpp @@ -37,53 +37,27 @@ void EditorRunNative::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) { - Ref eep = EditorExport::get_singleton()->get_export_platform(i); - if (eep.is_null()) { - continue; - } - Ref icon = eep->get_run_icon(); - if (!icon.is_null()) { - Ref im = icon->get_image(); - im = im->duplicate(); - im->clear_mipmaps(); - if (!im->is_empty()) { - im->resize(16 * EDSCALE, 16 * EDSCALE); - Ref small_icon = ImageTexture::create_from_image(im); - MenuButton *mb = memnew(MenuButton); - mb->get_popup()->connect("id_pressed", callable_mp(this, &EditorRunNative::run_native).bind(i)); - mb->connect("pressed", callable_mp(this, &EditorRunNative::run_native).bind(-1, i)); - mb->set_icon(small_icon); - add_child(mb); - menus[i] = mb; - } - } - } + case NOTIFICATION_THEME_CHANGED: { + remote_debug->set_icon(get_theme_icon(SNAME("PlayRemote"), SNAME("EditorIcons"))); } break; - case NOTIFICATION_PROCESS: { bool changed = EditorExport::get_singleton()->poll_export_platforms() || first; if (changed) { - for (KeyValue &E : menus) { - Ref eep = EditorExport::get_singleton()->get_export_platform(E.key); - MenuButton *mb = E.value; - int dc = eep->get_options_count(); - - if (dc == 0) { - mb->hide(); - } else { - mb->get_popup()->clear(); - mb->show(); - if (dc == 1) { - mb->set_tooltip_text(eep->get_option_tooltip(0)); - } else { - mb->set_tooltip_text(eep->get_options_tooltip()); - for (int i = 0; i < dc; i++) { - mb->get_popup()->add_icon_item(eep->get_option_icon(i), eep->get_option_label(i)); - mb->get_popup()->set_item_tooltip(-1, eep->get_option_tooltip(i)); - } + remote_debug->get_popup()->clear(); + for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) { + Ref eep = EditorExport::get_singleton()->get_export_platform(i); + if (eep.is_null()) { + continue; + } + int dc = MIN(eep->get_options_count(), 9000); + if (dc > 0) { + remote_debug->get_popup()->add_icon_item(eep->get_run_icon(), eep->get_name(), -1); + remote_debug->get_popup()->set_item_disabled(-1, true); + for (int j = 0; j < dc; j++) { + remote_debug->get_popup()->add_icon_item(eep->get_option_icon(j), eep->get_option_label(j), 10000 * i + j); + remote_debug->get_popup()->set_item_tooltip(-1, eep->get_option_tooltip(j)); + remote_debug->get_popup()->set_item_indent(-1, 2); } } } @@ -94,25 +68,22 @@ void EditorRunNative::_notification(int p_what) { } } -Error EditorRunNative::run_native(int p_idx, int p_platform) { - if (!EditorNode::get_singleton()->ensure_main_scene(true)) { - resume_idx = p_idx; - resume_platform = p_platform; +Error EditorRunNative::run_native(int p_id) { + if (p_id < 0) { return OK; } - Ref eep = EditorExport::get_singleton()->get_export_platform(p_platform); - ERR_FAIL_COND_V(eep.is_null(), ERR_UNAVAILABLE); + int platform = p_id / 10000; + int idx = p_id % 10000; - if (p_idx == -1) { - if (eep->get_options_count() == 1) { - menus[p_platform]->get_popup()->hide(); - p_idx = 0; - } else { - return ERR_INVALID_PARAMETER; - } + if (!EditorNode::get_singleton()->ensure_main_scene(true)) { + resume_id = p_id; + return OK; } + Ref eep = EditorExport::get_singleton()->get_export_platform(platform); + ERR_FAIL_COND_V(eep.is_null(), ERR_UNAVAILABLE); + Ref preset; for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { @@ -151,7 +122,7 @@ Error EditorRunNative::run_native(int p_idx, int p_platform) { } eep->clear_messages(); - Error err = eep->run(preset, p_idx, flags); + Error err = eep->run(preset, idx, flags); result_dialog_log->clear(); if (eep->fill_log_messages(result_dialog_log, err)) { if (eep->get_worst_message_type() >= EditorExportPlatform::EXPORT_MESSAGE_ERROR) { @@ -162,7 +133,7 @@ Error EditorRunNative::run_native(int p_idx, int p_platform) { } void EditorRunNative::resume_run_native() { - run_native(resume_idx, resume_platform); + run_native(resume_id); } void EditorRunNative::_bind_methods() { @@ -174,6 +145,13 @@ bool EditorRunNative::is_deploy_debug_remote_enabled() const { } EditorRunNative::EditorRunNative() { + remote_debug = memnew(MenuButton); + remote_debug->get_popup()->connect("id_pressed", callable_mp(this, &EditorRunNative::run_native)); + remote_debug->set_icon(get_theme_icon(SNAME("PlayRemote"), SNAME("EditorIcons"))); + remote_debug->set_tooltip_text(TTR("Remote Debug")); + + add_child(remote_debug); + result_dialog = memnew(AcceptDialog); result_dialog->set_title(TTR("Project Run")); result_dialog_log = memnew(RichTextLabel); @@ -184,6 +162,4 @@ EditorRunNative::EditorRunNative() { result_dialog->hide(); set_process(true); - resume_idx = 0; - resume_platform = 0; } diff --git a/editor/editor_run_native.h b/editor/editor_run_native.h index a87e27de979..2a5431e54b9 100644 --- a/editor/editor_run_native.h +++ b/editor/editor_run_native.h @@ -42,18 +42,17 @@ class EditorRunNative : public HBoxContainer { RichTextLabel *result_dialog_log = nullptr; AcceptDialog *result_dialog = nullptr; - HashMap menus; + MenuButton *remote_debug = nullptr; bool first = true; - int resume_idx; - int resume_platform; + int resume_id = -1; protected: static void _bind_methods(); void _notification(int p_what); public: - Error run_native(int p_idx, int p_platform); + Error run_native(int p_id); bool is_deploy_debug_remote_enabled() const; void resume_run_native(); diff --git a/editor/icons/PlayRemote.svg b/editor/icons/PlayRemote.svg new file mode 100644 index 00000000000..ea2195294f6 --- /dev/null +++ b/editor/icons/PlayRemote.svg @@ -0,0 +1 @@ +