Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

[macOS] Fix OS::alert in embedded and headless mode.

Pāvels Nadtočajevs8699e350adea
diff --git a/platform/macos/editor/embedded_game_view_plugin.h b/platform/macos/editor/embedded_game_view_plugin.h
index c3a09fe974f..b672e676df3 100644
--- a/platform/macos/editor/embedded_game_view_plugin.h
+++ b/platform/macos/editor/embedded_game_view_plugin.h
@@ -59,6 +59,7 @@ class GameViewDebuggerMacOS : public GameViewDebugger {
bool _msg_joy_start(const Array &p_args);
bool _msg_joy_stop(const Array &p_args);
bool _msg_warp_mouse(const Array &p_args);
+ bool _msg_alert(const Array &p_args);
public:
virtual bool capture(const String &p_message, const Array &p_data, int p_session) override;
diff --git a/platform/macos/editor/embedded_game_view_plugin.mm b/platform/macos/editor/embedded_game_view_plugin.mm
index c1869cab83e..1dce516f40f 100644
--- a/platform/macos/editor/embedded_game_view_plugin.mm
+++ b/platform/macos/editor/embedded_game_view_plugin.mm
@@ -34,6 +34,7 @@
#include "core/config/engine.h"
#include "core/input/input.h"
+#include "core/os/os.h"
#include "editor/editor_node.h"
#include "editor/gui/window_wrapper.h"
#include "scene/main/window.h"
@@ -130,6 +131,13 @@ bool GameViewDebuggerMacOS::_msg_warp_mouse(const Array &p_args) {
return true;
}
+bool GameViewDebuggerMacOS::_msg_alert(const Array &p_args) {
+ ERR_FAIL_COND_V_MSG(p_args.size() != 2, false, "alert: invalid number of arguments.");
+
+ OS::get_singleton()->alert(p_args[0], p_args[1]);
+ return true;
+}
+
void GameViewDebuggerMacOS::_init_capture_message_handlers() {
parse_message_handlers["game_view:set_context_id"] = &GameViewDebuggerMacOS::_msg_set_context_id;
parse_message_handlers["game_view:cursor_set_shape"] = &GameViewDebuggerMacOS::_msg_cursor_set_shape;
@@ -138,6 +146,7 @@ void GameViewDebuggerMacOS::_init_capture_message_handlers() {
parse_message_handlers["game_view:window_set_ime_active"] = &GameViewDebuggerMacOS::_msg_window_set_ime_active;
parse_message_handlers["game_view:window_set_ime_position"] = &GameViewDebuggerMacOS::_msg_window_set_ime_position;
parse_message_handlers["game_view:warp_mouse"] = &GameViewDebuggerMacOS::_msg_warp_mouse;
+ parse_message_handlers["game_view:alert"] = &GameViewDebuggerMacOS::_msg_alert;
}
bool GameViewDebuggerMacOS::capture(const String &p_message, const Array &p_data, int p_session) {
diff --git a/platform/macos/os_macos.h b/platform/macos/os_macos.h
index fed5be4adb1..a3b578fb585 100644
--- a/platform/macos/os_macos.h
+++ b/platform/macos/os_macos.h
@@ -205,6 +205,8 @@ public:
class OS_MacOS_Headless : public OS_MacOS {
public:
+ virtual void alert(const String &p_alert, const String &p_title) override;
+
virtual void run() override;
OS_MacOS_Headless(const char *p_execpath, int p_argc, char **p_argv);
@@ -214,6 +216,8 @@ public:
class OS_MacOS_Embedded : public OS_MacOS {
public:
+ virtual void alert(const String &p_alert, const String &p_title) override;
+
virtual void run() override;
OS_MacOS_Embedded(const char *p_execpath, int p_argc, char **p_argv);
diff --git a/platform/macos/os_macos.mm b/platform/macos/os_macos.mm
index 5b047a74fb4..e8997cc418e 100644
--- a/platform/macos/os_macos.mm
+++ b/platform/macos/os_macos.mm
@@ -41,6 +41,7 @@
#include "core/config/engine.h"
#include "core/crypto/crypto_core.h"
+#include "core/debugger/engine_debugger.h"
#include "core/input/input.h"
#include "core/io/file_access.h"
#include "core/os/main_loop.h"
@@ -1192,6 +1193,10 @@ OS_MacOS_NSApp::OS_MacOS_NSApp(const char *p_execpath, int p_argc, char **p_argv
// MARK: - OS_MacOS_Headless
+void OS_MacOS_Headless::alert(const String &p_alert, const String &p_title) {
+ WARN_PRINT(p_alert);
+}
+
void OS_MacOS_Headless::run() {
CFRunLoopGetCurrent();
@@ -1247,6 +1252,15 @@ OS_MacOS_Headless::OS_MacOS_Headless(const char *p_execpath, int p_argc, char **
#ifdef TOOLS_ENABLED
+void OS_MacOS_Embedded::alert(const String &p_alert, const String &p_title) {
+ if (EngineDebugger::get_singleton()) {
+ Array arr = { p_alert, p_title };
+ EngineDebugger::get_singleton()->send_message("game_view:alert", arr);
+ } else {
+ WARN_PRINT(p_alert);
+ }
+}
+
void OS_MacOS_Embedded::run() {
CFRunLoopGetCurrent();