Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show Unknown Title dialog when viewing game hash in Test Compatibility mode #800

Merged
merged 1 commit into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/data/context/GameContext.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ public:
/// <summary>
/// Sets the game play mode.
/// </summary>
void SetMode(Mode nMode) noexcept { m_nMode = nMode; }
void SetMode(Mode nMode)
{
m_nMode = nMode;

if (m_nGameId != 0)
OnActiveGameChanged();
}

/// <summary>
/// Gets the assets for the current game.
Expand Down
29 changes: 27 additions & 2 deletions src/ui/viewmodels/IntegrationMenuViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "RA_Log.h"
#include "RA_Resource.h"

#include "data/context/ConsoleContext.hh"
#include "data/context/GameContext.hh"
#include "data/context/UserContext.hh"

#include "services/IConfiguration.hh"
Expand All @@ -15,6 +17,7 @@
#include "ui/viewmodels/LoginViewModel.hh"
#include "ui/viewmodels/MessageBoxViewModel.hh"
#include "ui/viewmodels/OverlaySettingsViewModel.hh"
#include "ui/viewmodels/UnknownGameViewModel.hh"
#include "ui/viewmodels/WindowManager.hh"

namespace ra {
Expand Down Expand Up @@ -289,8 +292,30 @@ void IntegrationMenuViewModel::ReportBrokenAchievements()

void IntegrationMenuViewModel::ShowGameHash()
{
ra::ui::viewmodels::GameChecksumViewModel vmGameChecksum;
vmGameChecksum.ShowModal();
auto& pGameContext = ra::services::ServiceLocator::GetMutable<ra::data::context::GameContext>();
if (pGameContext.GetMode() == ra::data::context::GameContext::Mode::CompatibilityTest)
{
ra::ui::viewmodels::UnknownGameViewModel vmUnknownGame;
vmUnknownGame.InitializeTestCompatibilityMode();

auto sEstimatedGameTitle = ra::services::ServiceLocator::Get<ra::data::context::EmulatorContext>().GetGameTitle();
vmUnknownGame.SetEstimatedGameName(ra::Widen(sEstimatedGameTitle));
vmUnknownGame.SetSystemName(ra::services::ServiceLocator::Get<ra::data::context::ConsoleContext>().Name());

if (vmUnknownGame.ShowModal() == ra::ui::DialogResult::OK)
{
// Test button is disabled, can only get here by clicking Link
Expects(!vmUnknownGame.GetTestMode());

pGameContext.SetMode(ra::data::context::GameContext::Mode::Normal);
pGameContext.RefreshUnlocks();
}
}
else
{
ra::ui::viewmodels::GameChecksumViewModel vmGameChecksum;
vmGameChecksum.ShowModal();
}
}

} // namespace viewmodels
Expand Down
22 changes: 22 additions & 0 deletions src/ui/viewmodels/UnknownGameViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "api\SubmitNewTitle.hh"

#include "data\context\ConsoleContext.hh"
#include "data\context\GameContext.hh"

#include "services\IClipboard.hh"

Expand All @@ -16,6 +17,8 @@ namespace ui {
namespace viewmodels {

const IntModelProperty UnknownGameViewModel::SelectedGameIdProperty("UnknownGameViewModel", "SelectedGameId", 0);
const BoolModelProperty UnknownGameViewModel::IsSelectedGameEnabledProperty("UnknownGameViewModel", "IsSelectedGameEnabled", true);
const BoolModelProperty UnknownGameViewModel::IsAssociateEnabledProperty("UnknownGameViewModel", "IsAssociateEnabled", true);
const StringModelProperty UnknownGameViewModel::NewGameNameProperty("UnknownGameViewModel", "NewGameName", L"");
const StringModelProperty UnknownGameViewModel::ChecksumProperty("UnknownGameViewModel", "Checksum", L"");
const StringModelProperty UnknownGameViewModel::EstimatedGameNameProperty("UnknownGameViewModel", "EstimatedGameName", L"");
Expand All @@ -33,6 +36,9 @@ void UnknownGameViewModel::InitializeGameTitles()

m_vGameTitles.Add(0U, L"<New Title>");

SetValue(IsSelectedGameEnabledProperty, false);
SetValue(IsAssociateEnabledProperty, false);

ra::api::FetchGamesList::Request request;
request.ConsoleId = pConsoleContext.Id();

Expand All @@ -49,14 +55,30 @@ void UnknownGameViewModel::InitializeGameTitles()
}
else
{
m_vGameTitles.BeginUpdate();
for (const auto& pGame : response.Games)
m_vGameTitles.Add(pGame.Id, pGame.Name);
m_vGameTitles.EndUpdate();
}

m_vGameTitles.Freeze();

SetValue(IsAssociateEnabledProperty, true);
SetValue(IsSelectedGameEnabledProperty, true);
});
}

