project64/Source/Project64/UserInterface/Notification.cpp

311 lines
6.9 KiB
C++
Raw Normal View History

2016-01-27 09:11:59 +00:00
#include "stdafx.h"
2022-09-21 05:16:07 +00:00
2016-01-27 09:11:59 +00:00
#include <time.h>
CNotificationImp & Notify(void)
{
2016-11-27 20:34:02 +00:00
static CNotificationImp Notify;
return Notify;
2016-01-27 09:11:59 +00:00
}
CNotificationImp::CNotificationImp() :
2021-04-12 11:35:39 +00:00
m_hWnd(nullptr),
m_gfxPlugin(nullptr),
m_NextMsg(0)
2016-01-27 09:11:59 +00:00
{
_tzset();
}
void CNotificationImp::AppInitDone(void)
{
RegisterUISettings();
2016-01-27 09:11:59 +00:00
CNotificationSettings::RegisterNotifications();
}
void CNotificationImp::SetMainWindow(CMainGui * Gui)
{
m_hWnd = Gui;
}
void CNotificationImp::WindowMode(void) const
{
static bool InsideFunc = false;
if (InsideFunc)
{
return;
}
InsideFunc = true;
if (InFullScreen())
{
ChangeFullScreen();
for (int i = 0; i < 5; i++)
{
Sleep(50);
if (ProcessGuiMessages())
{
break;
}
}
}
InsideFunc = false;
}
void CNotificationImp::DisplayWarning(const char * Message) const
{
2021-04-12 11:35:39 +00:00
HWND Parent = nullptr;
if (m_hWnd)
{
Parent = reinterpret_cast<HWND>(m_hWnd->GetWindowHandle());
}
MessageBox(Parent, stdstr(Message).ToUTF16().c_str(), wGS(MSG_MSGBOX_WARNING_TITLE).c_str(), MB_OK | MB_ICONWARNING | MB_SETFOREGROUND);
}
void CNotificationImp::DisplayWarning(LanguageStringID StringID) const
{
DisplayWarning(g_Lang->GetString(StringID).c_str());
}
2016-01-27 09:11:59 +00:00
void CNotificationImp::DisplayError(LanguageStringID StringID) const
{
DisplayError(g_Lang->GetString(StringID).c_str());
}
void CNotificationImp::DisplayError(const char * Message) const
{
WriteTrace(TraceUserInterface, TraceError, Message);
WindowMode();
2021-04-12 11:35:39 +00:00
HWND Parent = nullptr;
2016-01-27 09:11:59 +00:00
if (m_hWnd)
{
Parent = reinterpret_cast<HWND>(m_hWnd->GetWindowHandle());
}
MessageBox(Parent, stdstr(Message).ToUTF16().c_str(), wGS(MSG_MSGBOX_ERROR_TITLE).c_str(), MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
2016-01-27 09:11:59 +00:00
}
void CNotificationImp::DisplayMessage(int DisplayTime, LanguageStringID StringID) const
{
DisplayMessage(DisplayTime, g_Lang->GetString(StringID).c_str());
}
void CNotificationImp::DisplayMessage(int DisplayTime, const char * Message) const
{
2022-09-26 02:31:54 +00:00
if (!m_hWnd)
{
return;
}
2016-01-27 09:11:59 +00:00
if (m_NextMsg > 0 || DisplayTime > 0)
{
2021-04-12 11:35:39 +00:00
time_t Now = time(nullptr);
2016-01-27 09:11:59 +00:00
if (DisplayTime == 0 && Now < m_NextMsg)
{
return;
}
if (DisplayTime > 0)
{
m_NextMsg = Now + DisplayTime;
}
if (m_NextMsg == 0)
{
m_NextMsg = 0;
}
}
if (InFullScreen())
{
if (m_gfxPlugin && m_gfxPlugin->DrawStatus)
{
WriteTrace(TraceVideoPlugin, TraceDebug, "DrawStatus - Starting");
2016-01-27 09:11:59 +00:00
m_gfxPlugin->DrawStatus(Message, FALSE);
WriteTrace(TraceVideoPlugin, TraceDebug, "DrawStatus - Done");
2016-01-27 09:11:59 +00:00
}
}
else
{
m_hWnd->SetStatusText(0, stdstr(Message).ToUTF16().c_str());
}
}
void CNotificationImp::DisplayMessage2(const char * Message) const
{
2022-09-26 02:31:54 +00:00
if (!m_hWnd)
{
return;
}
2016-01-27 09:11:59 +00:00
m_hWnd->SetStatusText(1, stdstr(Message).ToUTF16().c_str());
}
bool CNotificationImp::AskYesNoQuestion(const char * Question) const
{
WriteTrace(TraceUserInterface, TraceError, Question);
WindowMode();
2021-04-12 11:35:39 +00:00
HWND Parent = nullptr;
2016-01-27 09:11:59 +00:00
if (m_hWnd)
{
Parent = reinterpret_cast<HWND>(m_hWnd->GetWindowHandle());
}
int result = MessageBox(Parent, stdstr(Question).ToUTF16().c_str(), wGS(MSG_MSGBOX_WARNING_TITLE).c_str(), MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2 | MB_SETFOREGROUND);
2016-01-27 09:11:59 +00:00
return result == IDYES;
}
void CNotificationImp::SetGfxPlugin(CGfxPlugin * Plugin)
{
m_gfxPlugin = Plugin;
}
void CNotificationImp::FatalError(LanguageStringID StringID) const
{
FatalError(g_Lang->GetString(StringID).c_str());
}
2022-09-26 02:31:54 +00:00
void CNotificationImp::FatalError(const char * Message) const
2016-01-27 09:11:59 +00:00
{
WriteTrace(TraceUserInterface, TraceError, Message);
WindowMode();
2021-04-12 11:35:39 +00:00
HWND Parent = nullptr;
2022-09-26 02:31:54 +00:00
if (m_hWnd)
{
Parent = reinterpret_cast<HWND>(m_hWnd->GetWindowHandle());
}
MessageBox(Parent, stdstr(Message).ToUTF16().c_str(), L"Error", MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
2016-01-27 09:11:59 +00:00
ExitThread(0);
}
void CNotificationImp::AddRecentDir(const char * RomDir)
{
// Validate the passed string
2022-09-26 02:31:54 +00:00
if (HIWORD(RomDir) == NULL)
{
return;
}
2016-01-27 09:11:59 +00:00
// Get information about the stored ROM list
size_t MaxRememberedDirs = UISettingsLoadDword(Directory_RecentGameDirCount);
2016-01-27 09:11:59 +00:00
strlist RecentDirs;
size_t i;
for (i = 0; i < MaxRememberedDirs; i++)
{
2023-02-27 23:39:08 +00:00
stdstr RecentDir = UISettingsLoadStringIndex(Directory_RecentGameDirIndex, (int32_t)((UINT_PTR)i));
2016-01-27 09:11:59 +00:00
if (RecentDir.empty())
{
break;
}
RecentDirs.push_back(RecentDir);
}
// See if the directory is already in the list, if so then move it to the top of the list
2016-01-27 09:11:59 +00:00
strlist::iterator iter;
for (iter = RecentDirs.begin(); iter != RecentDirs.end(); iter++)
{
if (_stricmp(RomDir, iter->c_str()) != 0)
{
continue;
}
RecentDirs.erase(iter);
break;
}
RecentDirs.push_front(RomDir);
if (RecentDirs.size() > MaxRememberedDirs)
{
RecentDirs.pop_back();
}
for (i = 0, iter = RecentDirs.begin(); iter != RecentDirs.end(); iter++, i++)
{
2023-02-27 23:39:08 +00:00
UISettingsSaveStringIndex(Directory_RecentGameDirIndex, (int32_t)((UINT_PTR)i), *iter);
2016-01-27 09:11:59 +00:00
}
}
void CNotificationImp::RefreshMenu(void)
{
2022-09-26 02:31:54 +00:00
if (m_hWnd == nullptr)
{
return;
}
2016-01-27 09:11:59 +00:00
m_hWnd->RefreshMenu();
}
void CNotificationImp::HideRomBrowser(void)
{
2022-09-26 02:31:54 +00:00
if (m_hWnd == nullptr)
{
return;
}
2016-01-27 09:11:59 +00:00
m_hWnd->HideRomList();
}
void CNotificationImp::ShowRomBrowser(void)
{
2022-09-26 02:31:54 +00:00
if (m_hWnd == nullptr)
{
return;
}
if (UISettingsLoadBool(RomBrowser_Enabled))
2016-01-27 09:11:59 +00:00
{
// Display the ROM browser
2016-01-27 09:11:59 +00:00
m_hWnd->ShowRomList();
m_hWnd->HighLightLastRom();
}
}
void CNotificationImp::BringToTop(void)
{
2022-09-26 02:31:54 +00:00
if (m_hWnd == nullptr)
{
return;
}
2016-01-27 09:11:59 +00:00
m_hWnd->BringToTop();
}
void CNotificationImp::ChangeFullScreen(void) const
{
2022-09-26 02:31:54 +00:00
if (m_hWnd == nullptr)
{
return;
}
2016-01-27 09:11:59 +00:00
SendMessage((HWND)(m_hWnd->GetWindowHandle()), WM_COMMAND, MAKELPARAM(ID_OPTIONS_FULLSCREEN2, false), 0);
}
bool CNotificationImp::ProcessGuiMessages(void) const
{
2022-09-26 02:31:54 +00:00
if (m_hWnd == nullptr)
{
return false;
}
2016-01-27 09:11:59 +00:00
return m_hWnd->ProcessGuiMessages();
}
void CNotificationImp::BreakPoint(const char * FileName, int LineNumber)
{
if (g_Settings->LoadBool(Debugger_Enabled))
{
DisplayError(stdstr_f("Break point found at\n%s\n%d", FileName, LineNumber).c_str());
if (IsDebuggerPresent() != 0)
{
DebugBreak();
}
else
{
if (g_BaseSystem)
{
g_BaseSystem->CloseCpu();
}
2016-01-27 09:11:59 +00:00
}
}
else
{
DisplayError("Fatal Error: Stopping emulation");
if (g_BaseSystem)
{
g_BaseSystem->CloseCpu();
}
2016-01-27 09:11:59 +00:00
}
}