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)
|
AchievementManager::ResponseType AchievementManager::Login(const std::string& password)
|
||||||
{
|
{
|
||||||
if (!m_is_runtime_initialized)
|
if (!m_is_runtime_initialized)
|
||||||
return AchievementManager::ResponseType::MANAGER_NOT_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)
|
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);
|
callback(AchievementManager::ResponseType::MANAGER_NOT_INITIALIZED);
|
||||||
return;
|
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
|
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
|
// Reset this to zero so that RP immediately triggers on the first frame
|
||||||
m_last_ping_time = 0;
|
m_last_ping_time = 0;
|
||||||
|
|
||||||
|
if (m_update_callback)
|
||||||
|
m_update_callback();
|
||||||
callback(fetch_game_data_response);
|
callback(fetch_game_data_response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -199,6 +214,8 @@ void AchievementManager::LoadUnlockData(const ResponseCallback& callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(FetchUnlockData(false));
|
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);
|
HandleLeaderboardTriggeredEvent(runtime_event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (m_update_callback)
|
||||||
|
m_update_callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AchievementManager::GetPlayerDisplayName() const
|
std::string AchievementManager::GetPlayerDisplayName() const
|
||||||
|
@ -386,12 +405,16 @@ void AchievementManager::CloseGame()
|
||||||
ActivateDeactivateAchievements();
|
ActivateDeactivateAchievements();
|
||||||
ActivateDeactivateLeaderboards();
|
ActivateDeactivateLeaderboards();
|
||||||
ActivateDeactivateRichPresence();
|
ActivateDeactivateRichPresence();
|
||||||
|
if (m_update_callback)
|
||||||
|
m_update_callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AchievementManager::Logout()
|
void AchievementManager::Logout()
|
||||||
{
|
{
|
||||||
CloseGame();
|
CloseGame();
|
||||||
Config::SetBaseOrCurrent(Config::RA_API_TOKEN, "");
|
Config::SetBaseOrCurrent(Config::RA_API_TOKEN, "");
|
||||||
|
if (m_update_callback)
|
||||||
|
m_update_callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AchievementManager::Shutdown()
|
void AchievementManager::Shutdown()
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
UNKNOWN_FAILURE
|
UNKNOWN_FAILURE
|
||||||
};
|
};
|
||||||
using ResponseCallback = std::function<void(ResponseType)>;
|
using ResponseCallback = std::function<void(ResponseType)>;
|
||||||
|
using UpdateCallback = std::function<void()>;
|
||||||
|
|
||||||
struct PointSpread
|
struct PointSpread
|
||||||
{
|
{
|
||||||
|
@ -67,6 +68,7 @@ public:
|
||||||
|
|
||||||
static AchievementManager* GetInstance();
|
static AchievementManager* GetInstance();
|
||||||
void Init();
|
void Init();
|
||||||
|
void SetUpdateCallback(UpdateCallback callback);
|
||||||
ResponseType Login(const std::string& password);
|
ResponseType Login(const std::string& password);
|
||||||
void LoginAsync(const std::string& password, const ResponseCallback& callback);
|
void LoginAsync(const std::string& password, const ResponseCallback& callback);
|
||||||
bool IsLoggedIn() const;
|
bool IsLoggedIn() const;
|
||||||
|
@ -125,6 +127,7 @@ private:
|
||||||
rc_runtime_t m_runtime{};
|
rc_runtime_t m_runtime{};
|
||||||
Core::System* m_system{};
|
Core::System* m_system{};
|
||||||
bool m_is_runtime_initialized = false;
|
bool m_is_runtime_initialized = false;
|
||||||
|
UpdateCallback m_update_callback;
|
||||||
std::string m_display_name;
|
std::string m_display_name;
|
||||||
u32 m_player_score = 0;
|
u32 m_player_score = 0;
|
||||||
std::array<char, HASH_LENGTH> m_game_hash{};
|
std::array<char, HASH_LENGTH> m_game_hash{};
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "DolphinQt/Achievements/AchievementHeaderWidget.h"
|
#include "DolphinQt/Achievements/AchievementHeaderWidget.h"
|
||||||
#include "DolphinQt/Achievements/AchievementProgressWidget.h"
|
#include "DolphinQt/Achievements/AchievementProgressWidget.h"
|
||||||
#include "DolphinQt/Achievements/AchievementSettingsWidget.h"
|
#include "DolphinQt/Achievements/AchievementSettingsWidget.h"
|
||||||
|
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
||||||
#include "DolphinQt/QtUtils/WrapInScrollArea.h"
|
#include "DolphinQt/QtUtils/WrapInScrollArea.h"
|
||||||
|
|
||||||
AchievementsWindow::AchievementsWindow(QWidget* parent) : QDialog(parent)
|
AchievementsWindow::AchievementsWindow(QWidget* parent) : QDialog(parent)
|
||||||
|
@ -20,6 +21,8 @@ AchievementsWindow::AchievementsWindow(QWidget* parent) : QDialog(parent)
|
||||||
|
|
||||||
CreateMainLayout();
|
CreateMainLayout();
|
||||||
ConnectWidgets();
|
ConnectWidgets();
|
||||||
|
AchievementManager::GetInstance()->SetUpdateCallback(
|
||||||
|
[this] { QueueOnObject(this, &AchievementsWindow::UpdateData); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void AchievementsWindow::showEvent(QShowEvent* event)
|
void AchievementsWindow::showEvent(QShowEvent* event)
|
||||||
|
|
|
@ -7,11 +7,13 @@
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
#include "Core/AchievementManager.h"
|
#include "Core/AchievementManager.h"
|
||||||
|
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
||||||
|
|
||||||
class AchievementHeaderWidget;
|
class AchievementHeaderWidget;
|
||||||
class AchievementProgressWidget;
|
class AchievementProgressWidget;
|
||||||
class QTabWidget;
|
|
||||||
class QDialogButtonBox;
|
class QDialogButtonBox;
|
||||||
|
class QTabWidget;
|
||||||
|
class UpdateCallback;
|
||||||
|
|
||||||
class AchievementsWindow : public QDialog
|
class AchievementsWindow : public QDialog
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue