From 323bf277fee1a6846eaf03b9f471be868dda5144 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 14 Aug 2023 21:12:01 -0700 Subject: [PATCH 1/4] Split Windows hsMessageBox into its own file Co-Authored-By: dgelessus --- Sources/Plasma/CoreLib/CMakeLists.txt | 1 + Sources/Plasma/CoreLib/HeadSpin.cpp | 140 +++--------------------- Sources/Plasma/CoreLib/HeadSpin.h | 4 + Sources/Plasma/CoreLib/HeadSpin_Mac.mm | 39 ++----- Sources/Plasma/CoreLib/HeadSpin_Win.cpp | 117 ++++++++++++++++++++ 5 files changed, 150 insertions(+), 151 deletions(-) create mode 100644 Sources/Plasma/CoreLib/HeadSpin_Win.cpp diff --git a/Sources/Plasma/CoreLib/CMakeLists.txt b/Sources/Plasma/CoreLib/CMakeLists.txt index e0a0152a7d..ec8c64ac14 100644 --- a/Sources/Plasma/CoreLib/CMakeLists.txt +++ b/Sources/Plasma/CoreLib/CMakeLists.txt @@ -24,6 +24,7 @@ set(CoreLib_SOURCES plViewTransform.cpp hsWindows.cpp $<$:HeadSpin_Mac.mm> + $<$:HeadSpin_Win.cpp> ) if(CMAKE_USE_WIN32_THREADS_INIT) diff --git a/Sources/Plasma/CoreLib/HeadSpin.cpp b/Sources/Plasma/CoreLib/HeadSpin.cpp index 71ede140cf..059c43ffdb 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.cpp +++ b/Sources/Plasma/CoreLib/HeadSpin.cpp @@ -273,149 +273,43 @@ void hsStatusMessageF(const char * fmt, ...) #endif -class hsMinimizeClientGuard -{ - hsWindowHndl fWnd; - -public: - hsMinimizeClientGuard() - { -#ifdef HS_BUILD_FOR_WIN32 - fWnd = GetActiveWindow(); - // If the application's topmost window is fullscreen, minimize it before displaying an error - if ((GetWindowLong(fWnd, GWL_STYLE) & WS_POPUP) != 0) - ShowWindow(fWnd, SW_MINIMIZE); -#endif // HS_BUILD_FOR_WIN32 - } - - ~hsMinimizeClientGuard() - { -#ifdef HS_BUILD_FOR_WIN32 - ShowWindow(fWnd, SW_RESTORE); -#endif // HS_BUILD_FOR_WIN32 - } -}; - bool hsMessageBox_SuppressPrompts = false; -// macOS has its own implementation that needs to live -// in an Obj-C C++ file. -#ifndef HS_BUILD_FOR_APPLE -int hsMessageBoxWithOwner(hsWindowHndl owner, const char* message, const char* caption, int kind, int icon) +#if !defined(HS_BUILD_FOR_APPLE) && !defined(HS_BUILD_FOR_WIN32) +// Need a proper implementation for Linux, but for now let's just print out to the console +int hsMessageBoxWithOwner(hsWindowHndl owner, const ST::string& message, const ST::string& caption, int kind, int icon) { if (hsMessageBox_SuppressPrompts) return hsMBoxOk; -#if HS_BUILD_FOR_WIN32 - uint32_t flags = 0; - - if (kind == hsMessageBoxNormal) - flags |= MB_OK; - else if (kind == hsMessageBoxAbortRetyIgnore) - flags |= MB_ABORTRETRYIGNORE; - else if (kind == hsMessageBoxOkCancel) - flags |= MB_OKCANCEL; - else if (kind == hsMessageBoxRetryCancel) - flags |= MB_RETRYCANCEL; - else if (kind == hsMessageBoxYesNo) - flags |= MB_YESNO; - else if (kind == hsMessageBoxYesNoCancel) - flags |= MB_YESNOCANCEL; - else - flags |= MB_OK; - - if (icon == hsMessageBoxIconError) - flags |= MB_ICONERROR; - else if (icon == hsMessageBoxIconQuestion) - flags |= MB_ICONQUESTION; - else if (icon == hsMessageBoxIconExclamation) - flags |= MB_ICONEXCLAMATION; - else if (icon == hsMessageBoxIconAsterisk) - flags |= MB_ICONASTERISK; - else - flags |= MB_ICONERROR; - - hsMinimizeClientGuard guard; - int ans = MessageBox(owner, message, caption, flags); - - switch (ans) - { - case IDOK: return hsMBoxOk; - case IDCANCEL: return hsMBoxCancel; - case IDABORT: return hsMBoxAbort; - case IDRETRY: return hsMBoxRetry; - case IDIGNORE: return hsMBoxIgnore; - case IDYES: return hsMBoxYes; - case IDNO: return hsMBoxNo; - default: return hsMBoxCancel; - } - -#endif + hsStatusMessage(ST::format("{}\n{}", message, caption).c_str()); return hsMBoxCancel; } +#endif -int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t* message, const wchar_t* caption, int kind, int icon) +int hsMessageBoxWithOwner(hsWindowHndl owner, const char* message, const char* caption, int kind, int icon) { - if (hsMessageBox_SuppressPrompts) - return hsMBoxOk; - -#if HS_BUILD_FOR_WIN32 - uint32_t flags = 0; - - if (kind == hsMessageBoxNormal) - flags |= MB_OK; - else if (kind == hsMessageBoxAbortRetyIgnore) - flags |= MB_ABORTRETRYIGNORE; - else if (kind == hsMessageBoxOkCancel) - flags |= MB_OKCANCEL; - else if (kind == hsMessageBoxRetryCancel) - flags |= MB_RETRYCANCEL; - else if (kind == hsMessageBoxYesNo) - flags |= MB_YESNO; - else if (kind == hsMessageBoxYesNoCancel) - flags |= MB_YESNOCANCEL; - else - flags |= MB_OK; - - if (icon == hsMessageBoxIconError) - flags |= MB_ICONERROR; - else if (icon == hsMessageBoxIconQuestion) - flags |= MB_ICONQUESTION; - else if (icon == hsMessageBoxIconExclamation) - flags |= MB_ICONEXCLAMATION; - else if (icon == hsMessageBoxIconAsterisk) - flags |= MB_ICONASTERISK; - else - flags |= MB_ICONERROR; - - hsMinimizeClientGuard guard; - int ans = MessageBoxW(owner, message, caption, flags); + return hsMessageBoxWithOwner(owner, ST::string::from_latin_1(message), ST::string::from_latin_1(caption), kind, icon); +} - switch (ans) - { - case IDOK: return hsMBoxOk; - case IDCANCEL: return hsMBoxCancel; - case IDABORT: return hsMBoxAbort; - case IDRETRY: return hsMBoxRetry; - case IDIGNORE: return hsMBoxIgnore; - case IDYES: return hsMBoxYes; - case IDNO: return hsMBoxNo; - default: return hsMBoxCancel; - } +int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t* message, const wchar_t* caption, int kind, int icon) +{ + return hsMessageBoxWithOwner(owner, ST::string::from_wchar(message), ST::string::from_wchar(caption), kind, icon); +} -#endif - return hsMBoxCancel; +int hsMessageBox(const ST::string& message, const ST::string& caption, int kind, int icon) +{ + return hsMessageBoxWithOwner(nullptr, message, caption, kind, icon); } -#endif int hsMessageBox(const char* message, const char* caption, int kind, int icon) { - return hsMessageBoxWithOwner(nullptr, message, caption, kind, icon); + return hsMessageBoxWithOwner(nullptr, ST::string::from_latin_1(message), ST::string::from_latin_1(caption), kind, icon); } int hsMessageBox(const wchar_t* message, const wchar_t* caption, int kind, int icon) { - return hsMessageBoxWithOwner(nullptr, message, caption, kind, icon); + return hsMessageBoxWithOwner(nullptr, ST::string::from_wchar(message), ST::string::from_wchar(caption), kind, icon); } /**************************************/ diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index bb86647901..374c46902a 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -58,6 +58,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include +namespace ST { class string; } + //====================================== // Winblows Hacks //====================================== @@ -303,8 +305,10 @@ enum { // RETURN VALUES FROM hsMessageBox }; extern bool hsMessageBox_SuppressPrompts; +int hsMessageBox(const ST::string& message, const ST::string& caption, int kind, int icon=hsMessageBoxIconAsterisk); int hsMessageBox(const char* message, const char* caption, int kind, int icon=hsMessageBoxIconAsterisk); int hsMessageBox(const wchar_t* message, const wchar_t* caption, int kind, int icon=hsMessageBoxIconAsterisk); +int hsMessageBoxWithOwner(hsWindowHndl owner, const ST::string& message, const ST::string& caption, int kind, int icon=hsMessageBoxIconAsterisk); int hsMessageBoxWithOwner(hsWindowHndl owner, const char* message, const char* caption, int kind, int icon=hsMessageBoxIconAsterisk); int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t* message, const wchar_t* caption, int kind, int icon=hsMessageBoxIconAsterisk); diff --git a/Sources/Plasma/CoreLib/HeadSpin_Mac.mm b/Sources/Plasma/CoreLib/HeadSpin_Mac.mm index 3ff9a699c8..af6a801ebe 100644 --- a/Sources/Plasma/CoreLib/HeadSpin_Mac.mm +++ b/Sources/Plasma/CoreLib/HeadSpin_Mac.mm @@ -40,7 +40,10 @@ *==LICENSE==*/ -#include +#include "HeadSpin.h" + +#include +#import int hsMessageBoxWithOwner(hsWindowHndl owner, NSString* message, NSString* caption, int kind, int icon) { @@ -52,7 +55,7 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, NSString* message, NSString* capti NSAlert *alert = [NSAlert new]; alert.messageText = caption; alert.informativeText = message; - + if (icon == hsMessageBoxIconError) alert.alertStyle = NSAlertStyleCritical; else if (icon == hsMessageBoxIconQuestion) @@ -63,7 +66,7 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, NSString* message, NSString* capti alert.alertStyle = NSAlertStyleWarning; else alert.alertStyle = NSAlertStyleCritical; - + if (kind == hsMessageBoxNormal) [alert addButtonWithTitle:@"OK"]; else if (kind == hsMessageBoxAbortRetyIgnore) { @@ -89,7 +92,7 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, NSString* message, NSString* capti [lock signal]; [lock unlock]; }; - + //Plasma may call dialogs from any thread, not just the main thread //Check to see if we're on the main thread and directly execute //the dialog if we are. @@ -101,39 +104,19 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, NSString* message, NSString* capti [lock wait]; [lock unlock]; } - + return (int)response; } -int hsMessageBoxWithOwner(hsWindowHndl owner, const char* message, const char* caption, int kind, int icon) +int hsMessageBoxWithOwner(hsWindowHndl owner, const ST::string& message, const ST::string& caption, int kind, int icon) { if (hsMessageBox_SuppressPrompts) return hsMBoxOk; - - @autoreleasepool { - return hsMessageBoxWithOwner(owner, - [NSString stringWithCString:caption encoding:NSUTF8StringEncoding], - [NSString stringWithCString:message encoding:NSUTF8StringEncoding], - kind, - icon); - } -} -int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t* message, const wchar_t* caption, int kind, int icon) -{ - if (hsMessageBox_SuppressPrompts) - return hsMBoxOk; - @autoreleasepool { return hsMessageBoxWithOwner(owner, - [[[NSString alloc] initWithBytesNoCopy:(void *)caption - length:wcslen(caption)*sizeof(*caption) - encoding:NSUTF32LittleEndianStringEncoding freeWhenDone:NO - ] autorelease], - [[[NSString alloc] initWithBytesNoCopy:(void *)message - length:wcslen(caption)*sizeof(*caption) - encoding:NSUTF32LittleEndianStringEncoding freeWhenDone:NO - ] autorelease], + [NSString initWithUTF8String:message.data()], + [NSString initWithUTF8String:caption.data()], kind, icon); } diff --git a/Sources/Plasma/CoreLib/HeadSpin_Win.cpp b/Sources/Plasma/CoreLib/HeadSpin_Win.cpp new file mode 100644 index 0000000000..cf49c34b56 --- /dev/null +++ b/Sources/Plasma/CoreLib/HeadSpin_Win.cpp @@ -0,0 +1,117 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "HeadSpin.h" +#include "hsWindows.h" + +#include + +class hsMinimizeClientGuard +{ + hsWindowHndl fWnd; + +public: + hsMinimizeClientGuard() + { + fWnd = GetActiveWindow(); + // If the application's topmost window is fullscreen, minimize it before displaying an error + if ((GetWindowLong(fWnd, GWL_STYLE) & WS_POPUP) != 0) + ShowWindow(fWnd, SW_MINIMIZE); + } + + ~hsMinimizeClientGuard() + { + ShowWindow(fWnd, SW_RESTORE); + } +}; + + +int hsMessageBoxWithOwner(hsWindowHndl owner, const ST::string& message, const ST::string& caption, int kind, int icon) +{ + if (hsMessageBox_SuppressPrompts) + return hsMBoxOk; + + uint32_t flags = 0; + + if (kind == hsMessageBoxNormal) + flags |= MB_OK; + else if (kind == hsMessageBoxAbortRetyIgnore) + flags |= MB_ABORTRETRYIGNORE; + else if (kind == hsMessageBoxOkCancel) + flags |= MB_OKCANCEL; + else if (kind == hsMessageBoxRetryCancel) + flags |= MB_RETRYCANCEL; + else if (kind == hsMessageBoxYesNo) + flags |= MB_YESNO; + else if (kind == hsMessageBoxYesNoCancel) + flags |= MB_YESNOCANCEL; + else + flags |= MB_OK; + + if (icon == hsMessageBoxIconError) + flags |= MB_ICONERROR; + else if (icon == hsMessageBoxIconQuestion) + flags |= MB_ICONQUESTION; + else if (icon == hsMessageBoxIconExclamation) + flags |= MB_ICONEXCLAMATION; + else if (icon == hsMessageBoxIconAsterisk) + flags |= MB_ICONASTERISK; + else + flags |= MB_ICONERROR; + + hsMinimizeClientGuard guard; + int ans = MessageBoxW(owner, message.to_wchar().data(), caption.to_wchar().data(), flags); + + switch (ans) + { + case IDOK: return hsMBoxOk; + case IDCANCEL: return hsMBoxCancel; + case IDABORT: return hsMBoxAbort; + case IDRETRY: return hsMBoxRetry; + case IDIGNORE: return hsMBoxIgnore; + case IDYES: return hsMBoxYes; + case IDNO: return hsMBoxNo; + default: return hsMBoxCancel; + } + + return hsMBoxCancel; +} From 3daa4b4e4526376d3a00553f577d3b8c0112788c Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 14 Aug 2023 21:12:24 -0700 Subject: [PATCH 2/4] Pass ST::string to some hsMessageBoxes --- Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm | 3 +-- Sources/Plasma/Apps/plClient/plClient.cpp | 4 ++-- Sources/Plasma/Apps/plClient/plClientLoader.cpp | 2 +- Sources/Plasma/Apps/plClient/win32/winmain.cpp | 8 ++++---- Sources/Plasma/Apps/plCrashHandler/winmain.cpp | 2 +- Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp | 4 ++-- Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp | 2 +- Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp | 2 +- Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp | 2 +- Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp | 2 +- Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp | 2 +- Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp | 2 +- 12 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm index 5812cefc3b..a621a51efd 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm @@ -304,8 +304,7 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification pfConsoleEngine tempConsole; tempConsole.ExecuteFile(serverIni); } else { - hsMessageBox("No server.ini file found. Please check your URU installation.", "Error", - hsMessageBoxNormal); + hsMessageBox(ST_LITERAL("No server.ini file found. Please check your URU installation."), ST_LITERAL("Error"), hsMessageBoxNormal); [NSApplication.sharedApplication terminate:nil]; } diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 5c8af209ba..5aba7b4b43 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -442,7 +442,7 @@ bool plClient::InitPipeline(hsWindowHndl display, uint32_t devType) if (!devSel.GetRequested(&dmr, devType)) { - hsMessageBox("No suitable rendering devices found.","Plasma", hsMessageBoxNormal, hsMessageBoxIconError); + hsMessageBox(ST_LITERAL("No suitable rendering devices found."), ST_LITERAL("Plasma"), hsMessageBoxNormal, hsMessageBoxIconError); return true; } @@ -490,7 +490,7 @@ bool plClient::InitPipeline(hsWindowHndl display, uint32_t devType) { ISetGraphicsDefaults(); #ifdef PLASMA_EXTERNAL_RELEASE - hsMessageBox("There was an error initializing the video card.\nSetting defaults.", "Error", hsMessageBoxNormal); + hsMessageBox(ST_LITERAL("There was an error initializing the video card.\nSetting defaults."), ST_LITERAL("Error"), hsMessageBoxNormal); #else hsMessageBox( pipe->GetErrorString(), "Error creating pipeline", hsMessageBoxNormal ); #endif diff --git a/Sources/Plasma/Apps/plClient/plClientLoader.cpp b/Sources/Plasma/Apps/plClient/plClientLoader.cpp index 40dfa79176..1ced151838 100644 --- a/Sources/Plasma/Apps/plClient/plClientLoader.cpp +++ b/Sources/Plasma/Apps/plClient/plClientLoader.cpp @@ -57,7 +57,7 @@ void plClientLoader::Run() hsgResMgr::Init(resMgr); if (!plFileInfo("resource.dat").Exists()) { - hsMessageBox("Required file 'resource.dat' not found.", "Error", hsMessageBoxNormal); + hsMessageBox(ST_LITERAL("Required file 'resource.dat' not found."), ST_LITERAL("Error"), hsMessageBoxNormal); return; } plClientResMgr::Instance().ILoadResources("resource.dat"); diff --git a/Sources/Plasma/Apps/plClient/win32/winmain.cpp b/Sources/Plasma/Apps/plClient/win32/winmain.cpp index 9f45724a6c..0623917d07 100644 --- a/Sources/Plasma/Apps/plClient/win32/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/win32/winmain.cpp @@ -1132,7 +1132,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC { if(!CreateProcessW(s_patcherExeName, nullptr, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi)) { - hsMessageBox("Failed to launch patcher", "Error", hsMessageBoxNormal); + hsMessageBox(ST_LITERAL("Failed to launch patcher"), ST_LITERAL("Error"), hsMessageBoxNormal); } CloseHandle( pi.hThread ); CloseHandle( pi.hProcess ); @@ -1186,7 +1186,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC message = ST_LITERAL("Another copy of URU is already running"); break; } - hsMessageBox(message.to_wchar().c_str(), caption.to_wchar().c_str(), hsMessageBoxNormal); + hsMessageBox(message, caption, hsMessageBoxNormal); return PARABLE_NORMAL_EXIT; } #endif @@ -1204,13 +1204,13 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC } else { - hsMessageBox("No server.ini file found. Please check your URU installation.", "Error", hsMessageBoxNormal); + hsMessageBox(ST_LITERAL("No server.ini file found. Please check your URU installation."), ST_LITERAL("Error"), hsMessageBoxNormal); return PARABLE_NORMAL_EXIT; } // Begin initializing the client in the background if (!WinInit(hInst)) { - hsMessageBox("Failed to initialize plClient", "Error", hsMessageBoxNormal); + hsMessageBox(ST_LITERAL("Failed to initialize plClient"), ST_LITERAL("Error"), hsMessageBoxNormal); return PARABLE_NORMAL_EXIT; } diff --git a/Sources/Plasma/Apps/plCrashHandler/winmain.cpp b/Sources/Plasma/Apps/plCrashHandler/winmain.cpp index 064306157c..c1f8b589f5 100644 --- a/Sources/Plasma/Apps/plCrashHandler/winmain.cpp +++ b/Sources/Plasma/Apps/plCrashHandler/winmain.cpp @@ -380,7 +380,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine IShowCrashDialog(hInstance); return 0; } else { - hsMessageBox("You should never run this manually.", "Error", hsMessageBoxNormal, hsMessageBoxIconExclamation); + hsMessageBox(ST_LITERAL("You should never run this manually."), ST_LITERAL("Error"), hsMessageBoxNormal, hsMessageBoxIconExclamation); return 1; } } diff --git a/Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp b/Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp index 91188ce131..06de5424c9 100644 --- a/Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp @@ -327,11 +327,11 @@ bool plClientLauncher::CompleteSelfPatch(const std::function& waitProc) // so now we need to unlink the old patcher, and move ME into that fool's place... // then we can continue on our merry way! if (!plFileSystem::Unlink(plManifest::PatcherExecutable())) { - hsMessageBox("Failed to delete old patcher executable!", "Error", hsMessageBoxNormal, hsMessageBoxIconError); + hsMessageBox(ST_LITERAL("Failed to delete old patcher executable!"), ST_LITERAL("Error"), hsMessageBoxNormal, hsMessageBoxIconError); return true; } if (!plFileSystem::Move(plFileSystem::GetCurrentAppPath(), plManifest::PatcherExecutable())) { - hsMessageBox("Failed to move patcher executable!", "Error", hsMessageBoxNormal, hsMessageBoxIconError); + hsMessageBox(ST_LITERAL("Failed to move patcher executable!"), ST_LITERAL("Error"), hsMessageBoxNormal, hsMessageBoxIconError); return true; } diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp index e80177823c..48c1f41d44 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp @@ -358,7 +358,7 @@ bool pfConsole::MsgReceive( plMessage *msg ) #else "\nPress OK to continue parsing files." ); - hsMessageBox( msg.c_str(), str.c_str(), hsMessageBoxNormal ); + hsMessageBox(msg, str, hsMessageBoxNormal); #endif } } diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp index 3b5b27f12d..6a65dc351e 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp @@ -76,7 +76,7 @@ bool pfConsoleDirSrc::ParseDirectory(const plFileName& path, const char* mask /* error << fEngine->GetErrorMsg() << ":\n\nCommand: '" << fEngine->GetLastErrorLine() << "'\n\nPress OK to continue parsing files."; - hsMessageBox(error.to_string().c_str(), caption.to_string().c_str(), hsMessageBoxNormal); + hsMessageBox(error.to_string(), caption.to_string(), hsMessageBoxNormal); SetCheckProcessedFiles(true); return false; diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp index 569c3f4a1c..0c709d171a 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp @@ -1879,7 +1879,7 @@ void plDXPipeline::IPrintDeviceInitError() message = ST_LITERAL("There was an error initializing your video card. We have reset it to its Default settings."); break; } - hsMessageBox(message.to_wchar().c_str(), caption.to_wchar().c_str(), hsMessageBoxNormal, hsMessageBoxIconError); + hsMessageBox(message, caption, hsMessageBoxNormal, hsMessageBoxIconError); } // Reset device creation parameters to default and write to ini file diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp index adc7bef9c4..8d50952ffb 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp @@ -253,7 +253,7 @@ void plClothingItem::Write(hsStream *s, hsResMgr *mgr) if (accessoryKey == nullptr) { strBuf = ST::format("Couldn't find accessory \"{}\". It won't show at runtime.", fAccessoryName); - hsMessageBox(strBuf.c_str(), GetKeyName().c_str(), hsMessageBoxNormal); + hsMessageBox(strBuf, GetKeyName(), hsMessageBoxNormal); } } mgr->WriteKey(s, accessoryKey); diff --git a/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp b/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp index 707a76be84..308b048cc4 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp @@ -237,7 +237,7 @@ bool plAVIWriterImp::Open(const char* fileName, plPipeline* pipeline) &fBitmapInfo, // stream format fBitmapInfo.biSize); } while (err != AVIERR_OK && - hsMessageBox("Codec unavailable, try again?", "AVI Writer", hsMessageBoxYesNo) == hsMBoxYes); + hsMessageBox(ST_LITERAL("Codec unavailable, try again?"), ST_LITERAL("AVI Writer"), hsMessageBoxYesNo) == hsMBoxYes); if (err != AVIERR_OK) { diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp index 6ea5d8131f..b7149f92c5 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp @@ -1171,7 +1171,7 @@ void plResManager::PageInRoom(const plLocation& page, uint16_t objClassToRef, pl ST::string msg = ST::format("Data Problem: Age:{} Page:{} Error:{}", pageNode->GetPageInfo().GetAge(), pageNode->GetPageInfo().GetPage(), condStr); - hsMessageBox(msg.c_str(), "Error", hsMessageBoxNormal, hsMessageBoxIconError); + hsMessageBox(msg, ST_LITERAL("Error"), hsMessageBoxNormal, hsMessageBoxIconError); hsRefCnt_SafeUnRef(refMsg); return; From 7feef4212477dd366d43169b8a01e51535a3f9f7 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 15 Aug 2023 20:57:53 -0700 Subject: [PATCH 3/4] Move hsMessageBox from CoreLib to PubUtilLib/plMessageBox Co-Authored-By: dgelessus --- Sources/Plasma/Apps/plClient/CMakeLists.txt | 1 + .../Plasma/Apps/plClient/Mac-Cocoa/main.mm | 1 + Sources/Plasma/Apps/plClient/plClient.cpp | 1 + .../Plasma/Apps/plClient/plClientLoader.cpp | 1 + .../Plasma/Apps/plClient/win32/winmain.cpp | 1 + .../Plasma/Apps/plCrashHandler/CMakeLists.txt | 1 + .../Plasma/Apps/plCrashHandler/winmain.cpp | 1 + .../Plasma/Apps/plUruLauncher/CMakeLists.txt | 1 + .../Apps/plUruLauncher/plClientLauncher.cpp | 1 + Sources/Plasma/CoreLib/CMakeLists.txt | 3 - Sources/Plasma/CoreLib/HeadSpin.cpp | 39 ------ Sources/Plasma/CoreLib/HeadSpin.h | 36 ----- Sources/Plasma/CoreLib/HeadSpin_Mac.mm | 123 ------------------ .../FeatureLib/pfConsole/CMakeLists.txt | 1 + .../Plasma/FeatureLib/pfConsole/pfConsole.cpp | 1 + .../FeatureLib/pfConsole/pfConsoleDirSrc.cpp | 1 + .../FeatureLib/pfDXPipeline/CMakeLists.txt | 1 + .../FeatureLib/pfDXPipeline/plDXPipeline.cpp | 1 + Sources/Plasma/PubUtilLib/CMakeLists.txt | 1 + .../Plasma/PubUtilLib/plAvatar/CMakeLists.txt | 1 + .../PubUtilLib/plAvatar/plAvatarClothing.cpp | 1 + .../Plasma/PubUtilLib/plGImage/CMakeLists.txt | 1 + .../PubUtilLib/plGImage/plAVIWriter.cpp | 1 + .../PubUtilLib/plMessageBox/CMakeLists.txt | 23 ++++ .../PubUtilLib/plMessageBox/hsMessageBox.cpp | 69 ++++++++++ .../PubUtilLib/plMessageBox/hsMessageBox.h | 81 ++++++++++++ .../plMessageBox/hsMessageBox_Mac.mm | 115 ++++++++++++++++ .../plMessageBox/hsMessageBox_Win.cpp} | 10 +- .../PubUtilLib/plNetClient/CMakeLists.txt | 1 + .../PubUtilLib/plNetClient/plNetClientMgr.cpp | 1 + .../Plasma/PubUtilLib/plResMgr/CMakeLists.txt | 1 + .../PubUtilLib/plResMgr/plResManager.cpp | 1 + Sources/Tools/MaxComponent/CMakeLists.txt | 1 + .../Tools/MaxComponent/plComponentBase.cpp | 2 + .../MaxComponent/plPythonFileComponent.cpp | 2 + Sources/Tools/MaxExport/CMakeLists.txt | 1 + Sources/Tools/MaxExport/SimpleExport.cpp | 1 + Sources/Tools/MaxExport/plExportDlg.cpp | 1 + Sources/Tools/MaxMain/CMakeLists.txt | 1 + Sources/Tools/MaxMain/plGetLocationDlg.cpp | 3 +- 40 files changed, 325 insertions(+), 209 deletions(-) delete mode 100644 Sources/Plasma/CoreLib/HeadSpin_Mac.mm create mode 100644 Sources/Plasma/PubUtilLib/plMessageBox/CMakeLists.txt create mode 100644 Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp create mode 100644 Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h create mode 100644 Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm rename Sources/Plasma/{CoreLib/HeadSpin_Win.cpp => PubUtilLib/plMessageBox/hsMessageBox_Win.cpp} (92%) diff --git a/Sources/Plasma/Apps/plClient/CMakeLists.txt b/Sources/Plasma/Apps/plClient/CMakeLists.txt index 80d3296149..ee8ab6403d 100644 --- a/Sources/Plasma/Apps/plClient/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClient/CMakeLists.txt @@ -210,6 +210,7 @@ target_link_libraries( plGLight plInputCore plMessage + plMessageBox plModifier plNetClient plNetCommon diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm index a621a51efd..b88ea90982 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm @@ -65,6 +65,7 @@ #include "pfGameGUIMgr/pfGameGUIMgr.h" #include "plInputCore/plInputDevice.h" #include "plMessage/plDisplayScaleChangedMsg.h" +#include "plMessageBox/hsMessageBox.h" #include "plNetClient/plNetClientMgr.h" #include "plNetGameLib/plNetGameLib.h" #include "plProduct.h" diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 5aba7b4b43..6b1d14a3de 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -106,6 +106,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMessage/plResPatcherMsg.h" #include "plMessage/plRoomLoadNotifyMsg.h" #include "plMessage/plTransitionMsg.h" +#include "plMessageBox/hsMessageBox.h" #include "plModifier/plSimpleModifier.h" #include "plNetClient/plLinkEffectsMgr.h" #include "plNetClient/plNetLinkingMgr.h" diff --git a/Sources/Plasma/Apps/plClient/plClientLoader.cpp b/Sources/Plasma/Apps/plClient/plClientLoader.cpp index 1ced151838..114b3c0724 100644 --- a/Sources/Plasma/Apps/plClient/plClientLoader.cpp +++ b/Sources/Plasma/Apps/plClient/plClientLoader.cpp @@ -46,6 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plPipeline.h" #include "plClientResMgr/plClientResMgr.h" +#include "plMessageBox/hsMessageBox.h" #include "plNetClient/plNetClientMgr.h" #include "plPhysX/plSimulationMgr.h" #include "plResMgr/plResManager.h" diff --git a/Sources/Plasma/Apps/plClient/win32/winmain.cpp b/Sources/Plasma/Apps/plClient/win32/winmain.cpp index 0623917d07..db80f092fc 100644 --- a/Sources/Plasma/Apps/plClient/win32/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/win32/winmain.cpp @@ -68,6 +68,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plNetClient/plNetClientMgr.h" #include "plNetGameLib/plNetGameLib.h" #include "plMessage/plDisplayScaleChangedMsg.h" +#include "plMessageBox/hsMessageBox.h" #include "plPhysX/plPXSimulation.h" #include "plPipeline/hsG3DDeviceSelector.h" #include "plResMgr/plLocalization.h" diff --git a/Sources/Plasma/Apps/plCrashHandler/CMakeLists.txt b/Sources/Plasma/Apps/plCrashHandler/CMakeLists.txt index 2869955845..f86792d561 100644 --- a/Sources/Plasma/Apps/plCrashHandler/CMakeLists.txt +++ b/Sources/Plasma/Apps/plCrashHandler/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries( PRIVATE CoreLib plClipboard + plMessageBox pfCrashHandler $<$:Comctl32> diff --git a/Sources/Plasma/Apps/plCrashHandler/winmain.cpp b/Sources/Plasma/Apps/plCrashHandler/winmain.cpp index c1f8b589f5..0f4f4f28ed 100644 --- a/Sources/Plasma/Apps/plCrashHandler/winmain.cpp +++ b/Sources/Plasma/Apps/plCrashHandler/winmain.cpp @@ -59,6 +59,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "resource.h" #include "plClipboard/plClipboard.h" +#include "plMessageBox/hsMessageBox.h" #include "pfCrashHandler/plCrashSrv.h" diff --git a/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt b/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt index e32571fb10..62c4c23836 100644 --- a/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt +++ b/Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt @@ -27,6 +27,7 @@ target_link_libraries( CoreLib pnAsyncCore pnNetBase + plMessageBox plNetGameLib plStatusLog plWinDpi diff --git a/Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp b/Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp index 06de5424c9..a86f8d6928 100644 --- a/Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp @@ -51,6 +51,7 @@ Mead, WA 99021 #include "pnAsyncCore/pnAsyncCore.h" +#include "plMessageBox/hsMessageBox.h" #include "plNetGameLib/plNetGameLib.h" #include "plStatusLog/plStatusLog.h" diff --git a/Sources/Plasma/CoreLib/CMakeLists.txt b/Sources/Plasma/CoreLib/CMakeLists.txt index ec8c64ac14..6a45faf245 100644 --- a/Sources/Plasma/CoreLib/CMakeLists.txt +++ b/Sources/Plasma/CoreLib/CMakeLists.txt @@ -23,8 +23,6 @@ set(CoreLib_SOURCES plProduct.cpp plViewTransform.cpp hsWindows.cpp - $<$:HeadSpin_Mac.mm> - $<$:HeadSpin_Win.cpp> ) if(CMAKE_USE_WIN32_THREADS_INIT) @@ -85,7 +83,6 @@ target_link_libraries( "$<$:-framework Accelerate>" PRIVATE "$<$:-framework CoreFoundation>" - "$<$:-framework Cocoa>" ) target_include_directories( CoreLib diff --git a/Sources/Plasma/CoreLib/HeadSpin.cpp b/Sources/Plasma/CoreLib/HeadSpin.cpp index 059c43ffdb..79e7f7f9f7 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.cpp +++ b/Sources/Plasma/CoreLib/HeadSpin.cpp @@ -273,45 +273,6 @@ void hsStatusMessageF(const char * fmt, ...) #endif -bool hsMessageBox_SuppressPrompts = false; - -#if !defined(HS_BUILD_FOR_APPLE) && !defined(HS_BUILD_FOR_WIN32) -// Need a proper implementation for Linux, but for now let's just print out to the console -int hsMessageBoxWithOwner(hsWindowHndl owner, const ST::string& message, const ST::string& caption, int kind, int icon) -{ - if (hsMessageBox_SuppressPrompts) - return hsMBoxOk; - - hsStatusMessage(ST::format("{}\n{}", message, caption).c_str()); - return hsMBoxCancel; -} -#endif - -int hsMessageBoxWithOwner(hsWindowHndl owner, const char* message, const char* caption, int kind, int icon) -{ - return hsMessageBoxWithOwner(owner, ST::string::from_latin_1(message), ST::string::from_latin_1(caption), kind, icon); -} - -int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t* message, const wchar_t* caption, int kind, int icon) -{ - return hsMessageBoxWithOwner(owner, ST::string::from_wchar(message), ST::string::from_wchar(caption), kind, icon); -} - -int hsMessageBox(const ST::string& message, const ST::string& caption, int kind, int icon) -{ - return hsMessageBoxWithOwner(nullptr, message, caption, kind, icon); -} - -int hsMessageBox(const char* message, const char* caption, int kind, int icon) -{ - return hsMessageBoxWithOwner(nullptr, ST::string::from_latin_1(message), ST::string::from_latin_1(caption), kind, icon); -} - -int hsMessageBox(const wchar_t* message, const wchar_t* caption, int kind, int icon) -{ - return hsMessageBoxWithOwner(nullptr, ST::string::from_wchar(message), ST::string::from_wchar(caption), kind, icon); -} - /**************************************/ char* hsStrcpy(char* dst, const char* src) { diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index 374c46902a..0f0ce3517e 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -58,8 +58,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include -namespace ST { class string; } - //====================================== // Winblows Hacks //====================================== @@ -278,40 +276,6 @@ inline char *hsStrncpy(char *strDest, const char *strSource, size_t count) # define strnicmp strncasecmp #endif -enum { // Kind of MessageBox...passed to hsMessageBox - hsMessageBoxAbortRetyIgnore, - hsMessageBoxNormal, // Just Ok - hsMessageBoxOkCancel, - hsMessageBoxRetryCancel, - hsMessageBoxYesNo, - hsMessageBoxYesNoCancel, -}; - -enum { - hsMessageBoxIconError, - hsMessageBoxIconQuestion, - hsMessageBoxIconExclamation, - hsMessageBoxIconAsterisk, -}; - -enum { // RETURN VALUES FROM hsMessageBox - hsMBoxOk = 1, // OK button was selected. - hsMBoxCancel, // Cancel button was selected. - hsMBoxAbort, // Abort button was selected. - hsMBoxRetry, // Retry button was selected. - hsMBoxIgnore, // Ignore button was selected. - hsMBoxYes, // Yes button was selected. - hsMBoxNo // No button was selected. -}; - -extern bool hsMessageBox_SuppressPrompts; -int hsMessageBox(const ST::string& message, const ST::string& caption, int kind, int icon=hsMessageBoxIconAsterisk); -int hsMessageBox(const char* message, const char* caption, int kind, int icon=hsMessageBoxIconAsterisk); -int hsMessageBox(const wchar_t* message, const wchar_t* caption, int kind, int icon=hsMessageBoxIconAsterisk); -int hsMessageBoxWithOwner(hsWindowHndl owner, const ST::string& message, const ST::string& caption, int kind, int icon=hsMessageBoxIconAsterisk); -int hsMessageBoxWithOwner(hsWindowHndl owner, const char* message, const char* caption, int kind, int icon=hsMessageBoxIconAsterisk); -int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t* message, const wchar_t* caption, int kind, int icon=hsMessageBoxIconAsterisk); - // flag testing / clearing #define hsCheckBits(f,c) ((f & c)==c) #define hsTestBits(f,b) ( (f) & (b) ) diff --git a/Sources/Plasma/CoreLib/HeadSpin_Mac.mm b/Sources/Plasma/CoreLib/HeadSpin_Mac.mm deleted file mode 100644 index af6a801ebe..0000000000 --- a/Sources/Plasma/CoreLib/HeadSpin_Mac.mm +++ /dev/null @@ -1,123 +0,0 @@ -/*==LICENSE==* - -CyanWorlds.com Engine - MMOG client, server and tools -Copyright (C) 2011 Cyan Worlds, Inc. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -Additional permissions under GNU GPL version 3 section 7 - -If you modify this Program, or any covered work, by linking or -combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, -NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent -JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK -(or a modified version of those libraries), -containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, -PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG -JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the -licensors of this Program grant you additional -permission to convey the resulting work. Corresponding Source for a -non-source form of such a combination shall include the source code for -the parts of OpenSSL and IJG JPEG Library used as well as that of the covered -work. - -You can contact Cyan Worlds, Inc. by email legal@cyan.com - or by snail mail at: - Cyan Worlds, Inc. - 14617 N Newport Hwy - Mead, WA 99021 - -*==LICENSE==*/ - -#include "HeadSpin.h" - -#include -#import - -int hsMessageBoxWithOwner(hsWindowHndl owner, NSString* message, NSString* caption, int kind, int icon) -{ - // this is a private method - caller is responsible - // for wrapping in a valid autorelease pool - __block NSModalResponse response; - NSCondition *lock = [NSCondition new]; - dispatch_block_t alertBlock = ^{ - NSAlert *alert = [NSAlert new]; - alert.messageText = caption; - alert.informativeText = message; - - if (icon == hsMessageBoxIconError) - alert.alertStyle = NSAlertStyleCritical; - else if (icon == hsMessageBoxIconQuestion) - alert.alertStyle = NSAlertStyleInformational; - else if (icon == hsMessageBoxIconExclamation) - alert.alertStyle = NSAlertStyleWarning; - else if (icon == hsMessageBoxIconAsterisk) - alert.alertStyle = NSAlertStyleWarning; - else - alert.alertStyle = NSAlertStyleCritical; - - if (kind == hsMessageBoxNormal) - [alert addButtonWithTitle:@"OK"]; - else if (kind == hsMessageBoxAbortRetyIgnore) { - [alert addButtonWithTitle:@"Retry"]; - [alert addButtonWithTitle:@"Ignore"]; - } else if (kind == hsMessageBoxOkCancel) { - [alert addButtonWithTitle:@"OK"]; - [alert addButtonWithTitle:@"Cancel"]; - } else if (kind == hsMessageBoxRetryCancel) { - [alert addButtonWithTitle:@"Retry"]; - [alert addButtonWithTitle:@"Cancel"]; - } else if (kind == hsMessageBoxYesNo) { - [alert addButtonWithTitle:@"Yes"]; - [alert addButtonWithTitle:@"No"]; - } else if (kind == hsMessageBoxYesNoCancel) { - [alert addButtonWithTitle:@"Yes"]; - [alert addButtonWithTitle:@"No"]; - [alert addButtonWithTitle:@"Cancel"]; - } else - [alert addButtonWithTitle:@"OK"]; - response = [alert runModal]; - [lock lock]; - [lock signal]; - [lock unlock]; - }; - - //Plasma may call dialogs from any thread, not just the main thread - //Check to see if we're on the main thread and directly execute - //the dialog if we are. - if ([NSRunLoop currentRunLoop] == [NSRunLoop mainRunLoop]) { - alertBlock(); - } else { - [[NSRunLoop mainRunLoop] performInModes:@[NSDefaultRunLoopMode] block:alertBlock]; - [lock lock]; - [lock wait]; - [lock unlock]; - } - - return (int)response; -} - -int hsMessageBoxWithOwner(hsWindowHndl owner, const ST::string& message, const ST::string& caption, int kind, int icon) -{ - if (hsMessageBox_SuppressPrompts) - return hsMBoxOk; - - @autoreleasepool { - return hsMessageBoxWithOwner(owner, - [NSString initWithUTF8String:message.data()], - [NSString initWithUTF8String:caption.data()], - kind, - icon); - } -} diff --git a/Sources/Plasma/FeatureLib/pfConsole/CMakeLists.txt b/Sources/Plasma/FeatureLib/pfConsole/CMakeLists.txt index 567510a212..4dcc0ed748 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/CMakeLists.txt +++ b/Sources/Plasma/FeatureLib/pfConsole/CMakeLists.txt @@ -49,6 +49,7 @@ target_link_libraries( plNetGameLib plNetMessage plMessage + plMessageBox plModifier plParticleSystem plPhysical diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp index 48c1f41d44..7039582f9e 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsole.cpp @@ -74,6 +74,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMessage/plConsoleMsg.h" #include "plMessage/plInputEventMsg.h" #include "plMessage/plInputIfaceMgrMsg.h" +#include "plMessageBox/hsMessageBox.h" #include "plPipeline/plDebugText.h" #include "pfConsoleCore/pfConsoleEngine.h" diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp index 6a65dc351e..d833caef05 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleDirSrc.cpp @@ -51,6 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include "hsExceptions.h" +#include "plMessageBox/hsMessageBox.h" //// ParseDirectory ////////////////////////////////////////////////////////// diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/CMakeLists.txt b/Sources/Plasma/FeatureLib/pfDXPipeline/CMakeLists.txt index 226c63d1b9..f10ef1ffac 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/CMakeLists.txt +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/CMakeLists.txt @@ -47,6 +47,7 @@ target_link_libraries(pfDXPipeline plGImage plGLight plMessage + plMessageBox plResMgr plScene plStatusLog diff --git a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp index 0c709d171a..a73af795c9 100644 --- a/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp +++ b/Sources/Plasma/FeatureLib/pfDXPipeline/plDXPipeline.cpp @@ -113,6 +113,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plGLight/plShadowMaster.h" #include "plGLight/plShadowSlave.h" #include "plMessage/plDeviceRecreateMsg.h" +#include "plMessageBox/hsMessageBox.h" #include "plResMgr/plLocalization.h" #include "plScene/plRenderRequest.h" #include "plScene/plVisMgr.h" diff --git a/Sources/Plasma/PubUtilLib/CMakeLists.txt b/Sources/Plasma/PubUtilLib/CMakeLists.txt index d32dcdb9c2..aeef85ba79 100644 --- a/Sources/Plasma/PubUtilLib/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/CMakeLists.txt @@ -23,6 +23,7 @@ add_subdirectory(plInterp) add_subdirectory(plIntersect) add_subdirectory(plMath) add_subdirectory(plMessage) +add_subdirectory(plMessageBox) add_subdirectory(plModifier) add_subdirectory(plNetClient) add_subdirectory(plNetClientComm) diff --git a/Sources/Plasma/PubUtilLib/plAvatar/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plAvatar/CMakeLists.txt index 0cf597cf88..dedc16e092 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plAvatar/CMakeLists.txt @@ -96,6 +96,7 @@ target_link_libraries( plInputCore plInterp plMessage + plMessageBox plNetClient plNetCommon plNetMessage diff --git a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp index 8d50952ffb..80a6bb4275 100644 --- a/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp +++ b/Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp @@ -63,6 +63,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plDrawable/plSpaceTree.h" #include "plGImage/plMipmap.h" #include "plMessage/plRenderMsg.h" +#include "plMessageBox/hsMessageBox.h" #include "plResMgr/plKeyFinder.h" #include "plSDL/plSDL.h" #include "plSurface/hsGMaterial.h" diff --git a/Sources/Plasma/PubUtilLib/plGImage/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plGImage/CMakeLists.txt index 33b51e0e9d..6b5e5ab085 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plGImage/CMakeLists.txt @@ -49,6 +49,7 @@ target_link_libraries( pnDispatch pnMessage pnNucleusInc + plMessageBox plResMgr JPEG::JPEG PNG::PNG diff --git a/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp b/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp index 308b048cc4..2b971dcea6 100644 --- a/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp +++ b/Sources/Plasma/PubUtilLib/plGImage/plAVIWriter.cpp @@ -53,6 +53,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsTimer.h" #include "plMipmap.h" #include "plMessage/plRenderMsg.h" +#include "plMessageBox/hsMessageBox.h" #include "plPipeline.h" #include "pnDispatch/plDispatch.h" #include "pnKeyedObject/plFixedKey.h" diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plMessageBox/CMakeLists.txt new file mode 100644 index 0000000000..3f04b254aa --- /dev/null +++ b/Sources/Plasma/PubUtilLib/plMessageBox/CMakeLists.txt @@ -0,0 +1,23 @@ +set(plMessageBox_SOURCES + hsMessageBox.cpp + $<$:hsMessageBox_Mac.mm> + $<$:hsMessageBox_Win.cpp> +) + +set(plMessageBox_HEADERS + hsMessageBox.h +) + +plasma_library(plMessageBox + SOURCES ${plMessageBox_SOURCES} ${plMessageBox_HEADERS} +) +target_link_libraries( + plMessageBox + PUBLIC + CoreLib + PRIVATE + "$<$:-framework Cocoa>" +) + +source_group("Source Files" FILES ${plMessageBox_SOURCES}) +source_group("Header Files" FILES ${plMessageBox_HEADERS}) diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp new file mode 100644 index 0000000000..59df69e66c --- /dev/null +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp @@ -0,0 +1,69 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "hsMessageBox.h" + +bool hsMessageBox_SuppressPrompts = false; + +#if !defined(HS_BUILD_FOR_APPLE) && !defined(HS_BUILD_FOR_WIN32) +#include + +// Need a proper implementation for Linux, but for now let's just print out to the console +hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) +{ + if (hsMessageBox_SuppressPrompts) + return hsMBoxOk; + + hsStatusMessage(ST::format("{}\n{}", message, caption).c_str()); + return hsMBoxCancel; +} +#endif + +hsMessageBoxResult hsMessageBox(const char* message, const char* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) +{ + return hsMessageBox(ST::string::from_latin_1(message), ST::string::from_latin_1(caption), kind, icon); +} + +hsMessageBoxResult hsMessageBox(const wchar_t* message, const wchar_t* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) +{ + return hsMessageBox(ST::string::from_wchar(message), ST::string::from_wchar(caption), kind, icon); +} diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h new file mode 100644 index 0000000000..26390d4a38 --- /dev/null +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h @@ -0,0 +1,81 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#ifndef _hsMessageBox_h_ +#define _hsMessageBox_h_ + +#include "HeadSpin.h" +#include + +enum hsMessageBoxKind { // Kind of MessageBox...passed to hsMessageBox + hsMessageBoxAbortRetyIgnore, + hsMessageBoxNormal, // Just Ok + hsMessageBoxOkCancel, + hsMessageBoxRetryCancel, + hsMessageBoxYesNo, + hsMessageBoxYesNoCancel, +}; + +enum hsMessageBoxIcon { + hsMessageBoxIconError, + hsMessageBoxIconQuestion, + hsMessageBoxIconExclamation, + hsMessageBoxIconAsterisk, +}; + +enum hsMessageBoxResult { // RETURN VALUES FROM hsMessageBox + hsMBoxOk = 1, // OK button was selected. + hsMBoxCancel, // Cancel button was selected. + hsMBoxAbort, // Abort button was selected. + hsMBoxRetry, // Retry button was selected. + hsMBoxIgnore, // Ignore button was selected. + hsMBoxYes, // Yes button was selected. + hsMBoxNo // No button was selected. +}; + +extern bool hsMessageBox_SuppressPrompts; + +hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& caption, hsMessageBoxKind kind, hsMessageBoxIcon icon=hsMessageBoxIconAsterisk); +hsMessageBoxResult hsMessageBox(const char* message, const char* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon=hsMessageBoxIconAsterisk); +hsMessageBoxResult hsMessageBox(const wchar_t* message, const wchar_t* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon=hsMessageBoxIconAsterisk); + +#endif // _hsMessageBox_h_ diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm new file mode 100644 index 0000000000..378a71be29 --- /dev/null +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm @@ -0,0 +1,115 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "hsMessageBox.h" + +#import + +hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) +{ + if (hsMessageBox_SuppressPrompts) + return hsMBoxOk; + + @autoreleasepool { + NSString* nsMessage = [NSString stringWithUTF8String:message.data()]; + NSString* nsCaption = [NSString stringWithUTF8String:caption.data()]; + + __block NSModalResponse response; + NSCondition* lock = [NSCondition new]; + dispatch_block_t alertBlock = ^{ + NSAlert* alert = [NSAlert new]; + alert.messageText = nsCaption; + alert.informativeText = nsMessage; + + if (icon == hsMessageBoxIconError) + alert.alertStyle = NSAlertStyleCritical; + else if (icon == hsMessageBoxIconQuestion) + alert.alertStyle = NSAlertStyleInformational; + else if (icon == hsMessageBoxIconExclamation) + alert.alertStyle = NSAlertStyleWarning; + else if (icon == hsMessageBoxIconAsterisk) + alert.alertStyle = NSAlertStyleWarning; + else + alert.alertStyle = NSAlertStyleCritical; + + if (kind == hsMessageBoxNormal) + [alert addButtonWithTitle:@"OK"]; + else if (kind == hsMessageBoxAbortRetyIgnore) { + [alert addButtonWithTitle:@"Retry"]; + [alert addButtonWithTitle:@"Ignore"]; + } else if (kind == hsMessageBoxOkCancel) { + [alert addButtonWithTitle:@"OK"]; + [alert addButtonWithTitle:@"Cancel"]; + } else if (kind == hsMessageBoxRetryCancel) { + [alert addButtonWithTitle:@"Retry"]; + [alert addButtonWithTitle:@"Cancel"]; + } else if (kind == hsMessageBoxYesNo) { + [alert addButtonWithTitle:@"Yes"]; + [alert addButtonWithTitle:@"No"]; + } else if (kind == hsMessageBoxYesNoCancel) { + [alert addButtonWithTitle:@"Yes"]; + [alert addButtonWithTitle:@"No"]; + [alert addButtonWithTitle:@"Cancel"]; + } else + [alert addButtonWithTitle:@"OK"]; + response = [alert runModal]; + [lock lock]; + [lock signal]; + [lock unlock]; + }; + + //Plasma may call dialogs from any thread, not just the main thread + //Check to see if we're on the main thread and directly execute + //the dialog if we are. + if ([NSRunLoop currentRunLoop] == [NSRunLoop mainRunLoop]) { + alertBlock(); + } else { + [[NSRunLoop mainRunLoop] performInModes:@[NSDefaultRunLoopMode] block:alertBlock]; + [lock lock]; + [lock wait]; + [lock unlock]; + } + + // This is only really safe for OK and Cancel + return (hsMessageBoxResult)response; + } +} diff --git a/Sources/Plasma/CoreLib/HeadSpin_Win.cpp b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp similarity index 92% rename from Sources/Plasma/CoreLib/HeadSpin_Win.cpp rename to Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp index cf49c34b56..36f5b8393b 100644 --- a/Sources/Plasma/CoreLib/HeadSpin_Win.cpp +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp @@ -40,11 +40,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com *==LICENSE==*/ -#include "HeadSpin.h" +#include "hsMessageBox.h" #include "hsWindows.h" -#include - class hsMinimizeClientGuard { hsWindowHndl fWnd; @@ -65,7 +63,7 @@ class hsMinimizeClientGuard }; -int hsMessageBoxWithOwner(hsWindowHndl owner, const ST::string& message, const ST::string& caption, int kind, int icon) +hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) { if (hsMessageBox_SuppressPrompts) return hsMBoxOk; @@ -99,7 +97,7 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, const ST::string& message, const S flags |= MB_ICONERROR; hsMinimizeClientGuard guard; - int ans = MessageBoxW(owner, message.to_wchar().data(), caption.to_wchar().data(), flags); + int ans = MessageBoxW(nullptr, message.to_wchar().data(), caption.to_wchar().data(), flags); switch (ans) { @@ -112,6 +110,4 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, const ST::string& message, const S case IDNO: return hsMBoxNo; default: return hsMBoxCancel; } - - return hsMBoxCancel; } diff --git a/Sources/Plasma/PubUtilLib/plNetClient/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plNetClient/CMakeLists.txt index 4e3fb0547a..a2008740e9 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plNetClient/CMakeLists.txt @@ -60,6 +60,7 @@ target_link_libraries(plNetClient plContainer plDrawable plMessage + plMessageBox plModifier plNetClientRecorder plNetGameLib diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp index 7a73f48f6b..b7c11acbe1 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp @@ -71,6 +71,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMessage/plSDLModifierStateMsg.h" #include "plMessage/plSynchEnableMsg.h" #include "plMessage/plVaultNotifyMsg.h" +#include "plMessageBox/hsMessageBox.h" #include "plModifier/plResponderModifier.h" #include "plNetClientRecorder/plNetClientRecorder.h" #include "plNetCommon/plNetObjectDebugger.h" diff --git a/Sources/Plasma/PubUtilLib/plResMgr/CMakeLists.txt b/Sources/Plasma/PubUtilLib/plResMgr/CMakeLists.txt index dacac28e97..025374bf55 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/CMakeLists.txt +++ b/Sources/Plasma/PubUtilLib/plResMgr/CMakeLists.txt @@ -39,6 +39,7 @@ target_link_libraries( pnMessage pnNetCommon plMessage + plMessageBox plStatusLog INTERFACE pnFactory diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp index b7149f92c5..2f89e11cd2 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp @@ -62,6 +62,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "pnNetCommon/plNetApp.h" #include "plAgeDescription/plAgeDescription.h" +#include "plMessageBox/hsMessageBox.h" #include "plScene/plSceneNode.h" #include "plStatusLog/plStatusLog.h" diff --git a/Sources/Tools/MaxComponent/CMakeLists.txt b/Sources/Tools/MaxComponent/CMakeLists.txt index 385f0f9e7d..d492428d54 100644 --- a/Sources/Tools/MaxComponent/CMakeLists.txt +++ b/Sources/Tools/MaxComponent/CMakeLists.txt @@ -197,6 +197,7 @@ target_link_libraries( plIntersect plMath plMessage + plMessageBox plModifier plNetCommon plPipeline diff --git a/Sources/Tools/MaxComponent/plComponentBase.cpp b/Sources/Tools/MaxComponent/plComponentBase.cpp index eecdd174e3..fb2e2554ff 100644 --- a/Sources/Tools/MaxComponent/plComponentBase.cpp +++ b/Sources/Tools/MaxComponent/plComponentBase.cpp @@ -43,6 +43,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "HeadSpin.h" #include +#include "plMessageBox/hsMessageBox.h" + #include "plComponentBase.h" #include "plComponentReg.h" #include "MaxMain/plMaxNodeBase.h" diff --git a/Sources/Tools/MaxComponent/plPythonFileComponent.cpp b/Sources/Tools/MaxComponent/plPythonFileComponent.cpp index ae3f9339d1..6bdcad6cdd 100644 --- a/Sources/Tools/MaxComponent/plPythonFileComponent.cpp +++ b/Sources/Tools/MaxComponent/plPythonFileComponent.cpp @@ -81,6 +81,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plSurface/plGrassShaderMod.h" #include "plGrassComponent.h" +#include "plMessageBox/hsMessageBox.h" + #include "pfPython/plPythonFileMod.h" #include "pfPython/plPythonParameter.h" diff --git a/Sources/Tools/MaxExport/CMakeLists.txt b/Sources/Tools/MaxExport/CMakeLists.txt index a9bd6c2483..d1f67ccaa0 100644 --- a/Sources/Tools/MaxExport/CMakeLists.txt +++ b/Sources/Tools/MaxExport/CMakeLists.txt @@ -31,6 +31,7 @@ target_link_libraries( pnKeyedObject plAvatar plGImage + plMessageBox plPhysX plResMgr plScene diff --git a/Sources/Tools/MaxExport/SimpleExport.cpp b/Sources/Tools/MaxExport/SimpleExport.cpp index 93c31b2d60..194a4c4de7 100644 --- a/Sources/Tools/MaxExport/SimpleExport.cpp +++ b/Sources/Tools/MaxExport/SimpleExport.cpp @@ -75,6 +75,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plGImage/plCubicEnvironmap.h" #include "plGImage/plDynamicTextMap.h" #include "plGImage/plMipmap.h" +#include "plMessageBox/hsMessageBox.h" #include "plScene/plSceneNode.h" #include "plExportDlg.h" diff --git a/Sources/Tools/MaxExport/plExportDlg.cpp b/Sources/Tools/MaxExport/plExportDlg.cpp index fd51b0668b..2aca99c345 100644 --- a/Sources/Tools/MaxExport/plExportDlg.cpp +++ b/Sources/Tools/MaxExport/plExportDlg.cpp @@ -56,6 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "MaxMain/plMaxCFGFile.h" #include "MaxMain/plMaxNode.h" #include "plFileSystem.h" +#include "plMessageBox/hsMessageBox.h" extern HINSTANCE hInstance; diff --git a/Sources/Tools/MaxMain/CMakeLists.txt b/Sources/Tools/MaxMain/CMakeLists.txt index 9b2a40b482..1a74b77086 100644 --- a/Sources/Tools/MaxMain/CMakeLists.txt +++ b/Sources/Tools/MaxMain/CMakeLists.txt @@ -92,6 +92,7 @@ target_link_libraries( plGImage plInterp plMessage + plMessageBox plModifier plParticleSystem plPhysical diff --git a/Sources/Tools/MaxMain/plGetLocationDlg.cpp b/Sources/Tools/MaxMain/plGetLocationDlg.cpp index 6d140edb71..bd6809ef1e 100644 --- a/Sources/Tools/MaxMain/plGetLocationDlg.cpp +++ b/Sources/Tools/MaxMain/plGetLocationDlg.cpp @@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "MaxAPI.h" #include "pnKeyedObject/plKey.h" +#include "plMessageBox/hsMessageBox.h" #include "plMaxNode.h" #include "MaxComponent/plComponent.h" @@ -204,4 +205,4 @@ INT_PTR plGetLocationDlg::DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPa } return FALSE; -} \ No newline at end of file +} From c8a21f14e7587fbfb42ee563e7473b57a130bb40 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Wed, 16 Aug 2023 23:35:44 -0700 Subject: [PATCH 4/4] Convert all hsMessageBox inputs to ST::string Co-Authored-By: Adam Johnson --- Sources/Plasma/Apps/plClient/plClient.cpp | 2 +- .../PubUtilLib/plMessageBox/hsMessageBox.cpp | 11 +---- .../PubUtilLib/plMessageBox/hsMessageBox.h | 5 +-- .../plMessageBox/hsMessageBox_Mac.mm | 1 + .../plMessageBox/hsMessageBox_Win.cpp | 1 + .../PubUtilLib/plNetClient/plNetClientMgr.cpp | 3 +- .../PubUtilLib/plResMgr/plResManager.cpp | 41 +++++++++---------- 7 files changed, 27 insertions(+), 37 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 6b1d14a3de..9f6b741dd9 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -493,7 +493,7 @@ bool plClient::InitPipeline(hsWindowHndl display, uint32_t devType) #ifdef PLASMA_EXTERNAL_RELEASE hsMessageBox(ST_LITERAL("There was an error initializing the video card.\nSetting defaults."), ST_LITERAL("Error"), hsMessageBoxNormal); #else - hsMessageBox( pipe->GetErrorString(), "Error creating pipeline", hsMessageBoxNormal ); + hsMessageBox(ST::string(pipe->GetErrorString()), ST_LITERAL("Error creating pipeline"), hsMessageBoxNormal); #endif delete pipe; devSel.GetDefault(&dmr); diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp index 59df69e66c..3d2a678aab 100644 --- a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp @@ -45,6 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com bool hsMessageBox_SuppressPrompts = false; #if !defined(HS_BUILD_FOR_APPLE) && !defined(HS_BUILD_FOR_WIN32) +#include #include // Need a proper implementation for Linux, but for now let's just print out to the console @@ -57,13 +58,3 @@ hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& cap return hsMBoxCancel; } #endif - -hsMessageBoxResult hsMessageBox(const char* message, const char* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) -{ - return hsMessageBox(ST::string::from_latin_1(message), ST::string::from_latin_1(caption), kind, icon); -} - -hsMessageBoxResult hsMessageBox(const wchar_t* message, const wchar_t* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) -{ - return hsMessageBox(ST::string::from_wchar(message), ST::string::from_wchar(caption), kind, icon); -} diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h index 26390d4a38..8243e2f753 100644 --- a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h @@ -44,7 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define _hsMessageBox_h_ #include "HeadSpin.h" -#include + +namespace ST { class string; } enum hsMessageBoxKind { // Kind of MessageBox...passed to hsMessageBox hsMessageBoxAbortRetyIgnore, @@ -75,7 +76,5 @@ enum hsMessageBoxResult { // RETURN VALUES FROM hsMessageBox extern bool hsMessageBox_SuppressPrompts; hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& caption, hsMessageBoxKind kind, hsMessageBoxIcon icon=hsMessageBoxIconAsterisk); -hsMessageBoxResult hsMessageBox(const char* message, const char* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon=hsMessageBoxIconAsterisk); -hsMessageBoxResult hsMessageBox(const wchar_t* message, const wchar_t* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon=hsMessageBoxIconAsterisk); #endif // _hsMessageBox_h_ diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm index 378a71be29..69de1129ec 100644 --- a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm @@ -42,6 +42,7 @@ #include "hsMessageBox.h" +#include #import hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp index 36f5b8393b..1879538094 100644 --- a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsMessageBox.h" #include "hsWindows.h" +#include class hsMinimizeClientGuard { diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp index b7c11acbe1..cf65f85a55 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp @@ -1149,7 +1149,8 @@ void plNetClientMgr::IDisableNet () { { // KI may not be loaded ST::string title = ST::format("{} Error", plProduct::CoreName()); - hsMessageBox(fDisableMsg->str, title.c_str(), hsMessageBoxNormal, hsMessageBoxIconError ); + ST::string errMsg = ST::string(fDisableMsg->str); + hsMessageBox(errMsg, title, hsMessageBoxNormal, hsMessageBoxIconError); plClientMsg *quitMsg = new plClientMsg(plClientMsg::kQuit); quitMsg->Send(hsgResMgr::ResMgr()->FindKey(kClient_KEY)); } diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp index 2f89e11cd2..fb4bfc49ca 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp @@ -1367,26 +1367,24 @@ bool plResManager::VerifyPages() // Given an array of pages that are invalid (major version out-of-date or // whatnot), asks the user what we should do about them. -static void ICatPageNames(std::vector& pages, char* buf, int bufSize) +static ST::string ICatPageNames(std::vector& pages, const ST::string& msg) { + ST::string_stream ss; + ss << msg; + for (size_t i = 0; i < pages.size(); i++) { if (i >= 25) { - strcat(buf, "...\n"); + ss << ST_LITERAL("...\n"); break; } ST::string pageFile = pages[i]->GetPagePath().GetFileName(); - if (strlen(buf) + pageFile.size() > bufSize - 5) - { - strcat(buf, "...\n"); - break; - } - - strcat(buf, pageFile.c_str()); - strcat(buf, "\n"); + ss << pageFile << '\n'; } + + return ss.to_string(); } bool plResManager::IDeleteBadPages(std::vector& invalidPages, bool conflictingSeqNums) @@ -1394,19 +1392,19 @@ bool plResManager::IDeleteBadPages(std::vector& invalidPage #ifndef PLASMA_EXTERNAL_RELEASE if (!hsMessageBox_SuppressPrompts) { - char msg[4096]; + ST::string msg; // Prompt what to do if (conflictingSeqNums) - strcpy(msg, "The following pages have conflicting sequence numbers. This usually happens when " - "you copy data files between machines that had random sequence numbers assigned at " - "export. To avoid crashing, these pages will be deleted:\n\n"); + msg = ST_LITERAL("The following pages have conflicting sequence numbers. This usually happens when " + "you copy data files between machines that had random sequence numbers assigned at " + "export. To avoid crashing, these pages will be deleted:\n\n"); else - strcpy(msg, "The following pages are out of date and will be deleted:\n\n"); + msg = ST_LITERAL("The following pages are out of date and will be deleted:\n\n"); - ICatPageNames(invalidPages, msg, sizeof(msg)); + msg = ICatPageNames(invalidPages, msg); - hsMessageBox(msg, "Warning", hsMessageBoxNormal); + hsMessageBox(msg, ST_LITERAL("Warning"), hsMessageBoxNormal); } #endif // PLASMA_EXTERNAL_RELEASE @@ -1433,14 +1431,13 @@ bool plResManager::IWarnNewerPages(std::vector &newerPages) #ifndef PLASMA_EXTERNAL_RELEASE if (!hsMessageBox_SuppressPrompts) { - char msg[4096]; // Prompt what to do - strcpy(msg, "The following pages have newer version numbers than this client and cannot be \nloaded. " - "They will be ignored but their files will NOT be deleted:\n\n"); + ST::string msg = ST_LITERAL("The following pages have newer version numbers than this client and cannot be \nloaded. " + "They will be ignored but their files will NOT be deleted:\n\n"); - ICatPageNames(newerPages, msg, sizeof(msg)); + msg = ICatPageNames(newerPages, msg); - hsMessageBox(msg, "Warning", hsMessageBoxNormal); + hsMessageBox(msg, ST_LITERAL("Warning"), hsMessageBoxNormal); } #endif // PLASMA_EXTERNAL_RELEASE