diff --git a/editor/run/editor_run_bar.cpp b/editor/run/editor_run_bar.cpp index ff957023cb9..465fae5d9b9 100644 --- a/editor/run/editor_run_bar.cpp +++ b/editor/run/editor_run_bar.cpp @@ -185,13 +185,13 @@ void EditorRunBar::_write_movie_toggled(bool p_enabled) { } } -Vector EditorRunBar::_get_xr_mode_play_args(int p_xr_mode_id) { +Vector EditorRunBar::_get_xr_mode_play_args(RunXRModeMenuItem p_menu_item) { Vector play_args; - if (p_xr_mode_id == 0) { + if (p_menu_item == RunXRModeMenuItem::OFF) { // Play in regular mode, xr mode off. play_args.push_back("--xr-mode"); play_args.push_back("off"); - } else if (p_xr_mode_id == 1) { + } else if (p_menu_item == RunXRModeMenuItem::ON) { // Play in xr mode. play_args.push_back("--xr-mode"); play_args.push_back("on"); @@ -199,18 +199,27 @@ Vector EditorRunBar::_get_xr_mode_play_args(int p_xr_mode_id) { return play_args; } -void EditorRunBar::_quick_run_selected(const String &p_file_path, int p_id) { - play_custom_scene(p_file_path, _get_xr_mode_play_args(p_id)); +void EditorRunBar::_quick_run_selected(const String &p_file_path, int p_menu_item) { + play_custom_scene(p_file_path, _get_xr_mode_play_args(static_cast(p_menu_item))); } -void EditorRunBar::_play_custom_pressed(int p_id) { +void EditorRunBar::_play_custom_pressed(int p_menu_item) { + if (p_menu_item != RunXRModeMenuItem::INVALID) { + MenuButton *menu_button = Object::cast_to(play_custom_scene_button); + if (menu_button && menu_button->get_popup()) { + // Set the shortcut to the last selected option. + menu_button->get_popup()->set_item_shortcut(RunXRModeMenuItem::OFF, p_menu_item == RunXRModeMenuItem::OFF ? ED_GET_SHORTCUT("editor/run_specific_scene") : Ref()); + menu_button->get_popup()->set_item_shortcut(RunXRModeMenuItem::ON, p_menu_item == RunXRModeMenuItem::ON ? ED_GET_SHORTCUT("editor/run_specific_scene") : Ref()); + } + } + if (editor_run.get_status() == EditorRun::STATUS_STOP || current_mode != RunMode::RUN_CUSTOM) { stop_playing(); - EditorNode::get_singleton()->get_quick_open_dialog()->popup_dialog({ "PackedScene" }, callable_mp(this, &EditorRunBar::_quick_run_selected).bind(p_id)); + EditorNode::get_singleton()->get_quick_open_dialog()->popup_dialog({ "PackedScene" }, callable_mp(this, &EditorRunBar::_quick_run_selected).bind(p_menu_item)); play_custom_scene_button->set_pressed(false); } else { - Vector play_args = _get_xr_mode_play_args(p_id); + Vector play_args = _get_xr_mode_play_args(static_cast(p_menu_item)); // Reload if already running a custom scene. String last_custom_scene = run_custom_filename; // This is necessary to have a copy of the string. @@ -218,8 +227,17 @@ void EditorRunBar::_play_custom_pressed(int p_id) { } } -void EditorRunBar::_play_current_pressed(int p_id) { - Vector play_args = _get_xr_mode_play_args(p_id); +void EditorRunBar::_play_current_pressed(int p_menu_item) { + if (p_menu_item != RunXRModeMenuItem::INVALID) { + MenuButton *menu_button = Object::cast_to(play_scene_button); + if (menu_button && menu_button->get_popup()) { + // Set the shortcut to the last selected option. + menu_button->get_popup()->set_item_shortcut(RunXRModeMenuItem::OFF, p_menu_item == RunXRModeMenuItem::OFF ? ED_GET_SHORTCUT("editor/run_current_scene") : Ref()); + menu_button->get_popup()->set_item_shortcut(RunXRModeMenuItem::ON, p_menu_item == RunXRModeMenuItem::ON ? ED_GET_SHORTCUT("editor/run_current_scene") : Ref()); + } + } + + Vector play_args = _get_xr_mode_play_args(static_cast(p_menu_item)); if (editor_run.get_status() == EditorRun::STATUS_STOP || current_mode != RunMode::RUN_CURRENT) { play_current_scene(false, play_args); @@ -628,44 +646,48 @@ EditorRunBar::EditorRunBar() { } #endif // XR_DISABLED + ED_SHORTCUT_AND_COMMAND("editor/run_current_scene", TTRC("Run Current Scene"), Key::F6); + ED_SHORTCUT_OVERRIDE("editor/run_current_scene", "macos", KeyModifierMask::META | Key::R); + if (add_play_xr_mode_options) { MenuButton *menu_button = memnew(MenuButton); PopupMenu *popup = menu_button->get_popup(); - popup->add_item(TTRC("Run Scene in Regular Mode"), 0); - popup->add_item(TTRC("Run Scene in XR Mode"), 1); + popup->add_item(TTRC("Run Scene in Regular Mode"), RunXRModeMenuItem::OFF); + popup->add_item(TTRC("Run Scene in XR Mode"), RunXRModeMenuItem::ON); popup->connect(SceneStringName(id_pressed), callable_mp(this, &EditorRunBar::_play_current_pressed)); + popup->set_item_shortcut(RunXRModeMenuItem::ON, ED_GET_SHORTCUT("editor/run_current_scene")); play_scene_button = menu_button; } else { play_scene_button = memnew(Button); play_scene_button->set_toggle_mode(true); - play_scene_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::_play_current_pressed).bind(-1)); + play_scene_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::_play_current_pressed).bind(RunXRModeMenuItem::INVALID)); + play_scene_button->set_shortcut(ED_GET_SHORTCUT("editor/run_current_scene")); } main_hbox->add_child(play_scene_button); - ED_SHORTCUT_AND_COMMAND("editor/run_current_scene", TTRC("Run Current Scene"), Key::F6); - ED_SHORTCUT_OVERRIDE("editor/run_current_scene", "macos", KeyModifierMask::META | Key::R); - play_scene_button->set_shortcut(ED_GET_SHORTCUT("editor/run_current_scene")); play_scene_button->set_tooltip_text(TTRC("Play the currently edited scene.")); play_scene_button->set_theme_type_variation("RunBarButton"); play_scene_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY); + ED_SHORTCUT_AND_COMMAND("editor/run_specific_scene", TTRC("Run Specific Scene"), KeyModifierMask::CTRL | KeyModifierMask::SHIFT | Key::F5); + ED_SHORTCUT_OVERRIDE("editor/run_specific_scene", "macos", KeyModifierMask::META | KeyModifierMask::SHIFT | Key::R); + if (add_play_xr_mode_options) { MenuButton *menu_button = memnew(MenuButton); PopupMenu *popup = menu_button->get_popup(); - popup->add_item(TTRC("Run in Regular Mode"), 0); - popup->add_item(TTRC("Run in XR Mode"), 1); + popup->add_item(TTRC("Run in Regular Mode"), RunXRModeMenuItem::OFF); + popup->add_item(TTRC("Run in XR Mode"), RunXRModeMenuItem::ON); popup->connect(SceneStringName(id_pressed), callable_mp(this, &EditorRunBar::_play_custom_pressed)); + popup->set_item_shortcut(RunXRModeMenuItem::ON, ED_GET_SHORTCUT("editor/run_specific_scene")); play_custom_scene_button = menu_button; } else { play_custom_scene_button = memnew(Button); play_custom_scene_button->set_toggle_mode(true); - play_custom_scene_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::_play_custom_pressed).bind(-1)); + play_custom_scene_button->connect(SceneStringName(pressed), callable_mp(this, &EditorRunBar::_play_custom_pressed).bind(RunXRModeMenuItem::INVALID)); + play_custom_scene_button->set_shortcut(ED_GET_SHORTCUT("editor/run_specific_scene")); } main_hbox->add_child(play_custom_scene_button); - ED_SHORTCUT_AND_COMMAND("editor/run_specific_scene", TTRC("Run Specific Scene"), KeyModifierMask::CTRL | KeyModifierMask::SHIFT | Key::F5); - ED_SHORTCUT_OVERRIDE("editor/run_specific_scene", "macos", KeyModifierMask::META | KeyModifierMask::SHIFT | Key::R); - play_custom_scene_button->set_shortcut(ED_GET_SHORTCUT("editor/run_specific_scene")); play_custom_scene_button->set_tooltip_text(TTRC("Play a custom scene.")); play_custom_scene_button->set_theme_type_variation("RunBarButton"); play_custom_scene_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY); diff --git a/editor/run/editor_run_bar.h b/editor/run/editor_run_bar.h index df682c52c9f..5d383c6ba6e 100644 --- a/editor/run/editor_run_bar.h +++ b/editor/run/editor_run_bar.h @@ -53,6 +53,12 @@ class EditorRunBar : public MarginContainer { RUN_CUSTOM, }; + enum RunXRModeMenuItem { + INVALID = -1, + OFF = 0, + ON = 1, + }; + PanelContainer *main_panel = nullptr; HBoxContainer *main_hbox = nullptr; HBoxContainer *outer_hbox = nullptr; @@ -90,10 +96,10 @@ class EditorRunBar : public MarginContainer { void _movie_maker_item_pressed(int p_id); void _write_movie_toggled(bool p_enabled); - void _quick_run_selected(const String &p_file_path, int p_id = -1); + void _quick_run_selected(const String &p_file_path, int p_menu_item = RunXRModeMenuItem::INVALID); - void _play_current_pressed(int p_id = -1); - void _play_custom_pressed(int p_id = -1); + void _play_current_pressed(int p_menu_item = RunXRModeMenuItem::INVALID); + void _play_custom_pressed(int p_menu_item = RunXRModeMenuItem::INVALID); void _run_scene(const String &p_scene_path = "", const Vector &p_run_args = Vector()); void _run_native(const Ref &p_preset); @@ -101,7 +107,7 @@ class EditorRunBar : public MarginContainer { void _profiler_autostart_indicator_pressed(); private: - static Vector _get_xr_mode_play_args(int p_xr_mode_id); + static Vector _get_xr_mode_play_args(RunXRModeMenuItem p_menu_item); protected: void _notification(int p_what);