Initial draft for save all prefabs workflow
Signed-off-by: srikappa-amzn <srikappa@amazon.com>
This commit is contained in:
+149
-11
@@ -13,6 +13,10 @@
|
||||
|
||||
// Qt
|
||||
#include <QDateTime>
|
||||
#include <QCheckBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <AzQtComponents/Components/StyleManager.h>
|
||||
#include <AzQtComponents/Components/Widgets/CheckBox.h>
|
||||
|
||||
// AzCore
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
@@ -31,6 +35,7 @@
|
||||
#include <AzToolsFramework/UI/Layer/NameConflictWarning.hxx>
|
||||
#include <AzToolsFramework/API/EditorLevelNotificationBus.h>
|
||||
#include <AzToolsFramework/Entity/PrefabEditorEntityOwnershipInterface.h>
|
||||
#include <AzToolsFramework/Prefab/PrefabSystemComponentInterface.h>
|
||||
|
||||
// Editor
|
||||
#include "Settings.h"
|
||||
@@ -664,19 +669,116 @@ bool CCryEditDoc::SaveModified()
|
||||
return true;
|
||||
}
|
||||
|
||||
auto button = QMessageBox::question(AzToolsFramework::GetActiveWindow(), QString(), tr("Save changes to %1?").arg(GetTitle()),
|
||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||
switch (button)
|
||||
bool usePrefabSystemForLevels = false;
|
||||
AzFramework::ApplicationRequests::Bus::BroadcastResult(
|
||||
usePrefabSystemForLevels, &AzFramework::ApplicationRequests::IsPrefabSystemForLevelsEnabled);
|
||||
if (usePrefabSystemForLevels)
|
||||
{
|
||||
case QMessageBox::Cancel:
|
||||
return false;
|
||||
case QMessageBox::Yes:
|
||||
return DoFileSave();
|
||||
case QMessageBox::No:
|
||||
SetModifiedFlag(false);
|
||||
return true;
|
||||
auto prefabSystemComponentInterface = AZ::Interface<AzToolsFramework::Prefab::PrefabSystemComponentInterface>::Get();
|
||||
auto prefabEditorEntityOwnershipInterface = AZ::Interface<AzToolsFramework::PrefabEditorEntityOwnershipInterface>::Get();
|
||||
AzToolsFramework::SavePrefabsPreference savePrefabsPreference = prefabEditorEntityOwnershipInterface->GetSavePrefabsPreference();
|
||||
|
||||
QDialog saveModifiedMessageBox(AzToolsFramework::GetActiveWindow());
|
||||
saveModifiedMessageBox.setObjectName("SaveDirtyLevelDialog");
|
||||
|
||||
QVBoxLayout* contentLayout = new QVBoxLayout(&saveModifiedMessageBox);
|
||||
QFrame* levelEntitiesSaveQuestionFrame = new QFrame(&saveModifiedMessageBox);
|
||||
QHBoxLayout* levelEntitiesSaveQuestionLayout = new QHBoxLayout(&saveModifiedMessageBox);
|
||||
levelEntitiesSaveQuestionFrame->setObjectName("LevelEntitiesSaveQuestionFrame");
|
||||
QLabel* levelEntitiesSaveQuestionLabel = new QLabel("Do you want to save unsaved entities in the level?");
|
||||
|
||||
levelEntitiesSaveQuestionFrame->setLayout(levelEntitiesSaveQuestionLayout);
|
||||
QPixmap warningIcon(QString(":/Cards/img/UI20/Cards/warning.svg"));
|
||||
QLabel* warningIconContainer = new QLabel();
|
||||
warningIconContainer->setPixmap(warningIcon);
|
||||
warningIconContainer->setFixedWidth(warningIcon.width());
|
||||
levelEntitiesSaveQuestionLayout->addWidget(warningIconContainer);
|
||||
levelEntitiesSaveQuestionLayout->addWidget(levelEntitiesSaveQuestionLabel);
|
||||
contentLayout->addWidget(levelEntitiesSaveQuestionFrame);
|
||||
|
||||
QCheckBox* saveAllPrefabsCheckbox = new QCheckBox("Save all unsaved prefabs in the level too.");
|
||||
AzQtComponents::CheckBox::applyToggleSwitchStyle(saveAllPrefabsCheckbox);
|
||||
saveAllPrefabsCheckbox->setObjectName("SaveAllPrefabsCheckbox");
|
||||
QObject::connect(
|
||||
saveAllPrefabsCheckbox, &QCheckBox::stateChanged,
|
||||
[&savePrefabsPreference](int state)
|
||||
{
|
||||
savePrefabsPreference = static_cast<Qt::CheckState>(state) == Qt::CheckState::Checked
|
||||
? AzToolsFramework::SavePrefabsPreference::SaveAll
|
||||
: AzToolsFramework::SavePrefabsPreference::SaveNone;
|
||||
});
|
||||
contentLayout->addWidget(saveAllPrefabsCheckbox);
|
||||
QFrame* footerSeparatorLine = new QFrame();
|
||||
footerSeparatorLine->setObjectName("FooterSeparatorLine");
|
||||
footerSeparatorLine->setFrameShape(QFrame::HLine);
|
||||
contentLayout->addWidget(footerSeparatorLine);
|
||||
QHBoxLayout* footerLayout = new QHBoxLayout(&saveModifiedMessageBox);
|
||||
QCheckBox* saveAllPrefabsPreferenceCheckBox = new QCheckBox("Remember my preference.");
|
||||
AzQtComponents::CheckBox::applyToggleSwitchStyle(saveAllPrefabsPreferenceCheckBox);
|
||||
if (savePrefabsPreference == AzToolsFramework::SavePrefabsPreference::SaveAll)
|
||||
{
|
||||
saveAllPrefabsPreferenceCheckBox->setCheckState(Qt::CheckState::Checked);
|
||||
saveAllPrefabsCheckbox->setCheckState(Qt::CheckState::Checked);
|
||||
}
|
||||
QVBoxLayout* footerPreferenceLayout = new QVBoxLayout(&saveModifiedMessageBox);
|
||||
footerPreferenceLayout->addWidget(saveAllPrefabsPreferenceCheckBox);
|
||||
QLabel* prefabSavePreferenceHint = new QLabel("You can change this anytime in Edit -> Editor Settings -> GlobalPreferences.");
|
||||
prefabSavePreferenceHint->setObjectName("PrefabSavePreferenceHint");
|
||||
footerPreferenceLayout->addWidget(prefabSavePreferenceHint);
|
||||
footerLayout->addLayout(footerPreferenceLayout);
|
||||
QDialogButtonBox* prefabSaveConfirmationButtons = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
|
||||
footerLayout->addWidget(prefabSaveConfirmationButtons);
|
||||
|
||||
contentLayout->addLayout(footerLayout);
|
||||
|
||||
connect(prefabSaveConfirmationButtons, &QDialogButtonBox::accepted, &saveModifiedMessageBox, &QDialog::accept);
|
||||
connect(prefabSaveConfirmationButtons, &QDialogButtonBox::rejected, &saveModifiedMessageBox, &QDialog::reject);
|
||||
AzQtComponents::StyleManager::setStyleSheet(saveModifiedMessageBox.parentWidget(), QStringLiteral("style:Editor.qss"));
|
||||
|
||||
int prefabSaveSelection = saveModifiedMessageBox.exec();
|
||||
|
||||
if (saveAllPrefabsPreferenceCheckBox->checkState() == Qt::CheckState::Checked)
|
||||
{
|
||||
gSettings.SetSavePrefabsPreference(savePrefabsPreference);
|
||||
prefabEditorEntityOwnershipInterface->SetSavePrefabsPreference(savePrefabsPreference);
|
||||
}
|
||||
|
||||
switch (prefabSaveSelection)
|
||||
{
|
||||
case QDialog::Accepted:
|
||||
DoFileSave();
|
||||
if (savePrefabsPreference == AzToolsFramework::SavePrefabsPreference::SaveAll)
|
||||
{
|
||||
prefabSystemComponentInterface->SaveAllDirtyTemplates();
|
||||
}
|
||||
return true;
|
||||
case QDialog::Rejected:
|
||||
return false;
|
||||
}
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox saveModifiedMessageBox(AzToolsFramework::GetActiveWindow());
|
||||
saveModifiedMessageBox.setText(QString("Save changes to %1?").arg(GetTitle()));
|
||||
saveModifiedMessageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||
saveModifiedMessageBox.setIcon(QMessageBox::Icon::Question);
|
||||
|
||||
auto button = QMessageBox::question(
|
||||
AzToolsFramework::GetActiveWindow(), QString(), tr("Save changes to %1?").arg(GetTitle()),
|
||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
|
||||
switch (button)
|
||||
{
|
||||
case QMessageBox::Cancel:
|
||||
return false;
|
||||
case QMessageBox::Yes:
|
||||
return DoFileSave();
|
||||
case QMessageBox::No:
|
||||
SetModifiedFlag(false);
|
||||
return true;
|
||||
}
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
Q_UNREACHABLE();
|
||||
}
|
||||
|
||||
void CCryEditDoc::OnFileSaveAs()
|
||||
@@ -1258,6 +1360,42 @@ bool CCryEditDoc::SaveLevel(const QString& filename)
|
||||
if (openResult)
|
||||
{
|
||||
AZ::IO::FileIOStream stream(tempSaveFileHandle, AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeBinary, false);
|
||||
//SaveAllPrefabsDialog dlg(MainWindow::instance());
|
||||
//dlg.exec();
|
||||
/*
|
||||
AzToolsFramework::SavePrefabsPreference savePrefabsPreference =
|
||||
prefabEditorEntityOwnershipInterface->GetSavePrefabsPreference();
|
||||
if (savePrefabsPreference == AzToolsFramework::SavePrefabsPreference::Unspecified && !m_modified)
|
||||
{
|
||||
QMessageBox prefabSavePreferenceBox(AzToolsFramework::GetActiveWindow());
|
||||
prefabSavePreferenceBox.setText(QString("Save all prefabs in %1?").arg(GetTitle()));
|
||||
prefabSavePreferenceBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||
QCheckBox* checkbox = new QCheckBox("Remember my preference.");
|
||||
prefabSavePreferenceBox.setCheckBox(checkbox);
|
||||
prefabSavePreferenceBox.checkBox();
|
||||
int button = prefabSavePreferenceBox.exec();
|
||||
switch (button)
|
||||
{
|
||||
case QMessageBox::Yes:
|
||||
if (checkbox->checkState() == Qt::CheckState::Checked)
|
||||
{
|
||||
prefabEditorEntityOwnershipInterface->SetSavePrefabsPreference(
|
||||
AzToolsFramework::SavePrefabsPreference::SaveAll);
|
||||
gSettings.SetSavePrefabsPreference(AzToolsFramework::SavePrefabsPreference::SaveAll);
|
||||
}
|
||||
prefabEditorEntityOwnershipInterface->SetSaveAllPrefabs(true);
|
||||
break;
|
||||
case QMessageBox::No:
|
||||
if (checkbox->checkState() == Qt::CheckState::Checked)
|
||||
{
|
||||
prefabEditorEntityOwnershipInterface->SetSavePrefabsPreference(
|
||||
AzToolsFramework::SavePrefabsPreference::SaveNone);
|
||||
gSettings.SetSavePrefabsPreference(AzToolsFramework::SavePrefabsPreference::SaveNone);
|
||||
}
|
||||
prefabEditorEntityOwnershipInterface->SetSaveAllPrefabs(false);
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
contentsAllSaved = prefabEditorEntityOwnershipInterface->SaveToStream(stream, AZStd::string_view(filenameStrData.data(), filenameStrData.size()));
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user