From be8d5288ee6b3d580d6227804e1c24d1f1218cd3 Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Sat, 11 May 2013 11:53:21 +0000 Subject: [PATCH] - add platform independent message dialog; --- desmume/src/common.cpp | 39 ++++++++++++++++++++++++++++++ desmume/src/common.h | 14 +++++++++++ desmume/src/mc.cpp | 5 +--- desmume/src/saves.cpp | 6 +---- desmume/src/windows/main.cpp | 47 ++++++++++++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 9 deletions(-) diff --git a/desmume/src/common.cpp b/desmume/src/common.cpp index f758a7916..28bcdd6f7 100644 --- a/desmume/src/common.cpp +++ b/desmume/src/common.cpp @@ -52,3 +52,42 @@ char *removeSpecialChars(char *s) *buf = 0; return s; } + +// =============================================================================== +// Message dialogs +// =============================================================================== +#define MSG_PRINT { \ + va_list args; \ + va_start (args, fmt); \ + vprintf (fmt, args); \ + va_end (args); \ +} +void msgFakeInfo(const char *fmt, ...) +{ + MSG_PRINT; +} + +bool msgFakeConfirm(const char *fmt, ...) +{ + MSG_PRINT; + return true; +} + +void msgFakeError(const char *fmt, ...) +{ + MSG_PRINT; +} + +void msgFakeWarn(const char *fmt, ...) +{ + MSG_PRINT; +} + +msgBoxInterface msgBoxFake = { + msgFakeInfo, + msgFakeConfirm, + msgFakeError, + msgFakeWarn, +}; + +msgBoxInterface *msgbox = &msgBoxFake; diff --git a/desmume/src/common.h b/desmume/src/common.h index b8e564ea5..99d32b56e 100644 --- a/desmume/src/common.h +++ b/desmume/src/common.h @@ -82,5 +82,19 @@ char *intToBin(T val) extern char *trim(char *s, int len=-1); extern char *removeSpecialChars(char *s); +// =============================================================================== +// Message dialogs +// =============================================================================== +#define CALL_CONVENTION +typedef struct +{ + void (CALL_CONVENTION* info) (const char *fmt, ...); + bool (CALL_CONVENTION* confirm)(const char *fmt, ...); + void (CALL_CONVENTION* error) (const char *fmt, ...); + void (CALL_CONVENTION* warn) (const char *fmt, ...); +} msgBoxInterface; + +extern msgBoxInterface *msgbox; + #endif diff --git a/desmume/src/mc.cpp b/desmume/src/mc.cpp index 6e525046b..97564f1ed 100644 --- a/desmume/src/mc.cpp +++ b/desmume/src/mc.cpp @@ -460,10 +460,7 @@ void BackupDevice::reset_command() { case 0: case 1: - printf("Catastrophic error while autodetecting save type.\nIt will need to be specified manually\n"); - #ifdef _WINDOWS - MessageBox(0,"Catastrophic Error Code: Camel;\nyour save type has not been autodetected correctly;\nplease report to developers",0,0); - #endif + msgbox->error("Catastrophic error while autodetecting save type.\nIt will need to be specified manually\n"); addr_size = 1; //choose 1 just to keep the busted savefile from growing too big break; case 2: diff --git a/desmume/src/saves.cpp b/desmume/src/saves.cpp index 674b628ea..b6a50fa45 100644 --- a/desmume/src/saves.cpp +++ b/desmume/src/saves.cpp @@ -1107,11 +1107,7 @@ bool savestate_load(EMUFILE* is) if(!x && !SAV_silent_fail_flag) { - printf("Error loading savestate. It failed halfway through;\nSince there is no savestate backup system, your current game session is wrecked"); -#ifdef _WINDOWS - //HACK! we really need a better way to handle this kind of feedback - MessageBox(0,"Error loading savestate. It failed halfway through;\nSince there is no savestate backup system, your current game session is wrecked",0,0); -#endif + msgbox->error("Error loading savestate. It failed halfway through;\nSince there is no savestate backup system, your current game session is wrecked"); return false; } diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index a12bfbdad..460df66d9 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -240,6 +240,51 @@ using namespace std; +//====================== Message box +#define MSG_ARG \ + char msg_buf[1024] = {0}; \ + { \ + va_list args; \ + va_start (args, fmt); \ + vsprintf (msg_buf, fmt, args); \ + va_end (args); \ + } +void msgWndInfo(const char *fmt, ...) +{ + MSG_ARG; + printf("Info: %s\n", msg_buf); + MessageBox(MainWindow->getHWnd(), msg_buf, EMU_DESMUME_NAME_AND_VERSION(), MB_OK | MB_ICONINFORMATION); +} + +bool msgWndConfirm(const char *fmt, ...) +{ + MSG_ARG; + printf("Confirm: %s\n", msg_buf); + return (MessageBox(MainWindow->getHWnd(), msg_buf, EMU_DESMUME_NAME_AND_VERSION(), MB_YESNO | MB_ICONQUESTION) == IDYES); +} + +void msgWndError(const char *fmt, ...) +{ + MSG_ARG; + printf("Error: %s\n", msg_buf); + MessageBox(MainWindow->getHWnd(), msg_buf, EMU_DESMUME_NAME_AND_VERSION(), MB_OK | MB_ICONERROR); +} + +void msgWndWarn(const char *fmt, ...) +{ + MSG_ARG; + printf("Warning: %s\n", msg_buf); + MessageBox(MainWindow->getHWnd(), msg_buf, EMU_DESMUME_NAME_AND_VERSION(), MB_YESNO | MB_ICONWARNING); +} + +msgBoxInterface msgBoxWnd = { + msgWndInfo, + msgWndConfirm, + msgWndError, + msgWndWarn, +}; +//====================== Dialogs end + #ifdef EXPERIMENTAL_WIFI_COMM bool bSocketsAvailable = false; @@ -2846,6 +2891,8 @@ int _main() GetSystemInfo(&systemInfo); CommonSettings.num_cores = systemInfo.dwNumberOfProcessors; + msgbox = &msgBoxWnd; + char text[80]; path.ReadPathSettings();