Explorar o código

Merge pull request #47744 from KoBeWi/press_F_to_play_exit

Rémi Verschelde %!s(int64=3) %!d(string=hai) anos
pai
achega
6e6287f748
Modificáronse 3 ficheiros con 34 adicións e 2 borrados
  1. 5 0
      editor/editor_run.cpp
  2. 26 2
      scene/main/window.cpp
  3. 3 0
      scene/main/window.h

+ 5 - 0
editor/editor_run.cpp

@@ -258,6 +258,11 @@ Error EditorRun::run(const String &p_scene, const String &p_write_movie) {
 		}
 		}
 	}
 	}
 
 
+	// Pass the debugger stop shortcut to the running instance(s).
+	String shortcut;
+	VariantWriter::write_to_string(ED_GET_SHORTCUT("editor/stop"), shortcut);
+	OS::get_singleton()->set_environment("__GODOT_EDITOR_STOP_SHORTCUT__", shortcut);
+
 	printf("Running: %s", exec.utf8().get_data());
 	printf("Running: %s", exec.utf8().get_data());
 	for (const String &E : args) {
 	for (const String &E : args) {
 		printf(" %s", E.utf8().get_data());
 		printf(" %s", E.utf8().get_data());

+ 26 - 2
scene/main/window.cpp

@@ -32,7 +32,9 @@
 
 
 #include "core/config/project_settings.h"
 #include "core/config/project_settings.h"
 #include "core/debugger/engine_debugger.h"
 #include "core/debugger/engine_debugger.h"
+#include "core/input/shortcut.h"
 #include "core/string/translation.h"
 #include "core/string/translation.h"
+#include "core/variant/variant_parser.h"
 #include "scene/gui/control.h"
 #include "scene/gui/control.h"
 #include "scene/scene_string_names.h"
 #include "scene/scene_string_names.h"
 #include "scene/theme/theme_db.h"
 #include "scene/theme/theme_db.h"
@@ -1034,9 +1036,31 @@ bool Window::_can_consume_input_events() const {
 
 
 void Window::_window_input(const Ref<InputEvent> &p_ev) {
 void Window::_window_input(const Ref<InputEvent> &p_ev) {
 	if (EngineDebugger::is_active()) {
 	if (EngineDebugger::is_active()) {
-		// Quit from game window using F8.
+		// Quit from game window using the stop shortcut (F8 by default).
+		// The custom shortcut is provided via environment variable when running from the editor.
+		if (debugger_stop_shortcut.is_null()) {
+			String shortcut_str = OS::get_singleton()->get_environment("__GODOT_EDITOR_STOP_SHORTCUT__");
+			if (!shortcut_str.is_empty()) {
+				Variant shortcut_var;
+
+				VariantParser::StreamString ss;
+				ss.s = shortcut_str;
+
+				String errs;
+				int line;
+				VariantParser::parse(&ss, shortcut_var, errs, line);
+				debugger_stop_shortcut = shortcut_var;
+			}
+
+			if (debugger_stop_shortcut.is_null()) {
+				// Define a default shortcut if it wasn't provided or is invalid.
+				debugger_stop_shortcut.instantiate();
+				debugger_stop_shortcut->set_events({ (Variant)InputEventKey::create_reference(Key::F8) });
+			}
+		}
+
 		Ref<InputEventKey> k = p_ev;
 		Ref<InputEventKey> k = p_ev;
-		if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_keycode() == Key::F8) {
+		if (k.is_valid() && k->is_pressed() && !k->is_echo() && debugger_stop_shortcut->matches_event(k)) {
 			EngineDebugger::get_singleton()->send_message("request_quit", Array());
 			EngineDebugger::get_singleton()->send_message("request_quit", Array());
 		}
 		}
 	}
 	}

+ 3 - 0
scene/main/window.h

@@ -35,6 +35,7 @@
 
 
 class Control;
 class Control;
 class Font;
 class Font;
+class Shortcut;
 class StyleBox;
 class StyleBox;
 class Theme;
 class Theme;
 
 
@@ -151,6 +152,8 @@ private:
 	void _event_callback(DisplayServer::WindowEvent p_event);
 	void _event_callback(DisplayServer::WindowEvent p_event);
 	virtual bool _can_consume_input_events() const override;
 	virtual bool _can_consume_input_events() const override;
 
 
+	Ref<Shortcut> debugger_stop_shortcut;
+
 protected:
 protected:
 	Viewport *_get_embedder() const;
 	Viewport *_get_embedder() const;
 	virtual Rect2i _popup_adjust_rect() const { return Rect2i(); }
 	virtual Rect2i _popup_adjust_rect() const { return Rect2i(); }