void UnknownGameViewModel::InitializeTestCompatibilityMode()
{
const auto& pGameContext = ra::services::ServiceLocator::Get<ra::data::context::GameContext>();
m_vGameTitles.Add(pGameContext.GameId(), pGameContext.GameTitle());
m_vGameTitles.Freeze();
SetSelectedGameId(pGameContext.GameId());
SetChecksum(ra::Widen(pGameContext.GameHash()));

SetValue(IsSelectedGameEnabledProperty, false);
}

bool UnknownGameViewModel::Associate()
{
ra::api::SubmitNewTitle::Request request;
Expand Down
25 changes: 25 additions & 0 deletions src/ui/viewmodels/UnknownGameViewModel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ public:
/// </summary>
void InitializeGameTitles();

/// <summary>
/// Initializes the <see cref="GameTitles"/> collection (asynchronously).
/// </summary>
void InitializeTestCompatibilityMode();

/// <summary>
/// The <see cref="ModelProperty" /> for whether or not a game can be selected.
/// </summary>
static const BoolModelProperty IsSelectedGameEnabledProperty;

/// <summary>
/// Gets whether or not a game can be selected.
/// </summary>
bool IsSelectedGameEnabled() const { return GetValue(IsSelectedGameEnabledProperty); }

/// <summary>
/// The <see cref="ModelProperty" /> for the new game name.
/// </summary>
Expand Down Expand Up @@ -134,6 +149,16 @@ public:
/// </summary>
void SetTestMode(bool bValue) { SetValue(TestModeProperty, bValue); }

/// <summary>
/// The <see cref="ModelProperty" /> for whether or not the link button is enabled.
/// </summary>
static const BoolModelProperty IsAssociateEnabledProperty;

/// <summary>
/// Gets whether or not the link button is enabled.
/// </summary>
bool IsAssociateEnabled() const { return GetValue(IsAssociateEnabledProperty); }

/// <summary>
/// Command handler for Associate button.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/ui/win32/UnknownGameDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ UnknownGameDialog::UnknownGameDialog(ra::ui::viewmodels::UnknownGameViewModel& v

m_bindExistingTitle.BindItems(vmUnknownGame.GameTitles());
m_bindExistingTitle.BindSelectedItem(ra::ui::viewmodels::UnknownGameViewModel::SelectedGameIdProperty);
m_bindWindow.BindEnabled(IDC_RA_KNOWNGAMES, ra::ui::viewmodels::UnknownGameViewModel::IsSelectedGameEnabledProperty);

m_bindNewTitle.BindText(ra::ui::viewmodels::UnknownGameViewModel::NewGameNameProperty,
ra::ui::win32::bindings::TextBoxBinding::UpdateMode::KeyPress);
m_bindWindow.BindEnabled(IDC_RA_GAMETITLE, ra::ui::viewmodels::UnknownGameViewModel::IsSelectedGameEnabledProperty);

m_bindWindow.BindLabel(IDC_RA_GAMENAME, ra::ui::viewmodels::UnknownGameViewModel::EstimatedGameNameProperty);
m_bindWindow.BindLabel(IDC_RA_SYSTEMNAME, ra::ui::viewmodels::UnknownGameViewModel::SystemNameProperty);
m_bindWindow.BindLabel(IDC_RA_CHECKSUM, ra::ui::viewmodels::UnknownGameViewModel::ChecksumProperty);

m_bindWindow.BindEnabled(IDC_RA_LINK, ra::ui::viewmodels::UnknownGameViewModel::IsAssociateEnabledProperty);
m_bindWindow.BindEnabled(IDOK, ra::ui::viewmodels::UnknownGameViewModel::IsSelectedGameEnabledProperty);
}

BOOL UnknownGameDialog::OnInitDialog()
Expand Down
43 changes: 43 additions & 0 deletions tests/data/context/GameContext_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,49 @@ TEST_CLASS(GameContext_Tests)
const auto* pNote1 = game.FindCodeNote(1234U);
Assert::IsNull(pNote1);
}

