diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 84a4709e7..40f83ce40 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -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; diff --git a/src/core/host_interface.h b/src/core/host_interface.h index 1f93aa046..41cf708d4 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -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); diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 971042797..29be72d35 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -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); diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 47c3594a5..2c19072fe 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -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); diff --git a/src/duckstation-qt/qthostinterface.cpp b/src/duckstation-qt/qthostinterface.cpp index ad2a40ca3..896e0fe1c 100644 --- a/src/duckstation-qt/qthostinterface.cpp +++ b/src/duckstation-qt/qthostinterface.cpp @@ -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(); }); diff --git a/src/duckstation-qt/qthostinterface.h b/src/duckstation-qt/qthostinterface.h index 0d765122c..765c34286 100644 --- a/src/duckstation-qt/qthostinterface.h +++ b/src/duckstation-qt/qthostinterface.h @@ -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); diff --git a/src/duckstation-sdl/sdl_host_interface.cpp b/src/duckstation-sdl/sdl_host_interface.cpp index 5985cfcf5..2fe2a03ef 100644 --- a/src/duckstation-sdl/sdl_host_interface.cpp +++ b/src/duckstation-sdl/sdl_host_interface.cpp @@ -259,7 +259,7 @@ std::unique_ptr 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); diff --git a/src/duckstation-sdl/sdl_host_interface.h b/src/duckstation-sdl/sdl_host_interface.h index 815893983..6219f138d 100644 --- a/src/duckstation-sdl/sdl_host_interface.h +++ b/src/duckstation-sdl/sdl_host_interface.h @@ -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();