Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hsMessageBox Cleanups #1466

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/Plasma/Apps/plClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ target_link_libraries(
plGLight
plInputCore
plMessage
plMessageBox
plModifier
plNetClient
plNetCommon
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -304,8 +305,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];
}

Expand Down
7 changes: 4 additions & 3 deletions Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#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"
Expand Down Expand Up @@ -442,7 +443,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;
}

Expand Down Expand Up @@ -490,9 +491,9 @@ 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 );
hsMessageBox(ST::string(pipe->GetErrorString()), ST_LITERAL("Error creating pipeline"), hsMessageBoxNormal);
#endif
delete pipe;
devSel.GetDefault(&dmr);
Expand Down
3 changes: 2 additions & 1 deletion Sources/Plasma/Apps/plClient/plClientLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "plPipeline.h"

#include "plClientResMgr/plClientResMgr.h"
#include "plMessageBox/hsMessageBox.h"
#include "plNetClient/plNetClientMgr.h"
#include "plPhysX/plSimulationMgr.h"
#include "plResMgr/plResManager.h"
Expand All @@ -57,7 +58,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");
Expand Down
9 changes: 5 additions & 4 deletions Sources/Plasma/Apps/plClient/win32/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#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"
Expand Down Expand Up @@ -1132,7 +1133,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 );
Expand Down Expand Up @@ -1186,7 +1187,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
Expand All @@ -1204,13 +1205,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;
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/Apps/plCrashHandler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target_link_libraries(
PRIVATE
CoreLib
plClipboard
plMessageBox
pfCrashHandler

$<$<PLATFORM_ID:Windows>:Comctl32>
Expand Down
3 changes: 2 additions & 1 deletion Sources/Plasma/Apps/plCrashHandler/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "resource.h"

#include "plClipboard/plClipboard.h"
#include "plMessageBox/hsMessageBox.h"

#include "pfCrashHandler/plCrashSrv.h"

Expand Down Expand Up @@ -380,7 +381,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;
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ target_link_libraries(
CoreLib
pnAsyncCore
pnNetBase
plMessageBox
plNetGameLib
plStatusLog
plWinDpi
Expand Down
5 changes: 3 additions & 2 deletions Sources/Plasma/Apps/plUruLauncher/plClientLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Mead, WA 99021

#include "pnAsyncCore/pnAsyncCore.h"

#include "plMessageBox/hsMessageBox.h"
#include "plNetGameLib/plNetGameLib.h"
#include "plStatusLog/plStatusLog.h"

Expand Down Expand Up @@ -327,11 +328,11 @@ bool plClientLauncher::CompleteSelfPatch(const std::function<void()>& 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;
}

Expand Down
2 changes: 0 additions & 2 deletions Sources/Plasma/CoreLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ set(CoreLib_SOURCES
plProduct.cpp
plViewTransform.cpp
hsWindows.cpp
$<$<PLATFORM_ID:Darwin>:HeadSpin_Mac.mm>
)

if(CMAKE_USE_WIN32_THREADS_INIT)
Expand Down Expand Up @@ -84,7 +83,6 @@ target_link_libraries(
"$<$<PLATFORM_ID:Darwin>:-framework Accelerate>"
PRIVATE
"$<$<PLATFORM_ID:Darwin>:-framework CoreFoundation>"
"$<$<PLATFORM_ID:Darwin>:-framework Cocoa>"
)
target_include_directories(
CoreLib
Expand Down
145 changes: 0 additions & 145 deletions Sources/Plasma/CoreLib/HeadSpin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,151 +273,6 @@ 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 (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
return hsMBoxCancel;
}

int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t* message, const wchar_t* 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);

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
return hsMBoxCancel;
}
#endif

int hsMessageBox(const char* message, const char* caption, int kind, int icon)
{
return hsMessageBoxWithOwner(nullptr, message, caption, kind, icon);
}

int hsMessageBox(const wchar_t* message, const wchar_t* caption, int kind, int icon)
{
return hsMessageBoxWithOwner(nullptr, message, caption, kind, icon);
}

/**************************************/
char* hsStrcpy(char* dst, const char* src)
{
Expand Down
32 changes: 0 additions & 32 deletions Sources/Plasma/CoreLib/HeadSpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,38 +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 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 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) )
Expand Down
Loading