diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 47c8108c0..dad85837a 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -5,6 +5,10 @@ void D_DoAnonStats() { } +void D_ConfirmSendStats() +{ +} + #else // !NO_SEND_STATS #if defined(_WIN32) @@ -14,6 +18,11 @@ void D_DoAnonStats() #include extern int sys_ostype; #else +#ifdef __APPLE__ +#include +#else // !__APPLE__ +#include +#endif // __APPLE__ #include #include #include @@ -298,6 +307,57 @@ void D_DoAnonStats() t1.detach(); } +void D_ConfirmSendStats() +{ + if (sys_statsenabled >= 0) + { + return; + } + + // TODO: texts + static const char *const MESSAGE_TEXT = "send stats?"; + static const char *const TITLE_TEXT = GAMENAME; + + UCVarValue enabled = { 0 }; + +#ifdef _WIN32 + extern HWND Window; + enabled.Int = MessageBox(Window, MESSAGE_TEXT, TITLE_TEXT, MB_ICONQUESTION | MB_YESNO) == IDYES; +#elif defined __APPLE__ + const CFStringRef messageString = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, MESSAGE_TEXT, kCFStringEncodingASCII, kCFAllocatorNull); + const CFStringRef titleString = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, TITLE_TEXT, kCFStringEncodingASCII, kCFAllocatorNull); + if (messageString != nullptr && titleString != nullptr) + { + CFOptionFlags response; + const SInt32 result = CFUserNotificationDisplayAlert(0, kCFUserNotificationNoteAlertLevel, nullptr, nullptr, nullptr, + titleString, messageString, CFSTR("Yes"), CFSTR("No"), nullptr, &response); + enabled.Int = result == 0 && (response & 3) == kCFUserNotificationDefaultResponse; + CFRelease(titleString); + CFRelease(messageString); + } +#else // !__APPLE__ + const SDL_MessageBoxButtonData buttons[] = + { + { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Yes" }, + { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 1, "No" }, + }; + const SDL_MessageBoxData messageboxdata = + { + SDL_MESSAGEBOX_INFORMATION, + nullptr, + TITLE_TEXT, + MESSAGE_TEXT, + SDL_arraysize(buttons), + buttons, + nullptr + }; + int buttonid; + enabled.Int = SDL_ShowMessageBox(&messageboxdata, &buttonid) == 0 && buttonid == 0; +#endif // _WIN32 + + sys_statsenabled.ForceSet(enabled, CVAR_Int); +} + #endif // NO_SEND_STATS void D_ConfirmSendStats()