From c51d79cc4282a11847872e0d2fd339006362fad1 Mon Sep 17 00:00:00 2001 From: Aruki Date: Wed, 1 Feb 2017 10:54:53 -0700 Subject: [PATCH] Added "edit" button to resource selector context menu --- .../Animation/CAnimationParameters.cpp | 27 +++++---- src/Core/Resource/CResTypeInfo.cpp | 1 + src/Editor/CEditorApplication.cpp | 60 ++++++++++++++++++- src/Editor/CEditorApplication.h | 3 + src/Editor/CStartWindow.cpp | 2 - .../CharacterEditor/CCharacterEditor.cpp | 4 +- src/Editor/CharacterEditor/CCharacterEditor.h | 2 +- src/Editor/ModelEditor/CModelEditorWindow.cpp | 4 +- src/Editor/ModelEditor/CModelEditorWindow.h | 2 +- src/Editor/PropertyEdit/CPropertyDelegate.cpp | 4 -- .../ResourceBrowser/CResourceBrowser.cpp | 35 +---------- .../ResourceBrowser/CResourceTableModel.h | 24 +------- src/Editor/Widgets/CResourceSelector.cpp | 40 ++++++++++--- src/Editor/Widgets/CResourceSelector.h | 2 + 14 files changed, 124 insertions(+), 86 deletions(-) diff --git a/src/Core/Resource/Animation/CAnimationParameters.cpp b/src/Core/Resource/Animation/CAnimationParameters.cpp index 06e33ed0..f4cc6d98 100644 --- a/src/Core/Resource/Animation/CAnimationParameters.cpp +++ b/src/Core/Resource/Animation/CAnimationParameters.cpp @@ -178,19 +178,24 @@ u32 CAnimationParameters::Unknown(u32 Index) void CAnimationParameters::SetResource(const CAssetID& rkID) { - mCharacterID = rkID; - mCharIndex = 0; - mAnimIndex = 0; - - // Validate ID - if (mCharacterID.IsValid()) + if (mCharacterID != rkID) { - CResourceEntry *pEntry = gpResourceStore->FindEntry(rkID); + mCharacterID = rkID; + mCharIndex = 0; + mAnimIndex = 0; + mUnknown2 = 0; + mUnknown3 = 0; - if (!pEntry) - Log::Error("Invalid resource ID passed to CAnimationParameters: " + rkID.ToString()); - else if (pEntry->ResourceType() != eAnimSet) - Log::Error("Resource with invalid type passed to CAnimationParameters: " + pEntry->CookedAssetPath().GetFileName()); + // Validate ID + if (mCharacterID.IsValid()) + { + CResourceEntry *pEntry = gpResourceStore->FindEntry(rkID); + + if (!pEntry) + Log::Error("Invalid resource ID passed to CAnimationParameters: " + rkID.ToString()); + else if (pEntry->ResourceType() != eAnimSet) + Log::Error("Resource with invalid type passed to CAnimationParameters: " + pEntry->CookedAssetPath().GetFileName()); + } } } diff --git a/src/Core/Resource/CResTypeInfo.cpp b/src/Core/Resource/CResTypeInfo.cpp index ce8e34ca..deb69695 100644 --- a/src/Core/Resource/CResTypeInfo.cpp +++ b/src/Core/Resource/CResTypeInfo.cpp @@ -297,6 +297,7 @@ void CResTypeInfo::CResTypeInfoFactory::InitTypes() { CResTypeInfo *pType = new CResTypeInfo(eSaveWorld, "World Save Info"); AddExtension(pType, "SAVW", ePrime, eReturns); + pType->mHidden = true; } { CResTypeInfo *pType = new CResTypeInfo(eScan, "Scan"); diff --git a/src/Editor/CEditorApplication.cpp b/src/Editor/CEditorApplication.cpp index 60817d12..3525f47b 100644 --- a/src/Editor/CEditorApplication.cpp +++ b/src/Editor/CEditorApplication.cpp @@ -2,11 +2,14 @@ #include "IEditor.h" #include "CBasicViewport.h" #include "CProjectOverviewDialog.h" +#include "Editor/CharacterEditor/CCharacterEditor.h" +#include "Editor/ModelEditor/CModelEditorWindow.h" #include "Editor/ResourceBrowser/CResourceBrowser.h" #include "Editor/WorldEditor/CWorldEditor.h" #include #include #include +#include CEditorApplication::CEditorApplication(int& rArgc, char **ppArgv) : QApplication(rArgc, ppArgv) @@ -23,7 +26,6 @@ CEditorApplication::CEditorApplication(int& rArgc, char **ppArgv) CEditorApplication::~CEditorApplication() { delete mpWorldEditor; - delete mpResourceBrowser; delete mpProjectDialog; } @@ -35,6 +37,53 @@ void CEditorApplication::InitEditor() connect(mpProjectDialog, SIGNAL(ActiveProjectChanged(CGameProject*)), mpResourceBrowser, SLOT(RefreshResources())); } +void CEditorApplication::EditResource(CResourceEntry *pEntry) +{ + ASSERT(pEntry != nullptr); + + // Check if we're already editing this resource + if (mEditingMap.contains(pEntry)) + { + IEditor *pEd = mEditingMap[pEntry]; + pEd->show(); + pEd->raise(); + } + + else + { + // Attempt to load asset + CResource *pRes = pEntry->Load(); + + if (!pRes) + { + QMessageBox::warning(nullptr, "Error", "Failed to load resource!"); + return; + } + + // Launch editor window + IEditor *pEd = nullptr; + + switch (pEntry->ResourceType()) + { + case eModel: + pEd = new CModelEditorWindow((CModel*) pRes, mpWorldEditor); + break; + + case eAnimSet: + pEd = new CCharacterEditor((CAnimSet*) pRes, mpWorldEditor); + break; + } + + if (pEd) + { + pEd->show(); + mEditingMap[pEntry] = pEd; + } + else + QMessageBox::information(0, "Unsupported Resource", "This resource type is currently unsupported for editing."); + } +} + void CEditorApplication::AddEditor(IEditor *pEditor) { mEditorWindows << pEditor; @@ -80,6 +129,15 @@ void CEditorApplication::OnEditorClose() if (qobject_cast(pEditor) == nullptr) { + for (auto Iter = mEditingMap.begin(); Iter != mEditingMap.end(); Iter++) + { + if (Iter.value() == pEditor) + { + mEditingMap.erase(Iter); + break; + } + } + mEditorWindows.removeOne(pEditor); delete pEditor; } diff --git a/src/Editor/CEditorApplication.h b/src/Editor/CEditorApplication.h index 9fa70c78..6a48ab5d 100644 --- a/src/Editor/CEditorApplication.h +++ b/src/Editor/CEditorApplication.h @@ -8,6 +8,7 @@ class CBasicViewport; class CProjectOverviewDialog; class CResourceBrowser; +class CResourceEntry; class CWorldEditor; class IEditor; @@ -20,12 +21,14 @@ class CEditorApplication : public QApplication CResourceBrowser *mpResourceBrowser; CProjectOverviewDialog *mpProjectDialog; QVector mEditorWindows; + QMap mEditingMap; double mLastUpdate; public: CEditorApplication(int& rArgc, char **ppArgv); ~CEditorApplication(); void InitEditor(); + void EditResource(CResourceEntry *pEntry); // Accessors inline CWorldEditor* WorldEditor() const { return mpWorldEditor; } diff --git a/src/Editor/CStartWindow.cpp b/src/Editor/CStartWindow.cpp index 0e282611..a1debe8e 100644 --- a/src/Editor/CStartWindow.cpp +++ b/src/Editor/CStartWindow.cpp @@ -23,8 +23,6 @@ CStartWindow::CStartWindow(QWidget *parent) mpWorld = nullptr; mpWorldEditor = new CWorldEditor(0); - mpModelEditor = new CModelEditorWindow(this); - mpCharEditor = new CCharacterEditor(this); connect(ui->ActionAbout, SIGNAL(triggered()), this, SLOT(About())); connect(ui->ActionCharacterEditor, SIGNAL(triggered()), this, SLOT(LaunchCharacterEditor())); diff --git a/src/Editor/CharacterEditor/CCharacterEditor.cpp b/src/Editor/CharacterEditor/CCharacterEditor.cpp index 0fabcf4f..4af2afa6 100644 --- a/src/Editor/CharacterEditor/CCharacterEditor.cpp +++ b/src/Editor/CharacterEditor/CCharacterEditor.cpp @@ -10,7 +10,7 @@ const CVector3f CCharacterEditor::skDefaultOrbitTarget = CVector3f(0,0,1); const float CCharacterEditor::skDefaultOrbitDistance = 4.f; -CCharacterEditor::CCharacterEditor(QWidget *parent) +CCharacterEditor::CCharacterEditor(CAnimSet *pSet, QWidget *parent) : IEditor(parent) , ui(new Ui::CCharacterEditor) , mpScene(new CScene()) @@ -74,6 +74,8 @@ CCharacterEditor::CCharacterEditor(QWidget *parent) ui->splitter->setSizes(SplitterSizes); connect(ui->SkeletonHierarchyTreeView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(OnSkeletonTreeSelectionChanged(QModelIndex))); + + SetActiveAnimSet(pSet); } CCharacterEditor::~CCharacterEditor() diff --git a/src/Editor/CharacterEditor/CCharacterEditor.h b/src/Editor/CharacterEditor/CCharacterEditor.h index ef72d84d..c3414598 100644 --- a/src/Editor/CharacterEditor/CCharacterEditor.h +++ b/src/Editor/CharacterEditor/CCharacterEditor.h @@ -44,7 +44,7 @@ class CCharacterEditor : public IEditor static const float skDefaultOrbitDistance; public: - explicit CCharacterEditor(QWidget *parent = 0); + explicit CCharacterEditor(CAnimSet *pSet, QWidget *parent = 0); ~CCharacterEditor(); void EditorTick(float DeltaTime); void UpdateAnimTime(float DeltaTime); diff --git a/src/Editor/ModelEditor/CModelEditorWindow.cpp b/src/Editor/ModelEditor/CModelEditorWindow.cpp index 124c5c18..2a9cddac 100644 --- a/src/Editor/ModelEditor/CModelEditorWindow.cpp +++ b/src/Editor/ModelEditor/CModelEditorWindow.cpp @@ -22,7 +22,7 @@ #include #include -CModelEditorWindow::CModelEditorWindow(QWidget *pParent) +CModelEditorWindow::CModelEditorWindow(CModel *pModel, QWidget *pParent) : IEditor(pParent) , ui(new Ui::CModelEditorWindow) , mpScene(new CScene()) @@ -145,6 +145,8 @@ CModelEditorWindow::CModelEditorWindow(QWidget *pParent) connect(ui->AnimParamCSpinBox, SIGNAL(valueChanged(double)), this, SLOT(UpdateMaterial(double))); connect(ui->AnimParamDSpinBox, SIGNAL(valueChanged(double)), this, SLOT(UpdateMaterial(double))); // That was fun + + SetActiveModel(pModel); } CModelEditorWindow::~CModelEditorWindow() diff --git a/src/Editor/ModelEditor/CModelEditorWindow.h b/src/Editor/ModelEditor/CModelEditorWindow.h index f6ef0ff1..c28cf06a 100644 --- a/src/Editor/ModelEditor/CModelEditorWindow.h +++ b/src/Editor/ModelEditor/CModelEditorWindow.h @@ -31,7 +31,7 @@ class CModelEditorWindow : public IEditor bool mIgnoreSignals; public: - explicit CModelEditorWindow(QWidget *pParent = 0); + explicit CModelEditorWindow(CModel *pModel, QWidget *pParent = 0); ~CModelEditorWindow(); void SetActiveModel(CModel *pModel); CModelEditorViewport* Viewport() const; diff --git a/src/Editor/PropertyEdit/CPropertyDelegate.cpp b/src/Editor/PropertyEdit/CPropertyDelegate.cpp index 6b6ef64f..e098b12f 100644 --- a/src/Editor/PropertyEdit/CPropertyDelegate.cpp +++ b/src/Editor/PropertyEdit/CPropertyDelegate.cpp @@ -667,10 +667,6 @@ void CPropertyDelegate::SetCharacterModelData(QWidget *pEditor, const QModelInde if (Type == eAssetProperty) { Params.SetResource( static_cast(pEditor)->Entry()->ID() ); - // Reset all other parameters to 0 - Params.SetCharIndex(0); - for (u32 iUnk = 0; iUnk < 3; iUnk++) - Params.SetUnknown(iUnk, 0); } else if (Type == eEnumProperty) diff --git a/src/Editor/ResourceBrowser/CResourceBrowser.cpp b/src/Editor/ResourceBrowser/CResourceBrowser.cpp index fb7fc6c2..a738dc37 100644 --- a/src/Editor/ResourceBrowser/CResourceBrowser.cpp +++ b/src/Editor/ResourceBrowser/CResourceBrowser.cpp @@ -1,7 +1,6 @@ #include "CResourceBrowser.h" #include "ui_CResourceBrowser.h" -#include "Editor/ModelEditor/CModelEditorWindow.h" -#include "Editor/CharacterEditor/CCharacterEditor.h" +#include "Editor/CEditorApplication.h" #include #include #include @@ -111,37 +110,7 @@ void CResourceBrowser::OnDoubleClickResource(QModelIndex Index) { QModelIndex SourceIndex = mpProxyModel->mapToSource(Index); CResourceEntry *pEntry = mpModel->IndexEntry(SourceIndex); - - if (pEntry->ResourceType() == eModel) - { - CModel *pModel = (CModel*) pEntry->Load(); - - if (pModel) - { - CModelEditorWindow *pModelEd = new CModelEditorWindow(parentWidget()); - pModelEd->SetActiveModel(pModel); - pModelEd->show(); - } - else - QMessageBox::warning(this, "Error", "Failed to load resource"); - } - - else if (pEntry->ResourceType() == eAnimSet) - { - CAnimSet *pSet = (CAnimSet*) pEntry->Load(); - - if (pSet) - { - CCharacterEditor *pCharEd = new CCharacterEditor(parentWidget()); - pCharEd->SetActiveAnimSet(pSet); - pCharEd->show(); - } - else - QMessageBox::warning(this, "Error", "Failed to load resource"); - } - - else - QMessageBox::information(this, "Unsupported Resource", "The selected resource type is currently unsupported for editing."); + gpEdApp->EditResource(pEntry); } void CResourceBrowser::OnResourceSelectionChanged(const QModelIndex& rkNewIndex, const QModelIndex& /*rkPrevIndex*/) diff --git a/src/Editor/ResourceBrowser/CResourceTableModel.h b/src/Editor/ResourceBrowser/CResourceTableModel.h index 2ff8981a..489b9340 100644 --- a/src/Editor/ResourceBrowser/CResourceTableModel.h +++ b/src/Editor/ResourceBrowser/CResourceTableModel.h @@ -77,30 +77,10 @@ public: for (CResourceIterator It(pStore); It; ++It) { if (It->IsTransient()) continue; - EResType Type = It->ResourceType(); - switch (Type) - { - case eArea: - case eAreaCollision: - case eAreaLights: - case eAreaMaterials: - case eAreaSurfaceBounds: - case eAreaOctree: - case eAreaVisibilityTree: - case eMapArea: - case eMapWorld: - case ePathfinding: - case ePortalArea: - case eSaveArea: - case eSaveWorld: - case eStaticGeometryMap: - case eTweak: - case eWorld: - continue; - default: + CResTypeInfo *pInfo = It->TypeInfo(); + if (pInfo->IsVisibleInBrowser() && !It->IsHidden()) mEntries << *It; - } } } diff --git a/src/Editor/Widgets/CResourceSelector.cpp b/src/Editor/Widgets/CResourceSelector.cpp index f90d4fbd..c5df11e2 100644 --- a/src/Editor/Widgets/CResourceSelector.cpp +++ b/src/Editor/Widgets/CResourceSelector.cpp @@ -18,7 +18,7 @@ CResourceSelector::CResourceSelector(QWidget *pParent /*= 0*/) mpResNameLabel = new QLabel(this); mpSetButton = new QPushButton(this); - mpSetButton->setToolTip("Set"); + mpSetButton->setToolTip("Use selected asset in Resource Browser"); mpSetButton->setIcon(QIcon(":/icons/ArrowL_16px.png")); mpSetButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); mpSetButton->setFixedSize(16, 16); @@ -44,28 +44,38 @@ CResourceSelector::CResourceSelector(QWidget *pParent /*= 0*/) mpLayout->addWidget(mpClearButton); setLayout(mpLayout); - UpdateUI(); - // UI Connections connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CreateContextMenu(QPoint))); connect(mpSetButton, SIGNAL(clicked()), this, SLOT(Set())); connect(mpClearButton, SIGNAL(clicked()), this, SLOT(Clear())); // Set up context menu + mpEditAssetAction = new QAction("Edit", this); mpCopyNameAction = new QAction("Copy name", this); mpCopyPathAction = new QAction("Copy path", this); // Context menu connections + connect(mpEditAssetAction, SIGNAL(triggered()), this, SLOT(EditAsset())); connect(mpCopyNameAction, SIGNAL(triggered()), this, SLOT(CopyName())); connect(mpCopyPathAction, SIGNAL(triggered()), this, SLOT(CopyPath())); + + UpdateUI(); } void CResourceSelector::UpdateUI() { - mpResNameLabel->setText(mpResEntry ? TO_QSTRING(mpResEntry->Name()) + "." + TO_QSTRING(mpResEntry->CookedExtension().ToString()) : ""); - mpResNameLabel->setToolTip(mpResEntry ? TO_QSTRING(mpResEntry->CookedAssetPath(true)) : ""); - mpFindButton->setEnabled(mpResEntry != nullptr); - mpClearButton->setEnabled(mpResEntry != nullptr); + bool HasResource = mpResEntry != nullptr; + + // Update main UI + mpResNameLabel->setText(HasResource ? TO_QSTRING(mpResEntry->Name()) + "." + TO_QSTRING(mpResEntry->CookedExtension().ToString()) : ""); + mpResNameLabel->setToolTip(HasResource ? TO_QSTRING(mpResEntry->CookedAssetPath(true)) : ""); + mpFindButton->setEnabled(HasResource); + mpClearButton->setEnabled(HasResource); + + // Update context menu + mpEditAssetAction->setEnabled(HasResource); + mpCopyNameAction->setEnabled(HasResource); + mpCopyPathAction->setEnabled(HasResource); } void CResourceSelector::SetAllowedExtensions(const QString& /*rkExtension*/) @@ -99,11 +109,18 @@ void CResourceSelector::SetResource(CResource *pRes) void CResourceSelector::CreateContextMenu(const QPoint& rkPoint) { QMenu Menu; + Menu.addAction(mpEditAssetAction); + Menu.addSeparator(); Menu.addAction(mpCopyNameAction); Menu.addAction(mpCopyPathAction); Menu.exec(mapToGlobal(rkPoint)); } +void CResourceSelector::EditAsset() +{ + gpEdApp->EditResource(mpResEntry); +} + void CResourceSelector::CopyName() { gpEdApp->clipboard()->setText(mpResNameLabel->text()); @@ -118,8 +135,13 @@ void CResourceSelector::CopyPath() void CResourceSelector::Set() { // todo - validate this resource is a valid type - mpResEntry = gpEdApp->ResourceBrowser()->SelectedEntry(); - OnResourceChanged(); + CResourceBrowser *pBrowser = gpEdApp->ResourceBrowser(); + + if (pBrowser->isVisible() && pBrowser->SelectedEntry()) + { + mpResEntry = gpEdApp->ResourceBrowser()->SelectedEntry(); + OnResourceChanged(); + } } void CResourceSelector::Clear() diff --git a/src/Editor/Widgets/CResourceSelector.h b/src/Editor/Widgets/CResourceSelector.h index c32b2aba..e24778eb 100644 --- a/src/Editor/Widgets/CResourceSelector.h +++ b/src/Editor/Widgets/CResourceSelector.h @@ -21,6 +21,7 @@ class CResourceSelector : public QWidget QPushButton *mpClearButton; // Context Menu + QAction *mpEditAssetAction; QAction *mpCopyNameAction; QAction *mpCopyPathAction; @@ -39,6 +40,7 @@ public slots: void CreateContextMenu(const QPoint& rkPoint); void Set(); void Clear(); + void EditAsset(); void CopyName(); void CopyPath(); void OnResourceChanged();