diff --git a/platforms/ios/AppPlatform_iOS.h b/platforms/ios/AppPlatform_iOS.h index a558a9e5a..cee1848fb 100644 --- a/platforms/ios/AppPlatform_iOS.h +++ b/platforms/ios/AppPlatform_iOS.h @@ -47,6 +47,8 @@ class AppPlatform_iOS : public AppPlatform // Also add these to allow saving options. bool hasFileSystemAccess() override; + + void showMessageModal(const MessageModal& msg) override; private: Logger* m_pLogger; SoundSystem* m_pSoundSystem; diff --git a/platforms/ios/AppPlatform_iOS.mm b/platforms/ios/AppPlatform_iOS.mm index fe1e0b233..d780029be 100644 --- a/platforms/ios/AppPlatform_iOS.mm +++ b/platforms/ios/AppPlatform_iOS.mm @@ -177,3 +177,32 @@ return [assetPath UTF8String]; } + +void AppPlatform_iOS::showMessageModal(const MessageModal& msg) +{ + NSString *title; + switch(msg.type) + { + case MessageModal::TYPE_ERROR: + title = @"Error"; + break; + default: + LOG_W("Unhandled MessageModal type"); + // fall through + case MessageModal::TYPE_INFO: + title = @"Info"; + break; + } + + // this doesn't block the thread, it should + UIAlertView *alert = [[UIAlertView alloc] + initWithTitle:title + message:[NSString stringWithCString:msg.text.c_str() + encoding:[NSString defaultCStringEncoding]] + delegate:nil + cancelButtonTitle:@"OK" + otherButtonTitles:nil + ]; + [alert show]; + [alert release]; +} diff --git a/platforms/sdl/sdl2/base/AppPlatform_sdl2.cpp b/platforms/sdl/sdl2/base/AppPlatform_sdl2.cpp index 04817df7f..078b456b5 100644 --- a/platforms/sdl/sdl2/base/AppPlatform_sdl2.cpp +++ b/platforms/sdl/sdl2/base/AppPlatform_sdl2.cpp @@ -192,3 +192,27 @@ bool AppPlatform_sdl2::GetMouseButtonState(const SDL_Event& event) return result; } + +// this segfaults on wsl, why? +void AppPlatform_sdl2::showMessageModal(const MessageModal& msg) +{ + const char *title; + Uint32 flags = 0; + + switch (msg.type) + { + case MessageModal::TYPE_ERROR: + title = "Error"; + flags = SDL_MESSAGEBOX_ERROR; + break; + default: + LOG_W("Unhandled MessageModal type"); + // fall through + case MessageModal::TYPE_INFO: + title = "Info"; + flags = SDL_MESSAGEBOX_INFORMATION; + break; + } + + SDL_ShowSimpleMessageBox(flags, title, msg.text.c_str(), nullptr); +} diff --git a/platforms/sdl/sdl2/base/AppPlatform_sdl2.hpp b/platforms/sdl/sdl2/base/AppPlatform_sdl2.hpp index 7463f0198..fad671817 100644 --- a/platforms/sdl/sdl2/base/AppPlatform_sdl2.hpp +++ b/platforms/sdl/sdl2/base/AppPlatform_sdl2.hpp @@ -43,6 +43,8 @@ class AppPlatform_sdl2 : public AppPlatform_sdl void gameControllerAdded(int32_t index); void gameControllerRemoved(int32_t index); + void showMessageModal(const MessageModal& msg) override; + public: static bool GetMouseButtonState(const SDL_Event& event); diff --git a/platforms/windows/AppPlatform_win32.cpp b/platforms/windows/AppPlatform_win32.cpp index f54c64812..0ef527f9c 100644 --- a/platforms/windows/AppPlatform_win32.cpp +++ b/platforms/windows/AppPlatform_win32.cpp @@ -570,3 +570,26 @@ Keyboard::KeyState AppPlatform_win32::GetKeyState(UINT iMsg) return Keyboard::KeyState::DOWN; } } + +void AppPlatform_win32::showMessageModal(const MessageModal& msg) +{ + const char *title; + uint32_t flags = 0; + + switch (msg.type) + { + case MessageModal::TYPE_ERROR: + title = "Error"; + flags = MB_ICONERROR; + break; + default: + LOG_W("Unhandled MessageModal type"); + // fall through + case MessageModal::TYPE_INFO: + title = "Info"; + flags = MB_ICONINFORMATION; + break; + } + + MessageBoxA(NULL, msg.text.c_str(), title, flags); +} diff --git a/platforms/windows/AppPlatform_win32.hpp b/platforms/windows/AppPlatform_win32.hpp index 1dc3bb7e0..d85babf8f 100644 --- a/platforms/windows/AppPlatform_win32.hpp +++ b/platforms/windows/AppPlatform_win32.hpp @@ -87,6 +87,8 @@ class AppPlatform_win32 : public AppPlatform static bool GetMouseButtonState(UINT iMsg, WPARAM wParam); static Keyboard::KeyState GetKeyState(UINT iMsg); + void showMessageModal(const MessageModal& msg) override; + private: HICON m_cursor; diff --git a/source/client/app/AppPlatform.cpp b/source/client/app/AppPlatform.cpp index 0df9f4b57..a955de0c6 100644 --- a/source/client/app/AppPlatform.cpp +++ b/source/client/app/AppPlatform.cpp @@ -403,3 +403,22 @@ void AppPlatform::beginProfileDataWrite(unsigned int playerId) void AppPlatform::endProfileDataWrite(unsigned int playerId) { } + +void AppPlatform::showMessageModal(const MessageModal& msg) +{ + FILE *stream; + switch(msg.type) + { + case MessageModal::TYPE_ERROR: + stream = stderr; + break; + default: + LOG_W("Unhandled MessageModal type"); + // fall through + case MessageModal::TYPE_INFO: + stream = stdout; + break; + } + + fputs(msg.text.c_str(), stream); +} diff --git a/source/client/app/AppPlatform.hpp b/source/client/app/AppPlatform.hpp index 812224880..938437fc0 100644 --- a/source/client/app/AppPlatform.hpp +++ b/source/client/app/AppPlatform.hpp @@ -37,6 +37,25 @@ #define C_HOME_PATH "/games/com.mojang/" #define C_MAX_LOCAL_PLAYERS 4 +struct MessageModal +{ + enum Type + { + TYPE_INFO, + TYPE_ERROR + }; + + Type type; + std::string text; + + MessageModal(Type type, const std::string& text) + : type(type) + , text(text) + { + } +}; + + class GameControllerHandler; class AppPlatformListener; @@ -135,6 +154,8 @@ class AppPlatform virtual void beginProfileDataWrite(unsigned int playerId); virtual void endProfileDataWrite(unsigned int playerId); + virtual void showMessageModal(const MessageModal& msg); + public: ListenerMap m_listeners; std::string m_externalStorageDir; diff --git a/source/client/gui/screens/CreditsScreen.cpp b/source/client/gui/screens/CreditsScreen.cpp index 7267ac130..60c4287dd 100644 --- a/source/client/gui/screens/CreditsScreen.cpp +++ b/source/client/gui/screens/CreditsScreen.cpp @@ -32,6 +32,9 @@ void CreditsScreen::_initCreditsText() { m_credits.push_back("Failed to load credits.txt"); } + + // for testing only, should not make it into master, remove if found + AppPlatform::singleton()->showMessageModal(MessageModal(MessageModal::TYPE_INFO, "death")); } void CreditsScreen::init()