Skip to content

Commit

Permalink
Move remote debug buttons to a single menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruvzg committed Jan 14, 2023
1 parent 60d0317 commit 5406b00
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 67 deletions.
2 changes: 1 addition & 1 deletion editor/debugger/debug_adapter/debug_adapter_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ class EditorNode : public Node {

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);
Expand Down
94 changes: 35 additions & 59 deletions editor/editor_run_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(i);
if (eep.is_null()) {
continue;
}
Ref<ImageTexture> icon = eep->get_run_icon();
if (!icon.is_null()) {
Ref<Image> im = icon->get_image();
im = im->duplicate();
im->clear_mipmaps();
if (!im->is_empty()) {
im->resize(16 * EDSCALE, 16 * EDSCALE);
Ref<ImageTexture> 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<int, MenuButton *> &E : menus) {
Ref<EditorExportPlatform> 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<EditorExportPlatform> 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);
}
}
}
Expand All @@ -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<EditorExportPlatform> 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<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(platform);
ERR_FAIL_COND_V(eep.is_null(), ERR_UNAVAILABLE);

Ref<EditorExportPreset> preset;

for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand All @@ -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);
Expand All @@ -184,6 +162,4 @@ EditorRunNative::EditorRunNative() {
result_dialog->hide();

set_process(true);
resume_idx = 0;
resume_platform = 0;
}
7 changes: 3 additions & 4 deletions editor/editor_run_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,17 @@ class EditorRunNative : public HBoxContainer {
RichTextLabel *result_dialog_log = nullptr;
AcceptDialog *result_dialog = nullptr;

HashMap<int, MenuButton *> 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();
Expand Down
1 change: 1 addition & 0 deletions editor/icons/PlayRemote.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5406b00

Please sign in to comment.