From a5ec31ffef4945122e53815dbe052d548bbc094f Mon Sep 17 00:00:00 2001 From: Rosalie Wanders Date: Fri, 24 Feb 2023 21:37:24 +0100 Subject: [PATCH] RMG: hook up state callback --- Source/RMG/Callbacks.cpp | 13 ++++++++++++- Source/RMG/Callbacks.hpp | 2 ++ Source/RMG/UserInterface/MainWindow.cpp | 19 +++++++++++++++++++ Source/RMG/UserInterface/MainWindow.hpp | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Source/RMG/Callbacks.cpp b/Source/RMG/Callbacks.cpp index 27379cd3..b28bd67c 100644 --- a/Source/RMG/Callbacks.cpp +++ b/Source/RMG/Callbacks.cpp @@ -36,11 +36,12 @@ bool CoreCallbacks::Init(void) { // needed for Qt qRegisterMetaType("CoreDebugMessageType"); + qRegisterMetaType("CoreStateCallbackType"); this->LoadSettings(); l_CoreCallbacks = this; - return CoreSetupCallbacks(this->coreDebugCallback); + return CoreSetupCallbacks(this->coreDebugCallback, this->coreStateCallback); } void CoreCallbacks::Stop(void) @@ -78,3 +79,13 @@ void CoreCallbacks::coreDebugCallback(CoreDebugMessageType type, std::string con emit l_CoreCallbacks->OnCoreDebugCallback(type, QString::fromStdString(context), QString::fromStdString(message)); } + +void CoreCallbacks::coreStateCallback(CoreStateCallbackType type, int value) +{ + if (l_CoreCallbacks == nullptr) + { + return; + } + + emit l_CoreCallbacks->OnCoreStateCallback(type, value); +} diff --git a/Source/RMG/Callbacks.hpp b/Source/RMG/Callbacks.hpp index 5ab0f58b..74b42ddf 100644 --- a/Source/RMG/Callbacks.hpp +++ b/Source/RMG/Callbacks.hpp @@ -31,9 +31,11 @@ public: private: static void coreDebugCallback(CoreDebugMessageType type, std::string context, std::string message); + static void coreStateCallback(CoreStateCallbackType type, int value); signals: void OnCoreDebugCallback(CoreDebugMessageType type, QString context, QString message); + void OnCoreStateCallback(CoreStateCallbackType type, int value); }; #endif // RMG_CALLBACKS_HPP diff --git a/Source/RMG/UserInterface/MainWindow.cpp b/Source/RMG/UserInterface/MainWindow.cpp index e71bb55a..54ddf2fa 100644 --- a/Source/RMG/UserInterface/MainWindow.cpp +++ b/Source/RMG/UserInterface/MainWindow.cpp @@ -94,6 +94,7 @@ bool MainWindow::Init(QApplication* app, bool showUI) connect(coreCallBacks, &CoreCallbacks::OnCoreDebugCallback, this, &MainWindow::on_Core_DebugCallback); connect(coreCallBacks, &CoreCallbacks::OnCoreDebugCallback, &this->logDialog, &Dialog::LogDialog::AddLogLine); + connect(coreCallBacks, &CoreCallbacks::OnCoreStateCallback, this, &MainWindow::on_Core_StateCallback); connect(app, &QGuiApplication::applicationStateChanged, this, &MainWindow::on_QGuiApplication_applicationStateChanged); return true; @@ -2019,3 +2020,21 @@ void MainWindow::on_Core_DebugCallback(CoreDebugMessageType type, QString contex } this->ui_TimerId = this->startTimer(this->ui_TimerTimeout * 1000); } + +void MainWindow::on_Core_StateCallback(CoreStateCallbackType type, int value) +{ + if (type == CoreStateCallbackType::SaveStateLoaded) + { + if (value == 0) + { + OnScreenDisplaySetMessage("Failed to load save state."); + } + } + else if (type == CoreStateCallbackType::SaveStateSaved) + { + if (value == 0) + { + OnScreenDisplaySetMessage("Failed to save state."); + } + } +} diff --git a/Source/RMG/UserInterface/MainWindow.hpp b/Source/RMG/UserInterface/MainWindow.hpp index dc052f25..08e559aa 100644 --- a/Source/RMG/UserInterface/MainWindow.hpp +++ b/Source/RMG/UserInterface/MainWindow.hpp @@ -198,6 +198,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow void on_VidExt_ToggleFS(bool fullscreen); void on_Core_DebugCallback(CoreDebugMessageType type, QString context, QString message); + void on_Core_StateCallback(CoreStateCallbackType type, int value); }; } // namespace UserInterface