diff --git a/Source/Engine/Platform/SDL/SDLPlatform.Web.cpp b/Source/Engine/Platform/SDL/SDLPlatform.Web.cpp index cf9523e50..cd8582ce0 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.Web.cpp +++ b/Source/Engine/Platform/SDL/SDLPlatform.Web.cpp @@ -5,8 +5,6 @@ #include "SDLWindow.h" #include "Engine/Platform/MessageBox.h" #include "Engine/Core/Log.h" -#include -#include bool SDLPlatform::InitInternal() { @@ -56,152 +54,4 @@ DragDropEffect SDLWindow::DoDragDrop(const StringView& data, const Float2& offse return DragDropEffect::None; } -DialogResult MessageBox::Show(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon) -{ - StringAnsi textAnsi(text); - StringAnsi captionAnsi(caption); - - SDL_MessageBoxData data; - SDL_MessageBoxButtonData dataButtons[3]; - data.window = nullptr; - data.title = captionAnsi.GetText(); - data.message = textAnsi.GetText(); - data.colorScheme = nullptr; - - switch (icon) - { - case MessageBoxIcon::Error: - case MessageBoxIcon::Hand: - case MessageBoxIcon::Stop: - data.flags |= SDL_MESSAGEBOX_ERROR; - break; - case MessageBoxIcon::Asterisk: - case MessageBoxIcon::Information: - case MessageBoxIcon::Question: - data.flags |= SDL_MESSAGEBOX_INFORMATION; - break; - case MessageBoxIcon::Exclamation: - case MessageBoxIcon::Warning: - data.flags |= SDL_MESSAGEBOX_WARNING; - break; - default: - break; - } - - switch (buttons) - { - case MessageBoxButtons::AbortRetryIgnore: - dataButtons[0] = - { - SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, - (int)DialogResult::Abort, - "Abort" - }; - dataButtons[1] = - { - SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, - (int)DialogResult::Retry, - "Retry" - }; - dataButtons[2] = - { - 0, - (int)DialogResult::Ignore, - "Ignore" - }; - data.numbuttons = 3; - break; - case MessageBoxButtons::OK: - dataButtons[0] = - { - SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT | SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, - (int)DialogResult::OK, - "OK" - }; - data.numbuttons = 1; - break; - case MessageBoxButtons::OKCancel: - dataButtons[0] = - { - SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, - (int)DialogResult::OK, - "OK" - }; - dataButtons[1] = - { - SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, - (int)DialogResult::Cancel, - "Cancel" - }; - data.numbuttons = 2; - break; - case MessageBoxButtons::RetryCancel: - dataButtons[0] = - { - SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, - (int)DialogResult::Retry, - "Retry" - }; - dataButtons[1] = - { - SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, - (int)DialogResult::Cancel, - "Cancel" - }; - data.numbuttons = 2; - break; - case MessageBoxButtons::YesNo: - dataButtons[0] = - { - SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, - (int)DialogResult::Yes, - "Yes" - }; - dataButtons[1] = - { - SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, - (int)DialogResult::No, - "No" - }; - data.numbuttons = 2; - break; - case MessageBoxButtons::YesNoCancel: - { - dataButtons[0] = - { - SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, - (int)DialogResult::Yes, - "Yes" - }; - dataButtons[1] = - { - 0, - (int)DialogResult::No, - "No" - }; - dataButtons[2] = - { - SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, - (int)DialogResult::Cancel, - "Cancel" - }; - data.numbuttons = 3; - break; - } - default: - break; - } - data.buttons = dataButtons; - - int result = -1; - if (!SDL_ShowMessageBox(&data, &result)) - { - LOG(Error, "Failed to show SDL message box: {0}", String(SDL_GetError())); - return DialogResult::Abort; - } - if (result < 0) - return DialogResult::None; - return (DialogResult)result; -} - #endif diff --git a/Source/Engine/Platform/Web/WebPlatform.cpp b/Source/Engine/Platform/Web/WebPlatform.cpp index 2bc9d4c8d..6470a26f7 100644 --- a/Source/Engine/Platform/Web/WebPlatform.cpp +++ b/Source/Engine/Platform/Web/WebPlatform.cpp @@ -12,6 +12,7 @@ #include "Engine/Core/Collections/Dictionary.h" #include "Engine/Platform/CPUInfo.h" #include "Engine/Platform/MemoryStats.h" +#include "Engine/Platform/MessageBox.h" #include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Engine/Engine.h" #include "Engine/Engine/Web/WebGame.h" @@ -40,6 +41,14 @@ void WebGame::InitMainWindowSettings(CreateWindowSettings& settings) settings.Size.Y = height; } +DialogResult MessageBox::Show(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon) +{ + StringAnsi textAnsi(text); + StringAnsi captionAnsi(caption); + EM_ASM({ alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1)); }, captionAnsi.Get(), textAnsi.Get()); + return DialogResult::None; +} + void WebFileSystem::GetSpecialFolderPath(const SpecialFolder type, String& result) { result = TEXT("/");