diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp index b777bb6930..c21aff046e 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyCtrl.cpp @@ -36,7 +36,6 @@ void RegisterReflectedVarHandlers() EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew LocalStringPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew LightAnimationPropertyHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew UserPopupWidgetHandler()); - EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew LensFlareHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew ColorCurveHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew FloatCurveHandler()); EBUS_EVENT(AzToolsFramework::PropertyTypeRegistrationMessages::Bus, RegisterPropertyType, aznew MotionPropertyWidgetHandler()); diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.cpp index bce244e06b..89bb66b08a 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.cpp @@ -25,7 +25,6 @@ // Editor #include "GenericSelectItemDialog.h" #include "QtViewPaneManager.h" -#include "LensFlareEditor/LensFlareEditor.h" UserPropertyEditor::UserPropertyEditor(QWidget *pParent /*= nullptr*/) @@ -147,79 +146,6 @@ bool UserPopupWidgetHandler::ReadValuesIntoGUI(size_t index, UserPropertyEditor* #include -LensFlarePropertyWidget::LensFlarePropertyWidget(QWidget *pParent /*= nullptr*/) - :QWidget(pParent) -{ - m_valueEdit = new QLineEdit; - - QToolButton *mainButton = new QToolButton; - mainButton->setText("D"); - connect(mainButton, &QToolButton::clicked, this, &LensFlarePropertyWidget::OnEditClicked); - connect(m_valueEdit, &QLineEdit::editingFinished, m_valueEdit, [this] () {emit ValueChanged(m_valueEdit->text());}); - - QHBoxLayout *mainLayout = new QHBoxLayout(this); - mainLayout->addWidget(m_valueEdit, 1); - mainLayout->addWidget(mainButton); - mainLayout->setContentsMargins(1, 1, 1, 1); -} - -void LensFlarePropertyWidget::SetValue(const QString &value) -{ - m_valueEdit->setText(value); -} - -QString LensFlarePropertyWidget::GetValue() const -{ - return m_valueEdit->text(); -} - -void LensFlarePropertyWidget::OnEditClicked() -{ - const QtViewPane *lensFlarePane = GetIEditor()->OpenView(CLensFlareEditor::s_pLensFlareEditorClassName); - if (!lensFlarePane) - return; - - CLensFlareEditor *editor = FindViewPane(QtUtil::ToQString(CLensFlareEditor::s_pLensFlareEditorClassName)); - if (editor) - QTimer::singleShot(0, editor, SLOT(OnUpdateTreeCtrl())); -} - -QWidget* LensFlareHandler::CreateGUI(QWidget *pParent) -{ - LensFlarePropertyWidget* newCtrl = aznew LensFlarePropertyWidget(pParent); - connect(newCtrl, &LensFlarePropertyWidget::ValueChanged, newCtrl, [newCtrl]() - { - EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, newCtrl); - }); - - return newCtrl; -} - -void LensFlareHandler::ConsumeAttribute(LensFlarePropertyWidget* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) -{ - Q_UNUSED(GUI); Q_UNUSED(attrib); Q_UNUSED(attrValue); Q_UNUSED(debugName); -} - -void LensFlareHandler::WriteGUIValuesIntoProperty(size_t index, LensFlarePropertyWidget* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) -{ - Q_UNUSED(index); - Q_UNUSED(node); - CReflectedVarGenericProperty val = instance; - val.m_value = GUI->GetValue().toUtf8().data(); - instance = static_cast(val); -} - -bool LensFlareHandler::ReadValuesIntoGUI(size_t index, LensFlarePropertyWidget* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) -{ - Q_UNUSED(index); - Q_UNUSED(node); - CReflectedVarGenericProperty val = instance; - GUI->SetValue(val.m_value.c_str()); - return false; -} - - - QWidget* FloatCurveHandler::CreateGUI(QWidget *pParent) { CSplineCtrl *cSpline = new CSplineCtrl(pParent); diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.h b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.h index 00fb8e5f98..7ddbf6a338 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.h +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMiscCtrl.h @@ -70,39 +70,6 @@ public: }; - -class LensFlarePropertyWidget : public QWidget -{ - Q_OBJECT -public: - AZ_CLASS_ALLOCATOR(LensFlarePropertyWidget, AZ::SystemAllocator, 0); - LensFlarePropertyWidget(QWidget *pParent = nullptr); - - void SetValue(const QString &value); - QString GetValue() const; - - void OnEditClicked(); - -signals: - void ValueChanged(const QString &value); - -private: - QLineEdit *m_valueEdit; -}; - -class LensFlareHandler : public QObject, public AzToolsFramework::PropertyHandler < CReflectedVarGenericProperty, LensFlarePropertyWidget> -{ -public: - AZ_CLASS_ALLOCATOR(LensFlareHandler, AZ::SystemAllocator, 0); - bool IsDefaultHandler() const override { return false; } - QWidget* CreateGUI(QWidget *pParent) override; - - AZ::u32 GetHandlerName(void) const override { return AZ_CRC("ePropertyFlare", 0x5ce803df); } - void ConsumeAttribute(LensFlarePropertyWidget* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override; - void WriteGUIValuesIntoProperty(size_t index, LensFlarePropertyWidget* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override; - bool ReadValuesIntoGUI(size_t index, LensFlarePropertyWidget* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override; -}; - class FloatCurveHandler : public QObject, public AzToolsFramework::PropertyHandler < CReflectedVarSpline, CSplineCtrl> { public: diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp index b759b46ceb..055fc26a15 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedPropertyItem.cpp @@ -279,7 +279,6 @@ void ReflectedPropertyItem::SetVariable(IVariable *var) case ePropertyLocalString: case ePropertyLightAnimation: case ePropertyParticleName: - case ePropertyFlare: m_reflectedVarAdapter = new ReflectedVarGenericPropertyAdapter(desc.m_type); break; case ePropertyTexture: diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp index e0f7f29524..a805c07a2f 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/ReflectedVar.cpp @@ -308,8 +308,6 @@ AZ::u32 CReflectedVarGenericProperty::handler() return AZ_CRC("ePropertyLightAnimation", 0x277097da); case ePropertyParticleName: return AZ_CRC("ePropertyParticleName", 0xf44c7133); - case ePropertyFlare: - return AZ_CRC("ePropertyFlare", 0x5ce803df); default: AZ_Assert(false, "No property handlers defined for the property type"); return AZ_CRC("Default", 0xe35e00df); diff --git a/Code/Sandbox/Editor/CryEditDoc.cpp b/Code/Sandbox/Editor/CryEditDoc.cpp index 8819c8b382..41c49ab026 100644 --- a/Code/Sandbox/Editor/CryEditDoc.cpp +++ b/Code/Sandbox/Editor/CryEditDoc.cpp @@ -52,7 +52,6 @@ #include "ActionManager.h" #include "Include/IObjectManager.h" #include "Material/MaterialManager.h" -#include "LensFlareEditor/LensFlareManager.h" #include "ErrorReportDialog.h" #include "SurfaceTypeValidator.h" #include "ShaderCache.h" @@ -360,8 +359,6 @@ void CCryEditDoc::Save(TDocMultiArchive& arrXmlAr) SerializeMissions(arrXmlAr, currentMissionName, false); //! Serialize material manager. GetIEditor()->GetMaterialManager()->Serialize((*arrXmlAr[DMAS_GENERAL]).root, (*arrXmlAr[DMAS_GENERAL]).bLoading); - //! Serialize LensFlare manager. - GetIEditor()->GetLensFlareManager()->Serialize((*arrXmlAr[DMAS_GENERAL]).root, (*arrXmlAr[DMAS_GENERAL]).bLoading); SerializeShaderCache((*arrXmlAr[DMAS_GENERAL_NAMED_DATA])); SerializeNameSelection((*arrXmlAr[DMAS_GENERAL])); @@ -524,14 +521,6 @@ void CCryEditDoc::Load(TDocMultiArchive& arrXmlAr, const QString& szFilename) GetIEditor()->GetMaterialManager()->Serialize((*arrXmlAr[DMAS_GENERAL]).root, (*arrXmlAr[DMAS_GENERAL]).bLoading); } - ////////////////////////////////////////////////////////////////////////// - // Load LensFlares. - ////////////////////////////////////////////////////////////////////////// - { - CAutoLogTime logtime("Load Flares"); - GetIEditor()->GetLensFlareManager()->Serialize((*arrXmlAr[DMAS_GENERAL]).root, (*arrXmlAr[DMAS_GENERAL]).bLoading); - } - ////////////////////////////////////////////////////////////////////////// // Load View Settings ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/DatabaseFrameWnd.cpp b/Code/Sandbox/Editor/DatabaseFrameWnd.cpp deleted file mode 100644 index 89843c8247..0000000000 --- a/Code/Sandbox/Editor/DatabaseFrameWnd.cpp +++ /dev/null @@ -1,1491 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "DatabaseFrameWnd.h" - -// Qt -#include -#include -#include -#include - -// AzToolsFramework -#include - -// Editor -#include "BaseLibraryManager.h" -#include "BaseLibraryItem.h" -#include "StringDlg.h" -#include "QtViewPaneManager.h" -#include "Undo/Undo.h" - -#include "ui_DatabaseFrameWnd.h" - - -class CUndoSelectLibraryUndo - : public IUndoObject -{ -public: - CUndoSelectLibraryUndo(const QString& libraryName, const QString& wndClssName) - { - m_LibraryName = libraryName; - m_WndClassName = wndClssName; - } - ~CUndoSelectLibraryUndo(){} - -protected: - int GetSize() - { - return sizeof(*this); - } - QString GetDescription() { return "Select database library."; }; - void Undo(bool bUndo) - { - SelectLibrary(bUndo); - } - void Redo() - { - SelectLibrary(true); - } - -private: - - void SelectLibrary(bool bUndo) - { - CDatabaseFrameWnd* pDatabaseEditor = FindViewPane(m_WndClassName); - if (!pDatabaseEditor) - { - return; - } - - QString libraryNameForUndo(m_LibraryName); - if (bUndo) - { - m_LibraryName = pDatabaseEditor->GetSelectedLibraryName(); - } - pDatabaseEditor->SelectLibrary(libraryNameForUndo); - } - - QString m_LibraryName; - QString m_WndClassName; -}; - -static const int LIBRARY_CB_WIDTH(150); - -CDatabaseFrameWnd::CDatabaseFrameWnd(CBaseLibraryManager* pItemManager, QWidget* pParent) - : AzQtComponents::DockMainWindow(pParent) - , m_pItemManager(pItemManager) - , ui(new Ui::DatabaseFrameWnd) - , m_initialized(false) - , m_pLibraryItemTreeModel(nullptr) -{ - ui->setupUi(this); - m_sortRecursionType = SORT_RECURSION_FULL; - m_pLibrary = NULL; - m_bLibsLoaded = false; - m_pCurrentItem = NULL; - - GetIEditor()->RegisterNotifyListener(this); - GetIEditor()->GetUndoManager()->AddListener(this); - - m_pLibraryListComboBox = new QComboBox; - m_pLibraryListComboBox->setFixedSize(LIBRARY_CB_WIDTH, 16); - ui->m_toolBar->insertWidget(ui->m_toolBar->actions()[4], m_pLibraryListComboBox); - connect(m_pLibraryListComboBox, static_cast(&QComboBox::currentIndexChanged), this, &CDatabaseFrameWnd::OnChangedLibrary); - - m_pLibraryListModel = new LibraryListModel(m_pItemManager, this); - m_pLibraryListComboBox->setModel(m_pLibraryListModel); - - connect(ui->actionDBAddLib, &QAction::triggered, this, &CDatabaseFrameWnd::OnAddLibrary); - connect(ui->actionDBDelLib, &QAction::triggered, this, &CDatabaseFrameWnd::OnRemoveLibrary); - connect(ui->actionDBRemove, &QAction::triggered, this, &CDatabaseFrameWnd::OnRemoveItem); - connect(ui->actionDBSave, &QAction::triggered, this, &CDatabaseFrameWnd::OnSave); - connect(ui->actionDBLoadLib, &QAction::triggered, this, &CDatabaseFrameWnd::OnLoadLibrary); - connect(ui->actionDBReload, &QAction::triggered, this, &CDatabaseFrameWnd::OnReloadLib); - connect(ui->actionDBReloadLib, &QAction::triggered, this, &CDatabaseFrameWnd::OnReloadLib); - connect(ui->actionDBCopy, &QAction::triggered, this, &CDatabaseFrameWnd::OnCopy); - connect(ui->actionDBPaste, &QAction::triggered, this, &CDatabaseFrameWnd::OnPaste); - connect(ui->actionDBClone, &QAction::triggered, this, &CDatabaseFrameWnd::OnClone); - connect(ui->actionUndo, &QAction::triggered, this, &CDatabaseFrameWnd::OnUndo); - connect(ui->actionRedo, &QAction::triggered, this, &CDatabaseFrameWnd::OnRedo); -} - -CDatabaseFrameWnd::~CDatabaseFrameWnd() -{ - // Block Signals to prevent changes in the m_pLibraryListComboBox - // from triggering OnChangedLibrary on teardown. - m_pLibraryListComboBox->blockSignals(true); - - m_pLibraryListModel->clear(); - - GetIEditor()->UnregisterNotifyListener(this); - GetIEditor()->GetUndoManager()->RemoveListener(this); -} - -void CDatabaseFrameWnd::InitTreeCtrl() -{ - QTreeView* treeView = GetTreeCtrl(); - - connect(treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &CDatabaseFrameWnd::OnSelChangedItemTree); - treeView->installEventFilter(this); -} - -void CDatabaseFrameWnd::ReloadLibs() -{ - if (!m_pItemManager) - { - return; - } - - SelectItem(0); - - m_pLibraryListModel->Reload(); - - if (m_pLibraryListComboBox) - { - SelectLibrary(m_pLibraryListComboBox->itemData(0, Qt::UserRole).value()); - } - - m_bLibsLoaded = true; -} - -void CDatabaseFrameWnd::ReloadItems() -{ - SelectItem(0); - m_selectedGroup = ""; - m_pCurrentItem = 0; - m_cpoSelectedLibraryItems.clear(); - if (m_pItemManager) - { - m_pItemManager->SetSelectedItem(0); - } - ReleasePreviewControl(); - - if (m_pLibrary && m_pLibraryItemTreeModel) - { - m_pLibraryItemTreeModel->Reload(m_pLibrary); - GetTreeCtrl()->expandAll(); - } -} - -void CDatabaseFrameWnd::SelectLibrary(const QString& library, bool bForceSelect) -{ - QWaitCursor wait; - if (GetSelectedLibraryName() != library || bForceSelect) - { - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoSelectLibraryUndo(GetSelectedLibraryName(), GetClassName())); - } - - SelectItem(0); - m_pLibrary = FindLibrary(library); - ReloadItems(); - } - if (m_pLibraryListComboBox) - { - m_pLibraryListComboBox->setCurrentIndex(GetComboBoxIndex(m_pLibrary)); - } -} - -void CDatabaseFrameWnd::SelectLibrary(CBaseLibrary* pItem, bool bForceSelect) -{ - QWaitCursor wait; - if (m_pLibrary != pItem || bForceSelect) - { - if (CUndo::IsRecording() && m_pLibrary) - { - CUndo::Record(new CUndoSelectLibraryUndo(GetSelectedLibraryName(), GetClassName())); - } - - SelectItem(0); - m_pLibrary = pItem; - ReloadItems(); - } - if (m_pLibraryListComboBox) - { - m_pLibraryListComboBox->setCurrentIndex(GetComboBoxIndex(pItem)); - } -} - -void CDatabaseFrameWnd::SelectItem(CBaseLibraryItem* item, bool bForceReload) -{ - if (item == m_pCurrentItem && !bForceReload) - { - return; - } - - QModelIndex index = m_pLibraryItemTreeModel->index(item); - if (index.isValid()) - { - GetTreeCtrl()->expand(index.parent()); - GetTreeCtrl()->setCurrentIndex(index); - } - else - { - GetTreeCtrl()->selectionModel()->clearCurrentIndex(); - } -} - -CBaseLibrary* CDatabaseFrameWnd::FindLibrary(const QString& libraryName) -{ - return (CBaseLibrary*)m_pItemManager->FindLibrary(libraryName); -} - -int CDatabaseFrameWnd::GetComboBoxIndex(CBaseLibrary* pLibrary) -{ - return m_pLibraryListComboBox->findData(QVariant::fromValue(pLibrary)); -} - -CBaseLibrary* CDatabaseFrameWnd::NewLibrary(const QString& libraryName) -{ - return (CBaseLibrary*)m_pItemManager->AddLibrary(libraryName, false); -} - -void CDatabaseFrameWnd::DeleteLibrary(CBaseLibrary* pLibrary) -{ - m_pItemManager->DeleteLibrary(pLibrary->GetName()); -} - -void CDatabaseFrameWnd::DeleteItem(CBaseLibraryItem* pItem) -{ - m_pItemManager->DeleteItem(pItem); -} - -void CDatabaseFrameWnd::OnAddLibrary() -{ - StringDlg dlg(tr("New Library Name"), this); - CUndo undo(tr("Add Database Library").toUtf8()); - if (dlg.exec() == QDialog::Accepted) - { - if (!dlg.GetString().isEmpty()) - { - SelectItem(0); - // Make new library. - QString library = dlg.GetString(); - NewLibrary(library); - ReloadLibs(); - SelectLibrary(library); - GetIEditor()->SetModifiedFlag(); - } - } -} - -void CDatabaseFrameWnd::OnRemoveLibrary() -{ - QString library = GetSelectedLibraryName(); - if (library.isEmpty()) - { - return; - } - if (m_pLibrary->IsModified()) - { - QString ask = tr("Save changes to the library %1?").arg(library); - if (QMessageBox::question(this, tr("Editor"), ask) == QMessageBox::Yes) - { - OnSave(); - } - } - QString ask = tr("When removing library All items contained in this library will be deleted.\r\nAre you sure you want to remove libarary %1?\r\n(Note: Library file will not be deleted from the disk)").arg(library); - if (QMessageBox::question(this, tr("Editor"), ask) == QMessageBox::Yes) - { - SelectItem(0); - DeleteLibrary(m_pLibrary); - m_pLibrary = 0; - ReleasePreviewControl(); - ReloadLibs(); - GetIEditor()->SetModifiedFlag(); - } -} - -void CDatabaseFrameWnd::OnAddItem() -{ -} - -void CDatabaseFrameWnd::OnRemoveItem() -{ - // When we have no set of selected items, it may be the case that we are - // dealing with old fashioned selection. If such is the case, let's deal - // with it using the old code system, which should be deprecated. - if (m_cpoSelectedLibraryItems.empty()) - { - if (m_pCurrentItem) - { - // Remove prototype from prototype manager and library. - QString str = tr("Delete %1?").arg(m_pCurrentItem->GetName()); - if (QMessageBox::question(this, tr("Delete Confirmation"), str) == QMessageBox::Yes) - { - CUndo undo(tr("Remove library item").toUtf8()); - TSmartPtr pCurrent = m_pCurrentItem; - DeleteItem(pCurrent); - m_pLibraryItemTreeModel->Remove(m_pCurrentItem); - GetIEditor()->SetModifiedFlag(); - SelectItem(0); - } - } - } - else // This is to be used when deleting multiple items... - { - QString strMessageString = tr("Delete the following items:\n"); - int nItemCount(0); - std::set::iterator itCurrentIterator; - std::set::iterator itEnd; - - itEnd = m_cpoSelectedLibraryItems.end(); - itCurrentIterator = m_cpoSelectedLibraryItems.begin(); - // For now, we have a maximum limit of 7 items per messagebox... - for (nItemCount = 0; nItemCount < 7; ++nItemCount, itCurrentIterator++) - { - if (itCurrentIterator == itEnd) - { - // As there were less than 7 items selected, we got to put them all - // into the formated string for the messagebox. - break; - } - strMessageString += QStringLiteral("%1\n").arg((*itCurrentIterator)->GetName()); - } - if (itCurrentIterator != itEnd) - { - strMessageString += QStringLiteral("..."); - } - - if (QMessageBox::question(this, tr("Delete Confirmation"), strMessageString) == QMessageBox::Yes) - { - for (itCurrentIterator = m_cpoSelectedLibraryItems.begin(); itCurrentIterator != itEnd; itCurrentIterator++) - { - CBaseLibraryItem* pCurrent = *itCurrentIterator; - DeleteItem(pCurrent); - m_pLibraryItemTreeModel->Remove(pCurrent); - } - m_cpoSelectedLibraryItems.clear(); - GetIEditor()->SetModifiedFlag(); - SelectItem(0); - } - } -} - -void CDatabaseFrameWnd::OnRenameItem() -{ - if (m_pCurrentItem) - { - StringGroupDlg dlg; - dlg.SetGroup(m_pCurrentItem->GetGroupName()); - dlg.SetString(m_pCurrentItem->GetShortName()); - if (dlg.exec() == QDialog::Accepted) - { - static bool warn = true; - if (warn) - { - warn = false; - QMessageBox::warning(this, tr("Warning"), tr("Levels referencing this archetype will need to be exported.")); - } - - CUndo undo(tr("Rename library item").toUtf8()); - TSmartPtr curItem = m_pCurrentItem; - SetItemName(curItem, dlg.GetGroup(), dlg.GetString()); - ReloadItems(); - SelectItem(curItem, true); - curItem->SetModified(); - //m_pCurrentItem->Update(); - } - GetIEditor()->SetModifiedFlag(); - } -} - -void CDatabaseFrameWnd::OnChangedLibrary() -{ - CBaseLibrary* pBaseLibrary = NULL; - if (m_pLibraryListComboBox) - { - pBaseLibrary = m_pLibraryListComboBox->currentData(Qt::UserRole).value(); - } - - if (pBaseLibrary && pBaseLibrary != m_pLibrary) - { - CUndo undo("Change database library"); - SelectLibrary(pBaseLibrary); - } -} - -void CDatabaseFrameWnd::OnExportLibrary() -{ - if (!m_pLibrary) - { - return; - } - - QString filename; - if (CFileUtil::SelectSaveFile("Library XML Files (*.xml)", "xml", (Path::GetEditingGameDataFolder() + "/Materials").c_str(), filename)) - { - XmlNodeRef libNode = XmlHelpers::CreateXmlNode("MaterialLibrary"); - m_pLibrary->Serialize(libNode, false); - XmlHelpers::SaveXmlNode(GetIEditor()->GetFileUtil(), libNode, filename.toStdString().c_str()); - } -} - -void CDatabaseFrameWnd::OnSave() -{ - if (m_bLibsLoaded) - { - m_pLibrary->SetModified(true); - m_pItemManager->SaveAllLibs(); - m_pLibrary->SetModified(false); - } -} - -void CDatabaseFrameWnd::OnReloadLib() -{ - if (!m_pLibrary) - { - return; - } - - QString libname = m_pLibrary->GetName(); - QString file = m_pLibrary->GetFilename(); - - //If the file we want to reload does not exist (and isn't the level library), we can't reload it - //Just display a warning to the user and stop the reload process - if (!CFileUtil::Exists(file, false) && !m_pLibrary->IsLevelLibrary()) - { - QString str = tr("Layer %1 does not exist on disk yet. Have you ever saved it?\nReloading layer is not possible!"). - arg(libname); - if (QMessageBox::information(this, tr("Editor"), str)) - { - return; - } - } - - if (m_pLibrary->IsModified()) - { - QString str = tr("Layer %1 was modified.\nReloading layer will discard all modifications to this library!"). - arg(libname); - if (QMessageBox::question(this, tr("Editor"), str) != QMessageBox::Yes) - { - return; - } - } - - //Don't try to delete/load level library from disk. - //It's managed by the level and there doesn't seem to be a way to "reload" it - if (!m_pLibrary->IsLevelLibrary()) - { - m_pItemManager->DeleteLibrary(libname); - m_pItemManager->LoadLibrary(file, true); - } - - ReloadLibs(); - SelectLibrary(libname); -} - -void CDatabaseFrameWnd::OnLoadLibrary() -{ - assert(m_pItemManager); - CUndo undo(tr("Load Database Library").toUtf8()); - LoadLibrary(); -} - -void CDatabaseFrameWnd::LoadLibrary() -{ - AssetSelectionModel selection = GetAssetSelectionModel(); - - AzToolsFramework::EditorRequests::Bus::Broadcast( - &AzToolsFramework::EditorRequests::BrowseForAssets, - selection); - if (selection.IsValid()) - { - GetIEditor()->SuspendUndo(); - IDataBaseLibrary* matLib = m_pItemManager->LoadLibrary(Path::FullPathToGamePath( - selection.GetResult()->GetFullPath().c_str()).c_str()); - GetIEditor()->ResumeUndo(); - ReloadLibs(); - if (matLib) - { - SelectLibrary((CBaseLibrary*)matLib); - } - } -} - -bool CDatabaseFrameWnd::SetItemName(CBaseLibraryItem* item, const QString& groupName, const QString& itemName) -{ - assert(item); - // Make prototype name. - QString name; - if (!groupName.isEmpty()) - { - name = groupName + "."; - } - name += itemName; - QString fullName = name; - if (item->GetLibrary()) - { - fullName = item->GetLibrary()->GetName() + "." + name; - } - IDataBaseItem* pOtherItem = m_pItemManager->FindItemByName(fullName); - if (pOtherItem && pOtherItem != item) - { - // Ensure uniqness of name. - Warning("Duplicate Item Name %s", name.toUtf8().data()); - return false; - } - else - { - item->SetName(name); - } - return true; -} - -void CDatabaseFrameWnd::OnSelChangedItemTree(const QModelIndex& index) -{ - CBaseLibraryItem* item = index.data(Qt::UserRole).value(); - - if (item) - { - if (item->GetLibrary() != m_pLibrary && item->GetLibrary()) - { - SelectLibrary((CBaseLibrary*)item->GetLibrary()); - } - } - - m_pCurrentItem = item; - - if (item) - { - m_selectedGroup = item->GetGroupName(); - } - else - { - m_selectedGroup = ""; - } - - m_pItemManager->SetSelectedItem(item); -} - -bool CDatabaseFrameWnd::eventFilter(QObject* watched, QEvent* event) -{ - if (event->type() != QEvent::KeyPress || watched != GetTreeCtrl()) - { - return QMainWindow::eventFilter(watched, event); - } - - QKeyEvent* keyEvent = static_cast(event); - - bool bCtrl = keyEvent->modifiers() == Qt::ControlModifier; - - if (keyEvent->matches(QKeySequence::Copy)) - { - OnCopy(); // Ctrl+C - } - else if (keyEvent->matches(QKeySequence::Paste)) - { - OnPaste(); // Ctrl+V - } - else if (keyEvent->matches(QKeySequence::Cut)) - { - OnCut(); // Ctrl+X - } - else if (bCtrl && keyEvent->key() == Qt::Key_D) - { - OnClone(); // Ctrl+D - } - else if (keyEvent->matches(QKeySequence::Delete)) - { - OnRemoveItem(); - } - else if (keyEvent->key() == Qt::Key_F2) - { - OnRenameItem(); - } - else if (keyEvent->key() == Qt::Key_Insert) - { - OnAddItem(); - } - else - { - return QMainWindow::eventFilter(watched, event); - } - - return true; -} - -void CDatabaseFrameWnd::OnUndo() -{ - GetIEditor()->Undo(); -} - -void CDatabaseFrameWnd::OnRedo() -{ - GetIEditor()->Redo(); -} - -void CDatabaseFrameWnd::OnCut() -{ - if (m_pCurrentItem) - { - OnCopy(); - OnRemoveItem(); - } -} - -void CDatabaseFrameWnd::OnClone() -{ - OnCopy(); - OnPaste(); -} - -void CDatabaseFrameWnd::DoesItemExist(const QString& itemName, bool& bOutExist) const -{ - for (int i = 0, iItemCount(m_pLibrary->GetItemCount()); i < iItemCount; ++i) - { - IDataBaseItem* pItem = m_pLibrary->GetItem(i); - if (pItem == NULL) - { - continue; - } - if (pItem->GetName() == itemName) - { - bOutExist = true; - return; - } - } - bOutExist = false; -} - -QString CDatabaseFrameWnd::MakeValidName(const QString& candidateName, AZStd::function FuncForCheck) const -{ - bool bCheck = false; - FuncForCheck(candidateName, bCheck); - if (!bCheck) - { - return candidateName; - } - - int nCounter = 0; - const int nEnoughBigNumber = 1000000; - do - { - QString counterBuffer; - counterBuffer = QString::number(nCounter); - QString newName = candidateName + counterBuffer; - FuncForCheck(newName, bCheck); - if (!bCheck) - { - return newName; - } - } while (nCounter++ < nEnoughBigNumber); - - assert(0 && "CDatabaseFrameWnd::MakeValidName()"); - return candidateName; -} - -void CDatabaseFrameWnd::DoesGroupExist(const QString& groupName, bool& bOutExist) const -{ - bOutExist = m_pLibraryItemTreeModel->DoesGroupExist(groupName); -} - -QString CDatabaseFrameWnd::GetSelectedLibraryName() const -{ - return m_pLibrary ? m_pLibrary->GetName() : ""; -} - -void CDatabaseFrameWnd::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnBeginNewScene: - m_bLibsLoaded = false; - // Clear all prototypes and libraries. - SelectItem(0); - if (m_pLibraryListComboBox) - { - m_pLibraryListComboBox->clear(); - } - m_pLibrary = nullptr; - break; - - case eNotify_OnEndSceneOpen: - m_bLibsLoaded = false; - ReloadLibs(); - break; - - case eNotify_OnCloseScene: - { - m_bLibsLoaded = false; - CUndo undo(tr("Close Database Library").toUtf8()); - GetTreeCtrl()->selectionModel()->clear(); - GetTreeCtrl()->clearSelection(); - m_pLibraryItemTreeModel->Clear(); - m_pCurrentItem = nullptr; - m_cpoSelectedLibraryItems.clear(); - } - break; - - case eNotify_OnDataBaseUpdate: - if (m_pLibrary && m_pLibrary->IsModified()) - { - ReloadItems(); - } - break; - } -} - -void CDatabaseFrameWnd::SignalNumUndoRedo(const unsigned int& numUndo, const unsigned int& numRedo) -{ - ui->actionUndo->setEnabled(numUndo > 0); - ui->actionRedo->setEnabled(numRedo > 0); -} - -void CDatabaseFrameWnd::showEvent(QShowEvent* event) -{ - if (!m_initialized) - { - OnInitDialog(); - m_initialized = true; - } - - QMainWindow::showEvent(event); -} - -LibraryListModel::LibraryListModel(CBaseLibraryManager* itemManager, QObject* pParent) - : QAbstractListModel(pParent) - , m_pItemManager(itemManager) -{ -} - -int LibraryListModel::rowCount(const QModelIndex& parent) const -{ - return parent.isValid() ? 0 : m_pItemManager->GetLibraryCount(); -} - -QVariant LibraryListModel::data(const QModelIndex& index, int role) const -{ - const int row = index.row(); - - if (row < 0 || row >= m_pItemManager->GetLibraryCount()) - { - return {}; - } - - auto library = static_cast(m_pItemManager->GetLibrary(row)); - - switch (role) - { - case Qt::DisplayRole: - { - QString name = library->GetName(); - if (library->IsModified()) - { - name += "*"; - } - return name; - } - - case Qt::UserRole: - return QVariant::fromValue(library); - } - - return {}; -} - -void LibraryListModel::Reload() -{ - beginResetModel(); - - const int count = m_pItemManager->GetLibraryCount(); - - for (int i = 0; i < count; i++) - { - CBaseLibrary* pLibrary = static_cast(m_pItemManager->GetLibrary(i)); - connect(pLibrary, &CBaseLibrary::Modified, this, &LibraryListModel::LibraryModified); - } - - endResetModel(); -} - -void LibraryListModel::clear() -{ - beginResetModel(); - endResetModel(); -} - -void LibraryListModel::LibraryModified(bool) -{ - CBaseLibrary* library = qobject_cast(sender()); - - const int count = m_pItemManager->GetLibraryCount(); - - for (int i = 0; i < count; i++) - { - CBaseLibrary* pLibrary = static_cast(m_pItemManager->GetLibrary(i)); - if (pLibrary == library) - { - emit dataChanged(index(i, 0), index(i, 0)); - } - } -} - -LibraryItemTreeModel::LibraryItemTreeModel(CDatabaseFrameWnd* pParent) - : QAbstractItemModel(pParent) - , m_dialog(pParent) -{ -} - -Qt::ItemFlags LibraryItemTreeModel::flags(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return Qt::ItemFlags(); - } - - Qt::ItemFlags flags = QAbstractItemModel::flags(index); - - flags |= Qt::ItemIsEditable; - - if (!index.internalPointer()) - { - flags |= Qt::ItemIsDropEnabled; - } - else - { - flags |= Qt::ItemIsDragEnabled; - } - - return flags; -} - -int LibraryItemTreeModel::columnCount(const QModelIndex&) const -{ - return 1; -} - -int LibraryItemTreeModel::rowCount(const QModelIndex& parent) const -{ - if (!parent.isValid()) - { - return m_groups.size(); - } - else - { - if (!parent.internalPointer() && parent.row() >= 0 && parent.row() < m_groups.size()) - { - auto entry = std::begin(m_groups); - std::advance(entry, parent.row()); - return entry->second->second.size(); - } - } - - return 0; -} - -QModelIndex LibraryItemTreeModel::parent(const QModelIndex& index) const -{ - if (index.isValid() && index.internalPointer()) - { - auto group = static_cast(index.internalPointer()); - auto entry = m_groups.find(group->first); - return createIndex(std::distance(std::begin(m_groups), entry), 0, nullptr); - } - - return {}; -} - -QModelIndex LibraryItemTreeModel::index(int row, int column, const QModelIndex& parent) const -{ - if (column > 0) - { - return {}; - } - - if (!parent.isValid()) - { - if (row >= 0 && row < m_groups.size()) - { - return createIndex(row, 0, nullptr); - } - } - else - { - if (!parent.internalPointer() && parent.row() >= 0 && parent.row() < m_groups.size()) - { - auto entry = std::begin(m_groups); - std::advance(entry, parent.row()); - - if (row >= 0 && row < entry->second->second.size()) - { - return createIndex(row, 0, const_cast(entry->second.get())); - } - } - } - - return {}; -} - -QVariant LibraryItemTreeModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) - { - return {}; - } - - if (!index.internalPointer()) - { - switch (role) - { - case Qt::DisplayRole: - { - auto entry = std::begin(m_groups); - std::advance(entry, index.row()); - return entry->first; - } - case Qt::UserRole: - return QVariant::fromValue(nullptr); - } - } - else - { - auto group = static_cast(index.internalPointer()); - auto item = group->second[index.row()]; - - switch (role) - { - case Qt::DisplayRole: - return item->GetShortName(); - case Qt::UserRole: - return QVariant::fromValue(item); - } - } - - return {}; -} - -void LibraryItemTreeModel::RenameItem(CBaseLibraryItem* item, const QString& fullName) -{ - QString prevFullName = item->GetFullName(); - item->SetName(fullName); - item->SetModified(); - emit itemRenamed(item, prevFullName); -} - -bool LibraryItemTreeModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - if (!index.isValid() || role != Qt::EditRole) - { - return false; - } - - QString text = value.toString(); - - if (text.isEmpty()) - { - return false; - } - - if (text.contains(QLatin1Char('.'))) - { - QMessageBox::warning(AzToolsFramework::GetActiveWindow(), tr("Warning"), tr("The name must not contain \".\"")); - return false; - } - - if (!index.internalPointer()) - { - // rename group - - auto sourceEntry = std::begin(m_groups); - std::advance(sourceEntry, index.row()); - - if (text == sourceEntry->first) - { - return false; - } - - if (m_groups.find(text) != std::end(m_groups)) - { - QMessageBox::warning(AzToolsFramework::GetActiveWindow(), tr("Warning"), tr("The identical name exists.")); - return false; - } - - int sourceRow = index.row(); - int targetRow = std::distance(std::begin(m_groups), m_groups.lower_bound(text)); - - if (targetRow < sourceRow || targetRow > sourceRow + 1) - { - beginMoveRows({}, sourceRow, sourceRow, {}, targetRow); - } - - auto targetEntry = m_groups.insert({ text, sourceEntry->second }).first; - targetEntry->second->first = text; - m_groups.erase(sourceEntry); - - if (targetRow < sourceRow || targetRow > sourceRow + 1) - { - endMoveRows(); - } - else - { - emit dataChanged(index, index); - } - - CUndo undo(tr("Rename FlareGroupItem").toUtf8()); - - auto group = targetEntry->second.get(); - - for (int row = 0; row < group->second.size(); row++) - { - auto item = group->second[row]; - QString name = QString("%1.%2").arg(text).arg(item->GetShortName()); - RenameItem(item, name); - } - } - else - { - // rename single item - - auto group = static_cast(index.internalPointer()); - auto& items = group->second; - - auto item = items[index.row()]; - - if (text == item->GetShortName()) - { - return false; - } - - QString name = QString("%1.%2").arg(item->GetGroupName(), text); - - if (std::find_if(std::begin(items), std::end(items), - [&](const CBaseLibraryItem* item) - { - return item->GetName() == name; - }) != std::end(items)) - { - QMessageBox::warning(AzToolsFramework::GetActiveWindow(), tr("Warning"), tr("The identical name exists.")); - return false; - } - - CUndo undo(tr("Rename FlareGroupItem").toUtf8()); - RenameItem(item, name); - - emit dataChanged(index, index); - } - - return true; -} - -QModelIndex LibraryItemTreeModel::index(CBaseLibraryItem* item) const -{ - if (!item) - { - return {}; - } - - auto entry = m_groups.find(item->GetGroupName()); - if (entry == std::end(m_groups)) - { - return {}; - } - - auto& items = entry->second->second; - - auto it = std::find(std::begin(items), std::end(items), item); - if (it == std::end(items)) - { - return {}; - } - - return createIndex(std::distance(std::begin(items), it), 0, const_cast(entry->second.get())); -} - -bool LibraryItemTreeModel::removeRows(int row, int count, const QModelIndex& parent) -{ - if (!parent.isValid()) - { - beginRemoveRows({}, row, row + count - 1); - - auto first = std::begin(m_groups); - std::advance(first, row); - - auto last = std::begin(m_groups); - std::advance(last, row + count); - - m_groups.erase(first, last); - - endRemoveRows(); - } - else - { - beginRemoveRows(parent, row, row + count - 1); - - auto entry = std::begin(m_groups); - std::advance(entry, parent.row()); - - auto& items = entry->second->second; - items.erase(std::begin(items) + row, std::begin(items) + row + count); - - endRemoveRows(); - - if (items.empty()) - { - beginRemoveRows({}, parent.row(), parent.row()); - m_groups.erase(entry); - endRemoveRows(); - } - } - - return true; -} - -static bool LibraryItemLess(const CBaseLibraryItem* left, const CBaseLibraryItem* right) -{ - QString leftName = left->GetName(); - QString rightName = right->GetName(); - return leftName.compare(rightName) < 0; -} - -void LibraryItemTreeModel::Clear() -{ - beginResetModel(); - - m_groups.clear(); - - endResetModel(); -} - -void LibraryItemTreeModel::Reload(CBaseLibrary* pLibrary) -{ - beginResetModel(); - - m_groups.clear(); - - for (int i = 0; i < pLibrary->GetItemCount(); i++) - { - auto item = static_cast(pLibrary->GetItem(i)); - - QString itemName = item->GetName(); - QString groupName = item->GetGroupName(); - - auto entry = m_groups.find(groupName); - - if (entry == std::end(m_groups)) - { - entry = m_groups.insert({ groupName, std::make_shared(groupName, std::vector()) }).first; - } - - auto& items = entry->second->second; - items.insert(std::upper_bound(std::begin(items), std::end(items), item, LibraryItemLess), item); - } - - endResetModel(); -} - -QString LibraryItemTreeModel::GetFullName(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return QString(); - } - - if (!index.internalPointer()) - { - auto entry = std::begin(m_groups); - std::advance(entry, index.row()); - return entry->first; - } - else - { - auto group = static_cast(index.internalPointer()); - auto item = group->second[index.row()]; - return item->GetName(); - } -} - -void LibraryItemTreeModel::Add(CBaseLibraryItem* item) -{ - QString groupName = item->GetGroupName(); - - auto entry = m_groups.find(groupName); - if (entry == std::end(m_groups)) - { - int row = std::distance(std::begin(m_groups), m_groups.lower_bound(groupName)); - - emit beginInsertRows({}, row, row); - entry = m_groups.insert({ groupName, std::make_shared(groupName, std::vector()) }).first; - emit endInsertRows(); - } - - QModelIndex parentIndex = createIndex(std::distance(std::begin(m_groups), entry), 0, nullptr); - auto& items = entry->second->second; - - if (std::find(std::begin(items), std::end(items), item) == std::end(items)) - { - auto it = std::upper_bound(std::begin(items), std::end(items), item, LibraryItemLess); - int row = std::distance(std::begin(items), it); - - emit beginInsertRows(parentIndex, row, row); - items.insert(it, item); - emit endInsertRows(); - } -} - -std::vector LibraryItemTreeModel::ChildItems(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return {}; - } - - if (!index.internalPointer()) - { - auto entry = std::begin(m_groups); - std::advance(entry, index.row()); - return entry->second->second; - } - else - { - auto group = static_cast(index.internalPointer()); - return { - group->second[index.row()] - }; - } -} - -bool LibraryItemTreeModel::Remove(CBaseLibraryItem* pItem) -{ - QModelIndex itemIndex = index(pItem); - if (!itemIndex.isValid()) - { - return false; - } - return removeRow(itemIndex.row(), itemIndex.parent()); -} - -void LibraryItemTreeModel::Rename(CBaseLibraryItem* item, const QString& groupName, const QString& shortName) -{ - if (groupName != item->GetGroupName()) - { - auto entry = m_groups.find(groupName); - - if (entry == std::end(m_groups)) - { - int row = std::distance(std::begin(m_groups), m_groups.lower_bound(groupName)); - - emit beginInsertRows({}, row, row); - entry = m_groups.insert({ groupName, std::make_shared(groupName, std::vector()) }).first; - emit endInsertRows(); - } - - MoveItem(item, createIndex(std::distance(std::begin(m_groups), entry), 0, nullptr)); - } - - QString name = QString("%1.%2").arg(groupName).arg(shortName); - RenameItem(item, name); - - QModelIndex itemIndex = index(item); - emit dataChanged(itemIndex, itemIndex); -} - -QModelIndex LibraryItemTreeModel::FindLibraryItemByFullName(const QString& fullName) const -{ - for (auto& entry : m_groups) - { - auto& group = *entry.second; - auto& items = group.second; - - auto it = std::find_if(std::begin(items), std::end(items), - [&](CBaseLibraryItem* item) - { - return item->GetName() == fullName; - }); - - if (it != std::end(items)) - { - return createIndex(std::distance(std::begin(items), it), 0, &group); - } - } - - return {}; -} - -bool LibraryItemTreeModel::DoesGroupExist([[maybe_unused]] const QString& groupName) const -{ -#if 0 - auto it = std::find_if( - std::begin(m_root->m_children), - std::end(m_root->m_children), - [&](const TreeNode* node) - { - return node->m_text.compare(groupName, Qt::CaseInsensitive) == 0; - }); - - return it != std::end(m_root->m_children); -#else - return false; -#endif -} - -QStringList LibraryItemTreeModel::mimeTypes() const -{ - QStringList mimeTypes; - mimeTypes << QStringLiteral("application/x-o3de-libraryitems"); - return mimeTypes; -} - -QString LibraryItemTreeModel::MakeValidName(const Group& group, const QString& baseName) const -{ - auto& items = group.second; - - QString name = baseName; - - int counter = 0; - - while (std::find_if(std::begin(items), std::end(items), - [&](CBaseLibraryItem* item) - { - return item->GetShortName() == name; - }) != std::end(items)) - { - name = QString("%1%2").arg(baseName).arg(counter); - ++counter; - } - - return name; -} - -bool LibraryItemTreeModel::MoveItem(CBaseLibraryItem* item, const QModelIndex& targetParent) -{ - if (!targetParent.isValid() || targetParent.internalPointer()) - { - return false; - } - - auto sourceEntry = m_groups.find(item->GetGroupName()); - - auto targetEntry = std::begin(m_groups); - std::advance(targetEntry, targetParent.row()); - - if (sourceEntry == targetEntry) - { - return false; - } - - auto& sourceItems = sourceEntry->second->second; - auto sourceIt = std::find(std::begin(sourceItems), std::end(sourceItems), item); - int sourceRow = std::distance(std::begin(sourceItems), sourceIt); - - auto& targetItems = targetEntry->second->second; - auto targetIt = std::upper_bound( - std::begin(targetItems), - std::end(targetItems), - item, - [](CBaseLibraryItem* left, CBaseLibraryItem* right) - { - QString leftShortName = left->GetShortName(); - QString rightShortName = right->GetShortName(); - return leftShortName.compare(rightShortName) < 0; - }); - int targetRow = std::distance(std::begin(targetItems), targetIt); - - QModelIndex sourceParent = createIndex(std::distance(std::begin(m_groups), sourceEntry), 0, nullptr); - - beginMoveRows(sourceParent, sourceRow, sourceRow, targetParent, targetRow); - targetItems.insert(targetIt, item); - sourceItems.erase(sourceIt); - endMoveRows(); - - if (sourceItems.empty()) - { - removeRow(sourceParent.row(), {}); - } - - return true; -} - -bool LibraryItemTreeModel::dropMimeData(const QMimeData* data, [[maybe_unused]] Qt::DropAction action, [[maybe_unused]] int row, [[maybe_unused]] int column, const QModelIndex& index) -{ - if (data->hasFormat("application/x-o3de-libraryitems")) - { - QByteArray array = data->data("application/x-o3de-libraryitems"); - - QModelIndex targetParent = index; - - if (!targetParent.isValid()) - { - return false; - } - - if (targetParent.internalPointer()) - { - targetParent = parent(targetParent); - } - - int count = array.size() / sizeof(CBaseLibraryItem*); - auto items = reinterpret_cast(array.data()); - - auto entry = std::begin(m_groups); - std::advance(entry, targetParent.row()); - - CUndo undo(tr("Copy/Cut & Paste for Lens Flare").toUtf8()); - - for (int i = 0; i < count; i++) - { - auto item = items[i]; - - QString shortName = MakeValidName(*entry->second, item->GetShortName()); - - if (MoveItem(item, targetParent)) - { - RenameItem(item, QString("%1.%2").arg(entry->first).arg(shortName)); - } - } - - return true; - } - - return false; -} - -QMimeData* LibraryItemTreeModel::mimeData(const QModelIndexList& indexes) const -{ - QByteArray array; - - for (auto& index : indexes) - { - auto item = static_cast(index.data(Qt::UserRole).value()); - - if (item) - { - array.append(reinterpret_cast(&item), sizeof(CBaseLibraryItem*)); - } - } - - if (array.isEmpty()) - { - return nullptr; - } - - QMimeData* data = new QMimeData; - data->setData(QStringLiteral("application/x-o3de-libraryitems"), array); - return data; -} - -Qt::DropActions LibraryItemTreeModel::supportedDragActions() const -{ - return Qt::MoveAction; -} - -Qt::DropActions LibraryItemTreeModel::supportedDropActions() const -{ - return Qt::MoveAction; -} - -#include diff --git a/Code/Sandbox/Editor/DatabaseFrameWnd.h b/Code/Sandbox/Editor/DatabaseFrameWnd.h deleted file mode 100644 index 71ef50191c..0000000000 --- a/Code/Sandbox/Editor/DatabaseFrameWnd.h +++ /dev/null @@ -1,250 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once -//////////////////////////////////////////////////////////////////////////// -// Crytek Engine Source File. -// Copyright (C), Crytek Studios, 2011. -// ------------------------------------------------------------------------- -// File name: DatabaseFrameWnd.h -// Created: 10/Dec/2012 by Jaesik. -//////////////////////////////////////////////////////////////////////////// -#ifndef CRYINCLUDE_EDITOR_DATABASEFRAMEWND_H -#define CRYINCLUDE_EDITOR_DATABASEFRAMEWND_H - -#if !defined(Q_MOC_RUN) -#include -#include -#include "Undo/IUndoManagerListener.h" -#include "BaseLibrary.h" - -#include -#include -#include -#include -#endif - -class QComboBox; -class QTreeView; -class QMimeData; - -class CBaseLibraryItem; -class CBaseLibraryManager; - -class LibraryListModel; -class LibraryItemTreeModel; - -namespace Ui { - class DatabaseFrameWnd; -} - -class CDatabaseFrameWnd - : public AzQtComponents::DockMainWindow - , public IEditorNotifyListener - , public IUndoManagerListener -{ - Q_OBJECT -public: - CDatabaseFrameWnd(CBaseLibraryManager* pItemManager, QWidget* pParent = nullptr); - virtual ~CDatabaseFrameWnd(); - - enum SortRecursionType - { - SORT_RECURSION_NONE = 1, - SORT_RECURSION_ITEM = 2, - SORT_RECURSION_FULL = 9999 - }; - - virtual void ReloadLibs(); - virtual void ReloadItems(); - virtual void SelectLibrary(const QString& library, bool bForceSelect = false); - virtual void SelectLibrary(CBaseLibrary* pItem, bool bForceSelect = false); - virtual void SelectItem(CBaseLibraryItem* item, bool bForceReload = false); - - virtual CBaseLibrary* FindLibrary(const QString& libraryName); - virtual CBaseLibrary* NewLibrary(const QString& libraryName); - virtual void DeleteLibrary(CBaseLibrary* pLibrary); - virtual void DeleteItem(CBaseLibraryItem* pItem); - - virtual void ReleasePreviewControl(){} - - virtual bool SetItemName(CBaseLibraryItem* item, const QString& groupName, const QString& itemName); - - void DoesItemExist(const QString& itemName, bool& bOutExist) const; - void DoesGroupExist(const QString& groupName, bool& bOutExist) const; - - virtual void OnEditorNotifyEvent(EEditorNotifyEvent event) override; - - void SignalNumUndoRedo(const unsigned int& numUndo, const unsigned int& numRedo) override; - - QString GetSelectedLibraryName() const; - - virtual const char* GetClassName() = 0; - -protected: - int GetComboBoxIndex(CBaseLibrary* pLibrary); - - virtual void OnInitDialog() = 0; - - void showEvent(QShowEvent* event) override; - - void OnUndo(); - void OnRedo(); - - virtual void OnAddLibrary(); - virtual void OnRemoveLibrary(); - virtual void OnAddItem(); - virtual void OnRemoveItem(); - virtual void OnRenameItem(); - virtual void OnChangedLibrary(); - virtual void OnExportLibrary(); - virtual void OnSave(); - virtual void OnReloadLib(); - virtual void OnLoadLibrary(); - - void OnSelChangedItemTree(const QModelIndex& index); - bool eventFilter(QObject* watched, QEvent* event); - - virtual void OnCopy() = 0; - virtual void OnPaste() = 0; - virtual void OnCut(); - virtual void OnClone(); - - void InitTreeCtrl(); - - virtual AssetSelectionModel GetAssetSelectionModel() const = 0; - - void LoadLibrary(); - - QString MakeValidName(const QString& candidateName, AZStd::function cb) const; - - virtual QTreeView* GetTreeCtrl() = 0; - virtual const QTreeView* GetTreeCtrl() const = 0; - -private: - LibraryListModel* m_pLibraryListModel; - QComboBox* m_pLibraryListComboBox; - - bool m_bLibsLoaded; - -protected: - LibraryItemTreeModel* m_pLibraryItemTreeModel; - - //! Selected library. - _smart_ptr m_pLibrary; - - //! Last selected Item. (kept here for compatibility reasons) - // See comments on m_cpoSelectedLibraryItems for more details. - _smart_ptr m_pCurrentItem; - - // A set containing all the currently selected items - // (it's disabled for MOST, but not ALL cases). - // This should be the new standard way of storing selections as - // opposed to the former mean, it allows us to store multiple selections. - // The migration to this new style should be done according to the needs - // for multiple selection. - std::set m_cpoSelectedLibraryItems; - - //! Pointer to item manager. - CBaseLibraryManager* m_pItemManager; - SortRecursionType m_sortRecursionType; - QString m_selectedGroup; - - QScopedPointer ui; - - bool m_initialized; -}; - -class LibraryListModel - : public QAbstractListModel -{ - Q_OBJECT - -public: - LibraryListModel(CBaseLibraryManager* itemManager, QObject* pParent = nullptr); - - int rowCount(const QModelIndex& parent = {}) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - - void Reload(); - - void clear(); - -private: - void LibraryModified(bool bModified); - - CBaseLibraryManager* m_pItemManager; -}; - -class LibraryItemTreeModel - : public QAbstractItemModel -{ - Q_OBJECT - - using Group = std::pair >; - -public: - LibraryItemTreeModel(CDatabaseFrameWnd* pParent); - - QModelIndex parent(const QModelIndex& index) const override; - QModelIndex index(int row, int column, const QModelIndex& parent = {}) const override; - QModelIndex index(CBaseLibraryItem* pItem) const; - - int rowCount(const QModelIndex& parent) const override; - int columnCount(const QModelIndex& parent) const override; - - Qt::ItemFlags flags(const QModelIndex& index) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; - - bool removeRows(int row, int count, const QModelIndex& parent = {}) override; - - QStringList mimeTypes() const override; - bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override; - QMimeData* mimeData(const QModelIndexList& indexes) const override; - - Qt::DropActions supportedDragActions() const override; - Qt::DropActions supportedDropActions() const override; - - void Clear(); - - void Reload(CBaseLibrary* library); - - void Add(CBaseLibraryItem* item); - bool Remove(CBaseLibraryItem* item); - - void Rename(CBaseLibraryItem* item, const QString& groupName, const QString& shortName); - - std::vector ChildItems(const QModelIndex& index) const; - - QString GetFullName(const QModelIndex& index) const; - - QModelIndex FindLibraryItemByFullName(const QString& fullName) const; - bool DoesGroupExist(const QString& groupName) const; - -signals: - void itemRenamed(CBaseLibraryItem* item, const QString& prevFullName); - -protected: - void RenameItem(CBaseLibraryItem* item, const QString& fullName); - QString MakeValidName(const Group& group, const QString& baseName) const; - bool MoveItem(CBaseLibraryItem* item, const QModelIndex& parent); - - CDatabaseFrameWnd* m_dialog; - - std::map > m_groups; -}; - -Q_DECLARE_METATYPE(CBaseLibrary*) - -#endif // CRYINCLUDE_EDITOR_DATABASEFRAMEWND_H diff --git a/Code/Sandbox/Editor/DatabaseFrameWnd.qrc b/Code/Sandbox/Editor/DatabaseFrameWnd.qrc deleted file mode 100644 index 37d97f5c9f..0000000000 --- a/Code/Sandbox/Editor/DatabaseFrameWnd.qrc +++ /dev/null @@ -1,35 +0,0 @@ - - - res/db_library_bar_00.png - res/db_library_bar_01.png - res/db_library_bar_02.png - res/db_library_bar_03.png - res/db_library_bar_04.png - res/db_library_bar_05.png - res/db_standart_00.png - res/db_standart_01.png - res/db_standart_02.png - res/db_standart_03.png - res/db_library_item_bar_00.png - res/db_library_item_bar_01.png - res/db_library_item_bar_02.png - res/db_library_item_bar_03.png - res/db_library_item_bar_04.png - res/db_library_item_bar_05.png - res/db_library_open.svg - res/db_library_save.svg - res/db_library_add.svg - res/db_library_delete.svg - res/db_library_refresh.svg - res/db_library_undo.svg - res/db_library_redo.svg - res/db_library_copy.svg - res/db_library_paste.svg - res/db_library_additem.svg - res/db_library_cloneitem.svg - res/db_library_removeitem.svg - res/db_library_assignitem.svg - res/db_library_getproperties.svg - res/db_library_reload.svg - - diff --git a/Code/Sandbox/Editor/DatabaseFrameWnd.ui b/Code/Sandbox/Editor/DatabaseFrameWnd.ui deleted file mode 100644 index 655de74a6e..0000000000 --- a/Code/Sandbox/Editor/DatabaseFrameWnd.ui +++ /dev/null @@ -1,279 +0,0 @@ - - - DatabaseFrameWnd - - - - 0 - 0 - 633 - 42 - - - - - Lens Flare Toolbar - - - - 32 - 32 - - - - false - - - TopToolBarArea - - - false - - - - - - - - - - StandartToolBar - - - - 32 - 32 - - - - false - - - TopToolBarArea - - - false - - - - - - - - - - ItemToolBar - - - - 32 - 32 - - - - false - - - TopToolBarArea - - - false - - - - - - - - - - - - - :/DatabaseFrameWnd/db_library_open.svg:/DatabaseFrameWnd/db_library_open.svg - - - Load Library - - - Load Library - - - - - - :/DatabaseFrameWnd/db_library_save.svg:/DatabaseFrameWnd/db_library_save.svg - - - Save Modified Libraries - - - Save Modified Libraries - - - - - - :/DatabaseFrameWnd/db_library_add.svg:/DatabaseFrameWnd/db_library_add.svg - - - Add Library - - - Add Library - - - - - - :/DatabaseFrameWnd/db_library_delete.svg:/DatabaseFrameWnd/db_library_delete.svg - - - Remove Library - - - Remove Library - - - - - - :/DatabaseFrameWnd/db_library_refresh.svg:/DatabaseFrameWnd/db_library_refresh.svg - - - Reload Library - - - Reload Library - - - - - false - - - - :/DatabaseFrameWnd/db_library_undo.svg:/DatabaseFrameWnd/db_library_undo.svg - - - Undo last operation - - - Undo - - - - - false - - - - :/DatabaseFrameWnd/db_library_redo.svg:/DatabaseFrameWnd/db_library_redo.svg - - - Redo last undo operation - - - Redo - - - - - - :/DatabaseFrameWnd/db_library_copy.svg:/DatabaseFrameWnd/db_library_copy.svg - - - Copy Item - - - Copy Item - - - - - - :/DatabaseFrameWnd/db_library_paste.svg:/DatabaseFrameWnd/db_library_paste.svg - - - Paste Item - - - Paste Item - - - - - - :/DatabaseFrameWnd/db_library_additem.svg:/DatabaseFrameWnd/db_library_additem.svg - - - Add New Item - - - Add New Item - - - - - - :/DatabaseFrameWnd/db_library_cloneitem.svg:/DatabaseFrameWnd/db_library_cloneitem.svg - - - Clone Library Item - - - Clone Library Item - - - - - - :/DatabaseFrameWnd/db_library_removeitem.svg:/DatabaseFrameWnd/db_library_removeitem.svg - - - Remove Item - - - Remove Item - - - - - - :/DatabaseFrameWnd/db_library_assignitem.svg:/DatabaseFrameWnd/db_library_assignitem.svg - - - Assign Item to Selected Objects - - - Assign Item to Selected Objects - - - - - - :/DatabaseFrameWnd/db_library_getproperties.svg:/DatabaseFrameWnd/db_library_getproperties.svg - - - Get Properties From Selection - - - Get Properties From Selection - - - - - - :/DatabaseFrameWnd/db_library_reload.svg:/DatabaseFrameWnd/db_library_reload.svg - - - Reload Item - - - Reload Item - - - - - - diff --git a/Code/Sandbox/Editor/GameExporter.cpp b/Code/Sandbox/Editor/GameExporter.cpp index 8a93dbedce..8f0b6f6d0f 100644 --- a/Code/Sandbox/Editor/GameExporter.cpp +++ b/Code/Sandbox/Editor/GameExporter.cpp @@ -34,9 +34,6 @@ #include "Objects/ObjectManager.h" #include "Objects/EntityObject.h" -#include "LensFlareEditor/LensFlareManager.h" -#include "LensFlareEditor/LensFlareLibrary.h" -#include "LensFlareEditor/LensFlareItem.h" #include @@ -210,7 +207,6 @@ bool CGameExporter::Export(unsigned int flags, [[maybe_unused]] EEndian eExportE ExportLevelInfo(sLevelPath); - ExportLevelLensFlares(sLevelPath); ExportLevelResourceList(sLevelPath); ExportLevelUsedResourceList(sLevelPath); ExportLevelShaderCache(sLevelPath); @@ -554,67 +550,6 @@ void CGameExporter::ExportMaterials(XmlNodeRef& levelDataNode, const QString& pa m_numExportedMaterials = numMtls; } -////////////////////////////////////////////////////////////////////////// -void CGameExporter::ExportLevelLensFlares(const QString& path) -{ - GetIEditor()->SetStatusText(QObject::tr("Exporting Lens Flares...")); - std::vector objects; - GetIEditor()->GetObjectManager()->FindObjectsOfType(&CEntityObject::staticMetaObject, objects); - std::set flareNameSet; - for (int i = 0, iObjectSize(objects.size()); i < iObjectSize; ++i) - { - CEntityObject* pEntity = (CEntityObject*)objects[i]; - if (!pEntity->IsLight()) - { - continue; - } - QString flareName = pEntity->GetEntityPropertyString(CEntityObject::s_LensFlarePropertyName); - if (flareName.isEmpty() || flareName == "@root") - { - continue; - } - flareNameSet.insert(flareName); - } - - XmlNodeRef pRootNode = GetIEditor()->GetSystem()->CreateXmlNode("LensFlareList"); - pRootNode->setAttr("Version", FLARE_EXPORT_FILE_VERSION); - - CLensFlareManager* pLensManager = GetIEditor()->GetLensFlareManager(); - - if (CLensFlareLibrary* pLevelLib = (CLensFlareLibrary*)pLensManager->GetLevelLibrary()) - { - for (int i = 0; i < pLevelLib->GetItemCount(); i++) - { - CLensFlareItem* pItem = (CLensFlareItem*)pLevelLib->GetItem(i); - - if (flareNameSet.find(pItem->GetFullName()) == flareNameSet.end()) - { - continue; - } - - CBaseLibraryItem::SerializeContext ctx(pItem->CreateXmlData(), false); - pRootNode->addChild(ctx.node); - pItem->Serialize(ctx); - flareNameSet.erase(pItem->GetFullName()); - } - } - - std::set::iterator iFlareNameSet = flareNameSet.begin(); - for (; iFlareNameSet != flareNameSet.end(); ++iFlareNameSet) - { - QString flareName = *iFlareNameSet; - XmlNodeRef pFlareNode = GetIEditor()->GetSystem()->CreateXmlNode("LensFlare"); - pFlareNode->setAttr("name", flareName.toUtf8().data()); - pRootNode->addChild(pFlareNode); - } - - CCryMemFile lensFlareNames; - lensFlareNames.Write(pRootNode->getXMLData()->GetString(), pRootNode->getXMLData()->GetStringLength()); - - QString exportPathName = path + FLARE_EXPORT_FILE; - m_levelPak.m_pakFile.UpdateFile(exportPathName.toUtf8().data(), lensFlareNames); -} - ////////////////////////////////////////////////////////////////////////// void CGameExporter::ExportLevelResourceList(const QString& path) { diff --git a/Code/Sandbox/Editor/GameExporter.h b/Code/Sandbox/Editor/GameExporter.h index 87e24ef844..52731a7000 100644 --- a/Code/Sandbox/Editor/GameExporter.h +++ b/Code/Sandbox/Editor/GameExporter.h @@ -95,7 +95,6 @@ private: void ExportOcclusionMesh(const char* pszGamePath); void ExportMapInfo(XmlNodeRef& node); - void ExportLevelLensFlares(const QString& path); void ExportLevelResourceList(const QString& path); void ExportLevelUsedResourceList(const QString& path); void ExportLevelShaderCache(const QString& path); diff --git a/Code/Sandbox/Editor/IEditor.h b/Code/Sandbox/Editor/IEditor.h index e1f41b9f41..838f48573d 100644 --- a/Code/Sandbox/Editor/IEditor.h +++ b/Code/Sandbox/Editor/IEditor.h @@ -50,7 +50,6 @@ class CMaterialManager; class CMusicManager; class CMaterail; struct IEditorParticleManager; -class CLensFlareManager; class CEAXPresetManager; class CErrorReport; class CBaseLibraryItem; @@ -555,8 +554,6 @@ struct IEditor virtual IEditorPanelUtils* GetEditorPanelUtils() = 0; //! Get Music Manager. virtual CMusicManager* GetMusicManager() = 0; - //! Get Lens Flare Manager. - virtual CLensFlareManager* GetLensFlareManager() = 0; virtual float GetTerrainElevation(float x, float y) = 0; virtual Editor::EditorQtApplication* GetEditorQtApplication() = 0; virtual const QColor& GetColorByName(const QString& name) = 0; diff --git a/Code/Sandbox/Editor/IEditorImpl.cpp b/Code/Sandbox/Editor/IEditorImpl.cpp index a81aff86a9..060bf41189 100644 --- a/Code/Sandbox/Editor/IEditorImpl.cpp +++ b/Code/Sandbox/Editor/IEditorImpl.cpp @@ -60,7 +60,6 @@ AZ_POP_DISABLE_WARNING #include "ToolBox.h" #include "MainWindow.h" #include "Alembic/AlembicCompiler.h" -#include "LensFlareEditor/LensFlareManager.h" #include "UIEnumsDatabase.h" #include "Util/Ruler.h" #include "RenderHelpers/AxisHelper.h" @@ -170,7 +169,6 @@ CEditorImpl::CEditorImpl() , m_pToolBoxManager(nullptr) , m_pMaterialManager(nullptr) , m_pMusicManager(nullptr) - , m_pLensFlareManager(nullptr) , m_pErrorReport(nullptr) , m_pLasLoadedLevelErrorReport(nullptr) , m_pErrorsDlg(nullptr) @@ -230,7 +228,6 @@ CEditorImpl::CEditorImpl() m_pAnimationContext = new CAnimationContext; m_pImageUtil = new CImageUtil_impl(); - m_pLensFlareManager = new CLensFlareManager; m_pResourceSelectorHost.reset(CreateResourceSelectorHost()); m_pRuler = new CRuler; m_selectedRegion.min = Vec3(0, 0, 0); diff --git a/Code/Sandbox/Editor/IEditorImpl.h b/Code/Sandbox/Editor/IEditorImpl.h index 908136297b..3c440dd5fc 100644 --- a/Code/Sandbox/Editor/IEditorImpl.h +++ b/Code/Sandbox/Editor/IEditorImpl.h @@ -42,7 +42,6 @@ class CUndoManager; class CGameEngine; class CExportManager; class CErrorsDlg; -class CLensFlareManager; class CIconManager; class CBackgroundTaskManager; class CTrackViewSequenceManager; @@ -183,7 +182,6 @@ public: IDataBaseManager* GetDBItemManager(EDataBaseItemType itemType); CMaterialManager* GetMaterialManager() { return m_pMaterialManager; } CMusicManager* GetMusicManager() { return m_pMusicManager; }; - CLensFlareManager* GetLensFlareManager() { return m_pLensFlareManager; }; IBackgroundTaskManager* GetBackgroundTaskManager() override; IBackgroundScheduleManager* GetBackgroundScheduleManager() override; @@ -384,7 +382,6 @@ protected: CMaterialManager* m_pMaterialManager; CAlembicCompiler* m_pAlembicCompiler; CMusicManager* m_pMusicManager; - CLensFlareManager* m_pLensFlareManager; CErrorReport* m_pErrorReport; //! Contains the error reports for the last loaded level. CErrorReport* m_pLasLoadedLevelErrorReport; diff --git a/Code/Sandbox/Editor/LensFlareEditor/ILensFlareListener.h b/Code/Sandbox/Editor/LensFlareEditor/ILensFlareListener.h deleted file mode 100644 index 913faf2bb3..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/ILensFlareListener.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_ILENSFLARELISTENER_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_ILENSFLARELISTENER_H -#pragma once - -class CLensFlareItem; -class CLensFlareElement; - -class ILensFlareChangeItemListener -{ -public: - virtual void OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem) = 0; - virtual void OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem) = 0; -}; - -class ILensFlareChangeElementListener -{ -public: - virtual void OnLensFlareChangeElement(CLensFlareElement* pLensFlareElement) = 0; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_ILENSFLARELISTENER_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.cpp deleted file mode 100644 index d30db3f5f3..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.cpp +++ /dev/null @@ -1,326 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareAtomicList.h" - -// Qt -#include -#include - -// Editor -#include "LensFlareUtil.h" -#include "Util/Image.h" -#include "Util/ImageUtil.h" - - -struct QLensFlareAtomicListModel::Item -{ - QString text; - QSize size; - QPixmap pixmap; - EFlareType flareType; -}; - -CLensFlareAtomicList::CLensFlareAtomicList(QWidget* parent) - : CImageListCtrl(parent) - , m_model(new QLensFlareAtomicListModel(this)) -{ - setDragEnabled(true); - setDragDropMode(DragOnly); - setModel(m_model.data()); -} - -CLensFlareAtomicList::~CLensFlareAtomicList() -{ -} - -QModelIndex QLensFlareAtomicListModel::InsertItem(const FlareInfo& flareInfo) -{ - Item* pPreviewItem = new Item; - - if (flareInfo.imagename) - { - CImageEx* pImage = new CImageEx(); - if (CImageUtil::LoadImage(flareInfo.imagename, *pImage)) - { - pImage->SwapRedAndBlue(); - pPreviewItem->size = QSize(pImage->GetWidth(), pImage->GetHeight()); - QImage img(reinterpret_cast(pImage->GetData()), pImage->GetWidth(), pImage->GetHeight(), QImage::Format_RGB32); - pPreviewItem->pixmap = QPixmap::fromImage(img.copy()); - } - - delete pImage; - } - - if (pPreviewItem->pixmap.isNull()) - { - pPreviewItem->pixmap = QPixmap(":/water.png"); - pPreviewItem->size = QSize(64, 64); - } - - pPreviewItem->text = flareInfo.name; - pPreviewItem->flareType = flareInfo.type; - - const int row = m_items.count(); - beginInsertRows(QModelIndex(), row, row); - m_items.append(pPreviewItem); - endInsertRows(); - - return index(row, 0); -} - -void QLensFlareAtomicListModel::Populate() -{ - Clear(); - const FlareInfoArray::Props array = FlareInfoArray::Get(); - for (size_t i = 0; i < array.size; ++i) - { - const FlareInfo& flareInfo(array.p[i]); - if (LensFlareUtil::IsElement(flareInfo.type)) - { - InsertItem(flareInfo); - } - } -} - -void CLensFlareAtomicList::FillAtomicItems() -{ - if (m_model) - { - m_model->Populate(); - } -} - -void CLensFlareAtomicList::updateGeometries() -{ - ClearItemGeometries(); - - if (!model()) - { - return; - } - - const int rowCount = model()->rowCount(); - - const int nPageHorz = viewport()->width(); - const int nPageVert = viewport()->height(); - - if (nPageHorz == 0 || nPageVert == 0 || rowCount <= 0) - { - return; - } - - const QSize& borderSize = BorderSize(); - int x = borderSize.width(); - int y = borderSize.height(); - - QSize itemSize = ItemSize(); - const int nTextHeight = fontMetrics().height(); - const int xMax = nPageHorz - borderSize.width(); - int itemHeightMax = 0; - - for (int row = 0; row < rowCount; ++row) - { - QModelIndex index = m_model->index(row, 0); - itemSize = index.data(Qt::SizeHintRole).toSize(); - - if ((x + itemSize.width()) > xMax) - { - y += itemHeightMax + borderSize.height() + nTextHeight; - x = borderSize.width(); - itemHeightMax = 0; - } - - if (itemSize.height() > itemHeightMax) - { - itemHeightMax = itemSize.height(); - } - - SetItemGeometry(index, QRect(QPoint(x, y), itemSize)); - - x += itemSize.width() + borderSize.width(); - } - - verticalScrollBar()->setPageStep(viewport()->height()); - verticalScrollBar()->setRange(0, (y + itemHeightMax - viewport()->height())); -} - -QLensFlareAtomicListModel::QLensFlareAtomicListModel(QObject* parent) - : QAbstractListModel(parent) -{ -} - -QLensFlareAtomicListModel::~QLensFlareAtomicListModel() -{ -} - -void QLensFlareAtomicListModel::Clear() -{ - qDeleteAll(m_items); - m_items.clear(); -} - -int QLensFlareAtomicListModel::rowCount(const QModelIndex& parent) const -{ - if (parent.isValid()) - { - return 0; - } - - return m_items.count(); -} - -QVariant QLensFlareAtomicListModel::data(const QModelIndex& index, int role) const -{ - Item* item; - if (!index.isValid()) - { - return QVariant(); - } - else - { - item = ItemFromIndex(index); - if (!item) - { - return QVariant(); - } - } - - switch (role) - { - case Qt::DisplayRole: - case Qt::EditRole: - return item->text; - - case Qt::SizeHintRole: - return item->size; - - case Qt::DecorationRole: - return item->pixmap; - - case Qt::UserRole: - return item->flareType; - } - - return QVariant(); -} - -bool QLensFlareAtomicListModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - Item* item; - if (index.isValid()) - { - return false; - } - else - { - item = ItemFromIndex(index); - if (!item) - { - return false; - } - } - - switch (role) - { - case Qt::EditRole: - item->text = value.toString(); - break; - - case Qt::DecorationRole: - item->pixmap = value.value(); - break; - - case Qt::SizeHintRole: - item->size = value.toSize(); - break; - - default: - return false; - } - - emit dataChanged(index, index, QVector() << role); - return false; -} - -Qt::ItemFlags QLensFlareAtomicListModel::flags(const QModelIndex& index) const -{ - return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled; -} - -EFlareType QLensFlareAtomicListModel::FlareTypeFromIndex(QModelIndex index) const -{ - Item* item; - if (!index.isValid()) - { - return eFT_Max; - } - else - { - item = ItemFromIndex(index); - if (!item) - { - return eFT_Max; - } - } - - return item->flareType; -} - -QLensFlareAtomicListModel::Item* QLensFlareAtomicListModel::ItemFromIndex(QModelIndex index) const -{ - if (!index.isValid()) - { - return nullptr; - } - - return m_items.at(index.row()); -} - -QStringList QLensFlareAtomicListModel::mimeTypes() const -{ - return { - QStringLiteral("application/x-o3de-flaretypes") - }; -} - -QMimeData* QLensFlareAtomicListModel::mimeData(const QModelIndexList& indexes) const -{ - QMimeData* data = new QMimeData(); - - QByteArray encoded; - QDataStream stream(&encoded, QIODevice::WriteOnly); - - for (const QModelIndex& index : indexes) - { - stream << static_cast(FlareTypeFromIndex(index)); - } - - data->setData(QStringLiteral("application/x-o3de-flaretypes"), encoded); - - return data; -} - -bool QLensFlareAtomicListModel::dropMimeData([[maybe_unused]] const QMimeData* data, [[maybe_unused]] Qt::DropAction action, [[maybe_unused]] int row, [[maybe_unused]] int column, [[maybe_unused]] const QModelIndex& parent) -{ - return false; -} - -Qt::DropActions QLensFlareAtomicListModel::supportedDragActions() const -{ - return Qt::CopyAction; -} - -#include diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.h deleted file mode 100644 index 5748ff07f7..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareAtomicList.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREATOMICLIST_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREATOMICLIST_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "Controls/ImageListCtrl.h" -#endif - -#if !defined(Q_MOC_RUN) -#include -#include -#endif - -class CLensFlareEditor; -class QLensFlareAtomicListModel; - -class CLensFlareAtomicList - : public CImageListCtrl -{ - Q_OBJECT -public: - CLensFlareAtomicList(QWidget* parent = nullptr); - virtual ~CLensFlareAtomicList(); - - void FillAtomicItems(); - -protected: - void updateGeometries() override; - -private: - QScopedPointer m_model; -}; - -class QLensFlareAtomicListModel - : public QAbstractListModel -{ - struct Item; - Q_OBJECT -public: - QLensFlareAtomicListModel(QObject* parent = nullptr); - ~QLensFlareAtomicListModel(); - - void Clear(); - void Populate(); - - int rowCount(const QModelIndex& parent = QModelIndex()) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; - Qt::ItemFlags flags(const QModelIndex& index) const override; - - QStringList mimeTypes() const override; - QMimeData* mimeData(const QModelIndexList& indexes) const override; - bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override; - Qt::DropActions supportedDragActions() const override; - - EFlareType FlareTypeFromIndex(QModelIndex index) const; - -protected: - QModelIndex InsertItem(const FlareInfo& flareInfo); - Item* ItemFromIndex(QModelIndex index) const; - -private: - QVector m_items; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREATOMICLIST_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.cpp deleted file mode 100644 index 763b5bf19b..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.cpp +++ /dev/null @@ -1,1225 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareEditor.h" - -// Qt -#include -#include - -// AzToolsFramework -#include -#include - -// AzQtComponents -#include -#include -#include - -// LmbrCentral -#include // for LmbrCentral::LensFlareAsset - -// Editor -#include "Clipboard.h" -#include "StringDlg.h" -#include "Settings.h" -#include "Include/IObjectManager.h" -#include "LensFlareView.h" -#include "LensFlareAtomicList.h" -#include "LensFlareElementTree.h" -#include "LensFlareManager.h" -#include "LensFlareItem.h" -#include "LensFlareLibrary.h" -#include "LensFlareUndo.h" -#include "LensFlareLightEntityTree.h" -#include "Controls/ReflectedPropertyControl/ReflectedPropertyCtrl.h" -#include "ui_DatabaseFrameWnd.h" -#include "LyViewPaneNames.h" - - - - -CLensFlareEditor* CLensFlareEditor::s_pLensFlareEditor = NULL; -const char* CLensFlareEditor::s_pLensFlareEditorClassName = LyViewPane::LensFlareEditor; - -#define DISABLE_REFERENCETREE - -CLensFlareEditor::CLensFlareEditor(QWidget* pParent) - : CDatabaseFrameWnd(GetIEditor()->GetLensFlareManager(), pParent) - , m_pLensFlareView(NULL) - , m_pLensFlareAtomicList(NULL) - , m_pLensFlareElementTree(NULL) - , m_pWndProps(NULL) - , m_pLensFlareLightEntityTree(NULL) - , m_pLensFlareReferenceTree(NULL) - , m_LensFlareItemTree(NULL) -{ - assert(!s_pLensFlareEditor); - s_pLensFlareEditor = this; - - m_pLensFlareView = new CLensFlareView(this); - m_pLensFlareAtomicList = new CLensFlareAtomicList(this); - m_pLensFlareElementTree = new CLensFlareElementTree(this); - m_pWndProps = new ReflectedPropertyControl(this); - m_pWndProps->Setup(); - m_pLensFlareLightEntityTree = new CLensFlareLightEntityTree(this); -#ifndef DISABLE_REFERENCETREE - m_pLensFlareReferenceTree = new CLensFlareReferenceTree; -#endif - m_LensFlareItemTree = new CLensFlareItemTree(this); - - m_pLibraryItemTreeModel = new LensFlareItemTreeModel(this); - m_LensFlareItemTree->setModel(m_pLibraryItemTreeModel); - - setCentralWidget(m_pLensFlareView); - - setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); - setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); - setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); - setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); - - m_advancedDockManager = new AzQtComponents::FancyDocking(this, "lensFlareEditor"); - - addDockWidget(Qt::LeftDockWidgetArea, m_LensFlareItemTree, tr("Lens Flare Tree"), false); - addDockWidget(Qt::LeftDockWidgetArea, m_pLensFlareElementTree, tr("Element Tree"), false); - - addDockWidget(Qt::BottomDockWidgetArea, m_pLensFlareAtomicList, tr("Basic Set"), false); -#ifndef DISABLE_REFERENCETREE - addDockWidget(Qt::TopDockWidgetArea, m_pLensFlareReferenceTree, tr("Reference Tree"), false); -#endif - - addDockWidget(Qt::RightDockWidgetArea, m_pWndProps, tr("Properties"), false); - addDockWidget(Qt::RightDockWidgetArea, m_pLensFlareLightEntityTree, tr("Light Entities"), false); - - m_pLensFlareElementTree->RegisterListener(this); - m_pLensFlareElementTree->RegisterListener(m_pLensFlareView); - - m_pWndProps->ExpandAll(); - m_pWndProps->SetUpdateCallback(AZStd::bind(&CLensFlareEditor::OnUpdateProperties, this, AZStd::placeholders::_1)); - m_pWndProps->SetCallbackOnNonModified(false); - - connect(ui->actionDBAdd, &QAction::triggered, this, &CLensFlareEditor::OnAddItem); - connect(ui->actionDBAssignToSelection, &QAction::triggered, this, &CLensFlareEditor::OnAssignFlareToLightEntities); - connect(ui->actionDBGetFromSelection, &QAction::triggered, this, &CLensFlareEditor::OnGetFlareFromSelection); - - connect(m_pLibraryItemTreeModel, &LibraryItemTreeModel::itemRenamed, this, &CLensFlareEditor::OnItemTreeDataRenamed); - - AzQtComponents::StyleManager::setStyleSheet(this, "style:LensFlareEditor.qss"); -} - -CLensFlareEditor::~CLensFlareEditor() -{ - if (m_pLensFlareElementTree) - { - m_pLensFlareElementTree->UnregisterListener(this); - m_pLensFlareElementTree->UnregisterListener(m_pLensFlareView); - } - - ReleaseWindowsToBePutIntoPanels(); - s_pLensFlareEditor = NULL; -} - -QMenu* CLensFlareEditor::createPopupMenu() -{ - return QMainWindow::createPopupMenu(); -} - -void CLensFlareEditor::OnInitDialog() -{ - InitTreeCtrl(); - - connect(m_LensFlareItemTree->selectionModel(), &QItemSelectionModel::selectionChanged, this, &CLensFlareEditor::OnTvnItemSelChanged); - connect(m_LensFlareItemTree, &QWidget::customContextMenuRequested, this, &CLensFlareEditor::OnNotifyTreeRClick); - - m_pLensFlareAtomicList->FillAtomicItems(); - - ReloadLibs(); -} - -void CLensFlareEditor::addDockWidget(Qt::DockWidgetArea area, QWidget* widget, const QString& title, bool closable) -{ - QDockWidget* w = new AzQtComponents::StyledDockWidget(title); - w->setObjectName(widget->metaObject()->className()); - widget->setParent(w); - w->setWidget(widget); - if (!closable) - { - w->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); - } - QMainWindow::addDockWidget(area, w); -} - -void CLensFlareEditor::ReleaseWindowsToBePutIntoPanels() -{ - SAFE_DELETE(m_pWndProps); - SAFE_DELETE(m_pLensFlareAtomicList); - SAFE_DELETE(m_pLensFlareView); - SAFE_DELETE(m_pLensFlareElementTree); - SAFE_DELETE(m_pLensFlareLightEntityTree); -#ifndef DISABLE_REFERENCETREE - SAFE_DELETE(m_pLensFlareReferenceTree); -#endif -} - -const GUID& CLensFlareEditor::GetClassID() -{ - // {7e7a40e0-f0b8-4918-b94f-8cdd6c55f30b} - static const GUID guid = { - 0x7e7a40e0, 0xf0b8, 0x4918, { 0xb9, 0x4f, 0x8c, 0xdd, 0x6c, 0x55, 0xf3, 0x0b } - }; - return guid; -} - -void CLensFlareEditor::RegisterViewClass() -{ - AzToolsFramework::ViewPaneOptions options; - AzToolsFramework::RegisterViewPane(s_pLensFlareEditorClassName, LyViewPane::CategoryOther, options); - GetIEditor()->GetSettingsManager()->AddToolName("LensFlareEditor", "Lens Flare"); -} - -CLensFlareItem* CLensFlareEditor::GetSelectedLensFlareItem() const -{ - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return nullptr; - } - return static_cast(selected.first().data(Qt::UserRole).value()); -} - -void CLensFlareEditor::ResetElementTreeControl() -{ - m_pLensFlareElementTree->InvalidateLensFlareItem(); -} - -void CLensFlareEditor::SelectItem(CBaseLibraryItem* item, bool bForceReload) -{ - if (item != m_pCurrentItem || bForceReload) - { - //Ensure that the property window is emptied out whenever the selected library changes - m_pWndProps->RemoveAllItems(); - } - - CDatabaseFrameWnd::SelectItem(item, bForceReload); -} - -void CLensFlareEditor::OnTvnItemSelChanged(const QItemSelection& selected, const QItemSelection& deselected) -{ - QModelIndex hItem; - - QModelIndexList selectedIndexes = selected.indexes(); - if (!selectedIndexes.isEmpty()) - { - hItem = selectedIndexes.first(); - } - - QModelIndex hPrevItem; - - QModelIndexList deselectedIndexes = deselected.indexes(); - if (!deselectedIndexes.isEmpty()) - { - hPrevItem = deselectedIndexes.first(); - } - - SelectLensFlareItem(hItem, hPrevItem); - UpdateLensFlareItem(GetSelectedLensFlareItem()); -} - -void CLensFlareEditor::SelectLensFlareItem(const QModelIndex& hItem, const QModelIndex& hPrevItem) -{ - if (hPrevItem.isValid() && CUndo::IsRecording()) - { - QString fullItemName = m_pLibraryItemTreeModel->GetFullName(hPrevItem); - if (!fullItemName.isEmpty()) - { - CUndo::Record(new CUndoLensFlareItemSelectionChange(fullItemName)); - } - } - m_pWndProps->RemoveAllItems(); - if (!hItem.isValid()) - { - return; - } - CLensFlareItem* pSelectedLensFlareItem = static_cast(hItem.data(Qt::UserRole).value()); - SelectItem(pSelectedLensFlareItem); -} - -void CLensFlareEditor::SelectLensFlareItem(const QModelIndex& hItem) -{ - QModelIndex hPrevItem; - - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (!selected.isEmpty()) - { - hPrevItem = selected.first(); - } - - SelectLensFlareItem(hItem, hPrevItem); -} - -void CLensFlareEditor::SelectLensFlareItem(const QString& fullItemName) -{ - QModelIndex hNewItem = m_pLibraryItemTreeModel->FindLibraryItemByFullName(fullItemName); - if (!hNewItem.isValid()) - { - return; - } - - SelectLensFlareItem(hNewItem); -} - -void CLensFlareEditor::RemovePropertyItems() -{ - m_pWndProps->RemoveAllItems(); -} - -bool CLensFlareEditor::IsExistTreeItem(const QString& name, bool bExclusiveSelectedItem) -{ - CBaseLibraryItem* pSelectedItem = GetSelectedLensFlareItem(); - - for (int i = 0; i < m_pLibrary->GetItemCount(); i++) - { - CBaseLibraryItem* pItem = static_cast(m_pLibrary->GetItem(i)); - - if (!bExclusiveSelectedItem || pItem != pSelectedItem) - { - if (pItem->GetName() == name) - { - return true; - } - } - } - - return false; -} - -void CLensFlareEditor::RenameLensFlareItem(CLensFlareItem* pLensFlareItem, const QString& newGroupName, const QString& newShortName) -{ - if (pLensFlareItem == NULL || newShortName.isEmpty() || newGroupName.isEmpty()) - { - return; - } - - m_pLibraryItemTreeModel->Rename(pLensFlareItem, newGroupName, newShortName); -} - -IOpticsElementBasePtr CLensFlareEditor::FindOptics(const QString& itemPath, const QString& opticsPath) -{ - CLensFlareItem* pItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(itemPath); - if (pItem == NULL) - { - return NULL; - } - - IOpticsElementBasePtr pOptics = pItem->GetOptics(); - if (pOptics == NULL) - { - return NULL; - } - - return LensFlareUtil::FindOptics(pOptics, opticsPath); -} - -void CLensFlareEditor::UpdateLensOpticsNames(const QString& oldFullName, const QString& newFullName) -{ - std::vector pEntityObjects; - GetIEditor()->GetObjectManager()->FindObjectsOfType(&CEntityObject::staticMetaObject, pEntityObjects); - for (int i = 0, iObjectSize(pEntityObjects.size()); i < iObjectSize; ++i) - { - CEntityObject* pEntity = (CEntityObject*)pEntityObjects[i]; - if (pEntity == NULL) - { - continue; - } - if (pEntity->CheckFlags(OBJFLAG_DELETED)) - { - continue; - } - if (!pEntity->IsLight()) - { - continue; - } - if (oldFullName == pEntity->GetEntityPropertyString(CEntityObject::s_LensFlarePropertyName)) - { - pEntity->SetOpticsName(newFullName); - } - } -} - -void CLensFlareEditor::OnCopy() -{ - UpdateClipboard(FLARECLIPBOARDTYPE_COPY); -} - -void CLensFlareEditor::OnPaste() -{ - if (!m_pLibrary) - { - return; - } - - CClipboard clipboard(this); - if (clipboard.IsEmpty()) - { - return; - } - - XmlNodeRef clipboardXML = clipboard.Get(); - if (clipboardXML == NULL) - { - return; - } - - Paste(clipboardXML); -} - -void CLensFlareEditor::Paste(XmlNodeRef node) -{ - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - Paste(selected.first(), node); -} - -void CLensFlareEditor::Paste(const QModelIndex& hSelectedTreeItem, XmlNodeRef node) -{ - if (!m_pLibrary || node == NULL) - { - return; - } - - QString type; - node->getAttr("Type", type); - - QString sourceGroupName; - node->getAttr("GroupName", sourceGroupName); - - if (m_pLibrary == NULL) - { - return; - } - - bool bShouldCreateNewGroup(false); - if (!sourceGroupName.isEmpty()) - { - unsigned int nAnswer = CryMessageBox("Do you want to create a new group(YES) or add to the selected group(NO)?", "Question", MB_YESNOCANCEL); - if (nAnswer == IDCANCEL) - { - return; - } - bShouldCreateNewGroup = nAnswer == IDYES; - } - - QString targetGroupName; - - if (bShouldCreateNewGroup) - { - using namespace AZStd::placeholders; - targetGroupName = MakeValidName("NewGroup", AZStd::bind(&CDatabaseFrameWnd::DoesGroupExist, this, _1, _2)); - } - else - { - QModelIndex hTargetItem; - if (!m_pLibraryItemTreeModel->hasChildren(hSelectedTreeItem)) - { - hTargetItem = m_pLibraryItemTreeModel->parent(hSelectedTreeItem); - } - else - { - hTargetItem = hSelectedTreeItem; - } - - if (!hTargetItem.isValid()) - { - return; - } - - targetGroupName = m_pLibraryItemTreeModel->GetFullName(hTargetItem); - } - - CUndo undo(tr("Copy/Cut & Paste for Lens Flare").toUtf8()); - CLensFlareItem* pNewItem = NULL; - - for (int i = 0, iChildCount(node->getChildCount()); i < iChildCount; ++i) - { - LensFlareUtil::SClipboardData clipboardData; - clipboardData.FillThisFromXmlNode(node->getChild(i)); - - _smart_ptr pSourceItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(clipboardData.m_LensFlareFullPath); - if (pSourceItem == NULL) - { - continue; - } - - IOpticsElementBasePtr pSourceOptics = FindOptics(clipboardData.m_LensFlareFullPath, clipboardData.m_LensOpticsPath); - if (pSourceOptics == NULL) - { - continue; - } - - if (type == FLARECLIPBOARDTYPE_CUT) - { - if (clipboardData.m_From == LENSFLARE_ELEMENT_TREE) - { - LensFlareUtil::RemoveOptics(pSourceOptics); - } - else - { - DeleteItem(pSourceItem); - } - } - - QString sourceName; - if (clipboardData.m_From == LENSFLARE_ELEMENT_TREE) - { - sourceName = LensFlareUtil::GetShortName(pSourceOptics->GetName().c_str()); - } - else - { - sourceName = pSourceItem->GetShortName(); - } - - QString candidateName = targetGroupName + QString(".") + sourceName; - QString validName = MakeValidName(candidateName, - AZStd::bind(&CDatabaseFrameWnd::DoesItemExist, this, AZStd::placeholders::_1, AZStd::placeholders::_2)); - QString validShortName = LensFlareUtil::GetShortName(validName); - pNewItem = AddNewLensFlareItem(targetGroupName, validShortName); - assert(pNewItem); - if (pNewItem == NULL) - { - continue; - } - - if (LensFlareUtil::IsGroup(pSourceOptics->GetType())) - { - LensFlareUtil::CopyOptics(pSourceOptics, pNewItem->GetOptics(), true); - } - else - { - IOpticsElementBasePtr pNewOptics = LensFlareUtil::CreateOptics(pSourceOptics); - if (pNewOptics) - { - pNewItem->GetOptics()->AddElement(pNewOptics); - } - } - - if (type == FLARECLIPBOARDTYPE_CUT) - { - if (clipboardData.m_From == LENSFLARE_ITEM_TREE) - { - UpdateLensOpticsNames(pSourceItem->GetFullName(), pNewItem->GetFullName()); - } - if (pSourceItem != GetSelectedLensFlareItem()) - { - pSourceItem->UpdateLights(); - } - } - - LensFlareUtil::UpdateOpticsName(pNewItem->GetOptics()); - LensFlareUtil::ChangeOpticsRootName(pNewItem->GetOptics(), validShortName); - - ReloadItems(); - SelectLensFlareItem(m_pLibraryItemTreeModel->index(pNewItem), {}); - } -} - -void CLensFlareEditor::OnCut() -{ - UpdateClipboard(FLARECLIPBOARDTYPE_CUT); -} - -XmlNodeRef CLensFlareEditor::CreateXML(const char* type) const -{ - std::vector clipboardDataList; - QString groupName; - if (!GetClipboardDataList(clipboardDataList, groupName)) - { - return NULL; - } - return LensFlareUtil::CreateXMLFromClipboardData(type, groupName, false, clipboardDataList); -} - -void CLensFlareEditor::UpdateClipboard(const char* type) const -{ - std::vector clipboardDataList; - QString groupName; - if (!GetClipboardDataList(clipboardDataList, groupName)) - { - return; - } - LensFlareUtil::UpdateClipboard(type, groupName, false, clipboardDataList); -} - -bool CLensFlareEditor::GetClipboardDataList(std::vector& outList, QString& outGroupName) const -{ - CLensFlareLibrary* pLibrary = GetCurrentLibrary(); - if (pLibrary == NULL) - { - return false; - } - - std::vector clipboardDataList; - - CLensFlareItem* pLensFlareItem = GetSelectedLensFlareItem(); - if (pLensFlareItem) - { - clipboardDataList.push_back(LensFlareUtil::SClipboardData(LENSFLARE_ITEM_TREE, pLensFlareItem->GetFullName(), pLensFlareItem->GetShortName())); - } - else if (GetSelectedItemStatus() == eSIS_Group) - { - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return false; - } - outGroupName = selected.first().data(Qt::DisplayRole).toString(); - for (CBaseLibraryItem* pItem : m_pLibraryItemTreeModel->ChildItems(selected.first())) - { - pLensFlareItem = static_cast(pItem); - clipboardDataList.push_back(LensFlareUtil::SClipboardData(LENSFLARE_ITEM_TREE, pLensFlareItem->GetFullName(), pLensFlareItem->GetShortName())); - } - } - else - { - return false; - } - - outList = clipboardDataList; - - return true; -} - -void CLensFlareEditor::OnAddItem() -{ - if (!m_pLibrary) - { - return; - } - - StringGroupDlg dlg(tr("New Flare Name"), this); - dlg.SetGroup(m_selectedGroup); - - if (dlg.exec() != QDialog::Accepted || dlg.GetString().isEmpty()) - { - return; - } - - QString fullName = m_pItemManager->MakeFullItemName(m_pLibrary, dlg.GetGroup(), dlg.GetString()); - if (m_pItemManager->FindItemByName(fullName)) - { - Warning("Item with name %s already exist", fullName.toUtf8().data()); - return; - } - - CUndo undo(tr("Add flare library item").toUtf8()); - - CLensFlareItem* pNewLensFlare = AddNewLensFlareItem(dlg.GetGroup(), dlg.GetString()); - if (pNewLensFlare) - { - m_pLibraryItemTreeModel->Add(pNewLensFlare); - SelectItem(pNewLensFlare); - } -} - -CLensFlareItem* CLensFlareEditor::AddNewLensFlareItem(const QString& groupName, const QString& shortName) -{ - CLensFlareItem* pNewFlare = (CLensFlareItem*)m_pItemManager->CreateItem(m_pLibrary); - if (pNewFlare == NULL) - { - return NULL; - } - if (!SetItemName(pNewFlare, groupName, shortName)) - { - m_pItemManager->DeleteItem(pNewFlare); - return NULL; - } - pNewFlare->GetOptics()->SetName(pNewFlare->GetShortName().toUtf8().data()); - return pNewFlare; -} - -QModelIndex CLensFlareEditor::GetTreeLensFlareItem(CLensFlareItem* pItem) const -{ - return m_pLibraryItemTreeModel->index(pItem); -} - -void CLensFlareEditor::OnCopyNameToClipboard() -{ - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - QString itemName = m_pLibraryItemTreeModel->GetFullName(selected.first()); - CClipboard clipboard(this); - clipboard.PutString(itemName); -} - -void CLensFlareEditor::OnAssignFlareToLightEntities() -{ - CLensFlareItem* pLensFlareItem = GetSelectedLensFlareItem(); - if (pLensFlareItem == NULL) - { - return; - } - std::vector entityList; - LensFlareUtil::GetSelectedLightEntities(entityList); - - for (int i = 0, iEntityCount(entityList.size()); i < iEntityCount; ++i) - { - entityList[i]->ApplyOptics(pLensFlareItem->GetFullName(), pLensFlareItem->GetOptics()); - } - - m_pLensFlareLightEntityTree->OnLensFlareChangeItem(pLensFlareItem); -} - -void CLensFlareEditor::OnSelectAssignedObjects() -{ - std::vector lightEntities; - LensFlareUtil::GetLightEntityObjects(lightEntities); - - CLensFlareItem* pLensFlareItem = GetSelectedLensFlareItem(); - if (pLensFlareItem == NULL) - { - return; - } - - int iLightSize(lightEntities.size()); - std::vector assignedObjects; - assignedObjects.reserve(iLightSize); - - for (int i = 0; i < iLightSize; ++i) - { - CEntityObject* pLightEntity = lightEntities[i]; - if (pLightEntity == NULL) - { - continue; - } - - IOpticsElementBasePtr pTargetOptics = pLightEntity->GetOpticsElement(); - if (pTargetOptics == NULL) - { - continue; - } - - if (QString::compare(pLensFlareItem->GetFullName(), pTargetOptics->GetName().c_str(), Qt::CaseInsensitive)) - { - continue; - } - - assignedObjects.push_back(pLightEntity); - } - - if (assignedObjects.empty()) - { - return; - } - - GetIEditor()->ClearSelection(); - for (int i = 0, iAssignedObjectsSize(assignedObjects.size()); i < iAssignedObjectsSize; ++i) - { - GetIEditor()->SelectObject(assignedObjects[i]); - } -} - -void CLensFlareEditor::OnGetFlareFromSelection() -{ - CEntityObject* pEntity = LensFlareUtil::GetSelectedLightEntity(); - if (pEntity == NULL) - { - QMessageBox::warning(this, tr("Warning"), tr("Please select a light entity first.")); - return; - } - if (m_pLibrary == NULL) - { - return; - } - - QString fullFlareName = pEntity->GetEntityPropertyString(CEntityObject::s_LensFlarePropertyName); - int nDotPosition = fullFlareName.indexOf("."); - if (nDotPosition == -1) - { - return; - } - - QString libraryName = fullFlareName.left(nDotPosition); - if (m_pLibrary->GetName() != libraryName) - { - GetIEditor()->GetLensFlareManager()->LoadItemByName(fullFlareName); - SelectLibrary(libraryName); - } - - SelectItemByName(fullFlareName); -} - -void CLensFlareEditor::OnUpdateTreeCtrl() -{ - OnGetFlareFromSelection(); -} - -void CLensFlareEditor::OnNotifyTreeRClick() -{ - CLensFlareItem* pLensFlareItem = 0; - - QModelIndex hItem = LensFlareUtil::GetTreeItemByHitTest(*GetTreeCtrl()); - if (hItem.isValid()) - { - pLensFlareItem = static_cast(hItem.data(Qt::UserRole).value()); - } - - SelectItem(pLensFlareItem); - - bool bGrayedFlag = false; - if (!pLensFlareItem) - { - bGrayedFlag = true; - } - - CClipboard clipboard(this); - bool bPasteFlags = true; - if (clipboard.IsEmpty()) - { - bPasteFlags = false; - } - - bool bCopyPasteCloneFlag = true; - if (GetSelectedItemStatus() != eSIS_Flare && GetSelectedItemStatus() != eSIS_Group) - { - bCopyPasteCloneFlag = false; - } - - QMenu menu; - - QAction* actionDBCut = menu.addAction(tr("Cut")); - actionDBCut->setEnabled(bCopyPasteCloneFlag); - connect(actionDBCut, &QAction::triggered, this, &CLensFlareEditor::OnCut); - - QAction* actionDBCopy = menu.addAction(tr("Copy")); - actionDBCopy->setEnabled(bCopyPasteCloneFlag); - connect(actionDBCopy, &QAction::triggered, this, &CLensFlareEditor::OnCopy); - - QAction* actionDBPaste = menu.addAction(tr("Paste")); - actionDBPaste->setEnabled(bPasteFlags); - connect(actionDBPaste, &QAction::triggered, this, &CLensFlareEditor::OnPaste); - - QAction* actionDBClone = menu.addAction(tr("Clone")); - actionDBClone->setEnabled(bCopyPasteCloneFlag); - connect(actionDBClone, &QAction::triggered, this, &CLensFlareEditor::OnClone); - - menu.addSeparator(); - - QAction* actionDBRename = menu.addAction(tr("Rename\tF2")); - connect(actionDBRename, &QAction::triggered, this, &CLensFlareEditor::OnRenameItem); - - QAction* actionDBRemove = menu.addAction(tr("Delete\tDel")); - connect(actionDBRemove, &QAction::triggered, this, &CLensFlareEditor::OnRemoveItem); - - menu.addSeparator(); - - QAction* actionDBAssignToSelection = menu.addAction(tr("Assign to Selected Objects")); - actionDBAssignToSelection->setEnabled(!bGrayedFlag); - connect(actionDBAssignToSelection, &QAction::triggered, this, &CLensFlareEditor::OnAssignFlareToLightEntities); - - QAction* actionDBSelectAssignedObjects = menu.addAction(tr("Select Assigned Objects")); - actionDBSelectAssignedObjects->setEnabled(!bGrayedFlag); - connect(actionDBSelectAssignedObjects, &QAction::triggered, this, &CLensFlareEditor::OnSelectAssignedObjects); - - QAction* actionDBCopyNameToClipboard = menu.addAction(tr("Copy Name to ClipBoard")); - connect(actionDBCopyNameToClipboard, &QAction::triggered, this, &CLensFlareEditor::OnCopyNameToClipboard); - - menu.exec(QCursor::pos()); -} - -bool CLensFlareEditor::SelectItemByName(const QString& itemName) -{ - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(itemName); - if (pLensFlareItem == NULL) - { - return false; - } - - GetIEditor()->GetLensFlareManager()->SetSelectedItem(pLensFlareItem); - - SelectLensFlareItem(m_pLibraryItemTreeModel->index(pLensFlareItem)); - - return true; -} - - -void CLensFlareEditor::StartEditItem(const QModelIndex& hItem) -{ - if (!hItem.isValid()) - { - return; - } - GetTreeCtrl()->edit(hItem); -} - -bool CLensFlareEditor::GetFullLensFlareItemName(const QModelIndex& hItem, QString& outFullName) const -{ - if (!hItem.isValid()) - { - return false; - } - - outFullName = m_pLibraryItemTreeModel->GetFullName(hItem); - - return true; -} - -CLensFlareEditor::ESelectedItemStatus CLensFlareEditor::GetSelectedItemStatus() const -{ - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return eSIS_Unselected; - } - if (m_pLibraryItemTreeModel->hasChildren(selected.first())) - { - return eSIS_Group; - } - return eSIS_Flare; -} - -void CLensFlareEditor::SelectItemInLensFlareElementTreeByName(const QString& name) -{ - m_pLensFlareElementTree->SelectTreeItemByName(name); -} - -bool CLensFlareEditor::GetSelectedLensFlareName(QString& outName) const -{ - const CLensFlareElement* pElement = m_pLensFlareElementTree->GetCurrentLensFlareElement(); - if (pElement == NULL) - { - return false; - } - return pElement->GetName(outName); -} - -void CLensFlareEditor::ReloadItems() -{ - CDatabaseFrameWnd::ReloadItems(); - ResetElementTreeControl(); -} - -void CLensFlareEditor::OnRemoveItem() -{ - CLensFlareItem* pSelectedLensFlareItem = GetSelectedLensFlareItem(); - CUndo undo(tr("Remove Flare Group Item").toUtf8()); - - if (pSelectedLensFlareItem == NULL) - { - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - QModelIndex hLensFlareItem = selected.first(); - - QString fullLensFlareItemName = m_pLibraryItemTreeModel->GetFullName(hLensFlareItem); - - if (!fullLensFlareItemName.isEmpty()) - { - QString deleteMsgStr = tr("Delete %1?").arg(fullLensFlareItemName); - if (QMessageBox::question(this, tr("Confirmation"), deleteMsgStr) == QMessageBox::Yes) - { - CLensFlareLibrary* pLensFlareLibrary = GetCurrentLibrary(); - if (pLensFlareLibrary) - { - std::vector< _smart_ptr > deletedItems; - for (int i = 0, iItemCount(pLensFlareLibrary->GetItemCount()); i < iItemCount; ++i) - { - CLensFlareItem* pItem = (CLensFlareItem*)pLensFlareLibrary->GetItem(i); - if (pItem == NULL) - { - continue; - } - if (pItem->GetName().indexOf(fullLensFlareItemName) == -1) - { - continue; - } - QModelIndex hFlareItem = m_pLibraryItemTreeModel->index(pItem); - if (hFlareItem.isValid()) - { - UpdateLensOpticsNames(pItem->GetFullName(), ""); - deletedItems.push_back(pItem); - } - } - for (int i = 0, iDeleteItemSize(deletedItems.size()); i < iDeleteItemSize; ++i) - { - m_pLensFlareLightEntityTree->OnLensFlareDeleteItem(deletedItems[i]); - DeleteItem(deletedItems[i]); - } - - m_pLibraryItemTreeModel->removeRow(hLensFlareItem.row(), hLensFlareItem.parent()); - } - GetIEditor()->SetModifiedFlag(); - } - } - } - else - { - QString deleteMsgStr = tr("Delete %1?").arg(pSelectedLensFlareItem->GetName()); - // Remove prototype from prototype manager and library. - if (QMessageBox::question(this, tr("Confirmation"), deleteMsgStr) == QMessageBox::Yes) - { - m_pLensFlareLightEntityTree->OnLensFlareDeleteItem(pSelectedLensFlareItem); - - DeleteItem(pSelectedLensFlareItem); - - UpdateLensOpticsNames(pSelectedLensFlareItem->GetFullName(), ""); - - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (!selected.isEmpty()) - { - QModelIndex hLensFlareItem = selected.first(); - m_pLibraryItemTreeModel->removeRow(hLensFlareItem.row(), hLensFlareItem.parent()); - } - - m_pCurrentItem = NULL; - - GetIEditor()->SetModifiedFlag(); - SelectItem(0); - } - } -} - -void CLensFlareEditor::OnAddLibrary() -{ - StringDlg dlg(tr("Library Name"), this); - - dlg.SetCheckCallback([this](QString library) -> bool - { - QString path = m_pItemManager->MakeFilename(library); - if (CFileUtil::FileExists(path)) - { - QMessageBox::warning(this, tr("Library exists"), tr("Library '%1' already exists.").arg(library)); - return false; - } - return true; - }); - - if (dlg.exec() == QDialog::Accepted) - { - if (!dlg.GetString().isEmpty()) - { - SelectItem(0); - // Make new library. - QString library = dlg.GetString(); - NewLibrary(library); - ReloadLibs(); - SelectLibrary(library); - GetIEditor()->SetModifiedFlag(); - } - } -} - -void CLensFlareEditor::OnRenameItem() -{ - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - StartEditItem(selected.first()); -} - -void CLensFlareEditor::OnReloadLib() -{ - CDatabaseFrameWnd::OnReloadLib(); - CLensFlareLibrary* pLibrary = GetCurrentLibrary(); - if (pLibrary == NULL) - { - return; - } - for (int i = 0, iItemCount(pLibrary->GetItemCount()); i < iItemCount; ++i) - { - CLensFlareItem* pItem = (CLensFlareItem*)pLibrary->GetItem(i); - if (pItem == NULL) - { - continue; - } - pItem->UpdateLights(NULL); - } -} - -void CLensFlareEditor::RegisterLensFlareItemChangeListener(ILensFlareChangeItemListener* pListener) -{ - for (int i = 0, iSize(m_LensFlareChangeItemListenerList.size()); i < iSize; ++i) - { - if (m_LensFlareChangeItemListenerList[i] == pListener) - { - return; - } - } - m_LensFlareChangeItemListenerList.push_back(pListener); -} - -void CLensFlareEditor::UnregisterLensFlareItemChangeListener(ILensFlareChangeItemListener* pListener) -{ - auto iter = m_LensFlareChangeItemListenerList.begin(); - for (; iter != m_LensFlareChangeItemListenerList.end(); ++iter) - { - if (*iter == pListener) - { - m_LensFlareChangeItemListenerList.erase(iter); - return; - } - } -} - -void CLensFlareEditor::OnItemTreeDataRenamed(CBaseLibraryItem* pItem, const QString& prevFullName) -{ - CLensFlareItem* pLensFlareItem = static_cast(pItem); - - UpdateLensOpticsNames(prevFullName, pLensFlareItem->GetFullName()); - LensFlareUtil::ChangeOpticsRootName(pLensFlareItem->GetOptics(), pLensFlareItem->GetShortName()); - - if (pLensFlareItem == GetSelectedLensFlareItem()) - { - UpdateLensFlareItem(pLensFlareItem); - } - - GetIEditor()->GetLensFlareManager()->Modified(); -} - -void CLensFlareEditor::UpdateLensFlareItem(CLensFlareItem* pLensFlareItem) -{ - for (int i = 0, iSize(m_LensFlareChangeItemListenerList.size()); i < iSize; ++i) - { - m_LensFlareChangeItemListenerList[i]->OnLensFlareChangeItem(pLensFlareItem); - } -} - -void CLensFlareEditor::OnLensFlareChangeElement(CLensFlareElement* pLensFlareElement) -{ - ReflectedPropertyControl* pPropertyCtrl = m_pWndProps; - pPropertyCtrl->RemoveAllItems(); - - if (pLensFlareElement == NULL) - { - return; - } - - // Update properties in a property panel - if (pLensFlareElement && pLensFlareElement->GetProperties()) - { - pPropertyCtrl->AddVarBlock(pLensFlareElement->GetProperties()); - pPropertyCtrl->ExpandAllChildren(pPropertyCtrl->GetRootItem(), false); - pPropertyCtrl->setEnabled(true); - } -} - -void CLensFlareEditor::AddNewItemByAtomicOptics(const QModelIndex& hSelectedItem, EFlareType flareType) -{ - if (!LensFlareUtil::IsValidFlare(flareType)) - { - return; - } - - QString groupName; - QModelIndex hParentItem = hSelectedItem.parent(); - if (hParentItem.isValid()) - { - groupName = hParentItem.data(Qt::DisplayRole).toString(); - } - else - { - groupName = hSelectedItem.data(Qt::DisplayRole).toString(); - } - - FlareInfoArray::Props flareProps = FlareInfoArray::Get(); - QString itemName = MakeValidName(groupName + QString(".") + flareProps.p[flareType].name, - AZStd::bind(&CDatabaseFrameWnd::DoesItemExist, this, AZStd::placeholders::_1, AZStd::placeholders::_2)); - CLensFlareItem* pNewItem = AddNewLensFlareItem(groupName, LensFlareUtil::GetShortName(itemName)); - - if (pNewItem) - { - pNewItem->GetOptics()->AddElement(gEnv->pOpticsManager->Create(flareType)); - ReloadItems(); - SelectLensFlareItem(GetTreeLensFlareItem(pNewItem), {}); - } -} - -void CLensFlareEditor::OnUpdateProperties([[maybe_unused]] IVariable* var) -{ - GetIEditor()->GetLensFlareManager()->Modified(); -} - -AssetSelectionModel CLensFlareEditor::GetAssetSelectionModel() const -{ - return AssetSelectionModel::AssetTypeSelection(AZ::AzTypeInfo::Uuid()); -} - -LensFlareItemTreeModel::LensFlareItemTreeModel(CDatabaseFrameWnd* pParent) - : LibraryItemTreeModel(pParent) -{ -} - -QStringList LensFlareItemTreeModel::mimeTypes() const -{ - QStringList mimeTypes = LibraryItemTreeModel::mimeTypes(); - mimeTypes << QStringLiteral("application/x-o3de-flaretypes"); - return mimeTypes; -} - -bool LensFlareItemTreeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) -{ - if (LibraryItemTreeModel::dropMimeData(data, action, row, column, parent)) - { - return true; - } - - if (data->hasFormat(QStringLiteral("application/x-o3de-flaretypes"))) - { - QByteArray encoded = data->data(QStringLiteral("application/x-o3de-flaretypes")); - QDataStream stream(&encoded, QIODevice::ReadOnly); - - while (!stream.atEnd()) - { - int flareType; - stream >> flareType; - static_cast(m_dialog)->AddNewItemByAtomicOptics(parent, static_cast(flareType)); - } - - return true; - } - - return false; -} - -Qt::ItemFlags LensFlareItemTreeModel::flags(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return Qt::ItemFlags(); - } - - return LibraryItemTreeModel::flags(index) | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled; -} - -Qt::DropActions LensFlareItemTreeModel::supportedDragActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -Qt::DropActions LensFlareItemTreeModel::supportedDropActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -#include diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.h deleted file mode 100644 index d5753fa332..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareEditor.h +++ /dev/null @@ -1,233 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREEDITOR_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREEDITOR_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "DatabaseFrameWnd.h" -#include "LensFlareUtil.h" -#include "ILensFlareListener.h" -#include "LensFlareItemTree.h" -#include "UserMessageDefines.h" -#endif - -#include - -namespace AzQtComponents -{ - class FancyDocking; -} - -class CLensFlareView; -class CLensFlareElementTree; -class CLensFlareAtomicList; -class CLensFlareElementPropertyView; -class CLensFlareItem; -class CLensFlareLibrary; -class ReflectedPropertyControl; -class CLensFlareLightEntityTree; -class CLensFlareReferenceTree; - -class CLensFlareEditor - : public CDatabaseFrameWnd - , public ILensFlareChangeElementListener -{ - Q_OBJECT - -public: - static const GUID& GetClassID(); - static void RegisterViewClass(); - - CLensFlareEditor(QWidget* pParent = nullptr); - ~CLensFlareEditor(); - - QMenu* createPopupMenu() override; - - // CDatabaseFrameWnd overrides... - virtual void SelectItem(CBaseLibraryItem* item, bool bForceReload = false) override; - - CLensFlareItem* GetSelectedLensFlareItem() const; - bool GetSelectedLensFlareName(QString& outName) const; - void UpdateLensFlareItem(CLensFlareItem* pLensFlareItem); - void ResetElementTreeControl(); - - CLensFlareLibrary* GetCurrentLibrary() const - { - if (m_pLibrary == NULL) - { - return NULL; - } - return (CLensFlareLibrary*)&(*m_pLibrary); - } - - bool IsExistTreeItem(const QString& name, bool bExclusiveSelectedItem = false); - void RenameLensFlareItem(CLensFlareItem* pLensFlareItem, const QString& newGroupName, const QString& newShortName); - - IOpticsElementBasePtr FindOptics(const QString& itemPath, const QString& opticsPath); - - CLensFlareElementTree* GetLensFlareElementTree() - { - return m_pLensFlareElementTree; - } - - CLensFlareView* GetLensFlareView() const - { - return m_pLensFlareView; - } - - CLensFlareItemTree* GetLensFlareItemTree() - { - return m_LensFlareItemTree; - } - - void RemovePropertyItems(); - - ReflectedPropertyControl* GetPropertyCtrl() - { - return m_pWndProps; - } - - void UpdateLensOpticsNames(const QString& oldFullName, const QString& newFullName); - void SelectItemInLensFlareElementTreeByName(const QString& name); - void ReloadItems(); - - void RegisterLensFlareItemChangeListener(ILensFlareChangeItemListener* pListener); - void UnregisterLensFlareItemChangeListener(ILensFlareChangeItemListener* pListener); - - bool SelectItemByName(const QString& itemName); - - static CLensFlareEditor* GetLensFlareEditor() - { - return s_pLensFlareEditor; - } - - bool GetFullSelectedFlareItemName(QString& outFullName) const - { - QModelIndexList selected = GetTreeCtrl()->selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return false; - } - return GetFullLensFlareItemName(selected.first(), outFullName); - } - - void SelectLensFlareItem(const QString& fullItemName); - - const char* GetClassName() - { - return s_pLensFlareEditorClassName; - } - - void Paste(XmlNodeRef node); - void Paste(const QModelIndex& index, XmlNodeRef node); - XmlNodeRef CreateXML(const char* type) const; - - static const char* s_pLensFlareEditorClassName; - - QTreeView* GetTreeCtrl() override - { - return m_LensFlareItemTree; - } - - const QTreeView* GetTreeCtrl() const override - { - return m_LensFlareItemTree; - } - - void AddNewItemByAtomicOptics(const QModelIndex& hSelectedItem, EFlareType flareType); - -public slots: - void OnUpdateTreeCtrl(); - -protected: - static CLensFlareEditor* s_pLensFlareEditor; - - void OnInitDialog() override; - - void OnCopy(); - void OnPaste(); - void OnCut(); - - void UpdateClipboard(const char* type) const; - bool GetClipboardDataList(std::vector& outList, QString& outGroupName) const; - void OnLensFlareChangeElement(CLensFlareElement* pLensFlareElement); - - void OnAddLibrary(); - void OnAssignFlareToLightEntities(); - void OnSelectAssignedObjects(); - void OnGetFlareFromSelection(); - void OnRenameItem(); - void OnAddItem(); - void OnRemoveItem(); - void OnCopyNameToClipboard(); - void OnNotifyTreeRClick(); - - void OnTvnItemSelChanged(const QItemSelection& selected, const QItemSelection& deselected); - void OnReloadLib(); - void ReleaseWindowsToBePutIntoPanels(); - void SelectLensFlareItem(const QModelIndex& hItem); - void SelectLensFlareItem(const QModelIndex& hItem, const QModelIndex& hPrevItem); - - void StartEditItem(const QModelIndex& hItem); - bool GetFullLensFlareItemName(const QModelIndex& hItem, QString& outFullName) const; - AssetSelectionModel GetAssetSelectionModel() const override; - - CLensFlareItem* AddNewLensFlareItem(const QString& groupName, const QString& shortName); - QModelIndex GetTreeLensFlareItem(CLensFlareItem* pItem) const; - - void OnItemTreeDataRenamed(CBaseLibraryItem* pItem, const QString& prevFullName); - - enum ESelectedItemStatus - { - eSIS_Unselected, - eSIS_Group, - eSIS_Flare - }; - ESelectedItemStatus GetSelectedItemStatus() const; - - void addDockWidget(Qt::DockWidgetArea area, QWidget* widget, const QString& title, bool closable = true); - void OnUpdateProperties(IVariable* var); - -private: - - CLensFlareView* m_pLensFlareView; - CLensFlareAtomicList* m_pLensFlareAtomicList; - CLensFlareElementTree* m_pLensFlareElementTree; - ReflectedPropertyControl* m_pWndProps; - CLensFlareLightEntityTree* m_pLensFlareLightEntityTree; - CLensFlareReferenceTree* m_pLensFlareReferenceTree; - CLensFlareItemTree* m_LensFlareItemTree; - - std::vector m_LensFlareChangeItemListenerList; - AzQtComponents::FancyDocking* m_advancedDockManager = nullptr; -}; - -class LensFlareItemTreeModel - : public LibraryItemTreeModel -{ - Q_OBJECT - -public: - LensFlareItemTreeModel(CDatabaseFrameWnd* pParent); - - Qt::ItemFlags flags(const QModelIndex& index) const override; - - QStringList mimeTypes() const override; - bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override; - Qt::DropActions supportedDragActions() const override; - Qt::DropActions supportedDropActions() const override; -}; - -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREEDITOR_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.cpp deleted file mode 100644 index a51c788a8b..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.cpp +++ /dev/null @@ -1,381 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareElement.h" - -// Editor -#include "LensFlareElementTree.h" -#include "LensFlareUtil.h" -#include "LensFlareItem.h" -#include "LensFlareEditor.h" -#include "LensFlareView.h" -#include "LensFlareLibrary.h" - - -CLensFlareElement::CLensFlareElement() - : m_vars(NULL) - , m_pOpticsElement(NULL) - , m_pParent(NULL) -{ -} - -CLensFlareElement::~CLensFlareElement() -{ -} - -void CLensFlareElement::OnInternalVariableChange(IVariable* pVar) -{ - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return; - } - - IFuncVariable* pFuncVar = LensFlareUtil::GetFuncVariable(pOptics, pVar->GetUserData().toInt()); - if (pFuncVar == NULL) - { - return; - } - - switch (pVar->GetType()) - { - case IVariable::INT: - { - int var(0); - pVar->Get(var); - if (pFuncVar->paramType == e_COLOR) - { - ColorF color(pFuncVar->GetColorF()); - color.a = (float)var / 255.0f; - pFuncVar->InvokeSetter((void*)&color); - } - else if (pFuncVar->paramType == e_INT) - { - if (LensFlareUtil::HaveParameterLowBoundary(pFuncVar->name.c_str())) - { - LensFlareUtil::BoundaryProcess(var); - } - pFuncVar->InvokeSetter((void*)&var); - if (pFuncVar->GetInt() != var) - { - pVar->Set(pFuncVar->GetInt()); - } - } - } - break; - case IVariable::BOOL: - { - if (pFuncVar->paramType == e_BOOL) - { - bool var; - pVar->Get(var); - pFuncVar->InvokeSetter((void*)&var); - } - } - break; - case IVariable::FLOAT: - { - if (pFuncVar->paramType == e_FLOAT) - { - float var; - pVar->Get(var); - pFuncVar->InvokeSetter((void*)&var); - } - } - break; - case IVariable::VECTOR2: - { - if (pFuncVar->paramType == e_VEC2) - { - Vec2 var; - pVar->Get(var); - pFuncVar->InvokeSetter((void*)&var); - } - } - break; - case IVariable::VECTOR: - { - Vec3 var; - pVar->Get(var); - if (pFuncVar->paramType == e_COLOR) - { - ColorF color(pFuncVar->GetColorF()); - color.r = var.x; - color.g = var.y; - color.b = var.z; - pFuncVar->InvokeSetter((void*)&color); - } - else if (pFuncVar->paramType == e_VEC3) - { - pFuncVar->InvokeSetter((void*)&var); - } - } - break; - case IVariable::VECTOR4: - { - if (pFuncVar->paramType == e_VEC4) - { - Vec4 var; - pVar->Get(var); - pFuncVar->InvokeSetter((void*)&var); - } - } - break; - case IVariable::STRING: - { - QString var; - pVar->Get(var); - if (pFuncVar->paramType == e_TEXTURE2D || pFuncVar->paramType == e_TEXTURE3D || pFuncVar->paramType == e_TEXTURE_CUBE) - { - var = var.trimmed(); - ITexture* pTexture = NULL; - if (!var.isEmpty()) - { - pTexture = GetIEditor()->GetRenderer()->EF_LoadTexture(var.toUtf8().data()); - } - pFuncVar->InvokeSetter((void*)pTexture); - if (pTexture) - { - pTexture->Release(); - } - } - } - break; - } - - UpdateLights(); -} - -bool CLensFlareElement::IsEnable() -{ - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return false; - } - return pOptics->IsEnabled(); -} - -void CLensFlareElement::SetEnable(bool bEnable) -{ - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return; - } - pOptics->SetEnabled(bEnable); - UpdateLights(); -} - -EFlareType CLensFlareElement::GetOpticsType() -{ - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return eFT__Base__; - } - return pOptics->GetType(); -} - -bool CLensFlareElement::GetShortName(QString& outName) const -{ - QString fullName; - if (!GetName(fullName)) - { - return false; - } - int nPos = fullName.lastIndexOf('.'); - if (nPos == -1) - { - outName = fullName; - return true; - } - outName = fullName.right(fullName.length() - nPos - 1); - return true; -} - -void CLensFlareElement::UpdateLights() -{ - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return; - } - if (GetLensFlareTree()) - { - if (GetLensFlareTree()->GetLensFlareItem()) - { - GetLensFlareTree()->GetLensFlareItem()->UpdateLights(pOptics); - } - } -} - -void CLensFlareElement::UpdateProperty(IOpticsElementBasePtr pOptics) -{ - std::vector funcs; - - if (CLensFlareElementTree* lensFlareTree = GetLensFlareTree(); lensFlareTree) - { - auto callbackItr = m_callbackCache.find(lensFlareTree); - if (callbackItr == m_callbackCache.end()) - { - IVariable::OnSetCallback callback = - AZStd::bind(&CLensFlareElementTree::OnInternalVariableChange, lensFlareTree, AZStd::placeholders::_1); - - auto result = m_callbackCache.insert(AZStd::make_pair(lensFlareTree, callback)); - callbackItr = result.first; - } - - funcs.push_back(&(callbackItr->second)); - } - - if (CLensFlareView* lensFlareView = GetLensFlareView(); lensFlareView) - { - auto callbackItr = m_callbackCache.find(lensFlareView); - if (callbackItr == m_callbackCache.end()) - { - IVariable::OnSetCallback callback = - AZStd::bind(&CLensFlareView::OnInternalVariableChange, lensFlareView, AZStd::placeholders::_1); - - auto result = m_callbackCache.insert(AZStd::make_pair(lensFlareView, callback)); - callbackItr = result.first; - } - - funcs.push_back(&(callbackItr->second)); - } - - if (CLensFlareLibrary* lensFlareLibrary = GetLensFlareLibrary(); lensFlareLibrary) - { - auto callbackItr = m_callbackCache.find(lensFlareLibrary); - if (callbackItr == m_callbackCache.end()) - { - IVariable::OnSetCallback callback = - AZStd::bind(&CLensFlareLibrary::OnInternalVariableChange, lensFlareLibrary, AZStd::placeholders::_1); - - auto result = m_callbackCache.insert(AZStd::make_pair(lensFlareLibrary, callback)); - callbackItr = result.first; - } - - funcs.push_back(&(callbackItr->second)); - } - - LensFlareUtil::SetVariablesTemplateFromOptics(pOptics, m_vars, funcs); -} - -CLensFlareElementTree* CLensFlareElement::GetLensFlareTree() const -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return NULL; - } - return pEditor->GetLensFlareElementTree(); -} - -CLensFlareView* CLensFlareElement::GetLensFlareView() const -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return NULL; - } - return pEditor->GetLensFlareView(); -} - -CLensFlareLibrary* CLensFlareElement::GetLensFlareLibrary() const -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return NULL; - } - return pEditor->GetCurrentLibrary(); -} - -CLensFlareElement* CLensFlareElement::GetParent() const -{ - return m_pParent; -} - -void CLensFlareElement::SetParent(CLensFlareElement* pParent) -{ - m_pParent = pParent; -} - -int CLensFlareElement::GetChildCount() const -{ - return m_children.size(); -} - -CLensFlareElement* CLensFlareElement::GetChildAt(int nPos) const -{ - if (nPos < 0 || nPos >= m_children.size()) - { - return nullptr; - } - return m_children[nPos]; -} - -void CLensFlareElement::AddChild(CLensFlareElement* pElement) -{ - pElement->SetParent(this); - m_children.push_back(pElement); -} - -void CLensFlareElement::InsertChild(int nPos, CLensFlareElement* pElement) -{ - pElement->SetParent(this); - m_children.insert(std::begin(m_children) + nPos, pElement); -} - -void CLensFlareElement::RemoveChild(int nPos) -{ - m_children.erase(std::begin(m_children) + nPos); -} - -void CLensFlareElement::SwapChildren(int nPos1, int nPos2) -{ - std::swap(m_children[nPos1], m_children[nPos2]); -} - -void CLensFlareElement::RemoveAllChildren() -{ - m_children.clear(); -} - -int CLensFlareElement::GetChildIndex(const CLensFlareElement* pElement) const -{ - auto it = std::find_if( - std::begin(m_children), - std::end(m_children), - [=](const LensFlareElementPtr& pChild) - { - return pChild.get() == pElement; - }); - - if (it != std::end(m_children)) - { - return std::distance(std::begin(m_children), it); - } - else - { - return -1; - } -} - -int CLensFlareElement::GetRow() const -{ - return m_pParent ? m_pParent->GetChildIndex(this) : 0; -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.h deleted file mode 100644 index 9860fa597e..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElement.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENT_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENT_H -#pragma once - -#include "IFlares.h" - -#include "Util/Variable.h" - -class CLensFlareElementTree; -class CLensFlareView; -class CLensFlareLibrary; - -class CLensFlareElement - : public CRefCountBase -{ -public: - - typedef _smart_ptr LensFlareElementPtr; - typedef std::vector LensFlareElementList; - - CLensFlareElement(); - virtual ~CLensFlareElement(); - - CVarBlock* GetProperties() const - { - return m_vars; - } - - void OnInternalVariableChange(IVariable* pVar); - - bool IsEnable(); - void SetEnable(bool bEnable); - EFlareType GetOpticsType(); - - bool GetName(QString& outName) const - { - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - return false; - } - outName = pOptics->GetName(); - return true; - } - - bool GetShortName(QString& outName) const; - IOpticsElementBasePtr GetOpticsElement() const - { - return m_pOpticsElement; - } - void SetOpticsElement(IOpticsElementBasePtr pOptics) - { - m_pOpticsElement = pOptics; - UpdateProperty(m_pOpticsElement); - } - - CLensFlareElement* GetParent() const; - void SetParent(CLensFlareElement* pParent); - - int GetChildCount() const; - CLensFlareElement* GetChildAt(int nPos) const; - - void AddChild(CLensFlareElement* pElement); - void InsertChild(int nPos, CLensFlareElement* pElement); - - void RemoveChild(int nPos); - void RemoveAllChildren(); - - void SwapChildren(int nPos1, int nPos2); - - int GetChildIndex(const CLensFlareElement* pChild) const; - int GetRow() const; - -private: - - void UpdateLights(); - void UpdateProperty(IOpticsElementBasePtr pOptics); - - CLensFlareElementTree* GetLensFlareTree() const; - CLensFlareView* GetLensFlareView() const; - CLensFlareLibrary* GetLensFlareLibrary() const; - -private: - - IOpticsElementBasePtr m_pOpticsElement; - CVarBlockPtr m_vars; - - CLensFlareElement* m_pParent; - LensFlareElementList m_children; - - AZStd::map m_callbackCache; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENT_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.cpp deleted file mode 100644 index be687a5469..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.cpp +++ /dev/null @@ -1,1393 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareElementTree.h" - -// Qt -#include -#include -#include - -// Editor -#include "Clipboard.h" -#include "LensFlareItem.h" -#include "LensFlareManager.h" -#include "LensFlareUndo.h" -#include "LensFlareEditor.h" -#include "LensFlareLibrary.h" - - -template -static CLensFlareElement* FindLensFlareElement(CLensFlareElement* pRoot, Predicate pred) -{ - if (pred(pRoot)) - { - return pRoot; - } - - for (int i = 0, childCount = pRoot->GetChildCount(); i < childCount; i++) - { - if (CLensFlareElement* pElement = FindLensFlareElement(pRoot->GetChildAt(i), pred)) - { - return pElement; - } - } - - return nullptr; -} - -CLensFlareElementTree::CLensFlareElementTree(QWidget* pParent) - : QTreeView(pParent) - , m_model(new LensFlareElementTreeModel(this)) -{ - setHeaderHidden(true); - setContextMenuPolicy(Qt::CustomContextMenu); - setDragEnabled(true); - setAcceptDrops(true); - setDropIndicatorShown(true); - setDragDropMode(DragDrop); - - setModel(m_model.data()); - - connect(this, &QWidget::customContextMenuRequested, this, &CLensFlareElementTree::OnNotifyTreeRClick); - connect(selectionModel(), &QItemSelectionModel::selectionChanged, this, &CLensFlareElementTree::OnTvnSelchangedTree); - connect(model(), &QAbstractItemModel::dataChanged, this, &CLensFlareElementTree::OnDataChanged); - connect(model(), &QAbstractItemModel::rowsInserted, this, &CLensFlareElementTree::OnRowsInserted); - connect(model(), &QAbstractItemModel::rowsRemoved, this, &CLensFlareElementTree::OnRowsRemoved); - connect(model(), &QAbstractItemModel::modelReset, this, &QTreeView::expandAll); -} - -void CLensFlareElementTree::OnInternalVariableChange(IVariable* pVar) -{ - CLensFlareElement::LensFlareElementPtr pCurrentElement = GetCurrentLensFlareElement(); - if (pCurrentElement == NULL) - { - return; - } - pCurrentElement->OnInternalVariableChange(pVar); -} - -CLensFlareElement* CLensFlareElementTree::GetCurrentLensFlareElement() const -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return nullptr; - } - return selected.first().data(Qt::UserRole).value(); -} - -void CLensFlareElementTree::OnNotifyTreeRClick() -{ - CLensFlareElement* pElement = GetCurrentLensFlareElement(); - - // Copy, Cut and Clone can't be done about a Root item so those menus should be disable when the selected item is a root item. - bool bGrayed = false; - if (!pElement || pElement->GetOpticsType() == eFT_Root) - { - bGrayed = true; - } - - QMenu menu; - - QAction* actionDBFlareAddGroup = menu.addAction(tr("Add Group")); - connect(actionDBFlareAddGroup, &QAction::triggered, this, &CLensFlareElementTree::OnAddGroup); - - menu.addSeparator(); - - QAction* actionDBFlareCopy = menu.addAction(tr("Copy")); - connect(actionDBFlareCopy, &QAction::triggered, this, &CLensFlareElementTree::OnCopy); - - QAction* actionDBFlareCut = menu.addAction(tr("Cut")); - actionDBFlareCut->setEnabled(!bGrayed); - connect(actionDBFlareCut, &QAction::triggered, this, &CLensFlareElementTree::OnCut); - - QAction* actionDBFlarePaste = menu.addAction(tr("Paste")); - connect(actionDBFlarePaste, &QAction::triggered, this, &CLensFlareElementTree::OnPaste); - - QAction* actionDBFlareClone = menu.addAction(tr("Clone")); - connect(actionDBFlareClone, &QAction::triggered, this, &CLensFlareElementTree::OnClone); - - menu.addSeparator(); - - QAction* actionDBFlareRename = menu.addAction(tr("Rename\tF2")); - connect(actionDBFlareRename, &QAction::triggered, this, &CLensFlareElementTree::OnRenameItem); - - QAction* actionDBFlareRemove = menu.addAction(tr("Delete\tDel")); - connect(actionDBFlareRemove, &QAction::triggered, this, &CLensFlareElementTree::OnRemoveItem); - - QAction* actionDBFlareRemoveAll = menu.addAction(tr("Delete All")); - connect(actionDBFlareRemoveAll, &QAction::triggered, this, &CLensFlareElementTree::OnRemoveAll); - - menu.addSeparator(); - - QAction* actionDBFlareItemUp = menu.addAction(tr("Up")); - connect(actionDBFlareItemUp, &QAction::triggered, this, &CLensFlareElementTree::OnItemUp); - - QAction* actionDBFlareItemDown = menu.addAction(tr("Down")); - connect(actionDBFlareItemDown, &QAction::triggered, this, &CLensFlareElementTree::OnItemDown); - - menu.exec(QCursor::pos()); -} - -void CLensFlareElementTree::OnTvnSelchangedTree([[maybe_unused]] const QItemSelection& selected, const QItemSelection& deselected) -{ - QModelIndexList deselectedIndices = deselected.indexes(); - if (!deselectedIndices.isEmpty()) - { - CLensFlareElement* pPrevLensFlareElement = deselectedIndices.first().data(Qt::UserRole).value(); - ElementChanged(pPrevLensFlareElement); - } - - CallChangeListeners(); -} - -void CLensFlareElementTree::ElementChanged(CLensFlareElement* pPrevLensFlareElement) -{ - if (!pPrevLensFlareElement) - { - return; - } - QString itemName; - if (pPrevLensFlareElement->GetName(itemName)) - { - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoLensFlareElementSelection(m_model->GetLensFlareItem(), itemName)); - } - } -} - -void CLensFlareElementTree::OnDataChanged([[maybe_unused]] const QModelIndex& index) -{ - CallChangeListeners(); -} - -void CLensFlareElementTree::OnRowsInserted(const QModelIndex& parent, int first, [[maybe_unused]] int last) -{ - if (parent.isValid()) - { - expand(parent); - SelectItem(parent.model()->index(first, 0, parent)); - CallChangeListeners(); - } -} - -void CLensFlareElementTree::OnRowsRemoved(const QModelIndex& parent, int first, [[maybe_unused]] int last) -{ - if (parent.isValid()) - { - SelectItem(parent.model()->index(first, 0, parent)); - CallChangeListeners(); - } -} - -void CLensFlareElementTree::keyPressEvent(QKeyEvent* event) -{ - if (event->key() == Qt::Key_F2) - { - OnRenameItem(); - event->accept(); - return; - } - else if (event->matches(QKeySequence::Delete)) - { - OnRemoveItem(); - event->accept(); - return; - } - - QTreeView::keyPressEvent(event); -} - -XmlNodeRef CLensFlareElementTree::CreateXML(const char* type) const -{ - std::vector clipboardData; - if (GetClipboardList(type, clipboardData)) - { - return LensFlareUtil::CreateXMLFromClipboardData(type, "", false, clipboardData); - } - return NULL; -} - -void CLensFlareElementTree::UpdateClipboard(const char* type, bool bPasteAtSameLevel) -{ - std::vector clipboardData; - if (GetClipboardList(type, clipboardData)) - { - LensFlareUtil::UpdateClipboard(type, "", bPasteAtSameLevel, clipboardData); - } -} - -bool CLensFlareElementTree::GetClipboardList([[maybe_unused]] const char* type, std::vector& outList) const -{ - CLensFlareElement::LensFlareElementPtr pElement = GetCurrentLensFlareElement(); - if (pElement == NULL) - { - return false; - } - QString name; - if (!pElement->GetName(name)) - { - return false; - } - - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return false; - } - - CLensFlareItem* pLensFlareItem = pEditor->GetSelectedLensFlareItem(); - if (pLensFlareItem == NULL) - { - return false; - } - - outList.push_back(LensFlareUtil::SClipboardData(LENSFLARE_ELEMENT_TREE, pLensFlareItem->GetFullName(), name)); - - return true; -} - -void CLensFlareElementTree::OnAddGroup() -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - CUndo undo(tr("Add library item").toUtf8()); - m_model->AddElement(selected.first(), 0, eFT_Group); - GetIEditor()->GetLensFlareManager()->Modified(); -} - -void CLensFlareElementTree::OnCopy() -{ - UpdateClipboard(FLARECLIPBOARDTYPE_COPY, false); -} - -void CLensFlareElementTree::OnCut() -{ - Cut(false); -} - -void CLensFlareElementTree::Cut(bool bPasteAtSameLevel) -{ - UpdateClipboard(FLARECLIPBOARDTYPE_CUT, bPasteAtSameLevel); -} - -CLensFlareItem* CLensFlareElementTree::GetLensFlareItem() const -{ - return m_model->GetLensFlareItem(); -} - -void CLensFlareElementTree::OnPaste() -{ - CClipboard clipboard(this); - if (clipboard.IsEmpty()) - { - return; - } - - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - XmlNodeRef xmlNode = clipboard.Get(); - if (xmlNode == NULL) - { - return; - } - - CUndo undo(tr("Copy/Cut & Paste library item").toUtf8()); - m_model->Paste(selected.first(), xmlNode); -} - -void CLensFlareElementTree::OnClone() -{ - OnCopy(); - OnPaste(); -} - -void CLensFlareElementTree::OnRenameItem() -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - edit(selected.first()); -} - -void CLensFlareElementTree::OnRemoveItem() -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - QModelIndex index = selected.first(); - - // A root item must not be removed. - if (!index.parent().isValid()) - { - return; - } - - CLensFlareElement::LensFlareElementPtr pCurrentElement = m_model->GetLensFlareElement(index); - if (pCurrentElement == NULL) - { - return; - } - - QString name; - pCurrentElement->GetName(name); - - QString str = tr("Delete %1?").arg(name); - if (QMessageBox::question(this, tr("Delete Confirmation"), str) == QMessageBox::Yes) - { - CUndo undo(tr("Remove an optics element").toUtf8()); - m_model->removeRow(index.row(), index.parent()); - } -} - -void CLensFlareElementTree::OnRemoveAll() -{ - CUndo undo(tr("Remove All in FlareTreeCtrl").toUtf8()); - - if (QMessageBox::question(this, tr("Delete Confirmation"), tr("Do you want delete all?")) == QMessageBox::Yes) - { - m_model->RemoveAllElements(); - GetIEditor()->GetLensFlareManager()->Modified(); - } -} - -void CLensFlareElementTree::OnItemUp() -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - QModelIndex index = selected.first(); - int row = index.row(); - if (row == 0) - { - return; - } - - CUndo undo(tr("Copy/Cut & Paste library item").toUtf8()); - - CLensFlareElement* pElement = index.data(Qt::UserRole).value(); - m_model->MoveElement(pElement, row - 1, index.parent()); -} - -void CLensFlareElementTree::OnItemDown() -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - QModelIndex index = selected.first(); - int row = index.row(); - if (row == m_model->rowCount(index.parent()) - 1) - { - return; - } - - CUndo undo(tr("Copy/Cut & Paste library item").toUtf8()); - - CLensFlareElement* pElement = index.data(Qt::UserRole).value(); - m_model->MoveElement(pElement, row + 2, index.parent()); -} - -void CLensFlareElementTree::SelectItem(const QModelIndex& index) -{ - if (index.isValid()) - { - expand(index.parent()); - selectionModel()->select(index, QItemSelectionModel::ClearAndSelect); - } - else - { - selectionModel()->clear(); - } -} - -void CLensFlareElementTree::SelectTreeItemByName(const QString& name) -{ - SelectItem(m_model->GetTreeItemByName(name)); -} - -void CLensFlareElementTree::CallChangeListeners() -{ - CLensFlareElement* pElement = GetCurrentLensFlareElement(); - for (int i = 0, iSize(m_LensFlaresElementListeners.size()); i < iSize; ++i) - { - m_LensFlaresElementListeners[i]->OnLensFlareChangeElement(pElement); - } -} - -void CLensFlareElementTree::mousePressEvent(QMouseEvent* event) -{ - if (event->button() == Qt::LeftButton) - { - CUndo undo(tr("Changed Lens flares element").toUtf8()); - QTreeView::mousePressEvent(event); - } - else - { - QTreeView::mousePressEvent(event); - } -} - -void CLensFlareElementTree::InvalidateLensFlareItem() -{ - m_model->InvalidateLensFlareItem(); -} - -LensFlareElementTreeModel::LensFlareElementTreeModel(QObject* pParent) - : QAbstractItemModel(pParent) - , m_pRootElement(new CLensFlareElement) -{ - CLensFlareEditor::GetLensFlareEditor()->RegisterLensFlareItemChangeListener(this); -} - -LensFlareElementTreeModel::~LensFlareElementTreeModel() -{ - CLensFlareEditor::GetLensFlareEditor()->UnregisterLensFlareItemChangeListener(this); -} - -int LensFlareElementTreeModel::columnCount(const QModelIndex&) const -{ - return 1; -} - -QVariant LensFlareElementTreeModel::data(const QModelIndex& index, int role) const -{ - if (!index.isValid()) - { - return {}; - } - - auto pElement = static_cast(index.internalPointer()); - - switch (role) - { - case Qt::DisplayRole: - case Qt::EditRole: - { - QString shortName; - pElement->GetShortName(shortName); - return shortName; - } - - case Qt::CheckStateRole: - return pElement->IsEnable() ? Qt::Checked : Qt::Unchecked; - - case Qt::UserRole: - return QVariant::fromValue(pElement); - } - - return {}; -} - -void LensFlareElementTreeModel::EnableElement(CLensFlareElement* pLensFlareElement, bool bEnable) -{ - StoreUndo(); - pLensFlareElement->SetEnable(bEnable); -} - -void LensFlareElementTreeModel::RenameElement(CLensFlareElement* pLensFlareElement, const QString& newName) -{ - StoreUndo(); - IOpticsElementBasePtr pOptics = pLensFlareElement->GetOpticsElement(); - if (pOptics) - { - pOptics->SetName(newName.toUtf8().data()); - LensFlareUtil::UpdateOpticsName(pOptics); - } -} - -QModelIndex LensFlareElementTreeModel::GetRootItem() const -{ - if (m_pRootElement->GetChildCount() == 0) - { - return {}; - } - - auto pRootElement = m_pRootElement->GetChildAt(0); - assert(pRootElement->GetOpticsType() == eFT_Root); - - return createIndex(0, 0, pRootElement); -} - -bool LensFlareElementTreeModel::setData(const QModelIndex& index, const QVariant& value, int role) -{ - if (!index.isValid()) - { - return false; - } - - auto pElement = static_cast(index.internalPointer()); - - switch (role) - { - case Qt::CheckStateRole: - { - CUndo undo(tr("Update an enable checkbox for tree ctrl.").toUtf8()); - EnableElement(pElement, value.toInt() == Qt::Checked); - emit dataChanged(index, index); - return true; - } - - case Qt::EditRole: - { - QString text = value.toString(); - - CUndo undo(tr("Rename library item").toUtf8()); - - if (IsExistElement(text)) - { - QMessageBox::warning(0, tr("Warning"), tr("The identical name exists in a database")); - return false; - } - else if (text.contains(QLatin1Char('.'))) - { - QMessageBox::warning(0, tr("Warning"), tr("The name must not contain \".\"")); - return false; - } - else - { - CLensFlareElement* pLensFlareElement = GetLensFlareElement(index); - - QString prevName; - if (pLensFlareElement && pLensFlareElement->GetName(prevName)) - { - QString parentName(prevName); - int offset = parentName.lastIndexOf('.'); - if (offset == -1) - { - parentName = ""; - } - else - { - parentName.remove(offset + 1, parentName.length() - offset); - } - - if (index == GetRootItem()) - { - CLensFlareEditor* pLensFlareEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pLensFlareEditor) - { - CLensFlareItem* pLensFlareItem = pLensFlareEditor->GetSelectedLensFlareItem(); - if (pLensFlareItem) - { - QString candidateName = LensFlareUtil::ReplaceLastName(pLensFlareItem->GetName(), text); - if (pLensFlareEditor->IsExistTreeItem(candidateName, true)) - { - QMessageBox::warning(0, tr("Warning"), tr("The identical name exists in a database")); - return false; - } - pLensFlareEditor->RenameLensFlareItem(pLensFlareItem, pLensFlareItem->GetGroupName(), text); - } - } - else - { - QMessageBox::warning(0, tr("Warning"), tr("Renaming is not possible.")); - return false; - } - } - - RenameElement(pLensFlareElement, parentName + text); - emit dataChanged(index, index); - - GetIEditor()->GetLensFlareManager()->Modified(); - } - - return true; - } - } - } - - return false; -} - -Qt::ItemFlags LensFlareElementTreeModel::flags(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return Qt::ItemFlags(); - } - - auto pElement = index.data(Qt::UserRole).value(); - - Qt::ItemFlags flags = QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsUserCheckable | Qt::ItemIsDropEnabled; - - if (pElement->GetOpticsType() != eFT_Root) - { - flags |= Qt::ItemIsDragEnabled; - } - - return flags; -} - -QModelIndex LensFlareElementTreeModel::index(int row, int column, const QModelIndex& parent) const -{ - if (!hasIndex(row, column, parent)) - { - return {}; - } - - auto parentNode = GetLensFlareElement(parent); - auto childNode = parentNode->GetChildAt(row); - - if (childNode) - { - return createIndex(row, column, childNode); - } - else - { - return {}; - } -} - -QModelIndex LensFlareElementTreeModel::parent(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return {}; - } - - auto childNode = static_cast(index.internalPointer()); - auto parentNode = childNode->GetParent(); - - if (parentNode == m_pRootElement.get()) - { - return {}; - } - - return createIndex(parentNode->GetRow(), 0, parentNode); -} - -int LensFlareElementTreeModel::rowCount(const QModelIndex& parent) const -{ - if (parent.column() > 0) - { - return 0; - } - return GetLensFlareElement(parent)->GetChildCount(); -} - -bool LensFlareElementTreeModel::removeRows(int row, int count, const QModelIndex& parent) -{ - if (!parent.isValid()) - { - return false; - } - - auto pParent = static_cast(parent.internalPointer()); - - beginRemoveRows(parent, row, row + count - 1); - - for (int i = 0; i < count; i++) - { - CLensFlareElement* pChild = pParent->GetChildAt(row); - - IOpticsElementBasePtr pOptics = pChild->GetOpticsElement(); - if (pOptics) - { - LensFlareUtil::RemoveOptics(pOptics); - } - - pParent->RemoveChild(row); - } - - endRemoveRows(); - - GetIEditor()->GetLensFlareManager()->Modified(); // XXX - - if (m_pLensFlareItem) - { - m_pLensFlareItem->UpdateLights(); - } - - return true; -} - -QStringList LensFlareElementTreeModel::mimeTypes() const -{ - QStringList types; - types << QStringLiteral("application/x-o3de-flareelements"); - types << QStringLiteral("application/x-o3de-flaretypes"); - return types; -} - -QMimeData* LensFlareElementTreeModel::mimeData(const QModelIndexList& indexes) const -{ - QMimeData* data = new QMimeData(); - - QByteArray array; - - for (auto& index : indexes) - { - auto pElement = static_cast(index.data(Qt::UserRole).value()); - array.append(reinterpret_cast(&pElement), sizeof(CLensFlareElement*)); - } - - data->setData(QStringLiteral("application/x-o3de-flareelements"), array); - - return data; -} - -void LensFlareElementTreeModel::RemoveAllElements() -{ - QModelIndex index = GetRootItem(); - if (!index.isValid()) - { - return; - } - - auto pElement = index.data(Qt::UserRole).value(); - - beginResetModel(); - - pElement->RemoveAllChildren(); - pElement->GetOpticsElement()->RemoveAll(); - - endResetModel(); - - if (m_pLensFlareItem) - { - m_pLensFlareItem->UpdateLights(); - } -} - -bool LensFlareElementTreeModel::AddElement(const QModelIndex& parentIndex, int row, EFlareType flareType) -{ - if (!parentIndex.isValid()) - { - return false; - } - - auto pElement = GetLensFlareElement(parentIndex); - - int nIndex; - - if (LensFlareUtil::IsGroup(pElement->GetOpticsType())) - { - if (row != -1) - { - nIndex = row; - } - else - { - nIndex = pElement->GetChildCount(); - } - } - else - { - CLensFlareElement* pParentElement = GetLensFlareElement(parentIndex.parent()); - if (!pParentElement) - { - return false; - } - - if (!LensFlareUtil::IsGroup(pParentElement->GetOpticsType())) - { - return false; - } - - nIndex = LensFlareUtil::FindOpticsIndexUnderParentOptics(pElement->GetOpticsElement(), pParentElement->GetOpticsElement()); - if (nIndex == -1) - { - return false; - } - - pElement = pParentElement; - } - - CLensFlareElement::LensFlareElementPtr pNewElement = InsertAtomicElement(nIndex, flareType, pElement); - if (!pNewElement) - { - return false; - } - - if (m_pLensFlareItem) - { - m_pLensFlareItem->UpdateLights(); - } - - return true; -} - -CLensFlareElement::LensFlareElementPtr LensFlareElementTreeModel::InsertAtomicElement(int nIndex, EFlareType flareType, CLensFlareElement* pParentElement) -{ - IOpticsElementBasePtr pParent = pParentElement->GetOpticsElement(); - if (pParent == NULL) - { - return NULL; - } - - IOpticsElementBasePtr pNewOptics = gEnv->pOpticsManager->Create(flareType); - if (pNewOptics == NULL) - { - return NULL; - } - - if (nIndex < 0) - { - return NULL; - } - - CLensFlareElement::LensFlareElementPtr pElement = AddElement(pNewOptics, pParentElement); - if (pElement == NULL) - { - return NULL; - } - - pParent->InsertElement(nIndex, pNewOptics); - - emit beginInsertRows(createIndex(pParentElement->GetRow(), 0, pParentElement), nIndex, nIndex); - pParentElement->InsertChild(nIndex, pElement); - emit endInsertRows(); - - return pElement; -} - -void LensFlareElementTreeModel::MakeValidElementName(const QString& seedName, QString& outValidName) const -{ - if (!IsExistElement(seedName)) - { - outValidName = seedName; - return; - } - - int counter = 0; - do - { - QString numberString; - numberString = QString::number(counter); - QString candidateName = seedName + numberString; - if (!IsExistElement(candidateName)) - { - outValidName = candidateName; - return; - } - } while (++counter < 100000); // prevent from infinite loop -} - -bool LensFlareElementTreeModel::IsExistElement(const QString& name) const -{ - const auto predicate = [&](CLensFlareElement* pElement) - { - QString flareName; - return pElement->GetName(flareName) && !QString::compare(flareName, name, Qt::CaseInsensitive); - }; - auto pElement = ::FindLensFlareElement(m_pRootElement.get(), predicate); - return pElement != nullptr; -} - -CLensFlareElement::LensFlareElementPtr LensFlareElementTreeModel::AddElement(IOpticsElementBasePtr pOptics, CLensFlareElement* pParentElement) -{ - if (pOptics == NULL) - { - return NULL; - } - - IOpticsElementBasePtr pParent = pParentElement->GetOpticsElement(); - - CLensFlareElement* pLensFlareElement = NULL; - - if (pParent == NULL) - { - if (pOptics->GetType() != eFT_Root) - { - assert(0 && "CFlareManager::AddItem() - pOptics must be a root optics if the parent doesn't exist."); - return NULL; - } - } - else - { - if (!LensFlareUtil::IsGroup(pParent->GetType())) - { - return NULL; - } - - QString fullElementName; - if (!pParentElement->GetName(fullElementName)) - { - return NULL; - } - if (!fullElementName.isEmpty()) - { - fullElementName += "."; - } - fullElementName += LensFlareUtil::GetShortName(pOptics->GetName().c_str()).toLower(); - - QString validName; - MakeValidElementName(fullElementName, validName); - pOptics->SetName(validName.toUtf8().data()); - } - - pLensFlareElement = CreateElement(pOptics); - - if (LensFlareUtil::IsGroup(pOptics->GetType())) - { - for (int i = 0, iElementCount(pOptics->GetElementCount()); i < iElementCount; ++i) - { - CLensFlareElement::LensFlareElementPtr pChild = AddElement(pOptics->GetElementAt(i), pLensFlareElement); - pLensFlareElement->AddChild(pChild); - } - } - - GetIEditor()->GetLensFlareManager()->Modified(); - if (m_pLensFlareItem) - { - m_pLensFlareItem->UpdateLights(); - } - - return pLensFlareElement; -} - -bool LensFlareElementTreeModel::MoveElement(CLensFlareElement* pElement, int row, const QModelIndex& index) -{ - if (!index.isValid()) - { - return false; - } - - QModelIndex sourceParentIndex = parent(createIndex(0, 0, pElement)); - if (!sourceParentIndex.isValid()) - { - return false; - } - - QModelIndex targetParentIndex = index; - CLensFlareElement* pTargetParent = targetParentIndex.data(Qt::UserRole).value(); - - QString fullElementName; - if (!pTargetParent->GetName(fullElementName)) - { - return false; - } - if (!fullElementName.isEmpty()) - { - fullElementName += "."; - } - fullElementName += LensFlareUtil::GetShortName(pElement->GetOpticsElement()->GetName().c_str()).toLower(); - - QString validName; - MakeValidElementName(fullElementName, validName); - - int targetRow; - - if (!LensFlareUtil::IsGroup(pTargetParent->GetOpticsElement()->GetType())) - { - targetParentIndex = targetParentIndex.parent(); - pTargetParent = targetParentIndex.data(Qt::UserRole).value(); - targetRow = index.row(); - } - else - { - if (row != -1) - { - targetRow = row; - } - else - { - targetRow = pTargetParent->GetChildCount(); - } - } - - CLensFlareElement* pSourceParent = pElement->GetParent(); - int sourceRow = pElement->GetRow(); - - if (!beginMoveRows(sourceParentIndex, sourceRow, sourceRow, targetParentIndex, targetRow)) - { - return false; - } - - StoreUndo(); - - // insert before removing to increase reference count - - pTargetParent->InsertChild(targetRow, pElement); - pTargetParent->GetOpticsElement()->InsertElement(targetRow, pElement->GetOpticsElement()); - - if (pTargetParent == pSourceParent && targetRow < sourceRow) - { - ++sourceRow; - } - - pSourceParent->RemoveChild(sourceRow); - pSourceParent->GetOpticsElement()->Remove(sourceRow); - - pElement->GetOpticsElement()->SetName(validName.toUtf8().data()); - LensFlareUtil::UpdateOpticsName(pElement->GetOpticsElement()); - - endMoveRows(); - - return true; -} - -bool LensFlareElementTreeModel::dropMimeData(const QMimeData* data, [[maybe_unused]] Qt::DropAction action, int row, [[maybe_unused]] int column, const QModelIndex& parent) -{ - if (data->hasFormat(QStringLiteral("application/x-o3de-flaretypes"))) - { - // drop from atomic list - - QByteArray encoded = data->data(QStringLiteral("application/x-o3de-flaretypes")); - QDataStream stream(&encoded, QIODevice::ReadOnly); - - while (!stream.atEnd()) - { - int flareType; - stream >> flareType; - - CUndo undo(tr("Add Atomic Lens Flare Item").toUtf8()); - AddElement(parent, row, static_cast(flareType)); - } - - return true; - } - else if (data->hasFormat(QStringLiteral("application/x-o3de-flareelements"))) - { - QByteArray array = data->data("application/x-o3de-flareelements"); - - int count = array.size() / sizeof(CLensFlareElement*); - auto ppElements = reinterpret_cast(array.data()); - - CUndo undo(tr("Copy/Cut & Paste library item").toUtf8()); - - for (int i = 0; i < count; i++) - { - MoveElement(ppElements[i], row, parent); - } - - return true; - } - else - { - return false; - } -} - -CLensFlareElement* LensFlareElementTreeModel::FindLensFlareElement(IOpticsElementBasePtr pOptics) const -{ - return ::FindLensFlareElement(m_pRootElement.get(), [&](CLensFlareElement* pElement) - { - return pElement->GetOpticsElement() == pOptics; - }); -} - -Qt::DropActions LensFlareElementTreeModel::supportedDragActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -Qt::DropActions LensFlareElementTreeModel::supportedDropActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -void LensFlareElementTreeModel::UpdateLensFlareItem(CLensFlareItem* pLensFlareItem) -{ - m_pLensFlareItem = pLensFlareItem; - - m_pRootElement.reset(new CLensFlareElement); - - if (pLensFlareItem != NULL) - { - auto pChild = UpdateLensFlareElementsRecusively(m_pLensFlareItem->GetOptics()); - if (pChild) - { - m_pRootElement->AddChild(pChild); - } - } -} - -CLensFlareElement* LensFlareElementTreeModel::UpdateLensFlareElementsRecusively(IOpticsElementBasePtr pOptics) -{ - auto pElement = new CLensFlareElement; - pElement->SetOpticsElement(pOptics); - - for (int i = 0, iCount(pOptics->GetElementCount()); i < iCount; i++) - { - auto pChild = UpdateLensFlareElementsRecusively(pOptics->GetElementAt(i)); - if (pElement) - { - pElement->AddChild(pChild); - } - } - - return pElement; -} - -CLensFlareElement* LensFlareElementTreeModel::CreateElement(IOpticsElementBasePtr pOptics) -{ - StoreUndo(); - CLensFlareElement* pElement = new CLensFlareElement; - pElement->SetOpticsElement(pOptics); - return pElement; -} - -void LensFlareElementTreeModel::OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem) -{ - beginResetModel(); - UpdateLensFlareItem(pLensFlareItem); - endResetModel(); -} - -void LensFlareElementTreeModel::OnLensFlareDeleteItem([[maybe_unused]] CLensFlareItem* pLensFlareItem) -{ -} - -CLensFlareElement* LensFlareElementTreeModel::GetLensFlareElement(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return m_pRootElement.get(); - } - else - { - return static_cast(index.internalPointer()); - } -} - -void LensFlareElementTreeModel::Paste(const QModelIndex& hItem, XmlNodeRef xmlNode) -{ - if (!hItem.isValid()) - { - return; - } - - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - - QString type; - xmlNode->getAttr("Type", type); - - bool bPasteAtSameLevel = false; - xmlNode->getAttr("PasteAtSameLevel", bPasteAtSameLevel); - - QModelIndex hParentItem; - - IOpticsElementBasePtr pSelectedOptics = GetOpticsElementByTreeItem(hItem); - if (pSelectedOptics == NULL) - { - return; - } - - if (!LensFlareUtil::IsGroup(pSelectedOptics->GetType())) - { - hParentItem = hItem.parent(); - } - else - { - if (bPasteAtSameLevel) - { - hParentItem = hItem.parent(); - } - else - { - hParentItem = hItem; - } - } - - IOpticsElementBasePtr pParentOptics = GetOpticsElementByTreeItem(hParentItem); - if (pParentOptics == NULL) - { - return; - } - - for (int i = 0, iChildCount(xmlNode->getChildCount()); i < iChildCount; ++i) - { - LensFlareUtil::SClipboardData clipboardData; - clipboardData.FillThisFromXmlNode(xmlNode->getChild(i)); - - if (clipboardData.m_LensFlareFullPath == m_pLensFlareItem->GetFullName() && clipboardData.m_From == LENSFLARE_ITEM_TREE) - { - QString msg; - msg = tr("[%1] lens item can be pasted into the same item").arg(clipboardData.m_LensFlareFullPath); - CryMessageBox(msg.toUtf8().data(), "Warning", MB_OK); - continue; - } - - IOpticsElementBasePtr pSourceOptics = pEditor->FindOptics(clipboardData.m_LensFlareFullPath, clipboardData.m_LensOpticsPath); - if (pSourceOptics == NULL) - { - continue; - } - - CLensFlareItem* pSourceLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(clipboardData.m_LensFlareFullPath); - if (pSourceLensFlareItem == NULL) - { - continue; - } - - if (type == FLARECLIPBOARDTYPE_CUT) - { - if (m_pLensFlareItem->GetFullName() == clipboardData.m_LensFlareFullPath && LensFlareUtil::FindOptics(pSourceOptics, pSelectedOptics->GetName().c_str())) - { - QMessageBox::warning(0, tr("Warning"), tr("You can't paste this item here.")); - return; - } - } - - // if the copied optics type is root, the type should be converted to group type. - bool bForceConvertType = false; - if (pSourceOptics->GetType() == eFT_Root) - { - bForceConvertType = true; - } - - IOpticsElementBasePtr pNewOptics = LensFlareUtil::CreateOptics(pSourceOptics, bForceConvertType); - if (pNewOptics == NULL) - { - return; - } - - if (type == FLARECLIPBOARDTYPE_CUT) - { - if (pSourceLensFlareItem == m_pLensFlareItem) - { - QModelIndex hSourceItem = GetTreeItemByOpticsElement(pSourceOptics); - if (hSourceItem.isValid()) - { - removeRow(hSourceItem.row(), hSourceItem.parent()); - } - } - else if (clipboardData.m_From == LENSFLARE_ITEM_TREE) - { - CLensFlareLibrary* pLibrary = pEditor->GetCurrentLibrary(); - if (pLibrary) - { - QString lensFlareFullName = m_pLensFlareItem ? m_pLensFlareItem->GetFullName() : ""; - pLibrary->RemoveItem(pSourceLensFlareItem); - pEditor->ReloadItems(); - pSourceLensFlareItem->UpdateLights(); - pEditor->UpdateLensOpticsNames(pSourceLensFlareItem->GetFullName(), ""); - if (!lensFlareFullName.isEmpty()) - { - pEditor->SelectItemByName(lensFlareFullName); - } - } - - LensFlareUtil::RemoveOptics(pSourceOptics); - } - } - - CLensFlareElement* pParentElement = FindLensFlareElement(pParentOptics); - - // The children optics items were already added in a creation phase so we don't need to update the optics object. - CLensFlareElement::LensFlareElementPtr pNewElement = AddElement(pNewOptics, pParentElement); - assert(pNewElement); - if (!pNewElement) - { - return; - } - - int nInsertedPos; - if (hParentItem == hItem) - { - nInsertedPos = 0; - } - else - { - nInsertedPos = LensFlareUtil::FindOpticsIndexUnderParentOptics(pSelectedOptics, pParentOptics); - if (nInsertedPos > pParentOptics->GetElementCount() || nInsertedPos == -1) - { - nInsertedPos = pParentOptics->GetElementCount(); - } - } - - pParentOptics->InsertElement(nInsertedPos, pNewOptics); - LensFlareUtil::UpdateOpticsName(pNewOptics); - - emit beginInsertRows(createIndex(pParentElement->GetRow(), 0, pParentElement), nInsertedPos, nInsertedPos); - pParentElement->InsertChild(nInsertedPos, pNewElement); - emit endInsertRows(); - - // pSelectedLensFlareItem->UpdateLights(); - } -} - -IOpticsElementBasePtr LensFlareElementTreeModel::GetOpticsElementByTreeItem(const QModelIndex& index) const -{ - if (!index.isValid()) - { - return nullptr; - } - return GetLensFlareElement(index)->GetOpticsElement(); -} - -QModelIndex LensFlareElementTreeModel::GetTreeItemByName(const QString& name) const -{ - auto pElement = ::FindLensFlareElement(m_pRootElement.get(), [&](CLensFlareElement* pElement) - { - QString flareName; - return pElement->GetName(flareName) && flareName == name; - }); - - if (!pElement) - { - return {}; - } - - return createIndex(pElement->GetRow(), 0, pElement); -} - -QModelIndex LensFlareElementTreeModel::GetTreeItemByOpticsElement(const IOpticsElementBasePtr pOptics) const -{ - auto pElement = FindLensFlareElement(pOptics); - if (!pElement) - { - return {}; - } - return createIndex(pElement->GetRow(), 0, pElement); -} - -void LensFlareElementTreeModel::InvalidateLensFlareItem() -{ - OnLensFlareChangeItem(nullptr); -} - -void LensFlareElementTreeModel::StoreUndo(const QString& undoDescription) -{ - if (CUndo::IsRecording()) - { - if (undoDescription.isEmpty()) - { - CUndo::Record(new CUndoLensFlareItem(GetLensFlareItem())); - } - else - { - CUndo::Record(new CUndoLensFlareItem(GetLensFlareItem(), undoDescription)); - } - } -} - -#include diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.h deleted file mode 100644 index d2b0051032..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareElementTree.h +++ /dev/null @@ -1,197 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENTTREE_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENTTREE_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "LensFlareElement.h" -#include "LensFlareUtil.h" -#include "ILensFlareListener.h" - -#include -#include -#endif - -class CLensFlareItem; -class LensFlareElementTreeModel; -class QMouseEvent; - -class CLensFlareElementTree - : public QTreeView -{ - Q_OBJECT - -public: - - CLensFlareElementTree(QWidget* pParent = nullptr); - - void RegisterListener(ILensFlareChangeElementListener* pListener) - { - if (pListener) - { - m_LensFlaresElementListeners.push_back(pListener); - } - } - - void UnregisterListener(ILensFlareChangeElementListener* pListener) - { - if (pListener == NULL) - { - return; - } - std::vector::iterator ii = m_LensFlaresElementListeners.begin(); - for (; ii != m_LensFlaresElementListeners.end(); ) - { - if (*ii == pListener) - { - ii = m_LensFlaresElementListeners.erase(ii); - } - else - { - ++ii; - } - } - } - - CLensFlareElement::LensFlareElementPtr FindLensFlareElement(IOpticsElementBasePtr pElement) const; - - void OnInternalVariableChange(IVariable* pVar); - - CLensFlareElement* GetCurrentLensFlareElement() const; - void UpdateProperty(); - void UpdateClipboard(const char* type, bool bPasteAtSameLevel); - - void SelectTreeItemByName(const QString& name); - - CLensFlareItem* GetLensFlareItem() const; - void InvalidateLensFlareItem(); - -protected: - void CallChangeListeners(); - - void OnDataChanged(const QModelIndex& index); - void OnRowsInserted(const QModelIndex& index, int first, int last); - void OnRowsRemoved(const QModelIndex& index, int first, int last); - - void OnNotifyTreeRClick(); - void OnTvnSelchangedTree(const QItemSelection& selected, const QItemSelection& deselected); - - XmlNodeRef CreateXML(const char* type) const; - bool GetClipboardList(const char* type, std::vector& outList) const; - - //! Only the basic operations like following methods must have routine for undoing. - void ElementChanged(CLensFlareElement* pPrevLensFlareElement); - ///////////////////////////////////////////////////////////////////////////////////////// - - void OnAddGroup(); - void OnCopy(); - void OnCut(); - void OnPaste(); - void OnClone(); - void OnRenameItem(); - void OnRemoveItem(); - void OnRemoveAll(); - void OnItemUp(); - void OnItemDown(); - void mousePressEvent(QMouseEvent* event); - void keyPressEvent(QKeyEvent* event); - - void Cut(bool bPasteAtSameLevel); - -private: - void SelectItem(const QModelIndex& index); - - std::vector m_LensFlaresElementListeners; - - QScopedPointer m_model; -}; - -class LensFlareElementTreeModel - : public QAbstractItemModel - , public ILensFlareChangeItemListener -{ - Q_OBJECT - -public: - LensFlareElementTreeModel(QObject* pParent = nullptr); - ~LensFlareElementTreeModel(); - - int rowCount(const QModelIndex& parent = {}) const override; - int columnCount(const QModelIndex& parent = {}) const override; - - Qt::ItemFlags flags(const QModelIndex& index) const override; - QVariant data(const QModelIndex& index, int role) const override; - bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); - - QModelIndex index(int row, int column, const QModelIndex& parent = {}) const override; - QModelIndex parent(const QModelIndex& index) const override; - - bool removeRows(int row, int count, const QModelIndex& parent = {}) override; - - QStringList mimeTypes() const override; - QMimeData* mimeData(const QModelIndexList& indexes) const override; - bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override; - Qt::DropActions supportedDragActions() const override; - Qt::DropActions supportedDropActions() const override; - - CLensFlareElement* GetLensFlareElement(const QModelIndex& index) const; - - QModelIndex GetTreeItemByName(const QString& name) const; - - void Paste(const QModelIndex& index, XmlNodeRef xmlNode); - void Cut(const QModelIndex& index, bool bPasteAtSameLevel); - - CLensFlareItem* GetLensFlareItem() const - { - return m_pLensFlareItem; - } - - void InvalidateLensFlareItem(); - - void RemoveAllElements(); - bool AddElement(const QModelIndex& index, int row, EFlareType flareType); - - bool MoveElement(CLensFlareElement* pElement, int row, const QModelIndex& parentIndex); - -private: - QModelIndex GetRootItem() const; - IOpticsElementBasePtr GetOpticsElementByTreeItem(const QModelIndex& index) const; - - void OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem); - void OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem); - - void UpdateLensFlareItem(CLensFlareItem* pLensFlareItem); - CLensFlareElement* UpdateLensFlareElementsRecusively(IOpticsElementBasePtr pOptics); - CLensFlareElement* CreateElement(IOpticsElementBasePtr pOptics); - void Reload(); - - void MakeValidElementName(const QString& seedName, QString& outValidName) const; - bool IsExistElement(const QString& name) const; - CLensFlareElement::LensFlareElementPtr InsertAtomicElement(int nIndex, EFlareType flareType, CLensFlareElement* pParentElement); - CLensFlareElement::LensFlareElementPtr AddElement(IOpticsElementBasePtr pOptics, CLensFlareElement* pParentElement); - CLensFlareElement* FindLensFlareElement(IOpticsElementBasePtr pOptics) const; - - QModelIndex GetTreeItemByOpticsElement(const IOpticsElementBasePtr pOptics) const; - void EnableElement(CLensFlareElement* pLensFlareElement, bool bEnable); - void RenameElement(CLensFlareElement* pLensFlareElement, const QString& newName); - void StoreUndo(const QString& undoDescription = ""); - - CLensFlareElement::LensFlareElementPtr m_pRootElement; - CLensFlareItem* m_pLensFlareItem; -}; - -Q_DECLARE_METATYPE(CLensFlareElement*) - -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREELEMENTTREE_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.cpp deleted file mode 100644 index e20f1ac7cb..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareItem.h" - -// Editor -#include "LensFlareUtil.h" -#include "LensFlareEditor.h" -#include "LensFlareUndo.h" -#include "Objects/EntityObject.h" - - -CLensFlareItem::CLensFlareItem() -{ - m_pOptics = NULL; - CreateOptics(); -} - -CLensFlareItem::~CLensFlareItem() -{ -} - -void CLensFlareItem::Serialize(SerializeContext& ctx) -{ - if (ctx.bLoading) - { - CreateOptics(); - LensFlareUtil::FillOpticsFromXML(m_pOptics, ctx.node); - - for (int i = 0, iChildCount(ctx.node->getChildCount()); i < iChildCount; ++i) - { - AddChildOptics(m_pOptics, ctx.node->getChild(i)); - } - - CBaseLibraryItem::Serialize(ctx); - } - else - { - CBaseLibraryItem::Serialize(ctx); - } -} - -void CLensFlareItem::AddChildOptics(IOpticsElementBasePtr pParentOptics, const XmlNodeRef& pNode) -{ - if (pNode == NULL) - { - return; - } - - if (pNode->getTag() && strcmp(pNode->getTag(), "FlareItem")) - { - return; - } - - IOpticsElementBasePtr pOptics = LensFlareUtil::CreateOptics(pNode); - if (pOptics == NULL) - { - return; - } - - pParentOptics->AddElement(pOptics); - - for (int i = 0, iChildCount(pNode->getChildCount()); i < iChildCount; ++i) - { - AddChildOptics(pOptics, pNode->getChild(i)); - } -} - -void CLensFlareItem::CreateOptics() -{ - m_pOptics = gEnv->pOpticsManager->Create(eFT_Root); -} - -XmlNodeRef CLensFlareItem::CreateXmlData() const -{ - XmlNodeRef pRootNode = NULL; - if (LensFlareUtil::CreateXmlData(m_pOptics, pRootNode)) - { - pRootNode->setAttr("Name", m_pOptics->GetName().c_str()); - return pRootNode; - } - return NULL; -} - -void CLensFlareItem::SetName(const QString& name) -{ - QString newNameWithGroup; - QString newFullName; - LensFlareUtil::GetExpandedItemNames(this, LensFlareUtil::GetGroupNameFromName(name), LensFlareUtil::GetShortName(name), newNameWithGroup, newFullName); - - if (CUndo::IsRecording()) - { - CUndo::Record(new CUndoRenameLensFlareItem(GetFullName(), newFullName)); - } - - CBaseLibraryItem::SetName(name); - - if (m_pOptics) - { - m_pOptics->SetName(GetShortName().toUtf8().data()); - } -} - -void CLensFlareItem::UpdateLights(IOpticsElementBasePtr pSrcOptics) -{ - QString srcFullOpticsName = GetFullName(); - bool bUpdateChildren = false; - if (pSrcOptics == NULL) - { - if (m_pOptics == NULL) - { - return; - } - pSrcOptics = m_pOptics; - bUpdateChildren = true; - } - - std::vector lightEntities; - LensFlareUtil::GetLightEntityObjects(lightEntities); - - for (int i = 0, iLightSize(lightEntities.size()); i < iLightSize; ++i) - { - CEntityObject* pLightEntity = lightEntities[i]; - if (pLightEntity == NULL) - { - continue; - } - - IOpticsElementBasePtr pTargetOptics = pLightEntity->GetOpticsElement(); - if (pTargetOptics == NULL) - { - continue; - } - - QString targetFullOpticsName(pTargetOptics->GetName().c_str()); - if (srcFullOpticsName != targetFullOpticsName) - { - continue; - } - - QString srcOpticsName(pSrcOptics->GetName().c_str()); - IOpticsElementBasePtr pFoundOptics = NULL; - if (LensFlareUtil::GetShortName(targetFullOpticsName) == srcOpticsName) - { - pFoundOptics = pTargetOptics; - } - else - { - pFoundOptics = LensFlareUtil::FindOptics(pTargetOptics, srcOpticsName); - } - - if (pFoundOptics == NULL) - { - continue; - } - if (pFoundOptics->GetType() != pSrcOptics->GetType()) - { - continue; - } - - LensFlareUtil::CopyOptics(pSrcOptics, pFoundOptics, bUpdateChildren); - } -} - -void CLensFlareItem::ReplaceOptics(IOpticsElementBasePtr pNewData) -{ - if (pNewData == NULL) - { - return; - } - if (pNewData->GetType() != eFT_Root) - { - return; - } - CreateOptics(); - LensFlareUtil::CopyOptics(pNewData, m_pOptics); - m_pOptics->SetName(GetFullName().toUtf8().data()); - UpdateLights(); - - CLensFlareEditor* pLensFlareEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pLensFlareEditor == NULL) - { - return; - } - if (this != pLensFlareEditor->GetSelectedLensFlareItem()) - { - return; - } - pLensFlareEditor->UpdateLensFlareItem(this); - pLensFlareEditor->RemovePropertyItems(); -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.h deleted file mode 100644 index 6d1eedb5f9..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItem.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEM_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEM_H -#pragma once - -class IOpticsElementBase; -class CEntityObject; - -#include "BaseLibraryItem.h" -#include "Include/IDataBaseItem.h" - -class CLensFlareItem - : public CBaseLibraryItem -{ -public: - - CLensFlareItem(); - ~CLensFlareItem(); - - EDataBaseItemType GetType() const - { - return EDB_TYPE_FLARE; - } - - void SetName(const QString& name); - void Serialize(SerializeContext& ctx); - - void CreateOptics(); - - IOpticsElementBasePtr GetOptics() const - { - return m_pOptics; - } - - void ReplaceOptics(IOpticsElementBasePtr pNewData); - - XmlNodeRef CreateXmlData() const; - void UpdateLights(IOpticsElementBasePtr pSrcOptics = NULL); - -private: - - void GetLightEntityObjects(std::vector& outEntityLights) const; - static void AddChildOptics(IOpticsElementBasePtr pParentOptics, const XmlNodeRef& pNode); - - IOpticsElementBasePtr m_pOptics; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEM_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.cpp deleted file mode 100644 index 34cb442a38..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareItemTree.h" - -// Editor -#include "LensFlareItem.h" -#include "ViewManager.h" -#include "Objects/EntityObject.h" - - -CLensFlareItemTree::CLensFlareItemTree(QWidget* pParent) - : QTreeView(pParent) -{ - setHeaderHidden(true); - setSelectionMode(QAbstractItemView::SingleSelection); - setContextMenuPolicy(Qt::CustomContextMenu); - setDragEnabled(true); - setAcceptDrops(true); - setDropIndicatorShown(true); - setDragDropMode(DragDrop); -} - -CLensFlareItemTree::~CLensFlareItemTree() -{ -} - -void CLensFlareItemTree::startDrag(Qt::DropActions supportedDropActions) -{ - QTreeView::startDrag(supportedDropActions); -} - -void CLensFlareItemTree::mousePressEvent(QMouseEvent* event) -{ - if (event->button() == Qt::LeftButton) - { - CUndo undo(tr("Changed lens flare item").toUtf8()); - QTreeView::mousePressEvent(event); - } - else - { - QTreeView::mousePressEvent(event); - } -} - -void CLensFlareItemTree::AssignLensFlareToLightEntity(CViewport* pViewport) const -{ - QModelIndexList selected = selectionModel()->selectedIndexes(); - if (selected.isEmpty()) - { - return; - } - - CLensFlareItem* pLensFlareItem = static_cast(selected.first().data(Qt::UserRole).value()); - - QPoint viewportPos = QCursor::pos(); - pViewport->ScreenToClient(viewportPos); - HitContext hit; - if (!pViewport->HitTest(viewportPos, hit)) - { - return; - } - - if (hit.object && qobject_cast(hit.object)) - { - CEntityObject* pEntity = (CEntityObject*)hit.object; - if (pEntity->IsLight()) - { - CUndo undo(tr("Assign a lens flare item to a light entity").toUtf8()); - pEntity->ApplyOptics(pLensFlareItem->GetFullName(), pLensFlareItem->GetOptics()); - } - } -} - -#include diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.h deleted file mode 100644 index 1139604163..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareItemTree.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEMTREE_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEMTREE_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "LensFlareElement.h" -#include "ILensFlareListener.h" - -#include -#endif - -class QMouseEvent; -class CLensFlareItem; - -class CLensFlareItemTree - : public QTreeView -{ - Q_OBJECT - -public: - CLensFlareItemTree(QWidget* pParent = nullptr); - ~CLensFlareItemTree(); - -protected: - void startDrag(Qt::DropActions supportedDropActions) override; - void mousePressEvent(QMouseEvent* event) override; - -private: - - void AssignLensFlareToLightEntity(CViewport* pViewport) const; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREITEMTREE_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.cpp deleted file mode 100644 index b575b4595c..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareLibrary.h" - -// Editor -#include "LensFlareItem.h" - - -bool CLensFlareLibrary::Save() -{ - return SaveLibrary("LensFlareLibrary"); -} - -bool CLensFlareLibrary::Load(const QString& filename) -{ - if (filename.isEmpty()) - { - return false; - } - SetFilename(filename); - XmlNodeRef root = XmlHelpers::LoadXmlFromFile(filename.toUtf8().data()); - if (!root) - { - return false; - } - Serialize(root, true); - return true; -} - -void CLensFlareLibrary::Serialize(XmlNodeRef& root, bool bLoading) -{ - if (bLoading) - { - RemoveAllItems(); - QString name = GetName(); - root->getAttr("Name", name); - SetName(name); - for (int i = 0; i < root->getChildCount(); i++) - { - XmlNodeRef itemNode = root->getChild(i); - CLensFlareItem* pLensFlareItem = new CLensFlareItem; - AddItem(pLensFlareItem); - CBaseLibraryItem::SerializeContext ctx(itemNode, bLoading); - pLensFlareItem->Serialize(ctx); - } - SetModified(false); - m_bNewLibrary = false; - } - else - { - root->setAttr("Name", GetName().toUtf8().data()); - - for (int i = 0; i < GetItemCount(); i++) - { - CLensFlareItem* pItem = (CLensFlareItem*)GetItem(i); - if(pItem) - { - CBaseLibraryItem::SerializeContext ctx(pItem->CreateXmlData(), bLoading); - root->addChild(ctx.node); - pItem->Serialize(ctx); - } - } - } -} - -IOpticsElementBasePtr CLensFlareLibrary::GetOpticsOfItem(const char* szflareName) -{ - IOpticsElementBasePtr pOptics = NULL; - for (int i = 0; i < GetItemCount(); i++) - { - CLensFlareItem* pItem = (CLensFlareItem*)GetItem(i); - - if (pItem->GetFullName() == szflareName) - { - pOptics = pItem->GetOptics(); - break; - } - } - - return pOptics; -} - - -void CLensFlareLibrary::OnInternalVariableChange([[maybe_unused]] IVariable* pVar) -{ - SetModified(true); -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.h deleted file mode 100644 index 484ad3740a..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLibrary.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIBRARY_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIBRARY_H -#pragma once -#include "BaseLibrary.h" - -struct IVariable; - -class CRYEDIT_API CLensFlareLibrary - : public CBaseLibrary -{ -public: - CLensFlareLibrary(IBaseLibraryManager* pManager) - : CBaseLibrary(pManager) {}; - virtual bool Save(); - virtual bool Load(const QString& filename); - virtual void Serialize(XmlNodeRef& node, bool bLoading); - - IOpticsElementBasePtr GetOpticsOfItem(const char* szflareName); - - void OnInternalVariableChange(IVariable* pVar); -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIBRARY_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.cpp deleted file mode 100644 index 307364ea4f..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareLightEntityTree.h" - -// Editor -#include "Viewport.h" -#include "Include/IObjectManager.h" -#include "Objects/SelectionGroup.h" -#include "LensFlareItem.h" -#include "LensFlareEditor.h" - - -CLensFlareLightEntityTree::CLensFlareLightEntityTree(QWidget* pParent) - : QTreeView(pParent) - , m_model(new LensFlareLightEntityModel) -{ - setHeaderHidden(true); - - setModel(m_model.data()); - - connect(this, &QTreeView::doubleClicked, this, &CLensFlareLightEntityTree::OnTvnItemDoubleClicked); -} - -CLensFlareLightEntityTree::~CLensFlareLightEntityTree() -{ -} - -void CLensFlareLightEntityTree::OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem) -{ - m_model->OnLensFlareChangeItem(pLensFlareItem); -} - -void CLensFlareLightEntityTree::OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem) -{ - m_model->OnLensFlareDeleteItem(pLensFlareItem); -} - -void CLensFlareLightEntityTree::OnTvnItemDoubleClicked(const QModelIndex& index) -{ - CEntityObject* pObject = index.data(Qt::UserRole).value(); - - if (!qobject_cast(pObject)) - { - return; - } - - CSelectionGroup* pSelection = GetIEditor()->GetObjectManager()->GetSelection(); - if (pSelection) - { - int iSelectionCount(pSelection->GetCount()); - if (iSelectionCount == 1) - { - if (pSelection->GetObject(0) == pObject) - { - CViewport* vp = GetIEditor()->GetActiveView(); - if (vp) - { - vp->CenterOnSelection(); - } - return; - } - } - } - - GetIEditor()->GetObjectManager()->ClearSelection(); - GetIEditor()->GetObjectManager()->SelectObject(pObject); -} - -LensFlareLightEntityModel::LensFlareLightEntityModel(QObject* pParent) - : QAbstractListModel(pParent) -{ - CLensFlareEditor::GetLensFlareEditor()->RegisterLensFlareItemChangeListener(this); - GetIEditor()->GetObjectManager()->AddObjectEventListener(this); -} - -LensFlareLightEntityModel::~LensFlareLightEntityModel() -{ - CLensFlareEditor::GetLensFlareEditor()->UnregisterLensFlareItemChangeListener(this); - GetIEditor()->GetObjectManager()->RemoveObjectEventListener(this); -} - -void LensFlareLightEntityModel::OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem) -{ - beginResetModel(); - - m_pLensFlareItem = pLensFlareItem; - m_lightEntities.clear(); - - if (m_pLensFlareItem) - { - std::vector lightEntities; - LensFlareUtil::GetLightEntityObjects(lightEntities); - - for (int i = 0, iEntitySize(lightEntities.size()); i < iEntitySize; ++i) - { - AddLightEntity(lightEntities[i]); - } - } - - endResetModel(); -} - -void LensFlareLightEntityModel::OnLensFlareDeleteItem([[maybe_unused]] CLensFlareItem* pLensFlareItem) -{ - beginResetModel(); - - m_lightEntities.clear(); - m_pLensFlareItem = NULL; - - endResetModel(); -} - -void LensFlareLightEntityModel::OnObjectEvent(CBaseObject* pObject, int nEvent) -{ - if (!qobject_cast(pObject)) - { - return; - } - - switch (nEvent) - { - case CBaseObject::ON_RENAME: - case CBaseObject::ON_DELETE: - { - auto it = std::find(std::begin(m_lightEntities), std::end(m_lightEntities), pObject); - if (it == std::end(m_lightEntities)) - { - return; - } - int row = std::distance(std::begin(m_lightEntities), it); - if (nEvent == CBaseObject::ON_RENAME) - { - emit dataChanged(index(row, 0), index(row, 0)); - } - else - { - beginRemoveRows({}, row, row); - m_lightEntities.erase(it); - endRemoveRows(); - } - } - break; - - case CBaseObject::ON_ADD: - if (AddLightEntity((CEntityObject*)pObject)) - { - int row = m_lightEntities.size() - 1; - beginInsertRows({}, row, row); - endInsertRows(); - } - break; - } -} - -bool LensFlareLightEntityModel::AddLightEntity(CEntityObject* pEntity) -{ - if (pEntity == NULL || m_pLensFlareItem == NULL) - { - return false; - } - - QString lensFlareName = pEntity->GetEntityPropertyString(CEntityObject::s_LensFlarePropertyName); - if (lensFlareName.isEmpty()) - { - return false; - } - - QString fullName = m_pLensFlareItem->GetFullName(); - if (fullName.isEmpty()) - { - return false; - } - - if (QString::compare(lensFlareName, fullName, Qt::CaseInsensitive)) - { - return false; - } - - m_lightEntities.push_back(pEntity); - - return true; -} - -int LensFlareLightEntityModel::rowCount(const QModelIndex&) const -{ - return m_lightEntities.size(); -} - -QVariant LensFlareLightEntityModel::data(const QModelIndex& index, int role) const -{ - const int row = index.row(); - - if (row < 0 || row >= m_lightEntities.size()) - { - return {}; - } - - auto pEntity = m_lightEntities[row]; - - switch (role) - { - case Qt::DisplayRole: - return pEntity->GetName(); - - case Qt::UserRole: - return QVariant::fromValue(pEntity); - } - - return {}; -} - -#include diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.h deleted file mode 100644 index 21a271c08f..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareLightEntityTree.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIGHTENTITYTREE_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIGHTENTITYTREE_H -#pragma once - -#if !defined(Q_MOC_RUN) -#include "ILensFlareListener.h" - -#include -#include -#include "IObjectManager.h" // for IObjectManager::EventListener -#include "Objects/EntityObject.h" -#endif - -class LensFlareLightEntityModel; - -class CLensFlareLightEntityTree - : public QTreeView -{ - Q_OBJECT - -public: - CLensFlareLightEntityTree(QWidget* pParent = nullptr); - ~CLensFlareLightEntityTree(); - - void OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem); - void OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem); - -protected: - void OnTvnItemDoubleClicked(const QModelIndex& index); - - QScopedPointer m_model; -}; - -class LensFlareLightEntityModel - : public QAbstractListModel - , public ILensFlareChangeItemListener - , public IObjectManager::EventListener -{ - Q_OBJECT - -public: - LensFlareLightEntityModel(QObject* pParent = nullptr); - ~LensFlareLightEntityModel(); - - int rowCount(const QModelIndex& parent = {}) const override; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; - - void OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem); - void OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem); - -protected: - void OnObjectEvent(CBaseObject* pObject, int nEvent) override; - - bool AddLightEntity(CEntityObject* pEntity); - - std::vector m_lightEntities; - _smart_ptr m_pLensFlareItem; -}; - -Q_DECLARE_METATYPE(CEntityObject*) - -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLARELIGHTENTITYTREE_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.cpp deleted file mode 100644 index c28832898f..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareManager.h" - -// AzCore -#include -#include - -// Editor -#include "LensFlareEditor.h" -#include "LensFlareItem.h" -#include "LensFlareLibrary.h" -#include "LensFlareUtil.h" - - -////////////////////////////////////////////////////////////////////////// -// CLensFlareManager implementation. -////////////////////////////////////////////////////////////////////////// -CLensFlareManager::CLensFlareManager() - : CBaseLibraryManager() -{ - m_bUniqNameMap = true; - m_pLevelLibrary = (CBaseLibrary*)AddLibrary("Level", true); - AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusConnect(); -} - -////////////////////////////////////////////////////////////////////////// -CLensFlareManager::~CLensFlareManager() -{ - AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler::BusDisconnect(); -} - -////////////////////////////////////////////////////////////////////////// -void CLensFlareManager::ClearAll() -{ - CBaseLibraryManager::ClearAll(); - - m_pLevelLibrary = (CBaseLibrary*)AddLibrary("Level", true); -} - -////////////////////////////////////////////////////////////////////////// -CBaseLibraryItem* CLensFlareManager::MakeNewItem() -{ - return new CLensFlareItem; -} - -////////////////////////////////////////////////////////////////////////// -CBaseLibrary* CLensFlareManager::MakeNewLibrary() -{ - return new CLensFlareLibrary(this); -} - -////////////////////////////////////////////////////////////////////////// -QString CLensFlareManager::GetRootNodeName() -{ - return "FlareLibs"; -} - -////////////////////////////////////////////////////////////////////////// -QString CLensFlareManager::GetLibsPath() -{ - if (m_libsPath.isEmpty()) - { - m_libsPath += FLARE_LIBS_PATH; - } - - return m_libsPath; -} - -////////////////////////////////////////////////////////////////////////// -bool CLensFlareManager::LoadFlareItemByName(const QString& fullItemName, IOpticsElementBasePtr pDestOptics) -{ - if (pDestOptics == NULL) - { - return false; - } - - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)LoadItemByName(fullItemName); - if (pLensFlareItem == NULL) - { - return false; - } - - LensFlareUtil::CopyOptics(pLensFlareItem->GetOptics(), pDestOptics, true); - return true; -} - -////////////////////////////////////////////////////////////////////////// -void CLensFlareManager::Modified() -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - if (pEditor->GetCurrentLibrary()) - { - pEditor->GetCurrentLibrary()->SetModified(true); - } -} - -////////////////////////////////////////////////////////////////////////// -IDataBaseLibrary* CLensFlareManager::LoadLibrary(const QString& filename, [[maybe_unused]] bool bReload) -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - - QString fileNameWithGameFolder(filename); - - fileNameWithGameFolder.replace('\\', '/'); - - int nGamePathLength = static_cast(Path::GetEditingGameDataFolder().size()); - QString gamePathName; - if (nGamePathLength < filename.length()) - { - gamePathName = filename.left(nGamePathLength); - } - if (gamePathName != Path::GetEditingGameDataFolder().c_str()) - { - fileNameWithGameFolder.insert(0, "/"); - fileNameWithGameFolder.insert(0, Path::GetEditingGameDataFolder().c_str()); - } - - int nLibraryIndex(-1); - bool bSameAsCurrentLibrary(false); - - for (int i = 0; i < m_libs.size(); i++) - { - if (QString::compare(fileNameWithGameFolder, m_libs[i]->GetFilename(), Qt::CaseInsensitive) == 0) - { - IDataBaseLibrary* pExistingLib = m_libs[i]; - for (int j = 0; j < pExistingLib->GetItemCount(); j++) - { - UnregisterItem((CBaseLibraryItem*)pExistingLib->GetItem(j)); - } - pExistingLib->RemoveAllItems(); - nLibraryIndex = i; - if (pEditor) - { - bSameAsCurrentLibrary = pEditor->GetCurrentLibrary() == pExistingLib; - } - break; - } - } - - TSmartPtr pLib = MakeNewLibrary(); - if (!pLib->Load(filename)) - { - Error(QObject::tr("Failed to Load Item Library: %1").arg(filename).toUtf8().data()); - return NULL; - } - - if (nLibraryIndex != -1) - { - m_libs[nLibraryIndex] = pLib; - if (bSameAsCurrentLibrary && pEditor) - { - pEditor->ResetElementTreeControl(); - pEditor->SelectLibrary(pLib, true); - } - } - else - { - m_libs.push_back(pLib); - } - - pLib->SetFilename(filename); - - return pLib; -} - - -bool CLensFlareManager::IsLensFlareLibraryXML(const char* fileSourceFilePath) -{ - if ((!fileSourceFilePath) || (!AZStd::wildcard_match("*.xml", fileSourceFilePath))) - { - return false; - } - - using namespace AZ::IO; - - bool isLensFlareLibrary = false; - - // we are forced to read the asset to discover its type since "xml" was the chosen extension. - SystemFile::SizeType fileSize = SystemFile::Length(fileSourceFilePath); - if (fileSize > 0) - { - AZStd::vector buffer(fileSize + 1); - buffer[fileSize] = 0; - if (!AZ::IO::SystemFile::Read(fileSourceFilePath, buffer.data(), fileSize)) - { - return false; - } - - AZ::rapidxml::xml_document* xmlDoc = azcreate(AZ::rapidxml::xml_document, (), AZ::SystemAllocator, "LensFlareLibrary Temp XML Reader"); - if (xmlDoc->parse(buffer.data())) - { - AZ::rapidxml::xml_node* xmlRootNode = xmlDoc->first_node(); - if (xmlRootNode) - { - if (azstricmp(xmlRootNode->name(), "LensFlareLibrary") == 0) - { - isLensFlareLibrary = true; - } - } - } - - azdestroy(xmlDoc, AZ::SystemAllocator, AZ::rapidxml::xml_document); - } - - return isLensFlareLibrary; -} - - -AzToolsFramework::AssetBrowser::SourceFileDetails CLensFlareManager::GetSourceFileDetails(const char* fullSourceFileName) -{ - if (IsLensFlareLibraryXML(fullSourceFileName)) - { - return AzToolsFramework::AssetBrowser::SourceFileDetails("Icons/AssetBrowser/LensFlare_16.png"); - } - return AzToolsFramework::AssetBrowser::SourceFileDetails(); -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.h deleted file mode 100644 index 9cc7c6fad2..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareManager.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREMANAGER_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREMANAGER_H -#pragma once - -#include "BaseLibraryManager.h" -#include - -class IOpticsElementBase; -class CLensFlareEditor; - -AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING -AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING -class CRYEDIT_API CLensFlareManager - : public CBaseLibraryManager - , private AzToolsFramework::AssetBrowser::AssetBrowserInteractionNotificationBus::Handler - -{ -AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING -AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING -public: - CLensFlareManager(); - virtual ~CLensFlareManager(); - - void ClearAll(); - - virtual bool LoadFlareItemByName(const QString& fullItemName, IOpticsElementBasePtr pDestOptics); - void Modified(); - //! Path to libraries in this manager. - QString GetLibsPath(); - IDataBaseLibrary* LoadLibrary(const QString& filename, bool bReload = false); - - static bool IsLensFlareLibraryXML(const char* fullFilePath); - -private: - CBaseLibraryItem* MakeNewItem(); - CBaseLibrary* MakeNewLibrary(); - - //! Root node where this library will be saved. - QString GetRootNodeName(); - QString m_libsPath; - - //////////////////////////////////////////////////////////////////////////////////////////////////////////// - // AssetBrowser::AssetBrowserInteractionNotificationBus::Handler - AzToolsFramework::AssetBrowser::SourceFileDetails GetSourceFileDetails(const char* fullSourceFileName) override; - virtual AZ::s32 GetPriority() const override { return 1; } // get our priority in before others. - //////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -}; - -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREMANAGER_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.cpp deleted file mode 100644 index 3c628d1b34..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" -#include "LensFlareReferenceTree.h" - -BEGIN_MESSAGE_MAP (CLensFlareReferenceTree, CXTTreeCtrl) -END_MESSAGE_MAP () - -CLensFlareReferenceTree::CLensFlareReferenceTree() -{ -} - -CLensFlareReferenceTree::~CLensFlareReferenceTree() -{ -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.h deleted file mode 100644 index 77ca781a30..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareReferenceTree.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREREFERENCETREE_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREREFERENCETREE_H -#pragma once - -class CLensFlareReferenceTree - : public CXTTreeCtrl -{ -public: - - CLensFlareReferenceTree(); - ~CLensFlareReferenceTree(); - -private: - - DECLARE_MESSAGE_MAP() -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREREFERENCETREE_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.cpp deleted file mode 100644 index a6b35eba13..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareUndo.h" - -// Editor -#include "LensFlareEditor.h" -#include "LensFlareItem.h" -#include "LensFlareManager.h" -#include "LensFlareElementTree.h" - - -void RestoreLensFlareItem(CLensFlareItem* pLensFlareItem, IOpticsElementBasePtr pOptics, const QString& flarePathName) -{ - pLensFlareItem->ReplaceOptics(pOptics); - - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor) - { - if (pOptics->GetType() == eFT_Root) - { - pEditor->RenameLensFlareItem(pLensFlareItem, pLensFlareItem->GetGroupName(), LensFlareUtil::GetShortName(flarePathName)); - pEditor->UpdateLensFlareItem(pLensFlareItem); - } - } -} - -void ActivateLensFlareItem(CLensFlareItem* pLensFlareItem, bool bRestoreSelectInfo, const QString& selectedFlareItemName) -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - if (pLensFlareItem == pEditor->GetLensFlareElementTree()->GetLensFlareItem()) - { - pEditor->UpdateLensFlareItem(pLensFlareItem); - if (bRestoreSelectInfo) - { - pEditor->SelectItemInLensFlareElementTreeByName(selectedFlareItemName); - } - } -} - -CUndoLensFlareItem::CUndoLensFlareItem(CLensFlareItem* pLensFlareItem, const QString& undoDescription) -{ - if (pLensFlareItem) - { - m_Undo.m_pOptics = LensFlareUtil::CreateOptics(pLensFlareItem->GetOptics()); - m_flarePathName = pLensFlareItem->GetFullName(); - m_Undo.m_bRestoreSelectInfo = false; - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor) - { - m_Undo.m_bRestoreSelectInfo = pEditor->GetSelectedLensFlareName(m_Undo.m_selectedFlareItemName); - } - m_undoDescription = undoDescription; - } -} - -CUndoLensFlareItem::~CUndoLensFlareItem() -{ -} - -void CUndoLensFlareItem::Undo(bool bUndo) -{ - if (bUndo) - { - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(m_flarePathName); - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor && pLensFlareItem) - { - m_Redo.m_bRestoreSelectInfo = false; - m_Redo.m_pOptics = LensFlareUtil::CreateOptics(pLensFlareItem->GetOptics()); - m_Redo.m_bRestoreSelectInfo = pEditor->GetSelectedLensFlareName(m_Redo.m_selectedFlareItemName); - } - } - Restore(m_Undo); -} - -void CUndoLensFlareItem::Redo() -{ - Restore(m_Redo); -} - -void CUndoLensFlareItem::Restore(const SData& data) -{ - if (data.m_pOptics == NULL) - { - return; - } - - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(m_flarePathName); - if (pLensFlareItem == NULL) - { - return; - } - RestoreLensFlareItem(pLensFlareItem, data.m_pOptics, m_flarePathName); - ActivateLensFlareItem(pLensFlareItem, data.m_bRestoreSelectInfo, data.m_selectedFlareItemName); -} - -CUndoRenameLensFlareItem::CUndoRenameLensFlareItem(const QString& oldFullName, const QString& newFullName) -{ - m_undo.m_oldFullItemName = oldFullName; - m_undo.m_newFullItemName = newFullName; -} - -void CUndoRenameLensFlareItem::Undo(bool bUndo) -{ - if (bUndo) - { - m_redo.m_oldFullItemName = m_undo.m_newFullItemName; - m_redo.m_newFullItemName = m_undo.m_oldFullItemName; - } - - Rename(m_undo); -} - -void CUndoRenameLensFlareItem::Redo() -{ - Rename(m_redo); -} - -void CUndoRenameLensFlareItem::Rename(const SUndoDataStruct& data) -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(data.m_newFullItemName); - if (pLensFlareItem == NULL) - { - return; - } - - int nDotPos = data.m_oldFullItemName.indexOf("."); - if (nDotPos == -1) - { - return; - } - - QString shortName(LensFlareUtil::GetShortName(data.m_oldFullItemName)); - QString groupName(LensFlareUtil::GetGroupNameFromFullName(data.m_oldFullItemName)); - pEditor->RenameLensFlareItem(pLensFlareItem, groupName, shortName); - if (pLensFlareItem->GetOptics()) - { - pLensFlareItem->GetOptics()->SetName(shortName.toUtf8().data()); - LensFlareUtil::UpdateOpticsName(pLensFlareItem->GetOptics()); - } - pEditor->UpdateLensFlareItem(pLensFlareItem); -} - -CUndoLensFlareElementSelection::CUndoLensFlareElementSelection(CLensFlareItem* pLensFlareItem, const QString& flareTreeItemFullName, const QString& undoDescription) -{ - if (pLensFlareItem) - { - m_flarePathNameForUndo = pLensFlareItem->GetFullName(); - m_flareTreeItemFullNameForUndo = flareTreeItemFullName; - m_undoDescription = undoDescription; - } -} - -void CUndoLensFlareElementSelection::Undo(bool bUndo) -{ - if (bUndo) - { - m_flarePathNameForRedo = m_flarePathNameForUndo; - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor) - { - pEditor->GetSelectedLensFlareName(m_flareTreeItemFullNameForRedo); - } - } - - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(m_flarePathNameForUndo); - if (pLensFlareItem == NULL) - { - return; - } - ActivateLensFlareItem(pLensFlareItem, true, m_flareTreeItemFullNameForUndo); -} - -void CUndoLensFlareElementSelection::Redo() -{ - CLensFlareItem* pLensFlareItem = (CLensFlareItem*)GetIEditor()->GetLensFlareManager()->FindItemByName(m_flarePathNameForRedo); - if (pLensFlareItem == NULL) - { - return; - } - ActivateLensFlareItem(pLensFlareItem, true, m_flareTreeItemFullNameForRedo); -} - -CUndoLensFlareItemSelectionChange::CUndoLensFlareItemSelectionChange(const QString& fullLensFlareItemName, const QString& undoDescription) -{ - m_FullLensFlareItemNameForUndo = fullLensFlareItemName; - m_undoDescription = undoDescription; -} - -void CUndoLensFlareItemSelectionChange::Undo(bool bUndo) -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - - if (bUndo) - { - QString currentFullName; - pEditor->GetFullSelectedFlareItemName(currentFullName); - m_FullLensFlareItemNameForRedo = currentFullName; - } - - pEditor->SelectLensFlareItem(m_FullLensFlareItemNameForUndo); -} - -void CUndoLensFlareItemSelectionChange::Redo() -{ - CLensFlareEditor* pEditor = CLensFlareEditor::GetLensFlareEditor(); - if (pEditor == NULL) - { - return; - } - pEditor->SelectLensFlareItem(m_FullLensFlareItemNameForRedo); -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.h deleted file mode 100644 index cf8f76c321..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUndo.h +++ /dev/null @@ -1,143 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUNDO_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUNDO_H -#pragma once - -#include "Undo/IUndoObject.h" - -class CLensFlareItem; - -class CUndoLensFlareItem - : public IUndoObject -{ -public: - CUndoLensFlareItem(CLensFlareItem* pGroupItem, const QString& undoDescription = "Undo Lens Flare Tree"); - ~CUndoLensFlareItem(); - -protected: - int GetSize() - { - return sizeof(*this); - } - QString GetDescription() { return m_undoDescription; }; - void Undo(bool bUndo); - void Redo(); - -private: - - QString m_undoDescription; - - struct SData - { - SData() - { - m_pOptics = NULL; - } - - QString m_selectedFlareItemName; - bool m_bRestoreSelectInfo; - IOpticsElementBasePtr m_pOptics; - }; - - QString m_flarePathName; - SData m_Undo; - SData m_Redo; - - void Restore(const SData& data); -}; - -class CUndoRenameLensFlareItem - : public IUndoObject -{ -public: - - CUndoRenameLensFlareItem(const QString& oldFullName, const QString& newFullName); - -protected: - - int GetSize() - { - return sizeof(*this); - } - QString GetDescription() { return m_undoDescription; }; - void Undo(bool bUndo); - void Redo(); - -private: - - QString m_undoDescription; - - struct SUndoDataStruct - { - QString m_oldFullItemName; - QString m_newFullItemName; - }; - - void Rename(const SUndoDataStruct& data); - - SUndoDataStruct m_undo; - SUndoDataStruct m_redo; -}; - -class CUndoLensFlareElementSelection - : public IUndoObject -{ -public: - CUndoLensFlareElementSelection(CLensFlareItem* pLensFlareItem, const QString& flareTreeItemFullName, const QString& undoDescription = "Undo Lens Flare Element Tree"); - ~CUndoLensFlareElementSelection(){} - -protected: - int GetSize() - { - return sizeof(*this); - } - QString GetDescription() { return m_undoDescription; }; - void Undo(bool bUndo); - void Redo(); - -private: - - QString m_undoDescription; - - QString m_flarePathNameForUndo; - QString m_flareTreeItemFullNameForUndo; - - QString m_flarePathNameForRedo; - QString m_flareTreeItemFullNameForRedo; -}; - -class CUndoLensFlareItemSelectionChange - : public IUndoObject -{ -public: - CUndoLensFlareItemSelectionChange(const QString& fullLensFlareItemName, const QString& undoDescription = "Undo Lens Flare element selection"); - ~CUndoLensFlareItemSelectionChange(){} - -protected: - int GetSize() - { - return sizeof(*this); - } - QString GetDescription() { return m_undoDescription; }; - - void Undo(bool bUndo); - void Redo(); - -private: - QString m_undoDescription; - QString m_FullLensFlareItemNameForUndo; - QString m_FullLensFlareItemNameForRedo; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUNDO_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.cpp deleted file mode 100644 index e8ff29f987..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.cpp +++ /dev/null @@ -1,1012 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareUtil.h" - -// Editor -#include "Clipboard.h" -#include "Objects/EntityObject.h" -#include "Objects/SelectionGroup.h" -#include "Include/IObjectManager.h" - - -namespace LensFlareUtil -{ - IOpticsElementBasePtr CreateOptics(const XmlNodeRef& xmlNode) - { - IOpticsElementBasePtr pOpticsElement = NULL; - - const char* typeName; - if (!xmlNode->getAttr("Type", &typeName)) - { - return NULL; - } - - bool bEnable(true); - xmlNode->getAttr("Enable", bEnable); - - EFlareType flareType; - if (!GetFlareType(typeName, flareType)) - { - return NULL; - } - - pOpticsElement = gEnv->pOpticsManager->Create(flareType); - if (pOpticsElement == NULL) - { - return NULL; - } - - pOpticsElement->SetEnabled(bEnable); - - if (!FillOpticsFromXML(pOpticsElement, xmlNode)) - { - return NULL; - } - - return pOpticsElement; - } - - IOpticsElementBasePtr CreateOptics(IOpticsElementBasePtr pOptics, bool bForceTypeToGroup) - { - if (pOptics == NULL) - { - return NULL; - } - IOpticsElementBasePtr pNewOptics = NULL; - if (bForceTypeToGroup) - { - if (pOptics->GetType() == eFT_Root) - { - pNewOptics = gEnv->pOpticsManager->Create(eFT_Group); - } - } - if (pNewOptics == NULL) - { - pNewOptics = gEnv->pOpticsManager->Create(pOptics->GetType()); - if (pNewOptics == NULL) - { - return NULL; - } - } - CopyOptics(pOptics, pNewOptics, true); - return pNewOptics; - } - - bool FillOpticsFromXML(IOpticsElementBasePtr pOpticsElement, const XmlNodeRef& xmlNode) - { - if (!pOpticsElement) - { - return false; - } - - const char* name; - if (!xmlNode->getAttr("Name", &name)) - { - return false; - } - - const char* typeName; - if (!xmlNode->getAttr("Type", &typeName)) - { - return false; - } - EFlareType flareType; - if (!GetFlareType(typeName, flareType)) - { - return false; - } - if (flareType != pOpticsElement->GetType()) - { - return false; - } - - pOpticsElement->SetName(name); - - bool bEnable(true); - xmlNode->getAttr("Enable", bEnable); - pOpticsElement->SetEnabled(bEnable); - - XmlNodeRef pParamNode = xmlNode->findChild("Params"); - if (pParamNode == NULL) - { - return false; - } - - LensFlareUtil::FillParams(pParamNode, pOpticsElement); - return true; - } - - bool CreateXmlData(IOpticsElementBasePtr pOptics, XmlNodeRef& pOutNode) - { - pOutNode = gEnv->pSystem->CreateXmlNode("FlareItem"); - - if (pOptics == NULL || pOutNode == NULL) - { - return false; - } - - QString typeName; - if (!GetFlareTypeName(typeName, pOptics)) - { - return false; - } - - pOutNode->setAttr("Name", pOptics->GetName().c_str()); - pOutNode->setAttr("Type", typeName.toUtf8().data()); - pOutNode->setAttr("Enable", pOptics->IsEnabled()); - - XmlNodeRef pParamNode = pOutNode->createNode("Params"); - - CVarBlockPtr pVar; - SetVariablesTemplateFromOptics(pOptics, pVar); - - pVar->Serialize(pParamNode, false); - pOutNode->addChild(pParamNode); - - for (int i = 0, iElementCount(pOptics->GetElementCount()); i < iElementCount; ++i) - { - XmlNodeRef pNode = NULL; - IOpticsElementBasePtr pChildOptics = pOptics->GetElementAt(i); - if (!CreateXmlData(pChildOptics, pNode)) - { - continue; - } - - pOutNode->addChild(pNode); - } - - return true; - } - - void SetVariablesTemplateFromOptics(IOpticsElementBasePtr pOptics, CVarBlockPtr& pRootVar, std::vector& funcs) - { - if (pOptics == NULL) - { - return; - } - - SetVariablesTemplateFromOptics(pOptics, pRootVar); - - for (int i = 0, iNumVariables(pRootVar->GetNumVariables()); i < iNumVariables; ++i) - { - IVariable* pVariable = pRootVar->GetVariable(i); - if (pVariable == NULL) - { - continue; - } - for (int k = 0, iNumVariables2(pVariable->GetNumVariables()); k < iNumVariables2; ++k) - { - IVariable* pChildVariable(pVariable->GetVariable(k)); - if (pChildVariable == NULL) - { - continue; - } - for (int ii = 0, iSize(funcs.size()); ii < iSize; ++ii) - { - pChildVariable->AddOnSetCallback(funcs[ii]); - } - } - } - } - - extern void SetVariablesTemplateFromOptics(IOpticsElementBasePtr pOptics, CVarBlockPtr& pRootVar) - { - if (pOptics == NULL) - { - return; - } - - AZStd::vector paramGroups = pOptics->GetEditorParamGroups(); - pRootVar = new CVarBlock; - - for (int i = 0; i < paramGroups.size(); ++i) - { - CSmartVariableArray variableArray; - FuncVariableGroup* pGroup = ¶mGroups[i]; - if (pGroup == NULL) - { - continue; - } - - QString displayGroupName(pGroup->GetHumanName()); - if (displayGroupName == "Common") - { - FlareInfoArray::Props flareInfo = FlareInfoArray::Get(); - int nTypeIndex = (int)pOptics->GetType(); - if (nTypeIndex >= 0 && nTypeIndex < flareInfo.size) - { - displayGroupName += " : "; - displayGroupName += flareInfo.p[nTypeIndex].name; - } - } - - AddVariable(pRootVar, variableArray, pGroup->GetName(), displayGroupName.toUtf8().data(), ""); - - for (int k = 0; k < pGroup->GetVariableCount(); ++k) - { - IFuncVariable* pFuncVar = pGroup->GetVariable(k); - bool bHardMinLimitation = false; - - const std::pair range(pFuncVar->GetMin(), pFuncVar->GetMax()); - - if (pFuncVar->paramType == e_FLOAT) - { - CSmartVariable floatVar; - AddVariable(variableArray, floatVar, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - floatVar->SetLimits(range.first, range.second, 0, bHardMinLimitation, false); - floatVar->Set(pFuncVar->GetFloat()); - floatVar->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_INT) - { - CSmartVariable intVar; - AddVariable(variableArray, intVar, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - - bHardMinLimitation = HaveParameterLowBoundary(pFuncVar->name.c_str()); - intVar->SetLimits(range.first, range.second, 0, bHardMinLimitation, false); - - intVar->Set(pFuncVar->GetInt()); - intVar->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_BOOL) - { - CSmartVariable boolVar; - AddVariable(variableArray, boolVar, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - boolVar->Set(pFuncVar->GetBool()); - boolVar->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_VEC2) - { - CSmartVariable vec2Var; - AddVariable(variableArray, vec2Var, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - vec2Var->SetLimits(range.first, range.second, 0, bHardMinLimitation, false); - vec2Var->Set(pFuncVar->GetVec2()); - vec2Var->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_VEC3) - { - CSmartVariable vec3Var; - AddVariable(variableArray, vec3Var, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - vec3Var->SetLimits(range.first, range.second, 0, bHardMinLimitation, false); - vec3Var->Set(pFuncVar->GetVec3()); - vec3Var->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_VEC4) - { - CSmartVariable vec4Var; - AddVariable(variableArray, vec4Var, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str()); - vec4Var->SetLimits(range.first, range.second, 0, bHardMinLimitation, false); - vec4Var->Set(pFuncVar->GetVec4()); - vec4Var->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_COLOR) - { - CSmartVariable colorVar; - AddVariable(variableArray, colorVar, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str(), IVariable::DT_COLOR); - ColorF color(pFuncVar->GetColorF()); - Vec3 colorVec3(color.r, color.g, color.b); - colorVar->Set(colorVec3); - colorVar->SetUserData(MakeFuncKey(i, k)); - - CSmartVariable alphaVar; - QString alphaName(pFuncVar->name.c_str()); - alphaName += ".alpha"; - QString alphaHumanName(pFuncVar->humanName.c_str()); - alphaHumanName += " [alpha]"; - AddVariable(variableArray, alphaVar, alphaName.toUtf8().data(), alphaHumanName.toUtf8().data(), pFuncVar->description.c_str()); - alphaVar->SetLimits(0, 255, 0, bHardMinLimitation, false); - alphaVar->Set(color.a * 255.0f); - alphaVar->SetUserData(MakeFuncKey(i, k)); - } - else if (pFuncVar->paramType == e_MATRIX33) - { - // Reserved part - // This part is for future because Matrix33 type is suppose to be provided in a renderer side - } - else if (pFuncVar->paramType == e_TEXTURE2D || pFuncVar->paramType == e_TEXTURE3D || pFuncVar->paramType == e_TEXTURE_CUBE) - { - CSmartVariable textureVar; - ITexture* pTexture = pFuncVar->GetTexture(); - if (pTexture) - { - QString textureName = pTexture->GetName(); - textureVar->Set(textureName); - } - AddVariable(variableArray, textureVar, pFuncVar->name.c_str(), pFuncVar->humanName.c_str(), pFuncVar->description.c_str(), IVariable::DT_TEXTURE); - textureVar->SetUserData(MakeFuncKey(i, k)); - } - } - } - } - - void AddOptics(IOpticsElementBasePtr pParentOptics, const XmlNodeRef& xmlNode) - { - if (xmlNode == NULL) - { - return; - } - - if (strcmp(xmlNode->getTag(), "FlareItem")) - { - return; - } - - IOpticsElementBasePtr pOptics = CreateOptics(xmlNode); - if (pOptics == NULL) - { - return; - } - pParentOptics->AddElement(pOptics); - - for (int i = 0, iChildCount(xmlNode->getChildCount()); i < iChildCount; ++i) - { - AddOptics(pOptics, xmlNode->getChild(i)); - } - } - - void CopyVariable(IFuncVariable* pSrcVar, IFuncVariable* pDestVar) - { - if (!pSrcVar || !pDestVar) - { - return; - } - - if (pSrcVar->paramType != pDestVar->paramType) - { - return; - } - - if (pSrcVar->paramType == e_FLOAT) - { - float value = pSrcVar->GetFloat(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_BOOL) - { - bool value = pSrcVar->GetBool(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_INT) - { - int value = pSrcVar->GetInt(); - if (HaveParameterLowBoundary(pSrcVar->name.c_str())) - { - BoundaryProcess(value); - } - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_VEC2) - { - Vec2 value = pSrcVar->GetVec2(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_VEC3) - { - Vec3 value = pSrcVar->GetVec3(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_VEC4) - { - Vec4 value = pSrcVar->GetVec4(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_COLOR) - { - ColorF value = pSrcVar->GetColorF(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_MATRIX33) - { - Matrix33 value = pSrcVar->GetMatrix33(); - pDestVar->InvokeSetter((void*)&value); - } - else if (pSrcVar->paramType == e_TEXTURE2D || pSrcVar->paramType == e_TEXTURE3D || pSrcVar->paramType == e_TEXTURE_CUBE) - { - ITexture* value = pSrcVar->GetTexture(); - pDestVar->InvokeSetter((void*)value); - } - } - - void CopyOpticsAboutSameOpticsType(IOpticsElementBasePtr pSrcOptics, IOpticsElementBasePtr pDestOptics) - { - if (pSrcOptics->GetType() != pDestOptics->GetType()) - { - return; - } - - AZStd::vector srcVarGroups = pSrcOptics->GetEditorParamGroups(); - AZStd::vector destVarGroups = pDestOptics->GetEditorParamGroups(); - - if (srcVarGroups.size() != destVarGroups.size()) - { - return; - } - - pDestOptics->SetEnabled(pSrcOptics->IsEnabled()); - - for (int i = 0, iVarGroupSize(srcVarGroups.size()); i < iVarGroupSize; ++i) - { - FuncVariableGroup srcVarGroup = srcVarGroups[i]; - FuncVariableGroup destVarGroup = destVarGroups[i]; - - if (srcVarGroup.GetVariableCount() != destVarGroup.GetVariableCount()) - { - continue; - } - - for (int k = 0, iVarSize(srcVarGroup.GetVariableCount()); k < iVarSize; ++k) - { - IFuncVariable* pSrcVar = srcVarGroup.GetVariable(k); - IFuncVariable* pDestVar = destVarGroup.GetVariable(k); - CopyVariable(pSrcVar, pDestVar); - } - } - } - - bool FindGroupByName(AZStd::vector& groupList, const QString& name, int& outIndex) - { - for (int i = 0, iVarGroupSize(groupList.size()); i < iVarGroupSize; ++i) - { - if (name == groupList[i].GetName()) - { - outIndex = i; - return true; - } - } - return false; - } - - void CopyOpticsAboutDifferentOpticsType(IOpticsElementBasePtr pSrcOptics, IOpticsElementBasePtr pDestOptics) - { - if (pSrcOptics->GetType() == pDestOptics->GetType()) - { - return; - } - - AZStd::vector srcVarGroups = pSrcOptics->GetEditorParamGroups(); - AZStd::vector destVarGroups = pDestOptics->GetEditorParamGroups(); - - pDestOptics->SetEnabled(pSrcOptics->IsEnabled()); - - for (int i = 0, iVarGroupSize(destVarGroups.size()); i < iVarGroupSize; ++i) - { - FuncVariableGroup destVarGroup = destVarGroups[i]; - int nIndex = 0; - if (!FindGroupByName(srcVarGroups, destVarGroup.GetName(), nIndex)) - { - continue; - } - FuncVariableGroup srcVarGroup = srcVarGroups[nIndex]; - - for (int k = 0, iVarSize(destVarGroup.GetVariableCount()); k < iVarSize; ++k) - { - IFuncVariable* pDestVar = destVarGroup.GetVariable(k); - IFuncVariable* pSrcVar = srcVarGroup.FindVariable(pDestVar->name.c_str()); - CopyVariable(pSrcVar, pDestVar); - } - } - } - - void CopyOptics(IOpticsElementBasePtr pSrcOptics, IOpticsElementBasePtr pDestOptics, bool bReculsiveCopy) - { - if (pSrcOptics->GetType() == pDestOptics->GetType()) - { - CopyOpticsAboutSameOpticsType(pSrcOptics, pDestOptics); - } - else - { - CopyOpticsAboutDifferentOpticsType(pSrcOptics, pDestOptics); - } - - if (bReculsiveCopy) - { - pDestOptics->RemoveAll(); - for (int i = 0, iChildCount(pSrcOptics->GetElementCount()); i < iChildCount; ++i) - { - IOpticsElementBasePtr pSrcChildOptics = pSrcOptics->GetElementAt(i); - IOpticsElementBasePtr pNewOptics = gEnv->pOpticsManager->Create(pSrcChildOptics->GetType()); - if (pNewOptics == NULL) - { - continue; - } - pNewOptics->SetName(pSrcChildOptics->GetName().c_str()); - CopyOptics(pSrcChildOptics, pNewOptics, bReculsiveCopy); - pDestOptics->AddElement(pNewOptics); - } - } - } - - CEntityObject* GetSelectedLightEntity() - { - CBaseObject* pSelectedObj = GetIEditor()->GetSelectedObject(); - if (pSelectedObj == NULL) - { - return NULL; - } - if (!qobject_cast(pSelectedObj)) - { - return NULL; - } - CEntityObject* pEntity = (CEntityObject*)pSelectedObj; - if (!pEntity->IsLight()) - { - return NULL; - } - return pEntity; - } - - void GetSelectedLightEntities(std::vector& outLightEntities) - { - CSelectionGroup* pSelectionGroup = GetIEditor()->GetSelection(); - if (pSelectionGroup == NULL) - { - return; - } - int nSelectionCount = pSelectionGroup->GetCount(); - outLightEntities.reserve(nSelectionCount); - for (int i = 0; i < nSelectionCount; ++i) - { - CBaseObject* pSelectedObj = pSelectionGroup->GetObject(i); - if (!qobject_cast(pSelectedObj)) - { - continue; - } - CEntityObject* pEntity = (CEntityObject*)pSelectedObj; - if (!pEntity->IsLight()) - { - continue; - } - outLightEntities.push_back(pEntity); - } - } - - IOpticsElementBasePtr GetSelectedLightOptics() - { - CEntityObject* pEntity = GetSelectedLightEntity(); - if (pEntity == NULL) - { - return NULL; - } - IOpticsElementBasePtr pEntityOptics = pEntity->GetOpticsElement(); - if (pEntityOptics == NULL) - { - return NULL; - } - return pEntityOptics; - } - - IOpticsElementBasePtr FindOptics(IOpticsElementBasePtr pStartOptics, const QString& name) - { - if (pStartOptics == NULL) - { - return NULL; - } - - if (!QString::compare(pStartOptics->GetName().c_str(), name)) - { - return pStartOptics; - } - - for (int i = 0, iElementCount(pStartOptics->GetElementCount()); i < iElementCount; ++i) - { - IOpticsElementBasePtr pFoundOptics = FindOptics(pStartOptics->GetElementAt(i), name); - if (pFoundOptics) - { - return pFoundOptics; - } - } - - return NULL; - } - - void RemoveOptics(IOpticsElementBasePtr pOptics) - { - if (pOptics == NULL) - { - return; - } - - IOpticsElementBasePtr pParent = pOptics->GetParent(); - if (pParent == NULL) - { - return; - } - - for (int i = 0, iElementCount(pParent->GetElementCount()); i < iElementCount; ++i) - { - if (pOptics == pParent->GetElementAt(i)) - { - pParent->Remove(i); - break; - } - } - } - - void ChangeOpticsRootName(IOpticsElementBasePtr pOptics, const QString& newRootName) - { - if (pOptics == NULL) - { - return; - } - - QString opticsName = pOptics->GetName().c_str(); - QString opticsRootName; - - int nPos = opticsName.indexOf("."); - if (nPos == -1) - { - opticsRootName = opticsName; - } - else - { - opticsRootName = opticsName.left(nPos); - } - - opticsName.replace(opticsRootName, newRootName); - pOptics->SetName(opticsName.toUtf8().data()); - - for (int i = 0, iElementSize(pOptics->GetElementCount()); i < iElementSize; ++i) - { - ChangeOpticsRootName(pOptics->GetElementAt(i), newRootName); - } - } - - void UpdateClipboard(const QString& type, const QString& groupName, bool bPasteAtSameLevel, std::vector& dataList) - { - XmlNodeRef rootNode = CreateXMLFromClipboardData(type, groupName, bPasteAtSameLevel, dataList); - CClipboard clipboard(nullptr); - clipboard.Put(rootNode); - } - - XmlNodeRef CreateXMLFromClipboardData(const QString& type, const QString& groupName, bool bPasteAtSameLevel, std::vector& dataList) - { - XmlNodeRef rootNode = gEnv->pSystem->CreateXmlNode(); - rootNode->setTag("FlareDB"); - rootNode->setAttr("Type", type.toUtf8().data()); - rootNode->setAttr("GroupName", groupName.toUtf8().data()); - rootNode->setAttr("PasteAtSameLevel", bPasteAtSameLevel); - - for (int i = 0, iDataSize(dataList.size()); i < iDataSize; ++i) - { - XmlNodeRef xmlNode = gEnv->pSystem->CreateXmlNode(); - xmlNode->setTag("Data"); - dataList[i].FillXmlNode(xmlNode); - rootNode->addChild(xmlNode); - } - - return rootNode; - } - - void UpdateOpticsName(IOpticsElementBasePtr pOptics) - { - if (pOptics == NULL) - { - return; - } - - IOpticsElementBasePtr pParent = pOptics->GetParent(); - if (pParent) - { - QString oldName = pOptics->GetName().c_str(); - QString parentName = pParent->GetName().c_str(); - QString updatedName = parentName + QString(".") + GetShortName(oldName); - pOptics->SetName(updatedName.toUtf8().data()); - } - - for (int i = 0, iElementCount(pOptics->GetElementCount()); i < iElementCount; ++i) - { - UpdateOpticsName(pOptics->GetElementAt(i)); - } - } - - QString ReplaceLastName(const QString& fullName, const QString& shortName) - { - int nPos = fullName.lastIndexOf('.'); - if (nPos == -1) - { - return shortName; - } - QString newName = fullName.left(nPos + 1); - newName += shortName; - return newName; - } - - IFuncVariable* GetFuncVariable(IOpticsElementBasePtr pOptics, int nFuncKey) - { - if (pOptics == NULL) - { - return NULL; - } - - int nGroupIndex = (nFuncKey & 0xFFFF0000) >> 16; - int nVarIndex = (nFuncKey & 0x0000FFFF); - - AZStd::vector paramGroups = pOptics->GetEditorParamGroups(); - - if (nGroupIndex >= paramGroups.size()) - { - return NULL; - } - - FuncVariableGroup* pGroup = ¶mGroups[nGroupIndex]; - if (pGroup == NULL) - { - return NULL; - } - - if (nVarIndex >= pGroup->GetVariableCount()) - { - return NULL; - } - - return pGroup->GetVariable(nVarIndex); - } - - void GetLightEntityObjects(std::vector& outEntityLights) - { - std::vector pEntityObjects; - GetIEditor()->GetObjectManager()->FindObjectsOfType(&CEntityObject::staticMetaObject, pEntityObjects); - for (int i = 0, iObjectSize(pEntityObjects.size()); i < iObjectSize; ++i) - { - CEntityObject* pEntity = (CEntityObject*)pEntityObjects[i]; - if (pEntity == NULL) - { - continue; - } - if (pEntity->CheckFlags(OBJFLAG_DELETED)) - { - continue; - } - if (!pEntity->IsLight()) - { - continue; - } - outEntityLights.push_back(pEntity); - } - } - - void OutputOpticsDebug(IOpticsElementBasePtr pOptics) - { - QString opticsName; - opticsName = QStringLiteral("Optics Name : %1\n").arg(pOptics->GetName().c_str()); - OutputDebugString(opticsName.toUtf8().data()); - - AZStd::vector groupArray(pOptics->GetEditorParamGroups()); - for (int i = 0, iGroupCount(groupArray.size()); i < iGroupCount; ++i) - { - FuncVariableGroup* pGroup = &groupArray[i]; - - QString groupStr; - groupStr = QStringLiteral("\tGroup : %1\n").arg(pGroup->GetName()); - OutputDebugString(groupStr.toUtf8().data()); - - for (int k = 0, iParamCount(pGroup->GetVariableCount()); k < iParamCount; ++k) - { - IFuncVariable* pVar = pGroup->GetVariable(k); - if (pVar == NULL) - { - continue; - } - QString str; - if (pVar->paramType == e_FLOAT) - { - str = QStringLiteral("\t\t%1 : %2\n").arg(pVar->name.c_str()).arg(pVar->GetFloat()); - } - else if (pVar->paramType == e_INT) - { - str = QStringLiteral("\t\t%1 : %2\n").arg(pVar->name.c_str()).arg(pVar->GetInt()); - } - else if (pVar->paramType == e_BOOL) - { - str = QStringLiteral("\t\t%1 : %2\n").arg(pVar->name.c_str(), pVar->GetBool() ? "TRUE" : "FALSE"); - } - else if (pVar->paramType == e_VEC2) - { - str = QStringLiteral("\t\t%1 : %2,%3\n").arg(pVar->name.c_str()).arg(pVar->GetVec2().x).arg(pVar->GetVec2().y); - } - else if (pVar->paramType == e_VEC3) - { - str = QStringLiteral("\t\t%1 : %2,%3,%4\n").arg(pVar->name.c_str()).arg(pVar->GetVec3().x).arg(pVar->GetVec3().y).arg(pVar->GetVec3().z); - } - else if (pVar->paramType == e_VEC4) - { - str = QStringLiteral("\t\t%1 : %2,%3,%4,%5\n").arg(pVar->name.c_str()).arg(pVar->GetVec4().x).arg(pVar->GetVec4().y).arg(pVar->GetVec4().z); - } - else if (pVar->paramType == e_COLOR) - { - str = QStringLiteral("\t\t%1 : %2,%3,%4,%5\n").arg(pVar->name.c_str()).arg(pVar->GetColorF().r).arg(pVar->GetColorF().g).arg(pVar->GetColorF().b).arg(pVar->GetColorF().a); - } - else if (pVar->paramType == e_TEXTURE2D || pVar->paramType == e_TEXTURE3D || pVar->paramType == e_TEXTURE_CUBE) - { - if (pVar->GetTexture()) - { - str = QStringLiteral("\t\t%1 : %2\n").arg(pVar->name.c_str(), pVar->GetTexture()->GetName()); - } - else - { - str = QStringLiteral("\t\t%1 : NULL\n").arg(pVar->name.c_str()); - } - } - OutputDebugString(str.toUtf8().data()); - } - } - - for (int i = 0, iChildCount(pOptics->GetElementCount()); i < iChildCount; ++i) - { - OutputOpticsDebug(pOptics->GetElementAt(i)); - } - } - - void FillParams(XmlNodeRef& paramNode, IOpticsElementBase* pOptics) - { - if (pOptics == NULL) - { - return; - } - AZStd::vector groupArray(pOptics->GetEditorParamGroups()); - for (int i = 0, iGroupCount(paramNode->getChildCount()); i < iGroupCount; ++i) - { - XmlNodeRef groupNode = paramNode->getChild(i); - if (groupNode == NULL) - { - continue; - } - - int nGroupIndex(0); - if (!FindGroup(groupNode->getTag(), pOptics, nGroupIndex)) - { - continue; - } - - FuncVariableGroup* pGroup = &groupArray[nGroupIndex]; - for (int k = 0, iParamCount(pGroup->GetVariableCount()); k < iParamCount; ++k) - { - IFuncVariable* pVar = pGroup->GetVariable(k); - if (pVar == NULL) - { - continue; - } - - if (pVar->paramType == e_FLOAT) - { - float fValue(0); - if (groupNode->getAttr(pVar->name.c_str(), fValue)) - { - pVar->InvokeSetter((void*)&fValue); - } - } - else if (pVar->paramType == e_INT) - { - int nValue(0); - if (groupNode->getAttr(pVar->name.c_str(), nValue)) - { - pVar->InvokeSetter((void*)&nValue); - } - } - else if (pVar->paramType == e_BOOL) - { - bool bValue(false); - if (groupNode->getAttr(pVar->name.c_str(), bValue)) - { - pVar->InvokeSetter((void*)&bValue); - } - } - else if (pVar->paramType == e_VEC2) - { - Vec2 vec2Value; - if (groupNode->getAttr(pVar->name.c_str(), vec2Value)) - { - pVar->InvokeSetter((void*)&vec2Value); - } - } - else if (pVar->paramType == e_VEC3) - { - Vec3 vec3Value; - if (groupNode->getAttr(pVar->name.c_str(), vec3Value)) - { - pVar->InvokeSetter((void*)&vec3Value); - } - } - else if (pVar->paramType == e_VEC4) - { - const char* strVec4Value; - if (groupNode->getAttr(pVar->name.c_str(), &strVec4Value)) - { - Vec4 vec4Value; - ExtractVec4FromString(strVec4Value, vec4Value); - pVar->InvokeSetter((void*)&vec4Value); - } - } - else if (pVar->paramType == e_COLOR) - { - Vec3 vec3Value; - if (!groupNode->getAttr(pVar->name.c_str(), vec3Value)) - { - continue; - } - string alphaStr = string(pVar->name.c_str()) + ".alpha"; - int alpha; - if (!groupNode->getAttr(alphaStr.c_str(), alpha)) - { - continue; - } - ColorF color; - color.r = vec3Value.x; - color.g = vec3Value.y; - color.b = vec3Value.z; - color.a = (float)alpha / 255.0f; - pVar->InvokeSetter((void*)&color); - } - else if (pVar->paramType == e_MATRIX33) - { - //reserved - } - else if (pVar->paramType == e_TEXTURE2D || pVar->paramType == e_TEXTURE3D || pVar->paramType == e_TEXTURE_CUBE) - { - const char* textureName; - if (!groupNode->getAttr(pVar->name.c_str(), &textureName)) - { - continue; - } - ITexture* pTexture = NULL; - if (textureName && strlen(textureName) > 0) - { - pTexture = gEnv->pRenderer->EF_LoadTexture(textureName); - } - pVar->InvokeSetter((void*)pTexture); - if (pTexture) - { - pTexture->Release(); - } - } - } - } - } - - void GetExpandedItemNames(CBaseLibraryItem* item, const QString& groupName, const QString& itemName, QString& outNameWithGroup, QString& outFullName) - { - QString name; - if (!groupName.isEmpty()) - { - name = groupName + "."; - } - name += itemName; - QString fullName = name; - if (item->GetLibrary()) - { - fullName = item->GetLibrary()->GetName() + "." + name; - } - outNameWithGroup = name; - outFullName = fullName; - } - - QModelIndex GetTreeItemByHitTest(QTreeView& treeCtrl) - { - return treeCtrl.indexAt(treeCtrl.mapFromGlobal(QCursor::pos())); - } - - int FindOpticsIndexUnderParentOptics(IOpticsElementBasePtr pOptics, IOpticsElementBasePtr pParentOptics) - { - for (int i = 0, iElementSize(pParentOptics->GetElementCount()); i < iElementSize; ++i) - { - if (pParentOptics->GetElementAt(i) == pOptics) - { - return i + 1; - } - } - return -1; - } -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.h deleted file mode 100644 index d9fb3e380c..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareUtil.h +++ /dev/null @@ -1,363 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUTIL_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUTIL_H -#pragma once - -#include -#include - -#include "Util/Variable.h" - -#include "IFlares.h" -class CEntityObject; - -class QTreeView; - -#define LENSFLARE_ELEMENT_TREE "LensFlareElementTree" -#define LENSFLARE_ITEM_TREE "LensFlareItemTree" -#define FLARECLIPBOARDTYPE_COPY "Copy" -#define FLARECLIPBOARDTYPE_CUT "Cut" - -namespace LensFlareUtil -{ - inline bool IsElement(EFlareType type) - { - return type != eFT__Base__ && type != eFT_Root && type != eFT_Group; - } - inline bool IsGroup(EFlareType type) - { - return type == eFT_Root || type == eFT_Group; - } - inline bool IsValidFlare(EFlareType type) - { - return type >= eFT__Base__ && type < eFT_Max; - } - - inline void AddVariable(CVariableBase& varArray, CVariableBase& var, const char* varName, const char* humanVarName, const char* description, char dataType = IVariable::DT_SIMPLE) - { - if (varName) - { - var.SetName(varName); - } - if (humanVarName) - { - var.SetHumanName(humanVarName); - } - if (description) - { - var.SetDescription(description); - } - var.SetDataType(dataType); - varArray.AddVariable(&var); - } - - inline void AddVariable(CVarBlock* vars, CVariableBase& var, const char* varName, const char* humanVarName, const char* description, unsigned char dataType = IVariable::DT_SIMPLE) - { - if (varName) - { - var.SetName(varName); - } - if (humanVarName) - { - var.SetHumanName(humanVarName); - } - if (description) - { - var.SetDescription(description); - } - var.SetDataType(dataType); - vars->AddVariable(&var); - } - - inline bool GetFlareType(const QString& typeName, EFlareType& outType) - { - FlareInfoArray::Props array = FlareInfoArray::Get(); - for (size_t i = 0; i < array.size; ++i) - { - if (typeName == array.p[i].name) - { - outType = array.p[i].type; - return true; - } - } - return false; - } - - inline bool GetFlareTypeName(QString& outTypeName, IOpticsElementBasePtr pOptics) - { - if (pOptics == NULL) - { - return false; - } - - const FlareInfoArray::Props array = FlareInfoArray::Get(); - for (size_t i = 0; i < array.size; ++i) - { - if (array.p[i].type == pOptics->GetType()) - { - outTypeName = array.p[i].name; - return true; - } - } - - return false; - } - - inline QString GetShortName(const QString& name) - { - int nPos = name.lastIndexOf('.'); - if (nPos == -1) - { - return name; - } - return name.right(name.length() - nPos - 1); - } - - inline QString GetGroupNameFromName(const QString& name) - { - int nPos = name.lastIndexOf('.'); - if (nPos == -1) - { - return name; - } - return name.left(nPos); - } - - inline QString GetGroupNameFromFullName(const QString& fullItemName) - { - int nLastDotPos = fullItemName.lastIndexOf('.'); - if (nLastDotPos == -1) - { - return fullItemName; - } - - QString name = GetGroupNameFromName(fullItemName); - - int nFirstDotPos = name.indexOf('.'); - if (nFirstDotPos == -1) - { - return name; - } - - return name.right(name.length() - nFirstDotPos - 1); - } - - inline bool HaveParameterLowBoundary(const QString& paramName) - { - if (!QString::compare(paramName, "Noiseseed", Qt::CaseInsensitive) || !QString::compare(paramName, "translation", Qt::CaseInsensitive) || !QString::compare(paramName, "position", Qt::CaseInsensitive) || !QString::compare(paramName, "rotation", Qt::CaseInsensitive)) - { - return false; - } - return true; - } - - inline int MakeFuncKey(int nGroupIndex, int nVarIndex) - { - return (nGroupIndex << 16) | nVarIndex; - } - - template - inline void BoundaryProcess(T& fValue) - { - if (fValue < 0) - { - fValue = 0; - } - } - - inline void BoundaryProcess(Vec2& v) - { - if (v.x < 0) - { - v.x = 0; - } - if (v.y < 0) - { - v.y = 0; - } - } - - inline void BoundaryProcess(Vec3& v) - { - if (v.x < 0) - { - v.x = 0; - } - if (v.y < 0) - { - v.y = 0; - } - if (v.z < 0) - { - v.z = 0; - } - } - - inline void BoundaryProcess(Vec4& v) - { - if (v.x < 0) - { - v.x = 0; - } - if (v.y < 0) - { - v.y = 0; - } - if (v.z < 0) - { - v.z = 0; - } - if (v.w < 0) - { - v.w = 0; - } - } - - inline bool ExtractVec4FromString(const string& buffer, Vec4& outVec4) - { - int nCount(0); - string copiedBuffer(buffer); - int commaPos(0); - while (nCount < 4 || commaPos != -1) - { - commaPos = copiedBuffer.find(","); - string strV; - if (commaPos == -1) - { - strV = copiedBuffer; - } - else - { - strV = copiedBuffer.Left(commaPos); - strV += ","; - } - copiedBuffer.replace(0, commaPos + 1, ""); - outVec4[nCount++] = (float)atof(strV.c_str()); - } - return nCount == 4; - } - - void FillParams(XmlNodeRef& paramNode, IOpticsElementBase* pOptics); - - inline bool FindGroup(const char* groupName, IOpticsElementBase* pOptics, int& nOutGroupIndex) - { - if (groupName == NULL) - { - return false; - } - - AZStd::vector groupArray = pOptics->GetEditorParamGroups(); - for (int i = 0, iCount(groupArray.size()); i < iCount; ++i) - { - if (!_stricmp(groupArray[i].GetName(), groupName)) - { - nOutGroupIndex = i; - return true; - } - } - return false; - } - - struct SClipboardData - { - SClipboardData(){} - ~SClipboardData(){} - SClipboardData(const QString& from, const QString& lensFlareFullPath, const QString& lensOpticsPath) - : m_From(from) - , m_LensFlareFullPath(lensFlareFullPath) - , m_LensOpticsPath(lensOpticsPath) - { - } - - void FillXmlNode(XmlNodeRef node) - { - if (node == NULL) - { - return; - } - node->setAttr("From", m_From.toUtf8().data()); - node->setAttr("FlareFullPath", m_LensFlareFullPath.toUtf8().data()); - node->setAttr("OpticsPath", m_LensOpticsPath.toUtf8().data()); - } - - void FillThisFromXmlNode(XmlNodeRef node) - { - if (node == NULL) - { - return; - } - node->getAttr("From", m_From); - node->getAttr("FlareFullPath", m_LensFlareFullPath); - node->getAttr("OpticsPath", m_LensOpticsPath); - } - - QString m_From; - QString m_LensFlareFullPath; - QString m_LensOpticsPath; - }; - - struct SDragAndDropInfo - { - SDragAndDropInfo() - { - m_XMLContents = NULL; - m_bDragging = false; - } - ~SDragAndDropInfo() - { - Reset(); - } - void Reset() - { - m_XMLContents = NULL; - m_bDragging = false; - } - bool m_bDragging; - XmlNodeRef m_XMLContents; - }; - - inline SDragAndDropInfo& GetDragDropInfo() - { - static SDragAndDropInfo dragDropInfo; - return dragDropInfo; - } - - int FindOpticsIndexUnderParentOptics(IOpticsElementBasePtr pOptics, IOpticsElementBasePtr pParentOptics); - bool IsPointInWindow(const QWidget* pWindow, const QPoint& screenPos); - QModelIndex GetTreeItemByHitTest(QTreeView& treeCtrl); - QPoint GetDragCursorPos(QWidget* pWnd, const QPoint& point); - void GetExpandedItemNames(CBaseLibraryItem* item, const QString& groupName, const QString& itemName, QString& outNameWithGroup, QString& outFullName); - void GetSelectedLightEntities(std::vector& outLightEntities); - void GetLightEntityObjects(std::vector& outEntityLights); - IFuncVariable* GetFuncVariable(IOpticsElementBasePtr pOptics, int nFuncKey); - QString ReplaceLastName(const QString& fullName, const QString& shortName); - void UpdateOpticsName(IOpticsElementBasePtr pOptics); - XmlNodeRef CreateXMLFromClipboardData(const QString& type, const QString& groupName, bool bPasteAtSameLevel, std::vector& dataList); - void UpdateClipboard(const QString& type, const QString& groupName, bool bPasteAtSameLevel, std::vector& dataList); - void ChangeOpticsRootName(IOpticsElementBasePtr pOptics, const QString& newRootName); - void RemoveOptics(IOpticsElementBasePtr pOptics); - IOpticsElementBasePtr FindOptics(IOpticsElementBasePtr pStartOptics, const QString& name); - CEntityObject* GetSelectedLightEntity(); - IOpticsElementBasePtr GetSelectedLightOptics(); - IOpticsElementBasePtr CreateOptics(const XmlNodeRef& xmlNode); - IOpticsElementBasePtr CreateOptics(IOpticsElementBasePtr pOptics, bool bForceTypeToGroup = false); - bool FillOpticsFromXML(IOpticsElementBasePtr pOptics, const XmlNodeRef& xmlNode); - bool CreateXmlData(IOpticsElementBasePtr pOptics, XmlNodeRef& pOutNode); - void SetVariablesTemplateFromOptics(IOpticsElementBasePtr pOptics, CVarBlockPtr& pRootVar, std::vector& funcs); - void SetVariablesTemplateFromOptics(IOpticsElementBasePtr pOptics, CVarBlockPtr& pRootVar); - void CopyOptics(IOpticsElementBasePtr pSrcOptics, IOpticsElementBasePtr pDestOptics, bool bReculsiveCopy = true); - void OutputOpticsDebug(IOpticsElementBasePtr pOptics); -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREUTIL_H diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.cpp b/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.cpp deleted file mode 100644 index 05248b32f5..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "EditorDefs.h" - -#include "LensFlareView.h" - -// Editor -#include "LensFlareItem.h" -#include "LensFlareEditor.h" -#include "Objects/EntityObject.h" -#include "Material/MaterialManager.h" - - -CLensFlareView::CLensFlareView(QWidget* parent, Qt::WindowFlags f) - : CPreviewModelCtrl(parent, f) -{ - InitDialog(); -} - -CLensFlareView::~CLensFlareView() -{ - CLensFlareEditor::GetLensFlareEditor()->UnregisterLensFlareItemChangeListener(this); -} - -void CLensFlareView::InitDialog() -{ - CLensFlareEditor::GetLensFlareEditor()->RegisterLensFlareItemChangeListener(this); - - SetClearColor(ColorF(0, 0, 0, 0)); - SetGrid(true); - SetAxis(true); - EnableUpdate(true); - m_pLensFlareMaterial = GetIEditor()->GetMaterialManager()->LoadMaterial(CEntityObject::s_LensFlareMaterialName); - m_InitCameraPos = m_camera.GetPosition(); -} - -void CLensFlareView::RenderObject(_smart_ptr pMaterial, [[maybe_unused]] SRenderingPassInfo& passInfo) -{ - if (m_pLensFlareItem) - { - IOpticsElementBasePtr pOptics = m_pLensFlareItem->GetOptics(); - if (pOptics && m_pLensFlareMaterial) - { - _smart_ptr pMaterial = m_pLensFlareMaterial->GetMatInfo(); - if (pMaterial) - { - m_pRenderer->ForceUpdateGlobalShaderParameters(); - m_pRenderer->SetViewport(1, 1, m_pRenderer->GetWidth(), m_pRenderer->GetHeight()); - SShaderItem& shaderItem = pMaterial->GetShaderItem(); - SLensFlareRenderParam param; - param.pCamera = &m_camera; - param.pShader = shaderItem.m_pShader; - pOptics->Render(¶m, Vec3(0, 0, 0)); - } - } - } -} - -void CLensFlareView::OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem) -{ - if (m_pLensFlareItem != pLensFlareItem) - { - m_pLensFlareItem = pLensFlareItem; - Update(true); - m_bHaveAnythingToRender = m_pLensFlareItem != NULL; - } -} - -void CLensFlareView::OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem) -{ - if (m_pLensFlareItem == pLensFlareItem) - { - m_pLensFlareItem = NULL; - Update(); - m_bHaveAnythingToRender = false; - } -} - -void CLensFlareView::OnInternalVariableChange([[maybe_unused]] IVariable* pVar) -{ - Update(); -} - -void CLensFlareView::OnLensFlareChangeElement([[maybe_unused]] CLensFlareElement* pLensFlareElement) -{ - Update(); -} - -void CLensFlareView::OnEditorNotifyEvent(EEditorNotifyEvent event) -{ - switch (event) - { - case eNotify_OnCloseScene: - ReleaseObject(); - break; - } -} diff --git a/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.h b/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.h deleted file mode 100644 index f514211046..0000000000 --- a/Code/Sandbox/Editor/LensFlareEditor/LensFlareView.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREVIEW_H -#define CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREVIEW_H -#pragma once - -#include "ILensFlareListener.h" -#include "Controls/PreviewModelCtrl.h" - -class CLensFlareView - : public CPreviewModelCtrl - , public ILensFlareChangeItemListener - , public ILensFlareChangeElementListener -{ -public: - explicit CLensFlareView(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); - ~CLensFlareView(); - - void OnInternalVariableChange(IVariable* pVar); - void OnEditorNotifyEvent(EEditorNotifyEvent event); - -protected: - - void InitDialog(); - void ProcessKeys(){} - void RenderObject(_smart_ptr pMaterial, SRenderingPassInfo& passInfo); - - void OnLensFlareChangeItem(CLensFlareItem* pLensFlareItem); - void OnLensFlareDeleteItem(CLensFlareItem* pLensFlareItem); - void OnLensFlareChangeElement(CLensFlareElement* pLensFlareElement); - -private: - - QPoint m_prevPoint; - Vec3 m_InitCameraPos; - - _smart_ptr m_pLensFlareMaterial; - _smart_ptr m_pLensFlareItem; -}; -#endif // CRYINCLUDE_EDITOR_LENSFLAREEDITOR_LENSFLAREVIEW_H diff --git a/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h b/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h index 27ac7e8a46..45810da2cf 100644 --- a/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h +++ b/Code/Sandbox/Editor/Lib/Tests/IEditorMock.h @@ -96,7 +96,6 @@ public: MOCK_METHOD0(GetIEditorMaterialManager, IEditorMaterialManager* ()); MOCK_METHOD0(GetIconManager, IIconManager* ()); MOCK_METHOD0(GetMusicManager, CMusicManager* ()); - MOCK_METHOD0(GetLensFlareManager, CLensFlareManager* ()); MOCK_METHOD2(GetTerrainElevation, float(float , float )); MOCK_METHOD0(GetVegetationMap, class CVegetationMap* ()); MOCK_METHOD0(GetEditorQtApplication, Editor::EditorQtApplication* ()); diff --git a/Code/Sandbox/Editor/LyViewPaneNames.h b/Code/Sandbox/Editor/LyViewPaneNames.h index 3ea793b9c7..fdbf8bf90c 100644 --- a/Code/Sandbox/Editor/LyViewPaneNames.h +++ b/Code/Sandbox/Editor/LyViewPaneNames.h @@ -44,7 +44,6 @@ namespace LyViewPane static const char* const TerrainTool = "Terrain Tool"; static const char* const TerrainTextureLayers = "Terrain Texture Layers"; static const char* const ParticleEditor = "Particle Editor"; - static const char* const LensFlareEditor = "Lens Flare Editor"; static const char* const TimeOfDayEditor = "Time Of Day"; static const char* const AudioControlsEditor = "Audio Controls Editor"; static const char* const SubstanceEditor = "Substance Editor"; diff --git a/Code/Sandbox/Editor/MainWindow.cpp b/Code/Sandbox/Editor/MainWindow.cpp index 0ac7da33a7..96f4da7312 100644 --- a/Code/Sandbox/Editor/MainWindow.cpp +++ b/Code/Sandbox/Editor/MainWindow.cpp @@ -91,7 +91,6 @@ AZ_POP_DISABLE_WARNING #include "TrackView/TrackViewDialog.h" #include "ErrorReportDialog.h" -#include "LensFlareEditor/LensFlareEditor.h" #include "TimeOfDayDialog.h" #include "Dialogs/PythonScriptsDialog.h" @@ -1657,7 +1656,6 @@ void MainWindow::RegisterStdViewClasses() if (!AZ::Interface::Get()) { - CLensFlareEditor::RegisterViewClass(); CTimeOfDayDialog::RegisterViewClass(); } #ifdef ThumbnailDemo diff --git a/Code/Sandbox/Editor/Objects/EntityObject.cpp b/Code/Sandbox/Editor/Objects/EntityObject.cpp index 8beda36013..9e91fee940 100644 --- a/Code/Sandbox/Editor/Objects/EntityObject.cpp +++ b/Code/Sandbox/Editor/Objects/EntityObject.cpp @@ -29,18 +29,11 @@ #include "Include/IObjectManager.h" #include "Objects/ObjectManager.h" #include "ViewManager.h" -#include "LensFlareEditor/LensFlareManager.h" -#include "LensFlareEditor/LensFlareUtil.h" -#include "LensFlareEditor/LensFlareLibrary.h" #include "AnimationContext.h" #include "HitContext.h" #include "Objects/SelectionGroup.h" -const char* CEntityObject::s_LensFlarePropertyName("flare_Flare"); -const char* CEntityObject::s_LensFlareMaterialName("EngineAssets/Materials/lens_optics"); - - ////////////////////////////////////////////////////////////////////////// //! Undo Entity Link class CUndoEntityLink @@ -1985,14 +1978,7 @@ void CEntityObject::SetOpticsElement(IOpticsElementBase* pOptics) return; } pLight->SetLensOpticsElement(pOptics); - if (GetEntityPropertyBool("bFlareEnable") && pOptics) - { - CBaseObject::SetMaterial(s_LensFlareMaterialName); - } - else - { - SetMaterial(NULL); - } + SetMaterial(NULL); } ////////////////////////////////////////////////////////////////////////// @@ -2005,7 +1991,6 @@ void CEntityObject::ApplyOptics(const QString& opticsFullName, IOpticsElementBas { pLight->SetLensOpticsElement(NULL); } - SetFlareName(""); SetMaterial(NULL); } else @@ -2024,9 +2009,7 @@ void CEntityObject::ApplyOptics(const QString& opticsFullName, IOpticsElementBas } return; } - LensFlareUtil::CopyOptics(pOptics, pNewOptics); } - SetFlareName(opticsFullName); } } @@ -2040,19 +2023,8 @@ void CEntityObject::SetOpticsName(const QString& opticsFullName) { pLight->SetLensOpticsElement(NULL); } - SetFlareName(""); SetMaterial(NULL); } - else - { - if (GetOpticsElement()) - { - if (gEnv->pOpticsManager->Rename(GetOpticsElement()->GetName(), opticsFullName.toUtf8().data())) - { - SetFlareName(opticsFullName); - } - } - } } ////////////////////////////////////////////////////////////////////////// @@ -2080,27 +2052,6 @@ CDLight* CEntityObject::GetLightProperty() const return NULL; } -////////////////////////////////////////////////////////////////////////// -bool CEntityObject::GetValidFlareName(QString& outFlareName) const -{ - IVariable* pFlareVar(m_pProperties->FindVariable(s_LensFlarePropertyName)); - if (!pFlareVar) - { - return false; - } - - QString flareName; - pFlareVar->Get(flareName); - if (flareName.isEmpty() || flareName == "@root") - { - return false; - } - - outFlareName = flareName; - - return true; -} - ////////////////////////////////////////////////////////////////////////// void CEntityObject::PreInitLightProperty() { @@ -2108,42 +2059,6 @@ void CEntityObject::PreInitLightProperty() { return; } - - QString flareFullName; - if (GetValidFlareName(flareFullName)) - { - bool bEnableOptics = GetEntityPropertyBool("bFlareEnable"); - if (bEnableOptics) - { - CLensFlareManager* pLensManager = GetIEditor()->GetLensFlareManager(); - CLensFlareLibrary* pLevelLib = (CLensFlareLibrary*)pLensManager->GetLevelLibrary(); - IOpticsElementBasePtr pLevelOptics = pLevelLib->GetOpticsOfItem(flareFullName.toUtf8().data()); - if (pLevelLib && pLevelOptics) - { - int nOpticsIndex(0); - IOpticsElementBasePtr pNewOptics = GetOpticsElement(); - if (pNewOptics == NULL) - { - pNewOptics = gEnv->pOpticsManager->Create(eFT_Root); - } - - if (gEnv->pOpticsManager->AddOptics(pNewOptics, flareFullName.toUtf8().data(), nOpticsIndex)) - { - LensFlareUtil::CopyOptics(pLevelOptics, pNewOptics); - SetOpticsElement(pNewOptics); - } - else - { - CDLight* pLight = GetLightProperty(); - if (pLight) - { - pLight->SetLensOpticsElement(NULL); - SetMaterial(NULL); - } - } - } - } - } } ////////////////////////////////////////////////////////////////////////// @@ -2153,26 +2068,6 @@ void CEntityObject::UpdateLightProperty() { return; } - - QString flareName; - if (GetValidFlareName(flareName)) - { - IOpticsElementBasePtr pOptics = GetOpticsElement(); - if (pOptics == NULL) - { - pOptics = gEnv->pOpticsManager->Create(eFT_Root); - } - bool bEnableOptics = GetEntityPropertyBool("bFlareEnable"); - if (bEnableOptics && GetIEditor()->GetLensFlareManager()->LoadFlareItemByName(flareName, pOptics)) - { - pOptics->SetName(flareName.toUtf8().data()); - SetOpticsElement(pOptics); - } - else - { - SetOpticsElement(NULL); - } - } } ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/Objects/EntityObject.h b/Code/Sandbox/Editor/Objects/EntityObject.h index 9964cbd72f..923e83b4e6 100644 --- a/Code/Sandbox/Editor/Objects/EntityObject.h +++ b/Code/Sandbox/Editor/Objects/EntityObject.h @@ -224,7 +224,6 @@ public: void SetOpticsElement(IOpticsElementBase* pOptics); void ApplyOptics(const QString& opticsFullName, IOpticsElementBasePtr pOptics); void SetOpticsName(const QString& opticsFullName); - bool GetValidFlareName(QString& outFlareName) const; void PreInitLightProperty(); void UpdateLightProperty(); @@ -236,9 +235,6 @@ public: static void StoreUndoEntityLink(CSelectionGroup* pGroup); - static const char* s_LensFlarePropertyName; - static const char* s_LensFlareMaterialName; - void RegisterListener(IEntityObjectListener* pListener); void UnregisterListener(IEntityObjectListener* pListener); @@ -322,11 +318,6 @@ protected: void AdjustLightProperties(CVarBlockPtr& properties, const char* pSubBlock); IVariable* FindVariableInSubBlock(CVarBlockPtr& properties, IVariable* pSubBlockVar, const char* pVarName); - void SetFlareName(const QString& name) - { - SetEntityPropertyString(s_LensFlarePropertyName, name); - } - unsigned int m_bLoadFailed : 1; unsigned int m_bCalcPhysics : 1; unsigned int m_bDisplayBBox : 1; diff --git a/Code/Sandbox/Editor/Style/LensFlareEditor.qss b/Code/Sandbox/Editor/Style/LensFlareEditor.qss deleted file mode 100644 index 58d99c9f92..0000000000 --- a/Code/Sandbox/Editor/Style/LensFlareEditor.qss +++ /dev/null @@ -1,17 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#DatabaseFrameWnd QToolBar -{ - border-bottom: 2px solid #111111; -} - diff --git a/Code/Sandbox/Editor/Style/resources.qrc b/Code/Sandbox/Editor/Style/resources.qrc index aa32f29555..aec7e2cf68 100644 --- a/Code/Sandbox/Editor/Style/resources.qrc +++ b/Code/Sandbox/Editor/Style/resources.qrc @@ -4,6 +4,5 @@ EditorPreferencesDialog.qss LayoutConfigDialog.qss GraphicsSettingsDialog.qss - LensFlareEditor.qss diff --git a/Code/Sandbox/Editor/Util/Variable.h b/Code/Sandbox/Editor/Util/Variable.h index ab43d24e94..20c18d4409 100644 --- a/Code/Sandbox/Editor/Util/Variable.h +++ b/Code/Sandbox/Editor/Util/Variable.h @@ -163,7 +163,7 @@ struct IVariable DT_LIGHT_ANIMATION, // Light Animation Node in the global Light Animation Set DT_PARTICLE_EFFECT, DT_GEOM_CACHE, // Geometry cache - DT_FLARE, + DT_DEPRECATED, // formerly DT_FLARE DT_AUDIO_TRIGGER, DT_AUDIO_SWITCH, DT_AUDIO_SWITCH_STATE, diff --git a/Code/Sandbox/Editor/Util/VariablePropertyType.cpp b/Code/Sandbox/Editor/Util/VariablePropertyType.cpp index 5a3029807b..c80461182d 100644 --- a/Code/Sandbox/Editor/Util/VariablePropertyType.cpp +++ b/Code/Sandbox/Editor/Util/VariablePropertyType.cpp @@ -58,7 +58,6 @@ namespace Prop { IVariable::DT_USERITEMCB, "User", ePropertyUser, -1 }, { IVariable::DT_SEQUENCE_ID, "SequenceId", ePropertySequenceId, -1 }, { IVariable::DT_LIGHT_ANIMATION, "LightAnimation", ePropertyLightAnimation, -1 }, - { IVariable::DT_FLARE, "Flare", ePropertyFlare, 7 }, { IVariable::DT_PARTICLE_EFFECT, "ParticleEffect", ePropertyParticleName, 3 }, { IVariable::DT_GEOM_CACHE, "Geometry Cache", ePropertyGeomCache, 5 }, { IVariable::DT_AUDIO_TRIGGER, "Audio Trigger", ePropertyAudioTrigger, 6 }, diff --git a/Code/Sandbox/Editor/Util/VariablePropertyType.h b/Code/Sandbox/Editor/Util/VariablePropertyType.h index 86fc8e9c0f..76379c1bc0 100644 --- a/Code/Sandbox/Editor/Util/VariablePropertyType.h +++ b/Code/Sandbox/Editor/Util/VariablePropertyType.h @@ -50,7 +50,7 @@ enum PropertyType ePropertyUser, ePropertySequenceId, ePropertyLightAnimation, - ePropertyFlare, + ePropertyDeprecated1, // formerly ePropertyFlare ePropertyParticleName, ePropertyGeomCache, ePropertyAudioTrigger, diff --git a/Code/Sandbox/Editor/editor_files.cmake b/Code/Sandbox/Editor/editor_files.cmake index 50521d23aa..9acfb2aaf8 100644 --- a/Code/Sandbox/Editor/editor_files.cmake +++ b/Code/Sandbox/Editor/editor_files.cmake @@ -13,6 +13,5 @@ set(FILES main.cpp Style/Editor.qss Style/resources.qrc - Style/LensFlareEditor.qss EditorCryEdit.rc ) diff --git a/Code/Sandbox/Editor/editor_lib_files.cmake b/Code/Sandbox/Editor/editor_lib_files.cmake index 80ec582d19..e6337796d6 100644 --- a/Code/Sandbox/Editor/editor_lib_files.cmake +++ b/Code/Sandbox/Editor/editor_lib_files.cmake @@ -545,9 +545,6 @@ set(FILES Geometry/TriMesh.h AboutDialog.h AboutDialog.ui - DatabaseFrameWnd.h - DatabaseFrameWnd.ui - DatabaseFrameWnd.qrc DocMultiArchive.h EditMode/DeepSelection.h FBXExporterDialog.h @@ -571,31 +568,6 @@ set(FILES WipFeaturesDlg.qrc LevelIndependentFileMan.cpp LevelIndependentFileMan.h - LensFlareEditor/ILensFlareListener.h - LensFlareEditor/LensFlareAtomicList.cpp - LensFlareEditor/LensFlareAtomicList.h - LensFlareEditor/LensFlareEditor.cpp - LensFlareEditor/LensFlareEditor.h - LensFlareEditor/LensFlareElement.cpp - LensFlareEditor/LensFlareElement.h - LensFlareEditor/LensFlareElementTree.cpp - LensFlareEditor/LensFlareElementTree.h - LensFlareEditor/LensFlareItem.cpp - LensFlareEditor/LensFlareItem.h - LensFlareEditor/LensFlareItemTree.cpp - LensFlareEditor/LensFlareItemTree.h - LensFlareEditor/LensFlareLibrary.cpp - LensFlareEditor/LensFlareLibrary.h - LensFlareEditor/LensFlareLightEntityTree.cpp - LensFlareEditor/LensFlareLightEntityTree.h - LensFlareEditor/LensFlareManager.cpp - LensFlareEditor/LensFlareManager.h - LensFlareEditor/LensFlareUndo.cpp - LensFlareEditor/LensFlareUndo.h - LensFlareEditor/LensFlareUtil.cpp - LensFlareEditor/LensFlareUtil.h - LensFlareEditor/LensFlareView.cpp - LensFlareEditor/LensFlareView.h LogFileImpl.cpp LogFileImpl.h MatEditPreviewDlg.cpp @@ -706,7 +678,6 @@ set(FILES GraphicsSettingsDialog.cpp graphicssettingsdialog.ui AboutDialog.cpp - DatabaseFrameWnd.cpp ErrorReportTableModel.h ErrorReportTableModel.cpp EditMode/DeepSelection.cpp