diff --git a/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.cpp b/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.cpp index c11a9b9de1..1d4f354fb5 100644 --- a/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.cpp +++ b/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.cpp @@ -57,6 +57,7 @@ namespace O3DE::ProjectManager vLayout->addWidget(m_headerWidget); connect(m_gemModel, &GemModel::gemStatusChanged, this, &GemCatalogScreen::OnGemStatusChanged); + connect(m_gemModel, &GemModel::dependencyGemStatusChanged, this, &GemCatalogScreen::OnDependencyGemStatusChanged); connect(m_gemModel->GetSelectionModel(), &QItemSelectionModel::selectionChanged, this, [this]{ ShowInspector(); }); connect(m_headerWidget, &GemCatalogHeaderWidget::RefreshGems, this, &GemCatalogScreen::Refresh); connect(m_headerWidget, &GemCatalogHeaderWidget::OpenGemsRepo, this, &GemCatalogScreen::HandleOpenGemRepo); @@ -279,7 +280,8 @@ namespace O3DE::ProjectManager { notification += tr(" and "); } - if (added && GemModel::GetDownloadStatus(modelIndex) == GemInfo::DownloadStatus::NotDownloaded) + if (added && (GemModel::GetDownloadStatus(modelIndex) == GemInfo::DownloadStatus::NotDownloaded) || + (GemModel::GetDownloadStatus(modelIndex) == GemInfo::DownloadStatus::DownloadFailed)) { m_downloadController->AddGemDownload(GemModel::GetName(modelIndex)); GemModel::SetDownloadStatus(*m_gemModel, modelIndex, GemInfo::DownloadStatus::Downloading); @@ -304,6 +306,18 @@ namespace O3DE::ProjectManager } } + void GemCatalogScreen::OnDependencyGemStatusChanged(const QString& gemName) + { + QModelIndex modelIndex = m_gemModel->FindIndexByNameString(gemName); + bool added = GemModel::IsAddedDependency(modelIndex); + if (added && (GemModel::GetDownloadStatus(modelIndex) == GemInfo::DownloadStatus::NotDownloaded) || + (GemModel::GetDownloadStatus(modelIndex) == GemInfo::DownloadStatus::DownloadFailed)) + { + m_downloadController->AddGemDownload(GemModel::GetName(modelIndex)); + GemModel::SetDownloadStatus(*m_gemModel, modelIndex, GemInfo::DownloadStatus::Downloading); + } + } + void GemCatalogScreen::SelectGem(const QString& gemName) { QModelIndex modelIndex = m_gemModel->FindIndexByNameString(gemName); @@ -383,6 +397,7 @@ namespace O3DE::ProjectManager // Remove gem from gems to be added to update any dependencies GemModel::SetIsAdded(*m_gemModel, modelIndex, false); + GemModel::DeactivateDependentGems(*m_gemModel, modelIndex); // Unregister the gem auto unregisterResult = PythonBindingsInterface::Get()->UnregisterGem(selectedGemPath); @@ -660,6 +675,8 @@ namespace O3DE::ProjectManager QModelIndex index = m_gemModel->FindIndexByNameString(gemName); if (index.isValid()) { + GemModel::SetIsAdded(*m_gemModel, index, false); + GemModel::DeactivateDependentGems(*m_gemModel, index); GemModel::SetDownloadStatus(*m_gemModel, index, GemInfo::DownloadFailed); } } diff --git a/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.h b/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.h index 2deaa41b9e..20b0c27ff8 100644 --- a/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.h +++ b/Code/Tools/ProjectManager/Source/GemCatalog/GemCatalogScreen.h @@ -53,6 +53,7 @@ namespace O3DE::ProjectManager public slots: void OnGemStatusChanged(const QString& gemName, uint32_t numChangedDependencies); + void OnDependencyGemStatusChanged(const QString& gemName); void OnAddGemClicked(); void SelectGem(const QString& gemName); void OnGemDownloadResult(const QString& gemName, bool succeeded = true); diff --git a/Code/Tools/ProjectManager/Source/GemCatalog/GemModel.cpp b/Code/Tools/ProjectManager/Source/GemCatalog/GemModel.cpp index 95fdc8e1e2..ca9be341c6 100644 --- a/Code/Tools/ProjectManager/Source/GemCatalog/GemModel.cpp +++ b/Code/Tools/ProjectManager/Source/GemCatalog/GemModel.cpp @@ -357,6 +357,8 @@ namespace O3DE::ProjectManager if (!IsAdded(dependency)) { numChangedDependencies++; + const QString dependencyName = gemModel->GetName(dependency); + gemModel->emit dependencyGemStatusChanged(dependencyName); } } } @@ -381,6 +383,8 @@ namespace O3DE::ProjectManager if (!IsAdded(dependency)) { numChangedDependencies++; + const QString dependencyName = gemModel->GetName(dependency); + gemModel->emit dependencyGemStatusChanged(dependencyName); } } } @@ -479,6 +483,28 @@ namespace O3DE::ProjectManager return previouslyAdded && !added; } + void GemModel::DeactivateDependentGems(QAbstractItemModel& model, const QModelIndex& modelIndex) + { + GemModel* gemModel = GetSourceModel(&model); + AZ_Assert(gemModel, "Failed to obtain GemModel"); + + QVector dependentGems = gemModel->GatherDependentGems(modelIndex); + if (!dependentGems.isEmpty()) + { + // we need to deactivate all gems that depend on this one + for (auto dependentModelIndex : dependentGems) + { + DeactivateDependentGems(model, dependentModelIndex); + } + + } + else + { + // Deactivate this gem + SetIsAdded(model, modelIndex, false); + } + } + void GemModel::SetDownloadStatus(QAbstractItemModel& model, const QModelIndex& modelIndex, GemInfo::DownloadStatus status) { model.setData(modelIndex, status, RoleDownloadStatus); diff --git a/Code/Tools/ProjectManager/Source/GemCatalog/GemModel.h b/Code/Tools/ProjectManager/Source/GemCatalog/GemModel.h index bb89d46861..cb99581468 100644 --- a/Code/Tools/ProjectManager/Source/GemCatalog/GemModel.h +++ b/Code/Tools/ProjectManager/Source/GemCatalog/GemModel.h @@ -99,6 +99,7 @@ namespace O3DE::ProjectManager static bool NeedsToBeRemoved(const QModelIndex& modelIndex, bool includeDependencies = false); static bool HasRequirement(const QModelIndex& modelIndex); static void UpdateDependencies(QAbstractItemModel& model, const QString& gemName, bool isAdded); + static void DeactivateDependentGems(QAbstractItemModel& model, const QModelIndex& modelIndex); static void SetDownloadStatus(QAbstractItemModel& model, const QModelIndex& modelIndex, GemInfo::DownloadStatus status); bool DoGemsToBeAddedHaveRequirements() const; @@ -113,6 +114,7 @@ namespace O3DE::ProjectManager signals: void gemStatusChanged(const QString& gemName, uint32_t numChangedDependencies); + void dependencyGemStatusChanged(const QString& gemName); protected slots: void OnRowsAboutToBeRemoved(const QModelIndex& parent, int first, int last);