Added Disabled flag to Achievement Manager
The Disabled state sits between Game Closed and completely Shutdown - stronger than the former, as it refuses to let a game be opened again until AchievementManager is restored (which only happens upon a fresh core boot) but it isn't completely shut down and will still allow the player to be logged in and access the achievement settings and their (global) achievement header.
This commit is contained in:
parent
148c2f3c0d
commit
c8d8ca2ff7
|
@ -100,6 +100,13 @@ void AchievementManager::HashGame(const std::string& file_path, const ResponseCa
|
|||
callback(AchievementManager::ResponseType::MANAGER_NOT_INITIALIZED);
|
||||
return;
|
||||
}
|
||||
if (m_disabled)
|
||||
{
|
||||
INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager is disabled until core is rebooted.");
|
||||
OSD::AddMessage("Achievements are disabled until you restart emulation.",
|
||||
OSD::Duration::VERY_LONG, OSD::Color::RED);
|
||||
return;
|
||||
}
|
||||
m_system = &Core::System::GetInstance();
|
||||
m_queue.EmplaceItem([this, callback, file_path] {
|
||||
Hash new_hash;
|
||||
|
@ -122,6 +129,12 @@ void AchievementManager::HashGame(const std::string& file_path, const ResponseCa
|
|||
}
|
||||
{
|
||||
std::lock_guard lg{m_lock};
|
||||
if (m_disabled)
|
||||
{
|
||||
INFO_LOG_FMT(ACHIEVEMENTS, "Achievements disabled while hash was resolving.");
|
||||
callback(AchievementManager::ResponseType::EXPIRED_CONTEXT);
|
||||
return;
|
||||
}
|
||||
m_game_hash = std::move(new_hash);
|
||||
}
|
||||
LoadGameSync(callback);
|
||||
|
@ -142,14 +155,33 @@ void AchievementManager::HashGame(const DiscIO::Volume* volume, const ResponseCa
|
|||
INFO_LOG_FMT(ACHIEVEMENTS, "New volume is empty.");
|
||||
return;
|
||||
}
|
||||
if (m_disabled)
|
||||
{
|
||||
INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager is disabled until core is rebooted.");
|
||||
OSD::AddMessage("Achievements are disabled until core is rebooted.", OSD::Duration::VERY_LONG,
|
||||
OSD::Color::RED);
|
||||
return;
|
||||
}
|
||||
// Need to SetDisabled outside a lock because it uses m_lock internally.
|
||||
bool disable = false;
|
||||
{
|
||||
std::lock_guard lg{m_lock};
|
||||
if (m_loading_volume.get() != nullptr)
|
||||
{
|
||||
return;
|
||||
disable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_loading_volume = DiscIO::CreateVolume(volume->GetBlobReader().CopyReader());
|
||||
}
|
||||
}
|
||||
if (disable)
|
||||
{
|
||||
INFO_LOG_FMT(ACHIEVEMENTS, "Disabling Achievement Manager due to hash spam.");
|
||||
SetDisabled(true);
|
||||
callback(AchievementManager::ResponseType::EXPIRED_CONTEXT);
|
||||
return;
|
||||
}
|
||||
m_system = &Core::System::GetInstance();
|
||||
struct FilereaderState
|
||||
{
|
||||
|
@ -177,6 +209,12 @@ void AchievementManager::HashGame(const DiscIO::Volume* volume, const ResponseCa
|
|||
}
|
||||
{
|
||||
std::lock_guard lg{m_lock};
|
||||
if (m_disabled)
|
||||
{
|
||||
INFO_LOG_FMT(ACHIEVEMENTS, "Achievements disabled while hash was resolving.");
|
||||
callback(AchievementManager::ResponseType::EXPIRED_CONTEXT);
|
||||
return;
|
||||
}
|
||||
m_game_hash = std::move(new_hash);
|
||||
m_loading_volume.reset();
|
||||
}
|
||||
|
@ -197,6 +235,7 @@ void AchievementManager::LoadGameSync(const ResponseCallback& callback)
|
|||
INFO_LOG_FMT(ACHIEVEMENTS, "No RetroAchievements data found for this game.");
|
||||
OSD::AddMessage("No RetroAchievements data found for this game.", OSD::Duration::VERY_LONG,
|
||||
OSD::Color::RED);
|
||||
SetDisabled(true);
|
||||
callback(resolve_hash_response);
|
||||
return;
|
||||
}
|
||||
|
@ -773,6 +812,25 @@ AchievementManager::RichPresence AchievementManager::GetRichPresence()
|
|||
return rich_presence;
|
||||
}
|
||||
|
||||
void AchievementManager::SetDisabled(bool disable)
|
||||
{
|
||||
{
|
||||
std::lock_guard lg{m_lock};
|
||||
m_disabled = disable;
|
||||
}
|
||||
if (disable)
|
||||
{
|
||||
INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager has been disabled.");
|
||||
OSD::AddMessage("Please close all games to re-enable achievements.", OSD::Duration::VERY_LONG,
|
||||
OSD::Color::RED);
|
||||
CloseGame();
|
||||
}
|
||||
else
|
||||
{
|
||||
INFO_LOG_FMT(ACHIEVEMENTS, "Achievement Manager has been re-enabled.");
|
||||
}
|
||||
};
|
||||
|
||||
void AchievementManager::CloseGame()
|
||||
{
|
||||
{
|
||||
|
|
|
@ -136,6 +136,8 @@ public:
|
|||
u32* target);
|
||||
const std::unordered_map<AchievementId, LeaderboardStatus>& GetLeaderboardsInfo() const;
|
||||
RichPresence GetRichPresence();
|
||||
bool IsDisabled() const { return m_disabled; };
|
||||
void SetDisabled(bool disabled);
|
||||
|
||||
void CloseGame();
|
||||
void Logout();
|
||||
|
@ -193,6 +195,7 @@ private:
|
|||
bool m_is_runtime_initialized = false;
|
||||
UpdateCallback m_update_callback;
|
||||
std::unique_ptr<DiscIO::Volume> m_loading_volume;
|
||||
bool m_disabled = false;
|
||||
std::string m_display_name;
|
||||
u32 m_player_score = 0;
|
||||
BadgeStatus m_player_badge;
|
||||
|
|
|
@ -164,6 +164,10 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||
AchievementManager::GetInstance()->SetDisabled(false);
|
||||
#endif // USE_RETRO_ACHIEVEMENTS
|
||||
|
||||
const bool load_ipl = !StartUp.bWii && !Config::Get(Config::MAIN_SKIP_IPL) &&
|
||||
std::holds_alternative<BootParameters::Disc>(boot->parameters);
|
||||
if (load_ipl)
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "Common/StringUtil.h"
|
||||
#include "Common/Version.h"
|
||||
|
||||
#include "Core/AchievementManager.h"
|
||||
#include "Core/Boot/Boot.h"
|
||||
#include "Core/CommonTitles.h"
|
||||
#include "Core/Config/DefaultLocale.h"
|
||||
|
@ -168,6 +169,10 @@ void SConfig::SetRunningGameMetadata(const std::string& game_id, const std::stri
|
|||
if (!was_changed)
|
||||
return;
|
||||
|
||||
#ifdef USE_RETRO_ACHIEVEMENTS
|
||||
AchievementManager::GetInstance()->SetDisabled(true);
|
||||
#endif // USE_RETRO_ACHIEVEMENTS
|
||||
|
||||
if (game_id == "00000000")
|
||||
{
|
||||
m_title_name.clear();
|
||||
|
|
|
@ -37,6 +37,11 @@ AchievementHeaderWidget::AchievementHeaderWidget(QWidget* parent) : QWidget(pare
|
|||
m_game_progress_hard = new QProgressBar();
|
||||
m_game_progress_soft = new QProgressBar();
|
||||
m_rich_presence = new QLabel();
|
||||
m_locked_warning = new QLabel();
|
||||
|
||||
m_locked_warning->setText(tr("Achievements have been disabled.<br>Please close all running "
|
||||
"games to re-enable achievements."));
|
||||
m_locked_warning->setStyleSheet(QStringLiteral("QLabel { color : red; }"));
|
||||
|
||||
QSizePolicy sp_retain = m_game_progress_hard->sizePolicy();
|
||||
sp_retain.setRetainSizeWhenHidden(true);
|
||||
|
@ -54,6 +59,7 @@ AchievementHeaderWidget::AchievementHeaderWidget(QWidget* parent) : QWidget(pare
|
|||
text_col->addWidget(m_game_progress_hard);
|
||||
text_col->addWidget(m_game_progress_soft);
|
||||
text_col->addWidget(m_rich_presence);
|
||||
text_col->addWidget(m_locked_warning);
|
||||
QHBoxLayout* header_layout = new QHBoxLayout();
|
||||
header_layout->addLayout(icon_col);
|
||||
header_layout->addLayout(text_col);
|
||||
|
@ -148,6 +154,7 @@ void AchievementHeaderWidget::UpdateData()
|
|||
QString::fromUtf8(AchievementManager::GetInstance()->GetRichPresence().data()));
|
||||
if (!m_rich_presence->isVisible())
|
||||
m_rich_presence->setVisible(Config::Get(Config::RA_RICH_PRESENCE_ENABLED));
|
||||
m_locked_warning->setVisible(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -157,6 +164,10 @@ void AchievementHeaderWidget::UpdateData()
|
|||
m_game_progress_hard->setVisible(false);
|
||||
m_game_progress_soft->setVisible(false);
|
||||
m_rich_presence->setVisible(false);
|
||||
if (AchievementManager::GetInstance()->IsDisabled())
|
||||
{
|
||||
m_locked_warning->setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ private:
|
|||
QProgressBar* m_game_progress_hard;
|
||||
QProgressBar* m_game_progress_soft;
|
||||
QLabel* m_rich_presence;
|
||||
QLabel* m_locked_warning;
|
||||
QGroupBox* m_header_box;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue