Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,73 @@
/*
* 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.
*
*/
#include "EditorDefs.h"
#include "AssetEditorRequestsHandler.h"
// AzCore
#include <AzCore/Asset/AssetManager.h>
// Editor
#include "AssetEditorWindow.h"
#include "QtViewPaneManager.h"
AssetEditorRequestsHandler::AssetEditorRequestsHandler()
{
AzToolsFramework::AssetEditor::AssetEditorRequestsBus::Handler::BusConnect();
AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
}
AssetEditorRequestsHandler::~AssetEditorRequestsHandler()
{
AzToolsFramework::AssetEditor::AssetEditorRequestsBus::Handler::BusDisconnect();
AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
}
void AssetEditorRequestsHandler::NotifyRegisterViews()
{
using namespace AzToolsFramework::AssetEditor;
if (auto assetsWindowsToRestore = AZ::UserSettings::CreateFind<AssetEditorWindowSettings>(AZ::Crc32(AssetEditorWindowSettings::s_name), AZ::UserSettings::CT_GLOBAL))
{
//copy the current list and clear it since they will be re-added as we request to open them
auto windowsToOpen = assetsWindowsToRestore->m_openAssets;
assetsWindowsToRestore->m_openAssets.clear();
for (auto&& assetRef : windowsToOpen)
{
AssetEditorWindow::RegisterViewClass(assetRef);
}
}
}
void AssetEditorRequestsHandler::CreateNewAsset(const AZ::Data::AssetType& assetType)
{
using namespace AzToolsFramework::AssetEditor;
AzToolsFramework::OpenViewPane(LyViewPane::AssetEditor);
AssetEditorWidgetRequestsBus::Broadcast(&AssetEditorWidgetRequests::CreateAsset, assetType);
}
void AssetEditorRequestsHandler::OpenAssetEditor(const AZ::Data::Asset<AZ::Data::AssetData>& asset)
{
using namespace AzToolsFramework::AssetEditor;
// Open the AssetEditor if it isn't open already.
auto&& pane = QtViewPaneManager::instance()->OpenPane(LyViewPane::AssetEditor, QtViewPane::OpenMode::RestoreLayout);
AssetEditorWidgetRequestsBus::Broadcast(&AssetEditorWidgetRequests::OpenAsset, asset);
}
void AssetEditorRequestsHandler::OpenAssetEditorById(const AZ::Data::AssetId assetId)
{
AZ::Data::Asset<AZ::Data::AssetData> asset = AZ::Data::AssetManager::Instance().GetAsset<AZ::Data::AssetData>(assetId, AZ::Data::AssetLoadBehavior::NoLoad);
OpenAssetEditor(asset);
}
@@ -0,0 +1,39 @@
/*
* 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.
*
*/
#pragma once
#include <AzCore/Serialization/SerializeContext.h>
#include <AzToolsFramework/AssetEditor/AssetEditorBus.h>
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
class AssetEditorRequestsHandler
: public AzToolsFramework::AssetEditor::AssetEditorRequestsBus::Handler
, public AzToolsFramework::EditorEvents::Bus::Handler
{
public:
AZ_CLASS_ALLOCATOR(AssetEditorRequestsHandler, AZ::SystemAllocator, 0);
AssetEditorRequestsHandler();
~AssetEditorRequestsHandler() override;
//////////////////////////////////////////////////////////////////////////
// AssetEditorRequests
//////////////////////////////////////////////////////////////////////////
void CreateNewAsset(const AZ::Data::AssetType& assetType) override;
void OpenAssetEditor(const AZ::Data::Asset<AZ::Data::AssetData>& asset) override;
void OpenAssetEditorById(const AZ::Data::AssetId assetId) override;
//////////////////////////////////////////////////////////////////////////
// AzToolsFramework::EditorEvents::Bus::Handler
//////////////////////////////////////////////////////////////////////////
void NotifyRegisterViews() override;
};
@@ -0,0 +1,169 @@
/*
* 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.
*
*/
#include "EditorDefs.h"
#include "AssetEditorWindow.h"
// Qt
#include <QMessageBox>
// AzCore
#include <AzCore/Asset/AssetManager.h>
#include <AzCore/UserSettings/UserSettingsComponent.h>
// AzToolsFramework
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
#include <AzToolsFramework/API/ViewPaneOptions.h>
// Editor
#include "LyViewPaneNames.h"
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
#include <AssetEditor/ui_AssetEditorWindow.h>
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
namespace AssetEditorUtils
{
AssetEditorWindow* CreateAssetEditorWithAsset(const AZ::Data::Asset<AZ::Data::AssetData> assetRef)
{
AssetEditorWindow* assetEditorWindow = new AssetEditorWindow();
if (auto assetsWindowsToRestore = AZ::UserSettings::CreateFind<AzToolsFramework::AssetEditor::AssetEditorWindowSettings>(AZ::Crc32(AzToolsFramework::AssetEditor::AssetEditorWindowSettings::s_name), AZ::UserSettings::CT_GLOBAL))
{
assetsWindowsToRestore->m_openAssets.emplace(assetRef);
}
AZ::UserSettingsComponentRequestBus::Broadcast(&AZ::UserSettingsComponentRequestBus::Events::Save);
auto&& loadedAsset = AZ::Data::AssetManager::Instance().GetAsset(assetRef.GetId(), assetRef.GetType(), assetRef.GetAutoLoadBehavior());
loadedAsset.BlockUntilLoadComplete();
assetEditorWindow->OpenAsset(loadedAsset);
return assetEditorWindow;
}
}
AssetEditorWindow::AssetEditorWindow(QWidget* parent)
: QWidget(parent)
, m_ui(new Ui::AssetEditorWindowClass())
{
using namespace AzToolsFramework::AssetEditor;
m_ui->setupUi(this);
connect(m_ui->m_assetEditorWidget, &AssetEditorWidget::OnAssetSaveFailedSignal, this, &AssetEditorWindow::OnAssetSaveFailed);
connect(m_ui->m_assetEditorWidget, &AssetEditorWidget::OnAssetOpenedSignal, this, &AssetEditorWindow::OnAssetOpened);
BusConnect();
}
AssetEditorWindow::~AssetEditorWindow()
{
using namespace AzToolsFramework::AssetEditor;
BusDisconnect();
}
void AssetEditorWindow::RegisterViewClass(const AZ::Data::Asset<AZ::Data::AssetData>& asset)
{
AzToolsFramework::ViewPaneOptions options;
options.showInMenu = false;
auto& assetName = asset.GetHint();
const char* paneName = assetName.c_str();
AzToolsFramework::RegisterViewPane<AssetEditorWindow>(paneName, LyViewPane::CategoryTools, options, [asset](QWidget*) {return AssetEditorUtils::CreateAssetEditorWithAsset(asset); });
}
void AssetEditorWindow::CreateAsset(const AZ::Data::AssetType& assetType)
{
m_ui->m_assetEditorWidget->CreateAsset(assetType);
}
void AssetEditorWindow::OpenAsset(const AZ::Data::Asset<AZ::Data::AssetData>& asset)
{
m_ui->m_assetEditorWidget->OpenAsset(asset);
}
void AssetEditorWindow::OpenAssetById(const AZ::Data::AssetId assetId)
{
AZ::Data::Asset<AZ::Data::AssetData> asset = AZ::Data::AssetManager::Instance().GetAsset<AZ::Data::AssetData>(assetId, AZ::Data::AssetLoadBehavior::NoLoad);
OpenAsset(asset);
}
void AssetEditorWindow::SaveAssetAs(const AZStd::string_view assetPath)
{
if (assetPath.empty())
{
AZ_Warning("Asset Editor", false, "Could not save asset to empty path.");
return;
}
const char* engineRoot;
AzToolsFramework::ToolsApplicationRequestBus::BroadcastResult(engineRoot, &AzToolsFramework::ToolsApplicationRequests::GetEngineRootPath);
AZStd::string absoluteAssetPath;
AzFramework::StringFunc::Path::Join(engineRoot, assetPath.data(), absoluteAssetPath);
if (!m_ui->m_assetEditorWidget->SaveAssetToPath(absoluteAssetPath))
{
AZ_Warning("Asset Editor", false, "File was not saved correctly via SaveAssetAs.");
}
}
void AssetEditorWindow::RegisterViewClass()
{
AzToolsFramework::ViewPaneOptions options;
options.preferedDockingArea = Qt::LeftDockWidgetArea;
AzToolsFramework::RegisterViewPane<AssetEditorWindow>(LyViewPane::AssetEditor, LyViewPane::CategoryTools, options);
}
void AssetEditorWindow::OnAssetOpened(const AZ::Data::Asset<AZ::Data::AssetData>& asset)
{
if (asset)
{
AZStd::string assetPath;
AZStd::string assetName;
AZStd::string extension;
AZ::Data::AssetCatalogRequestBus::BroadcastResult(assetPath, &AZ::Data::AssetCatalogRequests::GetAssetPathById, asset.GetId());
AzFramework::StringFunc::Path::Split(assetPath.c_str(), nullptr, nullptr, &assetName, &extension);
// AZStd::string windowTitle = AZStd::string::format("Edit Asset: %s", (assetName + extension).c_str());
AZStd::string windowTitle = asset.GetHint();
qobject_cast<QWidget*>(parent())->setWindowTitle(tr(windowTitle.c_str()));
}
else
{
qobject_cast<QWidget*>(parent())->setWindowTitle(tr("Asset Editor"));
}
}
void AssetEditorWindow::closeEvent(QCloseEvent* event)
{
if (m_ui->m_assetEditorWidget->WaitingToSave())
{
// Don't need to ask to save, as a save is already queued.
m_ui->m_assetEditorWidget->SetCloseAfterSave();
event->ignore();
return;
}
if (m_ui->m_assetEditorWidget->TrySave([this]() { qobject_cast<QWidget*>(parent())->close(); }))
{
event->ignore();
}
}
void AssetEditorWindow::OnAssetSaveFailed(const AZStd::string& error)
{
QMessageBox::warning(this, tr("Unable to Save Asset"),
tr(error.c_str()), QMessageBox::Ok, QMessageBox::Ok);
}
#include <AssetEditor/moc_AssetEditorWindow.cpp>
@@ -0,0 +1,62 @@
/*
* 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.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzCore/Asset/AssetCommon.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/UserSettings/UserSettings.h>
#include <AzToolsFramework/AssetEditor/AssetEditorBus.h>
#include <QWidget>
#endif
namespace Ui
{
class AssetEditorWindowClass;
}
/**
* Window pane wrapper for the Asset Editor widget.
*/
class AssetEditorWindow
: public QWidget
, AzToolsFramework::AssetEditor::AssetEditorWidgetRequestsBus::Handler
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(AssetEditorWindow, AZ::SystemAllocator, 0);
explicit AssetEditorWindow(QWidget* parent = nullptr);
~AssetEditorWindow() override;
//////////////////////////////////////////////////////////////////////////
// AssetEditorWindow
//////////////////////////////////////////////////////////////////////////
void CreateAsset(const AZ::Data::AssetType& assetType) override;
void OpenAsset(const AZ::Data::Asset<AZ::Data::AssetData>& asset) override;
void OpenAssetById(const AZ::Data::AssetId assetId) override;
void SaveAssetAs(const AZStd::string_view assetPath) override;
static void RegisterViewClass();
static void RegisterViewClass(const AZ::Data::Asset<AZ::Data::AssetData>& asset);
protected Q_SLOTS:
void OnAssetSaveFailed(const AZStd::string& error);
void OnAssetOpened(const AZ::Data::Asset<AZ::Data::AssetData>& asset);
protected:
void closeEvent(QCloseEvent* event) override;
private:
QScopedPointer<Ui::AssetEditorWindowClass> m_ui;
};
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AssetEditorWindowClass</class>
<widget class="QWidget" name="AssetEditorWindowClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>200</width>
<height>200</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="windowTitle">
<string>Asset Editor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="AzToolsFramework::AssetEditor::AssetEditorWidget" name="m_assetEditorWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AzToolsFramework::AssetEditor::AssetEditorWidget</class>
<extends>QWidget</extends>
<header>AzToolsFramework/AssetEditor/AssetEditorWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>