Add UpdateCallback to AchievementManager
AchievementManager now has a SetUpdateCallback method for providing a single universal callback for anytime something important changes in the achievement state, such as logging in/out, game load/close, or events such as achievement unlocks. AchievementsWindow sets this callback in its own init to its UpdateData method so that the AchievementsWindow gets updated when one of these changes takes place.
This commit is contained in:
parent
582042de1f
commit
fbaeaf305b
|
@ -38,11 +38,20 @@ void AchievementManager::Init()
|
|||
}
|
||||
}
|
||||
|
||||
void AchievementManager::SetUpdateCallback(UpdateCallback callback)
|
||||
{
|
||||
m_update_callback = std::move(callback);
|
||||
m_update_callback();
|
||||
}
|
||||
|
||||
AchievementManager::ResponseType AchievementManager::Login(const std::string& password)
|
||||
{
|
||||
if (!m_is_runtime_initialized)
|
||||
return AchievementManager::ResponseType::MANAGER_NOT_INITIALIZED;
|
||||
return VerifyCredentials(password);
|
||||
AchievementManager::ResponseType r_type = VerifyCredentials(password);
|
||||
if (m_update_callback)
|
||||
m_update_callback();
|
||||
return r_type;
|
||||
}
|
||||
|
||||
void AchievementManager::LoginAsync(const std::string& password, const ResponseCallback& callback)
|
||||
|
@ -52,7 +61,11 @@ void AchievementManager::LoginAsync(const std::string& password, const ResponseC
|
|||
callback(AchievementManager::ResponseType::MANAGER_NOT_INITIALIZED);
|
||||
return;
|
||||
}
|
||||
m_queue.EmplaceItem([this, password, callback] { callback(VerifyCredentials(password)); });
|
||||
m_queue.EmplaceItem([this, password, callback] {
|
||||
callback(VerifyCredentials(password));
|
||||
if (m_update_callback)
|
||||
m_update_callback();
|
||||
});
|
||||
}
|
||||
|
||||
bool AchievementManager::IsLoggedIn() const
|
||||
|
@ -179,6 +192,8 @@ void AchievementManager::LoadGameByFilenameAsync(const std::string& iso_path,
|
|||
// Reset this to zero so that RP immediately triggers on the first frame
|
||||
m_last_ping_time = 0;
|
||||
|
||||
if (m_update_callback)
|
||||
m_update_callback();
|
||||
callback(fetch_game_data_response);
|
||||
});
|
||||
}
|
||||
|
@ -199,6 +214,8 @@ void AchievementManager::LoadUnlockData(const ResponseCallback& callback)
|
|||
}
|
||||
|
||||
callback(FetchUnlockData(false));
|
||||
if (m_update_callback)
|
||||
m_update_callback();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -316,6 +333,8 @@ void AchievementManager::AchievementEventHandler(const rc_runtime_event_t* runti
|
|||
HandleLeaderboardTriggeredEvent(runtime_event);
|
||||
break;
|
||||
}
|
||||
if (m_update_callback)
|
||||
m_update_callback();
|
||||
}
|
||||
|
||||
std::string AchievementManager::GetPlayerDisplayName() const
|
||||
|
@ -386,12 +405,16 @@ void AchievementManager::CloseGame()
|
|||
ActivateDeactivateAchievements();
|
||||
ActivateDeactivateLeaderboards();
|
||||
ActivateDeactivateRichPresence();
|
||||
if (m_update_callback)
|
||||
m_update_callback();
|
||||
}
|
||||
|
||||
void AchievementManager::Logout()
|
||||
{
|
||||
CloseGame();
|
||||
Config::SetBaseOrCurrent(Config::RA_API_TOKEN, "");
|
||||
if (m_update_callback)
|
||||
m_update_callback();
|
||||
}
|
||||
|
||||
void AchievementManager::Shutdown()
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
UNKNOWN_FAILURE
|
||||
};
|
||||
using ResponseCallback = std::function<void(ResponseType)>;
|
||||
using UpdateCallback = std::function<void()>;
|
||||
|
||||
struct PointSpread
|
||||
{
|
||||
|
@ -67,6 +68,7 @@ public:
|
|||
|
||||
static AchievementManager* GetInstance();
|
||||
void Init();
|
||||
void SetUpdateCallback(UpdateCallback callback);
|
||||
ResponseType Login(const std::string& password);
|
||||
void LoginAsync(const std::string& password, const ResponseCallback& callback);
|
||||
bool IsLoggedIn() const;
|
||||
|
@ -125,6 +127,7 @@ private:
|
|||
rc_runtime_t m_runtime{};
|
||||
Core::System* m_system{};
|
||||
bool m_is_runtime_initialized = false;
|
||||
UpdateCallback m_update_callback;
|
||||
std::string m_display_name;
|
||||
u32 m_player_score = 0;
|
||||
std::array<char, HASH_LENGTH> m_game_hash{};
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "DolphinQt/Achievements/AchievementHeaderWidget.h"
|
||||
#include "DolphinQt/Achievements/AchievementProgressWidget.h"
|
||||
#include "DolphinQt/Achievements/AchievementSettingsWidget.h"
|
||||
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
||||
#include "DolphinQt/QtUtils/WrapInScrollArea.h"
|
||||
|
||||
AchievementsWindow::AchievementsWindow(QWidget* parent) : QDialog(parent)
|
||||
|
@ -20,6 +21,8 @@ AchievementsWindow::AchievementsWindow(QWidget* parent) : QDialog(parent)
|
|||
|
||||
CreateMainLayout();
|
||||
ConnectWidgets();
|
||||
AchievementManager::GetInstance()->SetUpdateCallback(
|
||||
[this] { QueueOnObject(this, &AchievementsWindow::UpdateData); });
|
||||
}
|
||||
|
||||
void AchievementsWindow::showEvent(QShowEvent* event)
|
||||
|
|
|
@ -7,11 +7,13 @@
|
|||
#include <QDialog>
|
||||
|
||||
#include "Core/AchievementManager.h"
|
||||
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
||||
|
||||
class AchievementHeaderWidget;
|
||||
class AchievementProgressWidget;
|
||||
class QTabWidget;
|
||||
class QDialogButtonBox;
|
||||
class QTabWidget;
|
||||
class UpdateCallback;
|
||||
|
||||
class AchievementsWindow : public QDialog
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue