[LYN-4929] Correct gems not showing as enabled for a template (#1722)

* When there are multiple project templates present, we re-gather the gems when changing the selected the project template.
* In case the user enabled or disabled any gem and they select a new project template, we show a warning dialog where users can either cancel the operation or proceed to the new project template. The warning dialog will only appear in case the enabled gems actually differ from the currently used template's default.
* New helper function to select the used project template.
* Storing the currently used project template index and only update the template details and emitting the changed event in case the user has actually chosen another template. This avoids emitting signals in case the user clicks on the already selected template.

Signed-off-by: Benjamin Jillich <jillich@amazon.com>
This commit is contained in:
Benjamin Jillich
2021-07-01 09:53:17 -07:00
committed by GitHub
parent 74de7f785c
commit 1586c00fc8
5 changed files with 89 additions and 9 deletions
@@ -81,8 +81,14 @@ namespace O3DE::ProjectManager
{
if (button && button->property(k_templateIndexProperty).isValid())
{
int projectIndex = button->property(k_templateIndexProperty).toInt();
UpdateTemplateDetails(m_templates.at(projectIndex));
int projectTemplateIndex = button->property(k_templateIndexProperty).toInt();
if (m_selectedTemplateIndex != projectTemplateIndex)
{
const int oldIndex = m_selectedTemplateIndex;
m_selectedTemplateIndex = projectTemplateIndex;
UpdateTemplateDetails(m_templates.at(m_selectedTemplateIndex));
emit OnTemplateSelectionChanged(/*oldIndex=*/oldIndex, /*newIndex=*/m_selectedTemplateIndex);
}
}
});
@@ -115,7 +121,8 @@ namespace O3DE::ProjectManager
flowLayout->addWidget(templateButton);
}
m_projectTemplateButtonGroup->buttons().first()->setChecked(true);
// Select the first project template (default selection).
SelectProjectTemplate(0, /*blockSignals=*/true);
}
containerLayout->addWidget(templatesScrollArea);
}
@@ -159,8 +166,9 @@ namespace O3DE::ProjectManager
QString NewProjectSettingsScreen::GetProjectTemplatePath()
{
const int templateIndex = m_projectTemplateButtonGroup->checkedButton()->property(k_templateIndexProperty).toInt();
return m_templates.at(templateIndex).m_path;
AZ_Assert(m_selectedTemplateIndex == m_projectTemplateButtonGroup->checkedButton()->property(k_templateIndexProperty).toInt(),
"Selected template index not in sync with the currently checked project template button.");
return m_templates.at(m_selectedTemplateIndex).m_path;
}
QFrame* NewProjectSettingsScreen::CreateTemplateDetails(int margin)
@@ -216,4 +224,27 @@ namespace O3DE::ProjectManager
m_templateSummary->setText(templateInfo.m_summary);
m_templateIncludedGems->Update(templateInfo.m_includedGems);
}
void NewProjectSettingsScreen::SelectProjectTemplate(int index, bool blockSignals)
{
const QList<QAbstractButton*> buttons = m_projectTemplateButtonGroup->buttons();
if (index >= buttons.size())
{
return;
}
if (blockSignals)
{
m_projectTemplateButtonGroup->blockSignals(true);
}
QAbstractButton* button = buttons.at(index);
button->setChecked(true);
m_selectedTemplateIndex = button->property(k_templateIndexProperty).toInt();
if (blockSignals)
{
m_projectTemplateButtonGroup->blockSignals(false);
}
}
} // namespace O3DE::ProjectManager