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

resync asset list state after game assets list updated #1121

Merged
merged 2 commits into from
Oct 10, 2024
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
33 changes: 21 additions & 12 deletions src/ui/viewmodels/AssetListViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,22 @@ void AssetListViewModel::AddOrRemoveFilteredItem(gsl::index nAssetIndex)
}
}

void AssetListViewModel::SyncAsset(AssetSummaryViewModel& vmSummary, const ra::data::models::AssetModelBase& pAsset)
{
vmSummary.SetLabel(pAsset.GetName());
vmSummary.SetType(pAsset.GetType());
vmSummary.SetCategory(pAsset.GetCategory());
vmSummary.SetChanges(pAsset.GetChanges());
vmSummary.SetState(pAsset.GetState());
vmSummary.SetWarning(pAsset.GetValidationError());

const auto* pAchievement = dynamic_cast<const ra::data::models::AchievementModel*>(&pAsset);
if (pAchievement != nullptr)
vmSummary.SetPoints(pAchievement->GetPoints());
else
vmSummary.SetPoints(0);
}

bool AssetListViewModel::AddOrRemoveFilteredItem(const ra::data::models::AssetModelBase& pAsset)
{
const auto nIndex = GetFilteredAssetIndex(pAsset);
Expand All @@ -501,22 +517,15 @@ bool AssetListViewModel::AddOrRemoveFilteredItem(const ra::data::models::AssetMo
{
auto pSummary = std::make_unique<AssetSummaryViewModel>();
pSummary->SetId(ra::to_signed(pAsset.GetID()));
pSummary->SetLabel(pAsset.GetName());
pSummary->SetType(pAsset.GetType());
pSummary->SetCategory(pAsset.GetCategory());
pSummary->SetChanges(pAsset.GetChanges());
pSummary->SetState(pAsset.GetState());
pSummary->SetWarning(pAsset.GetValidationError());

const auto* pAchievement = dynamic_cast<const ra::data::models::AchievementModel*>(&pAsset);
if (pAchievement != nullptr)
pSummary->SetPoints(pAchievement->GetPoints());
else
pSummary->SetPoints(0);
SyncAsset(*pSummary, pAsset);

m_vFilteredAssets.Append(std::move(pSummary));
return true;
}
else
{
SyncAsset(*m_vFilteredAssets.GetItemAt(nIndex), pAsset);
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/ui/viewmodels/AssetListViewModel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ private:
bool MatchesFilter(const ra::data::models::AssetModelBase& pAsset) const;
void AddOrRemoveFilteredItem(gsl::index nAssetIndex);
bool AddOrRemoveFilteredItem(const ra::data::models::AssetModelBase& pAsset);
static void SyncAsset(AssetSummaryViewModel& vmSummary, const ra::data::models::AssetModelBase& pAsset);
gsl::index GetFilteredAssetIndex(const ra::data::models::AssetModelBase& pAsset) const;
void ApplyFilter();

Expand Down
2 changes: 1 addition & 1 deletion src/ui/win32/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void ShowFolder(FileDialogViewModel& vmFileDialog, HWND hParentWnd)

void FileDialog::Presenter::DoShowModal(ra::ui::WindowViewModelBase& oViewModel, HWND hParentWnd)
{
auto& vmFileDialog = reinterpret_cast<FileDialogViewModel&>(oViewModel);
auto& vmFileDialog = dynamic_cast<FileDialogViewModel&>(oViewModel);

if (vmFileDialog.GetMode() == FileDialogViewModel::Mode::Folder)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ui/win32/MessageBoxDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void MessageBoxDialog::Presenter::ShowModal(ra::ui::WindowViewModelBase& oViewMo

void MessageBoxDialog::Presenter::DoShowModal(ra::ui::WindowViewModelBase& oViewModel, HWND hParentWnd)
{
auto& oMessageBoxViewModel = reinterpret_cast<MessageBoxViewModel&>(oViewModel);
auto& oMessageBoxViewModel = dynamic_cast<MessageBoxViewModel&>(oViewModel);
int nButton = 0;

if (pTaskDialog == nullptr || oMessageBoxViewModel.GetHeader().empty())
Expand Down
4 changes: 2 additions & 2 deletions src/ui/win32/OverlaySettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool OverlaySettingsDialog::Presenter::IsSupported(const ra::ui::WindowViewModel

void OverlaySettingsDialog::Presenter::ShowModal(ra::ui::WindowViewModelBase& vmViewModel, HWND hParentWnd)
{
auto& vmSettings = reinterpret_cast<ra::ui::viewmodels::OverlaySettingsViewModel&>(vmViewModel);
auto& vmSettings = dynamic_cast<ra::ui::viewmodels::OverlaySettingsViewModel&>(vmViewModel);

OverlaySettingsDialog oDialog(vmSettings);
oDialog.CreateModalWindow(MAKEINTRESOURCE(IDD_RA_OVERLAYSETTINGS), this, hParentWnd);
Expand Down Expand Up @@ -96,7 +96,7 @@ BOOL OverlaySettingsDialog::OnCommand(WORD nCommand)
{
if (nCommand == IDC_RA_BROWSE)
{
auto& vmSettings = reinterpret_cast<ra::ui::viewmodels::OverlaySettingsViewModel&>(m_vmWindow);
auto& vmSettings = dynamic_cast<ra::ui::viewmodels::OverlaySettingsViewModel&>(m_vmWindow);
vmSettings.BrowseLocation();
return TRUE;
}
Expand Down
3 changes: 3 additions & 0 deletions src/ui/win32/bindings/ComboBoxBinding.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public:

void BindItems(ViewModelCollectionBase& pViewModels, const IntModelProperty& pIdProperty, const StringModelProperty& pTextProperty)
{
#pragma warning(push)
#pragma warning(disable : 26465) // const_cast forces a call to the const implementation
BindItems(const_cast<const ViewModelCollectionBase&>(pViewModels), pIdProperty, pTextProperty);
#pragma warning(pop)

m_pMutableViewModelCollection = &pViewModels;
pViewModels.AddNotifyTarget(*this);
Expand Down
Loading