TEST_METHOD(TestSetModeNotify)
{
class NotifyHarness : public GameContext::NotifyTarget
{
public:
bool m_bNotified = false;

protected:
void OnActiveGameChanged() noexcept override { m_bNotified = true; }
};
NotifyHarness notifyHarness;

GameContextHarness game;
game.mockServer.HandleRequest<ra::api::FetchGameData>([](const ra::api::FetchGameData::Request&, ra::api::FetchGameData::Response& response)
{
response.Title = L"GameTitle";
response.ImageIcon = "9743";
return true;
});

Assert::AreEqual(GameContext::Mode::Normal, game.GetMode());

game.AddNotifyTarget(notifyHarness);
game.LoadGame(0U);

Assert::AreEqual(0U, game.GameId());
Assert::IsFalse(notifyHarness.m_bNotified);

game.SetMode(GameContext::Mode::CompatibilityTest);
Assert::AreEqual(GameContext::Mode::CompatibilityTest, game.GetMode());
Assert::IsFalse(notifyHarness.m_bNotified);

game.LoadGame(1U, GameContext::Mode::CompatibilityTest);
Assert::AreEqual(1U, game.GameId());
Assert::AreEqual(GameContext::Mode::CompatibilityTest, game.GetMode());
Assert::IsTrue(notifyHarness.m_bNotified);

notifyHarness.m_bNotified = false;
game.SetMode(GameContext::Mode::Normal);
Assert::AreEqual(GameContext::Mode::Normal, game.GetMode());
Assert::IsTrue(notifyHarness.m_bNotified);
}
};

} // namespace tests
Expand Down
45 changes: 45 additions & 0 deletions tests/ui/viewmodels/IntegrationMenuViewModel_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
#include "ui\viewmodels\MemoryInspectorViewModel.hh"
#include "ui\viewmodels\OverlaySettingsViewModel.hh"
#include "ui\viewmodels\RichPresenceMonitorViewModel.hh"
#include "ui\viewmodels\UnknownGameViewModel.hh"

#include "tests\data\DataAsserts.hh"
#include "tests\ui\UIAsserts.hh"
#include "tests\mocks\MockAchievementRuntime.hh"
#include "tests\mocks\MockConfiguration.hh"
#include "tests\mocks\MockConsoleContext.hh"
#include "tests\mocks\MockDesktop.hh"
#include "tests\mocks\MockEmulatorContext.hh"
#include "tests\mocks\MockGameContext.hh"
Expand All @@ -40,6 +43,7 @@ TEST_CLASS(IntegrationMenuViewModel_Tests)
{
public:
ra::api::mocks::MockServer mockServer;
ra::data::context::mocks::MockConsoleContext mockConsoleContext;
ra::data::context::mocks::MockEmulatorContext mockEmulatorContext;
ra::data::context::mocks::MockGameContext mockGameContext;
ra::data::context::mocks::MockUserContext mockUserContext;
Expand Down Expand Up @@ -530,6 +534,47 @@ TEST_CLASS(IntegrationMenuViewModel_Tests)
menu.AssertShowWindow<ra::ui::viewmodels::GameChecksumViewModel>(IDM_RA_GETROMCHECKSUM, true, "", DialogResult::None);
}

TEST_METHOD(TestShowGameHashTestCompatibilityModeCancel)
{
IntegrationMenuViewModelHarness menu;

bool bDialogShown = false;
menu.mockDesktop.ExpectWindow<ra::ui::viewmodels::UnknownGameViewModel>([&bDialogShown](ra::ui::viewmodels::UnknownGameViewModel& vmUnknown)
{
bDialogShown = true;

Assert::IsFalse(vmUnknown.IsSelectedGameEnabled());

return DialogResult::Cancel;
});

menu.mockGameContext.SetMode(ra::data::context::GameContext::Mode::CompatibilityTest);
menu.ActivateMenuItem(IDM_RA_GETROMCHECKSUM);

Assert::IsTrue(bDialogShown);
Assert::AreEqual(ra::data::context::GameContext::Mode::CompatibilityTest, menu.mockGameContext.GetMode());
}

TEST_METHOD(TestShowGameHashTestCompatibilityModeAssociate)
{
IntegrationMenuViewModelHarness menu;

bool bDialogShown = false;
menu.mockDesktop.ExpectWindow<ra::ui::viewmodels::UnknownGameViewModel>([&bDialogShown](ra::ui::viewmodels::UnknownGameViewModel& vmUnknown)
{
bDialogShown = true;

Assert::IsFalse(vmUnknown.IsSelectedGameEnabled());

return DialogResult::OK;
});

menu.mockGameContext.SetMode(ra::data::context::GameContext::Mode::CompatibilityTest);
menu.ActivateMenuItem(IDM_RA_GETROMCHECKSUM);

Assert::IsTrue(bDialogShown);
Assert::AreEqual(ra::data::context::GameContext::Mode::Normal, menu.mockGameContext.GetMode());
}
};

} // namespace tests
Expand Down
Loading