Added Project Preview to Project Settings and Fixed Issues with Moving Projects (#1380)

* Updated Project Settings Screen with preview and fixed moving projects

* Tests for some Project Utils

* Remove old defined consts

* Update UX to use display name when avaliable where appropriate

* Use newPreviewImagePath for temp changing preview.png otherwise use iconPath for preview in UX

* Removed use of newPreviewImagePath in ProjectButton
This commit is contained in:
AMZN-nggieber
2021-06-22 17:24:48 -07:00
committed by GitHub
parent 2323cdd9e4
commit e21443b5d6
27 changed files with 679 additions and 143 deletions
@@ -11,6 +11,7 @@
*/
#include <GemCatalog/GemCatalogScreen.h>
#include <ProjectManagerDefs.h>
#include <PythonBindingsInterface.h>
#include <ScreenHeaderWidget.h>
#include <ScreensCtrl.h>
@@ -24,6 +25,7 @@
#include <QStackedWidget>
#include <QTabWidget>
#include <QVBoxLayout>
#include <QDir>
namespace O3DE::ProjectManager
{
@@ -101,8 +103,11 @@ namespace O3DE::ProjectManager
void UpdateProjectCtrl::HandleGemsButton()
{
m_stack->setCurrentWidget(m_gemCatalogScreen);
Update();
if (UpdateProjectSettings(true))
{
m_stack->setCurrentWidget(m_gemCatalogScreen);
Update();
}
}
void UpdateProjectCtrl::HandleBackButton()
@@ -114,7 +119,10 @@ namespace O3DE::ProjectManager
}
else
{
emit GotoPreviousScreenRequest();
if (UpdateProjectSettings(true))
{
emit GotoPreviousScreenRequest();
}
}
}
@@ -124,38 +132,9 @@ namespace O3DE::ProjectManager
if (m_stack->currentIndex() == ScreenOrder::Settings && m_updateSettingsScreen)
{
if (m_updateSettingsScreen)
if (!UpdateProjectSettings())
{
if (!m_updateSettingsScreen->Validate())
{
QMessageBox::critical(this, tr("Invalid project settings"), tr("Invalid project settings"));
return;
}
ProjectInfo newProjectSettings = m_updateSettingsScreen->GetProjectInfo();
// Update project if settings changed
if (m_projectInfo != newProjectSettings)
{
auto result = PythonBindingsInterface::Get()->UpdateProject(newProjectSettings);
if (!result.IsSuccess())
{
QMessageBox::critical(this, tr("Project update failed"), tr(result.GetError().c_str()));
return;
}
}
// Check if project path has changed and move it
if (newProjectSettings.m_path != m_projectInfo.m_path)
{
if (!ProjectUtils::MoveProject(m_projectInfo.m_path, newProjectSettings.m_path))
{
QMessageBox::critical(this, tr("Project move failed"), tr("Failed to move project."));
return;
}
}
m_projectInfo = newProjectSettings;
return;
}
}
else if (m_stack->currentIndex() == ScreenOrder::Gems && m_gemCatalogScreen)
@@ -190,14 +169,15 @@ namespace O3DE::ProjectManager
{
if (m_stack->currentIndex() == ScreenOrder::Gems)
{
m_header->setTitle(QString(tr("Edit Project Settings: \"%1\"")).arg(m_projectInfo.m_projectName));
m_header->setTitle(QString(tr("Edit Project Settings: \"%1\"")).arg(m_projectInfo.GetProjectDisplayName()));
m_header->setSubTitle(QString(tr("Configure Gems")));
m_nextButton->setText(tr("Finalize"));
m_nextButton->setText(tr("Save"));
}
else
{
m_header->setTitle("");
m_header->setSubTitle(QString(tr("Edit Project Settings: \"%1\"")).arg(m_projectInfo.m_projectName));
m_header->setSubTitle(QString(tr("Edit Project Settings: \"%1\"")).arg(m_projectInfo.GetProjectDisplayName()));
m_nextButton->setText(tr("Save"));
}
}
@@ -207,4 +187,70 @@ namespace O3DE::ProjectManager
m_updateSettingsScreen->SetProjectInfo(m_projectInfo);
}
bool UpdateProjectCtrl::UpdateProjectSettings(bool shouldConfirm)
{
AZ_Assert(m_updateSettingsScreen, "Update settings screen is nullptr.")
ProjectInfo newProjectSettings = m_updateSettingsScreen->GetProjectInfo();
if (m_projectInfo != newProjectSettings)
{
if (shouldConfirm)
{
QMessageBox::StandardButton warningResult = QMessageBox::warning(
this,
QObject::tr("Unsaved Changes!"),
QObject::tr("Would you like to save your changes to project settings?"),
QMessageBox::No | QMessageBox::Yes
);
if (warningResult == QMessageBox::No)
{
return true;
}
}
if (!m_updateSettingsScreen->Validate())
{
QMessageBox::critical(this, tr("Invalid project settings"), tr("Invalid project settings"));
return false;
}
// Update project if settings changed
{
auto result = PythonBindingsInterface::Get()->UpdateProject(newProjectSettings);
if (!result.IsSuccess())
{
QMessageBox::critical(this, tr("Project update failed"), tr(result.GetError().c_str()));
return false;
}
}
// Check if project path has changed and move it
if (newProjectSettings.m_path != m_projectInfo.m_path)
{
if (!ProjectUtils::MoveProject(m_projectInfo.m_path, newProjectSettings.m_path))
{
QMessageBox::critical(this, tr("Project move failed"), tr("Failed to move project."));
return false;
}
}
if (!newProjectSettings.m_newPreviewImagePath.isEmpty())
{
if (!ProjectUtils::ReplaceFile(
QDir(newProjectSettings.m_path).filePath(newProjectSettings.m_iconPath), newProjectSettings.m_newPreviewImagePath))
{
QMessageBox::critical(this, tr("File replace failed"), tr("Failed to replace project preview image."));
return false;
}
m_updateSettingsScreen->ResetProjectPreviewPath();
}
m_projectInfo = newProjectSettings;
}
return true;
}
} // namespace O3DE::ProjectManager