Added "edit" button to resource selector context menu
This commit is contained in:
parent
4e8ecdb79c
commit
c51d79cc42
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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 <Common/AssertMacro.h>
|
||||
#include <Common/CTimer.h>
|
||||
#include <Core/GameProject/CGameProject.h>
|
||||
#include <QMessageBox>
|
||||
|
||||
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<CWorldEditor*>(pEditor) == nullptr)
|
||||
{
|
||||
for (auto Iter = mEditingMap.begin(); Iter != mEditingMap.end(); Iter++)
|
||||
{
|
||||
if (Iter.value() == pEditor)
|
||||
{
|
||||
mEditingMap.erase(Iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mEditorWindows.removeOne(pEditor);
|
||||
delete pEditor;
|
||||
}
|
||||
|
|
|
@ -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<IEditor*> mEditorWindows;
|
||||
QMap<CResourceEntry*,IEditor*> mEditingMap;
|
||||
double mLastUpdate;
|
||||
|
||||
public:
|
||||
CEditorApplication(int& rArgc, char **ppArgv);
|
||||
~CEditorApplication();
|
||||
void InitEditor();
|
||||
void EditResource(CResourceEntry *pEntry);
|
||||
|
||||
// Accessors
|
||||
inline CWorldEditor* WorldEditor() const { return mpWorldEditor; }
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <assimp/scene.h>
|
||||
#include <assimp/postprocess.h>
|
||||
|
||||
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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -667,10 +667,6 @@ void CPropertyDelegate::SetCharacterModelData(QWidget *pEditor, const QModelInde
|
|||
if (Type == eAssetProperty)
|
||||
{
|
||||
Params.SetResource( static_cast<CResourceSelector*>(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)
|
||||
|
|
|
@ -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 <Core/GameProject/AssetNameGeneration.h>
|
||||
#include <Core/GameProject/CAssetNameMap.h>
|
||||
#include <QFileDialog>
|
||||
|
@ -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*/)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue