Skip to content

Commit

Permalink
honor Enabled Leaderboards setting (#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored May 31, 2024
1 parent 2997a81 commit 03ec95c
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 9 deletions.
24 changes: 18 additions & 6 deletions src/services/AchievementRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,8 @@ static void HandleLeaderboardStartedEvent(const rc_client_leaderboard_t& pLeader

const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardStarted) !=
ra::ui::viewmodels::PopupLocation::None)
ra::ui::viewmodels::PopupLocation::None &&
pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
{
ra::services::ServiceLocator::Get<ra::services::IAudioSystem>().PlayAudioFile(L"Overlay\\lb.wav");
auto& pOverlayManager = ra::services::ServiceLocator::GetMutable<ra::ui::viewmodels::OverlayManager>();
Expand All @@ -1783,7 +1784,8 @@ static void HandleLeaderboardFailedEvent(const rc_client_leaderboard_t& pLeaderb

const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardCanceled) !=
ra::ui::viewmodels::PopupLocation::None)
ra::ui::viewmodels::PopupLocation::None &&
pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
{
ra::services::ServiceLocator::Get<ra::services::IAudioSystem>().PlayAudioFile(L"Overlay\\lbcancel.wav");
auto& pOverlayManager = ra::services::ServiceLocator::GetMutable<ra::ui::viewmodels::OverlayManager>();
Expand All @@ -1796,7 +1798,8 @@ static void ShowSimplifiedScoreboard(const rc_client_leaderboard_t& pLeaderboard
{
auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardScoreboard) ==
ra::ui::viewmodels::PopupLocation::None)
ra::ui::viewmodels::PopupLocation::None ||
!pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
{
return;
}
Expand Down Expand Up @@ -1825,6 +1828,10 @@ static void HandleLeaderboardSubmittedEvent(const rc_client_leaderboard_t& pLead
return;
}

const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (!pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
return;

std::unique_ptr<ra::ui::viewmodels::PopupMessageViewModel> vmPopup(new ra::ui::viewmodels::PopupMessageViewModel);
vmPopup->SetDescription(ra::Widen(pLeaderboard.title));
std::wstring sTitle = L"Leaderboard Submitted";
Expand Down Expand Up @@ -1871,7 +1878,6 @@ static void HandleLeaderboardSubmittedEvent(const rc_client_leaderboard_t& pLead

if (bSubmit)
{
const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (!pConfiguration.IsFeatureEnabled(ra::services::Feature::Hardcore))
{
vmPopup->SetErrorDetail(L"Submission requires Hardcore mode");
Expand Down Expand Up @@ -1918,7 +1924,8 @@ static void HandleLeaderboardTrackerShowEvent(const rc_client_leaderboard_tracke
{
const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardTracker) !=
ra::ui::viewmodels::PopupLocation::None)
ra::ui::viewmodels::PopupLocation::None &&
pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
{
auto& pOverlayManager = ra::services::ServiceLocator::GetMutable<ra::ui::viewmodels::OverlayManager>();
auto& pScoreTracker = pOverlayManager.AddScoreTracker(pTracker.id);
Expand All @@ -1937,7 +1944,8 @@ static void HandleLeaderboardScoreboardEvent(const rc_client_leaderboard_scorebo
{
auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (pConfiguration.GetPopupLocation(ra::ui::viewmodels::Popup::LeaderboardScoreboard) ==
ra::ui::viewmodels::PopupLocation::None)
ra::ui::viewmodels::PopupLocation::None ||
!pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
{
return;
}
Expand Down Expand Up @@ -2037,6 +2045,10 @@ static void HandleServerError(const rc_client_server_error_t& pServerError)

if (strcmp(pServerError.api, "submit_lboard_entry") == 0)
{
const auto& pConfiguration = ra::services::ServiceLocator::Get<ra::services::IConfiguration>();
if (!pConfiguration.IsFeatureEnabled(ra::services::Feature::Leaderboards))
return;

const auto nLeaderboardId = pServerError.related_id;
const auto& pGameContext = ra::services::ServiceLocator::Get<ra::data::context::GameContext>();
const auto* pLeaderboard = pGameContext.Assets().FindLeaderboard(nLeaderboardId);
Expand Down
5 changes: 2 additions & 3 deletions src/ui/viewmodels/IntegrationMenuViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ui/viewmodels/GameChecksumViewModel.hh"
#include "ui/viewmodels/LoginViewModel.hh"
#include "ui/viewmodels/MessageBoxViewModel.hh"
#include "ui/viewmodels/OverlayManager.hh"
#include "ui/viewmodels/OverlaySettingsViewModel.hh"
#include "ui/viewmodels/UnknownGameViewModel.hh"
#include "ui/viewmodels/WindowManager.hh"
Expand Down Expand Up @@ -248,13 +249,11 @@ void IntegrationMenuViewModel::ToggleLeaderboards()

if (!bLeaderboardsActive)
{
// TODO: disallow disabling leaderboards
//pGameContext.DeactivateLeaderboards();
ra::services::ServiceLocator::GetMutable<ra::ui::viewmodels::OverlayManager>().ClearLeaderboardPopups();
ra::ui::viewmodels::MessageBoxViewModel::ShowMessage(L"Leaderboards are now disabled.");
}
else
{
//pGameContext.ActivateLeaderboards();
ra::ui::viewmodels::MessageBoxViewModel::ShowMessage(L"Leaderboards are now enabled.");
}

Expand Down
15 changes: 15 additions & 0 deletions src/ui/viewmodels/OverlayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,21 @@ void OverlayManager::ClearPopups()
RequestRender();
}

void OverlayManager::ClearLeaderboardPopups()
{
{
std::lock_guard<std::mutex> pGuard(m_pPopupQueueMutex);

for (auto& pScoreboard : m_vScoreboards)
pScoreboard.SetDestroyPending();

for (auto& pTracker : m_vScoreTrackers)
pTracker->SetDestroyPending();
}

RequestRender();
}

ra::ui::Position OverlayManager::GetRenderLocation(const ra::ui::viewmodels::PopupViewModelBase& vmPopup,
int nX, int nY, const ra::ui::drawing::ISurface& pSurface, const PopupLocations& pPopupLocations)
{
Expand Down
5 changes: 5 additions & 0 deletions src/ui/viewmodels/OverlayManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ public:
/// </summary>
virtual void ClearPopups();

/// <summary>
/// Clear leaderboard popups.
/// </summary>
void ClearLeaderboardPopups();

/// <summary>
/// Sets the function to call when there's something to be rendered.
/// </summary>
Expand Down
Loading

0 comments on commit 03ec95c

Please sign in to comment.