Merge pull request #113387 from m4gr3d/fix_run_scene_shortcut

[XR] Update the shortcuts to play current / specific scene based on the last selected XR run mode option
This commit is contained in:
Rémi Verschelde 2025-12-03 14:58:13 +01:00
commit c5e643380d
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 54 additions and 26 deletions

View file

@ -185,13 +185,13 @@ void EditorRunBar::_write_movie_toggled(bool p_enabled) {
} }
} }
Vector<String> EditorRunBar::_get_xr_mode_play_args(int p_xr_mode_id) { Vector<String> EditorRunBar::_get_xr_mode_play_args(RunXRModeMenuItem p_menu_item) {
Vector<String> play_args; Vector<String> play_args;
if (p_xr_mode_id == 0) { if (p_menu_item == RunXRModeMenuItem::OFF) {
// Play in regular mode, xr mode off. // Play in regular mode, xr mode off.
play_args.push_back("--xr-mode"); play_args.push_back("--xr-mode");
play_args.push_back("off"); play_args.push_back("off");
} else if (p_xr_mode_id == 1) { } else if (p_menu_item == RunXRModeMenuItem::ON) {
// Play in xr mode. // Play in xr mode.
play_args.push_back("--xr-mode"); play_args.push_back("--xr-mode");
play_args.push_back("on"); play_args.push_back("on");
@ -199,18 +199,27 @@ Vector<String> EditorRunBar::_get_xr_mode_play_args(int p_xr_mode_id) {
return play_args; return play_args;
} }
void EditorRunBar::_quick_run_selected(const String &p_file_path, int 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(p_id)); play_custom_scene(p_file_path, _get_xr_mode_play_args(static_cast<RunXRModeMenuItem>(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<MenuButton>(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<Shortcut>());
menu_button->get_popup()->set_item_shortcut(RunXRModeMenuItem::ON, p_menu_item == RunXRModeMenuItem::ON ? ED_GET_SHORTCUT("editor/run_specific_scene") : Ref<Shortcut>());
}
}
if (editor_run.get_status() == EditorRun::STATUS_STOP || current_mode != RunMode::RUN_CUSTOM) { if (editor_run.get_status() == EditorRun::STATUS_STOP || current_mode != RunMode::RUN_CUSTOM) {
stop_playing(); 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); play_custom_scene_button->set_pressed(false);
} else { } else {
Vector<String> play_args = _get_xr_mode_play_args(p_id); Vector<String> play_args = _get_xr_mode_play_args(static_cast<RunXRModeMenuItem>(p_menu_item));
// Reload if already running a custom scene. // Reload if already running a custom scene.
String last_custom_scene = run_custom_filename; // This is necessary to have a copy of the string. 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) { void EditorRunBar::_play_current_pressed(int p_menu_item) {
Vector<String> play_args = _get_xr_mode_play_args(p_id); if (p_menu_item != RunXRModeMenuItem::INVALID) {
MenuButton *menu_button = Object::cast_to<MenuButton>(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<Shortcut>());
menu_button->get_popup()->set_item_shortcut(RunXRModeMenuItem::ON, p_menu_item == RunXRModeMenuItem::ON ? ED_GET_SHORTCUT("editor/run_current_scene") : Ref<Shortcut>());
}
}
Vector<String> play_args = _get_xr_mode_play_args(static_cast<RunXRModeMenuItem>(p_menu_item));
if (editor_run.get_status() == EditorRun::STATUS_STOP || current_mode != RunMode::RUN_CURRENT) { if (editor_run.get_status() == EditorRun::STATUS_STOP || current_mode != RunMode::RUN_CURRENT) {
play_current_scene(false, play_args); play_current_scene(false, play_args);
@ -628,44 +646,48 @@ EditorRunBar::EditorRunBar() {
} }
#endif // XR_DISABLED #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) { if (add_play_xr_mode_options) {
MenuButton *menu_button = memnew(MenuButton); MenuButton *menu_button = memnew(MenuButton);
PopupMenu *popup = menu_button->get_popup(); PopupMenu *popup = menu_button->get_popup();
popup->add_item(TTRC("Run Scene in Regular Mode"), 0); popup->add_item(TTRC("Run Scene in Regular Mode"), RunXRModeMenuItem::OFF);
popup->add_item(TTRC("Run Scene in XR Mode"), 1); popup->add_item(TTRC("Run Scene in XR Mode"), RunXRModeMenuItem::ON);
popup->connect(SceneStringName(id_pressed), callable_mp(this, &EditorRunBar::_play_current_pressed)); 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; play_scene_button = menu_button;
} else { } else {
play_scene_button = memnew(Button); play_scene_button = memnew(Button);
play_scene_button->set_toggle_mode(true); 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); 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_tooltip_text(TTRC("Play the currently edited scene."));
play_scene_button->set_theme_type_variation("RunBarButton"); play_scene_button->set_theme_type_variation("RunBarButton");
play_scene_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY); 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) { if (add_play_xr_mode_options) {
MenuButton *menu_button = memnew(MenuButton); MenuButton *menu_button = memnew(MenuButton);
PopupMenu *popup = menu_button->get_popup(); PopupMenu *popup = menu_button->get_popup();
popup->add_item(TTRC("Run in Regular Mode"), 0); popup->add_item(TTRC("Run in Regular Mode"), RunXRModeMenuItem::OFF);
popup->add_item(TTRC("Run in XR Mode"), 1); popup->add_item(TTRC("Run in XR Mode"), RunXRModeMenuItem::ON);
popup->connect(SceneStringName(id_pressed), callable_mp(this, &EditorRunBar::_play_custom_pressed)); 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; play_custom_scene_button = menu_button;
} else { } else {
play_custom_scene_button = memnew(Button); play_custom_scene_button = memnew(Button);
play_custom_scene_button->set_toggle_mode(true); 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); 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_tooltip_text(TTRC("Play a custom scene."));
play_custom_scene_button->set_theme_type_variation("RunBarButton"); play_custom_scene_button->set_theme_type_variation("RunBarButton");
play_custom_scene_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY); play_custom_scene_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY);

View file

@ -53,6 +53,12 @@ class EditorRunBar : public MarginContainer {
RUN_CUSTOM, RUN_CUSTOM,
}; };
enum RunXRModeMenuItem {
INVALID = -1,
OFF = 0,
ON = 1,
};
PanelContainer *main_panel = nullptr; PanelContainer *main_panel = nullptr;
HBoxContainer *main_hbox = nullptr; HBoxContainer *main_hbox = nullptr;
HBoxContainer *outer_hbox = nullptr; HBoxContainer *outer_hbox = nullptr;
@ -90,10 +96,10 @@ class EditorRunBar : public MarginContainer {
void _movie_maker_item_pressed(int p_id); void _movie_maker_item_pressed(int p_id);
void _write_movie_toggled(bool p_enabled); 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_current_pressed(int p_menu_item = RunXRModeMenuItem::INVALID);
void _play_custom_pressed(int p_id = -1); void _play_custom_pressed(int p_menu_item = RunXRModeMenuItem::INVALID);
void _run_scene(const String &p_scene_path = "", const Vector<String> &p_run_args = Vector<String>()); void _run_scene(const String &p_scene_path = "", const Vector<String> &p_run_args = Vector<String>());
void _run_native(const Ref<EditorExportPreset> &p_preset); void _run_native(const Ref<EditorExportPreset> &p_preset);
@ -101,7 +107,7 @@ class EditorRunBar : public MarginContainer {
void _profiler_autostart_indicator_pressed(); void _profiler_autostart_indicator_pressed();
private: private:
static Vector<String> _get_xr_mode_play_args(int p_xr_mode_id); static Vector<String> _get_xr_mode_play_args(RunXRModeMenuItem p_menu_item);
protected: protected:
void _notification(int p_what); void _notification(int p_what);