HostInterface: Add a ConfirmMessage() method
This commit is contained in:
parent
8ffdcf1b7e
commit
e9dea6e0f7
|
@ -160,6 +160,12 @@ void HostInterface::ReportMessage(const char* message)
|
|||
Log_InfoPrintf(message);
|
||||
}
|
||||
|
||||
bool HostInterface::ConfirmMessage(const char* message)
|
||||
{
|
||||
Log_WarningPrintf("ConfirmMessage(\"%s\") -> Yes");
|
||||
return true;
|
||||
}
|
||||
|
||||
void HostInterface::ReportFormattedError(const char* format, ...)
|
||||
{
|
||||
std::va_list ap;
|
||||
|
@ -180,6 +186,16 @@ void HostInterface::ReportFormattedMessage(const char* format, ...)
|
|||
ReportMessage(message.c_str());
|
||||
}
|
||||
|
||||
bool HostInterface::ConfirmFormattedMessage(const char* format, ...)
|
||||
{
|
||||
std::va_list ap;
|
||||
va_start(ap, format);
|
||||
std::string message = StringUtil::StdStringFromFormatV(format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ConfirmMessage(message.c_str());
|
||||
}
|
||||
|
||||
void HostInterface::DrawFPSWindow()
|
||||
{
|
||||
const bool show_fps = true;
|
||||
|
|
|
@ -68,9 +68,11 @@ public:
|
|||
|
||||
virtual void ReportError(const char* message);
|
||||
virtual void ReportMessage(const char* message);
|
||||
virtual bool ConfirmMessage(const char* message);
|
||||
|
||||
void ReportFormattedError(const char* format, ...);
|
||||
void ReportFormattedMessage(const char* format, ...);
|
||||
bool ConfirmFormattedMessage(const char* format, ...);
|
||||
|
||||
/// Adds OSD messages, duration is in seconds.
|
||||
void AddOSDMessage(const char* message, float duration = 2.0f);
|
||||
|
|
|
@ -35,7 +35,7 @@ MainWindow::~MainWindow()
|
|||
|
||||
void MainWindow::reportError(const QString& message)
|
||||
{
|
||||
QMessageBox::critical(nullptr, tr("DuckStation Error"), message, QMessageBox::Ok);
|
||||
QMessageBox::critical(this, tr("DuckStation"), message, QMessageBox::Ok);
|
||||
}
|
||||
|
||||
void MainWindow::reportMessage(const QString& message)
|
||||
|
@ -43,6 +43,11 @@ void MainWindow::reportMessage(const QString& message)
|
|||
m_ui.statusBar->showMessage(message, 2000);
|
||||
}
|
||||
|
||||
bool MainWindow::confirmMessage(const QString& message)
|
||||
{
|
||||
return (QMessageBox::question(this, tr("DuckStation"), message) == QMessageBox::Yes);
|
||||
}
|
||||
|
||||
void MainWindow::createDisplayWindow(QThread* worker_thread, bool use_debug_device)
|
||||
{
|
||||
DebugAssert(!m_display_widget);
|
||||
|
@ -336,12 +341,14 @@ void MainWindow::connectSignals()
|
|||
|
||||
connect(m_host_interface, &QtHostInterface::errorReported, this, &MainWindow::reportError,
|
||||
Qt::BlockingQueuedConnection);
|
||||
connect(m_host_interface, &QtHostInterface::messageReported, this, &MainWindow::reportMessage);
|
||||
connect(m_host_interface, &QtHostInterface::messageConfirmed, this, &MainWindow::confirmMessage,
|
||||
Qt::BlockingQueuedConnection);
|
||||
connect(m_host_interface, &QtHostInterface::createDisplayWindowRequested, this, &MainWindow::createDisplayWindow,
|
||||
Qt::BlockingQueuedConnection);
|
||||
connect(m_host_interface, &QtHostInterface::destroyDisplayWindowRequested, this, &MainWindow::destroyDisplayWindow);
|
||||
connect(m_host_interface, &QtHostInterface::setFullscreenRequested, this, &MainWindow::setFullscreen);
|
||||
connect(m_host_interface, &QtHostInterface::toggleFullscreenRequested, this, &MainWindow::toggleFullscreen);
|
||||
connect(m_host_interface, &QtHostInterface::messageReported, this, &MainWindow::reportMessage);
|
||||
connect(m_host_interface, &QtHostInterface::emulationStarted, this, &MainWindow::onEmulationStarted);
|
||||
connect(m_host_interface, &QtHostInterface::emulationStopped, this, &MainWindow::onEmulationStopped);
|
||||
connect(m_host_interface, &QtHostInterface::emulationPaused, this, &MainWindow::onEmulationPaused);
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
private Q_SLOTS:
|
||||
void reportError(const QString& message);
|
||||
void reportMessage(const QString& message);
|
||||
bool confirmMessage(const QString& message);
|
||||
void createDisplayWindow(QThread* worker_thread, bool use_debug_device);
|
||||
void destroyDisplayWindow();
|
||||
void setFullscreen(bool fullscreen);
|
||||
|
|
|
@ -54,6 +54,11 @@ void QtHostInterface::ReportMessage(const char* message)
|
|||
emit messageReported(QString::fromLocal8Bit(message));
|
||||
}
|
||||
|
||||
bool QtHostInterface::ConfirmMessage(const char* message)
|
||||
{
|
||||
return messageConfirmed(QString::fromLocal8Bit(message));
|
||||
}
|
||||
|
||||
void QtHostInterface::setDefaultSettings()
|
||||
{
|
||||
HostInterface::UpdateSettings([this]() { HostInterface::SetDefaultSettings(); });
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
|
||||
void ReportError(const char* message) override;
|
||||
void ReportMessage(const char* message) override;
|
||||
bool ConfirmMessage(const char* message) override;
|
||||
|
||||
void setDefaultSettings();
|
||||
|
||||
|
@ -64,6 +65,7 @@ public:
|
|||
Q_SIGNALS:
|
||||
void errorReported(const QString& message);
|
||||
void messageReported(const QString& message);
|
||||
bool messageConfirmed(const QString& message);
|
||||
void emulationStarted();
|
||||
void emulationStopped();
|
||||
void emulationPaused(bool paused);
|
||||
|
|
|
@ -259,7 +259,7 @@ std::unique_ptr<SDLHostInterface> SDLHostInterface::Create()
|
|||
|
||||
void SDLHostInterface::ReportError(const char* message)
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "DuckStation Error", message, m_window);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "DuckStation", message, m_window);
|
||||
}
|
||||
|
||||
void SDLHostInterface::ReportMessage(const char* message)
|
||||
|
@ -267,6 +267,31 @@ void SDLHostInterface::ReportMessage(const char* message)
|
|||
AddOSDMessage(message, 2.0f);
|
||||
}
|
||||
|
||||
bool SDLHostInterface::ConfirmMessage(const char* message)
|
||||
{
|
||||
SDL_MessageBoxData mbd = {};
|
||||
mbd.flags = SDL_MESSAGEBOX_INFORMATION;
|
||||
mbd.window = m_window;
|
||||
mbd.title = "DuckStation";
|
||||
mbd.message = message;
|
||||
mbd.numbuttons = 2;
|
||||
|
||||
// Why the heck these are reversed I have no idea...
|
||||
SDL_MessageBoxButtonData buttons[2] = {};
|
||||
buttons[1].flags = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
|
||||
buttons[1].buttonid = 0;
|
||||
buttons[1].text = "Yes";
|
||||
buttons[0].flags = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
|
||||
buttons[0].buttonid = 1;
|
||||
buttons[0].text = "No";
|
||||
mbd.buttons = buttons;
|
||||
mbd.numbuttons = countof(buttons);
|
||||
|
||||
int button_id = 0;
|
||||
SDL_ShowMessageBox(&mbd, &button_id);
|
||||
return (button_id == 0);
|
||||
}
|
||||
|
||||
void SDLHostInterface::HandleSDLEvent(const SDL_Event* event)
|
||||
{
|
||||
ImGui_ImplSDL2_ProcessEvent(event);
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
|
||||
void ReportError(const char* message) override;
|
||||
void ReportMessage(const char* message) override;
|
||||
bool ConfirmMessage(const char* message) override;
|
||||
|
||||
void Run();
|
||||
|
||||
|
|
Loading…
Reference in New Issue