Merge pull request #65753 from KoBeWi/run_1000000_instances

Add a dialog to customize run instances
This commit is contained in:
Rémi Verschelde 2024-02-08 10:53:06 +01:00
commit 0ebda8e0f4
No known key found for this signature in database
GPG key ID: C3336907360768E1
6 changed files with 404 additions and 126 deletions

View file

@ -37,6 +37,7 @@
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/plugins/script_editor_plugin.h"
#include "editor/run_instances_dialog.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/menu_button.h"
@ -93,22 +94,13 @@ DebuggerEditorPlugin::DebuggerEditorPlugin(PopupMenu *p_debug_menu) {
debug_menu->set_item_tooltip(-1,
TTR("When this option is enabled, the editor debug server will stay open and listen for new sessions started outside of the editor itself."));
// Multi-instance, start/stop
instances_menu = memnew(PopupMenu);
instances_menu->set_name("RunInstances");
instances_menu->set_hide_on_checkable_item_selection(false);
debug_menu->add_child(instances_menu);
// Multi-instance, start/stop.
debug_menu->add_separator();
debug_menu->add_submenu_item(TTR("Run Multiple Instances"), "RunInstances");
for (int i = 1; i <= 4; i++) {
instances_menu->add_radio_check_item(vformat(TTRN("Run %d Instance", "Run %d Instances", i), i));
instances_menu->set_item_metadata(i - 1, i);
}
instances_menu->set_item_checked(0, true);
instances_menu->connect("index_pressed", callable_mp(this, &DebuggerEditorPlugin::_select_run_count));
debug_menu->add_item(TTR("Run Multiple Instances..."), RUN_MULTIPLE_INSTANCES);
debug_menu->connect("id_pressed", callable_mp(this, &DebuggerEditorPlugin::_menu_option));
run_instances_dialog = memnew(RunInstancesDialog);
EditorNode::get_singleton()->get_gui_base()->add_child(run_instances_dialog);
}
DebuggerEditorPlugin::~DebuggerEditorPlugin() {
@ -116,14 +108,6 @@ DebuggerEditorPlugin::~DebuggerEditorPlugin() {
memdelete(file_server);
}
void DebuggerEditorPlugin::_select_run_count(int p_index) {
int len = instances_menu->get_item_count();
for (int idx = 0; idx < len; idx++) {
instances_menu->set_item_checked(idx, idx == p_index);
}
EditorSettings::get_singleton()->set_project_metadata("debug_options", "run_debug_instances", instances_menu->get_item_metadata(p_index));
}
void DebuggerEditorPlugin::_menu_option(int p_option) {
switch (p_option) {
case RUN_FILE_SERVER: {
@ -201,6 +185,10 @@ void DebuggerEditorPlugin::_menu_option(int p_option) {
EditorSettings::get_singleton()->set_project_metadata("debug_options", "server_keep_open", !ischecked);
} break;
case RUN_MULTIPLE_INSTANCES: {
run_instances_dialog->popup_centered();
} break;
}
}
@ -227,7 +215,6 @@ void DebuggerEditorPlugin::_update_debug_options() {
bool check_live_debug = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_live_debug", true);
bool check_reload_scripts = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_reload_scripts", true);
bool check_server_keep_open = EditorSettings::get_singleton()->get_project_metadata("debug_options", "server_keep_open", false);
int instances = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_instances", 1);
if (check_deploy_remote) {
_menu_option(RUN_DEPLOY_REMOTE_DEBUG);
@ -259,10 +246,4 @@ void DebuggerEditorPlugin::_update_debug_options() {
if (check_server_keep_open) {
_menu_option(SERVER_KEEP_OPEN);
}
int len = instances_menu->get_item_count();
for (int idx = 0; idx < len; idx++) {
bool checked = (int)instances_menu->get_item_metadata(idx) == instances;
instances_menu->set_item_checked(idx, checked);
}
}

View file

@ -36,6 +36,7 @@
class EditorFileServer;
class MenuButton;
class PopupMenu;
class RunInstancesDialog;
class DebuggerEditorPlugin : public EditorPlugin {
GDCLASS(DebuggerEditorPlugin, EditorPlugin);
@ -43,7 +44,7 @@ class DebuggerEditorPlugin : public EditorPlugin {
private:
PopupMenu *debug_menu = nullptr;
EditorFileServer *file_server = nullptr;
PopupMenu *instances_menu = nullptr;
RunInstancesDialog *run_instances_dialog = nullptr;
enum MenuOptions {
RUN_FILE_SERVER,
@ -56,11 +57,11 @@ private:
RUN_DEPLOY_REMOTE_DEBUG,
RUN_RELOAD_SCRIPTS,
SERVER_KEEP_OPEN,
RUN_MULTIPLE_INSTANCES,
};
void _update_debug_options();
void _notification(int p_what);
void _select_run_count(int p_index);
void _menu_option(int p_option);
public: