123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- // Description : CEditorImpl class implementation.
- #include "EditorDefs.h"
- #include "IEditorImpl.h"
- #include <EditorCommonAPI.h>
- // Qt
- #include <QByteArray>
- // AzCore
- #include <AzCore/IO/Path/Path.h>
- #include <AzCore/JSON/document.h>
- #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
- #include <AzCore/Utils/Utils.h>
- // AzFramework
- #include <AzFramework/Terrain/TerrainDataRequestBus.h>
- // AzToolsFramework
- #include <AzToolsFramework/UI/UICore/WidgetHelpers.h>
- #include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h>
- // AzQtComponents
- #include <AzQtComponents/Components/Widgets/ColorPicker.h>
- #include <AzQtComponents/Utilities/Conversions.h>
- // Editor
- #include "CryEdit.h"
- #include "Dialogs/ErrorsDlg.h"
- #include "PluginManager.h"
- #include "ViewManager.h"
- #include "DisplaySettings.h"
- #include "LevelIndependentFileMan.h"
- #include "TrackView/TrackViewSequenceManager.h"
- #include "AnimationContext.h"
- #include "GameEngine.h"
- #include "ToolBox.h"
- #include "MainWindow.h"
- #include "Settings.h"
- #include "Include/IObjectManager.h"
- #include "Include/ISourceControl.h"
- #include "Objects/SelectionGroup.h"
- #include "Objects/ObjectManager.h"
- #include "EditorFileMonitor.h"
- #include "MainStatusBar.h"
- #include "Util/FileUtil_impl.h"
- #include "Util/ImageUtil_impl.h"
- #include "LogFileImpl.h"
- #include "Editor/AssetDatabase/AssetDatabaseLocationListener.h"
- #include "Editor/AzAssetBrowser/AzAssetBrowserRequestHandler.h"
- #include "Editor/AssetEditor/AssetEditorRequestsHandler.h"
- #include "Core/QtEditorApplication.h" // for Editor::EditorQtApplication
- static CCryEditDoc * theDocument;
- #include <QMimeData>
- #include <QMessageBox>
- #include <QProcess>
- #if defined(EXTERNAL_CRASH_REPORTING)
- #include <ToolsCrashHandler.h>
- #endif
- #ifndef VERIFY
- #define VERIFY(EXPRESSION) { auto e = EXPRESSION; assert(e); }
- #endif
- const char* CEditorImpl::m_crashLogFileName = "SessionStatus/editor_statuses.json";
- CEditorImpl::CEditorImpl()
- : m_operationMode(eOperationModeNone)
- , m_pSystem(nullptr)
- , m_pFileUtil(nullptr)
- , m_pClassFactory(nullptr)
- , m_pCommandManager(nullptr)
- , m_pObjectManager(nullptr)
- , m_pPluginManager(nullptr)
- , m_pViewManager(nullptr)
- , m_pUndoManager(nullptr)
- , m_marker(0, 0, 0)
- , m_selectedAxis(AXIS_TERRAIN)
- , m_refCoordsSys(COORDS_LOCAL)
- , m_bAxisVectorLock(false)
- , m_bUpdates(true)
- , m_bTerrainAxisIgnoreObjects(false)
- , m_pDisplaySettings(nullptr)
- , m_bSelectionLocked(true)
- , m_pGameEngine(nullptr)
- , m_pAnimationContext(nullptr)
- , m_pSequenceManager(nullptr)
- , m_pToolBoxManager(nullptr)
- , m_pMusicManager(nullptr)
- , m_pErrorReport(nullptr)
- , m_pLasLoadedLevelErrorReport(nullptr)
- , m_pErrorsDlg(nullptr)
- , m_pSourceControl(nullptr)
- , m_pSelectionTreeManager(nullptr)
- , m_pConsoleSync(nullptr)
- , m_pSettingsManager(nullptr)
- , m_pLevelIndependentFileMan(nullptr)
- , m_bMatEditMode(false)
- , m_bShowStatusText(true)
- , m_bInitialized(false)
- , m_bExiting(false)
- , m_QtApplication(static_cast<Editor::EditorQtApplication*>(qApp))
- , m_pImageUtil(nullptr)
- , m_pLogFile(nullptr)
- {
- // note that this is a call into EditorCore.dll, which stores the g_pEditorPointer for all shared modules that share EditorCore.dll
- // this means that they don't need to do SetIEditor(...) themselves and its available immediately
- SetIEditor(this);
- m_pFileUtil = new CFileUtil_impl();
- m_pLogFile = new CLogFileImpl();
- m_pLevelIndependentFileMan = new CLevelIndependentFileMan;
- SetPrimaryCDFolder();
- gSettings.Load();
- m_pErrorReport = new CErrorReport;
- m_pClassFactory = CClassFactory::Instance();
- m_pCommandManager = new CEditorCommandManager;
- m_pEditorFileMonitor.reset(new CEditorFileMonitor());
- m_pDisplaySettings = new CDisplaySettings;
- m_pDisplaySettings->LoadRegistry();
- m_pPluginManager = new CPluginManager;
- m_pObjectManager = new CObjectManager;
- m_pViewManager = new CViewManager;
- m_pUndoManager = new CUndoManager;
- m_pToolBoxManager = new CToolBoxManager;
- m_pSequenceManager = new CTrackViewSequenceManager;
- m_pAnimationContext = new CAnimationContext;
- m_pImageUtil = new CImageUtil_impl();
- m_selectedRegion.min = Vec3(0, 0, 0);
- m_selectedRegion.max = Vec3(0, 0, 0);
- DetectVersion();
- RegisterTools();
- m_pAssetDatabaseLocationListener = nullptr;
- m_pAssetBrowserRequestHandler = nullptr;
- m_assetEditorRequestsHandler = nullptr;
- if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
- {
- if (AZ::IO::FixedMaxPath crashLogPath; settingsRegistry->Get(crashLogPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_ProjectUserPath))
- {
- crashLogPath /= m_crashLogFileName;
- AZ::IO::SystemFile::CreateDir(crashLogPath.ParentPath().FixedMaxPathString().c_str());
- QFile::setPermissions(crashLogPath.c_str(), QFileDevice::ReadOther | QFileDevice::WriteOther);
- }
- }
- }
- void CEditorImpl::Initialize()
- {
- #if defined(EXTERNAL_CRASH_REPORTING)
- CrashHandler::ToolsCrashHandler::InitCrashHandler("Editor", {});
- #endif
- // Must be set before QApplication is initialized, so that we support HighDpi monitors, like the Retina displays
- // on Windows 10
- QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
- // Prevents (native) sibling widgets from causing problems with docked QOpenGLWidgets on Windows
- // The problem is due to native widgets ending up with pixel formats that are incompatible with the GL pixel format
- // (generally due to a lack of an alpha channel). This blocks the creation of a shared GL context.
- // And on macOS it prevents all kinds of bugs related to native widgets, specially regarding toolbars (duplicate toolbars, artifacts, crashes).
- QCoreApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
- // Activate QT immediately so that its available as soon as CEditorImpl is (and thus GetIEditor())
- InitializeEditorCommon(GetIEditor());
- }
- //The only purpose of that function is to be called at the very begining of the shutdown sequence so that we can instrument and track
- //how many crashes occur while shutting down
- void CEditorImpl::OnBeginShutdownSequence()
- {
- }
- void CEditorImpl::OnEarlyExitShutdownSequence()
- {
- }
- void CEditorImpl::Uninitialize()
- {
- if (m_pSystem)
- {
- UninitializeEditorCommonISystem(m_pSystem);
- }
- UninitializeEditorCommon();
- }
- void CEditorImpl::UnloadPlugins()
- {
- AZStd::scoped_lock lock(m_pluginMutex);
- // Flush core buses. We're about to unload DLLs and need to ensure we don't have module-owned functions left behind.
- AZ::Data::AssetBus::ExecuteQueuedEvents();
- AZ::TickBus::ExecuteQueuedEvents();
- // first, stop anyone from accessing plugins that provide things like source control.
- // note that m_psSourceControl is re-queried
- m_pSourceControl = nullptr;
- // Send this message to ensure that any widgets queued for deletion will get deleted before their
- // plugin containing their vtable is unloaded. If not, access violations can occur
- QCoreApplication::sendPostedEvents(Q_NULLPTR, QEvent::DeferredDelete);
- GetPluginManager()->ReleaseAllPlugins();
- GetPluginManager()->UnloadAllPlugins();
- }
- void CEditorImpl::LoadPlugins()
- {
- AZStd::scoped_lock lock(m_pluginMutex);
- static const QString editor_plugins_folder("EditorPlugins");
- // Build, verify, and set the engine root's editor plugin folder
- QString editorPluginPathStr;
- AZStd::string_view exeFolder;
- AZ::ComponentApplicationBus::BroadcastResult(exeFolder, &AZ::ComponentApplicationRequests::GetExecutableFolder);
- QDir testDir;
- testDir.setPath(AZStd::string(exeFolder).c_str());
- if (testDir.exists() && testDir.cd(editor_plugins_folder))
- {
- editorPluginPathStr = testDir.absolutePath();
- }
- // If no editor plugin path was found based on the root engine path, then fallback to the current editor.exe path
- if (editorPluginPathStr.isEmpty())
- {
- editorPluginPathStr = QString("%1/%2").arg(qApp->applicationDirPath(), editor_plugins_folder);
- }
- QString pluginSearchPath = QDir::toNativeSeparators(QString("%1/*" AZ_DYNAMIC_LIBRARY_EXTENSION).arg(editorPluginPathStr));
- GetPluginManager()->LoadPlugins(pluginSearchPath.toUtf8().data());
- }
- CEditorImpl::~CEditorImpl()
- {
- gSettings.Save();
- m_bExiting = true; // Can't save level after this point (while Crash)
- SAFE_RELEASE(m_pSourceControl);
- SAFE_DELETE(m_pViewManager)
- SAFE_DELETE(m_pObjectManager) // relies on prefab manager
- SAFE_DELETE(m_pPluginManager)
- SAFE_DELETE(m_pAnimationContext) // relies on undo manager
- SAFE_DELETE(m_pUndoManager)
- if (m_pDisplaySettings)
- {
- m_pDisplaySettings->SaveRegistry();
- }
- SAFE_DELETE(m_pDisplaySettings)
- SAFE_DELETE(m_pToolBoxManager)
- SAFE_DELETE(m_pCommandManager)
- SAFE_DELETE(m_pClassFactory)
- SAFE_DELETE(m_pLasLoadedLevelErrorReport)
- SAFE_DELETE(m_pSettingsManager);
- SAFE_DELETE(m_pAssetDatabaseLocationListener);
- SAFE_DELETE(m_pAssetBrowserRequestHandler);
- SAFE_DELETE(m_assetEditorRequestsHandler);
- // Game engine should be among the last things to be destroyed, as it
- // destroys the engine.
- SAFE_DELETE(m_pErrorsDlg);
- SAFE_DELETE(m_pLevelIndependentFileMan);
- SAFE_DELETE(m_pGameEngine);
- // The error report must be destroyed after the game, as the engine
- // refers to the error report and the game destroys the engine.
- SAFE_DELETE(m_pErrorReport);
- SAFE_DELETE(m_pFileUtil); // Vladimir@Conffx
- SAFE_DELETE(m_pImageUtil); // Vladimir@Conffx
- SAFE_DELETE(m_pLogFile); // Vladimir@Conffx
- }
- void CEditorImpl::SetPrimaryCDFolder()
- {
- QString szFolder = qApp->applicationDirPath();
- QDir::setCurrent(szFolder);
- }
- void CEditorImpl::SetGameEngine(CGameEngine* ge)
- {
- m_pAssetDatabaseLocationListener = new AssetDatabase::AssetDatabaseLocationListener();
- m_pAssetBrowserRequestHandler = new AzAssetBrowserRequestHandler();
- m_assetEditorRequestsHandler = aznew AssetEditorRequestsHandler();
- m_pSystem = ge->GetSystem();
- m_pGameEngine = ge;
- InitializeEditorCommonISystem(m_pSystem);
- m_templateRegistry.LoadTemplates("Editor");
- m_pObjectManager->LoadClassTemplates("Editor");
- m_pObjectManager->RegisterCVars();
- m_pAnimationContext->Init();
- }
- void CEditorImpl::RegisterTools()
- {
- }
- void CEditorImpl::ExecuteCommand(const char* sCommand, ...)
- {
- va_list args;
- va_start(args, sCommand);
- ExecuteCommand(QString::asprintf(sCommand, args));
- va_end(args);
- }
- void CEditorImpl::ExecuteCommand(const QString& command)
- {
- m_pCommandManager->Execute(command.toUtf8().data());
- }
- void CEditorImpl::Update()
- {
- if (!m_bUpdates)
- {
- return;
- }
- // Make sure this is not called recursively
- m_bUpdates = false;
- if (IsInPreviewMode())
- {
- SetModifiedFlag(false);
- SetModifiedModule(eModifiedNothing);
- }
- m_bUpdates = true;
- }
- ISystem* CEditorImpl::GetSystem()
- {
- return m_pSystem;
- }
- IEditorClassFactory* CEditorImpl::GetClassFactory()
- {
- return m_pClassFactory;
- }
- CCryEditDoc* CEditorImpl::GetDocument() const
- {
- return theDocument;
- }
- bool CEditorImpl::IsLevelLoaded() const
- {
- return GetDocument() && GetDocument()->IsDocumentReady();
- }
- void CEditorImpl::SetDocument(CCryEditDoc* pDoc)
- {
- theDocument = pDoc;
- }
- void CEditorImpl::SetModifiedFlag(bool modified)
- {
- if (GetDocument() && GetDocument()->IsDocumentReady())
- {
- GetDocument()->SetModifiedFlag(modified);
- if (modified)
- {
- GetDocument()->SetLevelExported(false);
- }
- }
- }
- void CEditorImpl::SetModifiedModule(EModifiedModule eModifiedModule, bool boSet)
- {
- if (GetDocument())
- {
- GetDocument()->SetModifiedModules(eModifiedModule, boSet);
- }
- }
- bool CEditorImpl::IsLevelExported() const
- {
- CCryEditDoc* pDoc = GetDocument();
- if (pDoc)
- {
- return pDoc->IsLevelExported();
- }
- return false;
- }
- bool CEditorImpl::SetLevelExported(bool boExported)
- {
- if (GetDocument())
- {
- GetDocument()->SetLevelExported(boExported);
- return true;
- }
- return false;
- }
- bool CEditorImpl::IsModified()
- {
- if (GetDocument())
- {
- return GetDocument()->IsModified();
- }
- return false;
- }
- bool CEditorImpl::SaveDocument()
- {
- if (m_bExiting)
- {
- return false;
- }
- if (GetDocument())
- {
- return GetDocument()->Save();
- }
- else
- {
- return false;
- }
- }
- QString CEditorImpl::GetPrimaryCDFolder()
- {
- return m_primaryCDFolder;
- }
- QString CEditorImpl::GetLevelFolder()
- {
- return GetGameEngine()->GetLevelPath();
- }
- QString CEditorImpl::GetLevelName()
- {
- m_levelNameBuffer = GetGameEngine()->GetLevelName();
- return m_levelNameBuffer;
- }
- QString CEditorImpl::GetLevelDataFolder()
- {
- return Path::AddPathSlash(Path::AddPathSlash(GetGameEngine()->GetLevelPath()) + "LevelData");
- }
- QString CEditorImpl::GetSearchPath(EEditorPathName path)
- {
- return gSettings.searchPaths[path][0];
- }
- QString CEditorImpl::GetResolvedUserFolder()
- {
- m_userFolder = Path::GetResolvedUserSandboxFolder();
- return m_userFolder;
- }
- void CEditorImpl::SetDataModified()
- {
- GetDocument()->SetModifiedFlag(true);
- }
- void CEditorImpl::SetStatusText(const QString& pszString)
- {
- if (m_bShowStatusText && !m_bMatEditMode && GetMainStatusBar())
- {
- GetMainStatusBar()->SetStatusText(pszString);
- }
- }
- IMainStatusBar* CEditorImpl::GetMainStatusBar()
- {
- return MainWindow::instance()->StatusBar();
- }
- void CEditorImpl::SetOperationMode(EOperationMode mode)
- {
- m_operationMode = mode;
- gSettings.operationMode = mode;
- }
- EOperationMode CEditorImpl::GetOperationMode()
- {
- return m_operationMode;
- }
- void CEditorImpl::SetAxisConstraints(AxisConstrains axisFlags)
- {
- m_selectedAxis = axisFlags;
- m_pViewManager->SetAxisConstrain(axisFlags);
- SetTerrainAxisIgnoreObjects(false);
- // Update all views.
- UpdateViews(eUpdateObjects, nullptr);
- }
- AxisConstrains CEditorImpl::GetAxisConstrains()
- {
- return m_selectedAxis;
- }
- void CEditorImpl::SetTerrainAxisIgnoreObjects(bool bIgnore)
- {
- m_bTerrainAxisIgnoreObjects = bIgnore;
- }
- bool CEditorImpl::IsTerrainAxisIgnoreObjects()
- {
- return m_bTerrainAxisIgnoreObjects;
- }
- void CEditorImpl::SetReferenceCoordSys(RefCoordSys refCoords)
- {
- m_refCoordsSys = refCoords;
- // Update all views.
- UpdateViews(eUpdateObjects, nullptr);
- // Update the construction plane infos.
- CViewport* pViewport = GetActiveView();
- if (pViewport)
- {
- pViewport->MakeConstructionPlane(GetIEditor()->GetAxisConstrains());
- }
- Notify(eNotify_OnRefCoordSysChange);
- }
- RefCoordSys CEditorImpl::GetReferenceCoordSys()
- {
- return m_refCoordsSys;
- }
- CBaseObject* CEditorImpl::NewObject(const char* typeName, const char* fileName, const char* name, float x, float y, float z, bool modifyDoc)
- {
- CUndo undo("Create new object");
- IEditor* editor = GetIEditor();
- if (modifyDoc)
- {
- editor->SetModifiedFlag();
- editor->SetModifiedModule(eModifiedBrushes);
- }
- CBaseObject* object = editor->GetObjectManager()->NewObject(typeName, nullptr, fileName, name);
- if (!object)
- {
- return nullptr;
- }
- object->SetPos(Vec3(x, y, z));
- return object;
- }
- //////////////////////////////////////////////////////////////////////////
- void CEditorImpl::DeleteObject(CBaseObject* obj)
- {
- SetModifiedFlag();
- GetIEditor()->SetModifiedModule(eModifiedBrushes);
- GetObjectManager()->DeleteObject(obj);
- }
- CBaseObject* CEditorImpl::GetSelectedObject()
- {
- if (m_pObjectManager->GetSelection()->GetCount() != 1)
- {
- return nullptr;
- }
- return m_pObjectManager->GetSelection()->GetObject(0);
- }
- void CEditorImpl::SelectObject(CBaseObject* obj)
- {
- GetObjectManager()->SelectObject(obj);
- }
- IObjectManager* CEditorImpl::GetObjectManager()
- {
- return m_pObjectManager;
- };
- CSettingsManager* CEditorImpl::GetSettingsManager()
- {
- // Do not go any further before XML class is ready to use
- if (!gEnv)
- {
- return nullptr;
- }
- if (!GetISystem())
- {
- return nullptr;
- }
- if (!m_pSettingsManager)
- {
- m_pSettingsManager = new CSettingsManager(eSettingsManagerMemoryStorage);
- }
- return m_pSettingsManager;
- }
- CSelectionGroup* CEditorImpl::GetSelection()
- {
- return m_pObjectManager->GetSelection();
- }
- int CEditorImpl::ClearSelection()
- {
- if (GetSelection()->IsEmpty())
- {
- return 0;
- }
- CUndo undo("Clear Selection");
- return GetObjectManager()->ClearSelection();
- }
- void CEditorImpl::LockSelection(bool bLock)
- {
- // Selection must be not empty to enable selection lock.
- if (!GetSelection()->IsEmpty())
- {
- m_bSelectionLocked = bLock;
- }
- else
- {
- m_bSelectionLocked = false;
- }
- }
- bool CEditorImpl::IsSelectionLocked()
- {
- return m_bSelectionLocked;
- }
- CViewManager* CEditorImpl::GetViewManager()
- {
- return m_pViewManager;
- }
- CViewport* CEditorImpl::GetActiveView()
- {
- MainWindow* mainWindow = MainWindow::instance();
- if (mainWindow)
- {
- CLayoutViewPane* viewPane = mainWindow->GetActiveView();
- if (viewPane)
- {
- return qobject_cast<QtViewport*>(viewPane->GetViewport());
- }
- }
- return nullptr;
- }
- void CEditorImpl::SetActiveView(CViewport* viewport)
- {
- m_pViewManager->SelectViewport(viewport);
- }
- void CEditorImpl::UpdateViews(int flags, const AABB* updateRegion)
- {
- AABB prevRegion = m_pViewManager->GetUpdateRegion();
- if (updateRegion)
- {
- m_pViewManager->SetUpdateRegion(*updateRegion);
- }
- m_pViewManager->UpdateViews(flags);
- if (updateRegion)
- {
- m_pViewManager->SetUpdateRegion(prevRegion);
- }
- }
- void CEditorImpl::ReloadTrackView()
- {
- Notify(eNotify_OnReloadTrackView);
- }
- void CEditorImpl::ResetViews()
- {
- m_pViewManager->ResetViews();
- m_pDisplaySettings->SetRenderFlags(m_pDisplaySettings->GetRenderFlags());
- }
- IEditorFileMonitor* CEditorImpl::GetFileMonitor()
- {
- return m_pEditorFileMonitor.get();
- }
- float CEditorImpl::GetTerrainElevation(float x, float y)
- {
- float terrainElevation = AzFramework::Terrain::TerrainDataRequests::GetDefaultTerrainHeight();
- AzFramework::Terrain::TerrainDataRequestBus::BroadcastResult(terrainElevation
- , &AzFramework::Terrain::TerrainDataRequests::GetHeightFromFloats, x, y,
- AzFramework::Terrain::TerrainDataRequests::Sampler::BILINEAR, nullptr);
- return terrainElevation;
- }
- const QColor& CEditorImpl::GetColorByName(const QString& name)
- {
- return m_QtApplication->GetColorByName(name);
- }
- void CEditorImpl::SetSelectedRegion(const AABB& box)
- {
- m_selectedRegion = box;
- }
- void CEditorImpl::GetSelectedRegion(AABB& box)
- {
- box = m_selectedRegion;
- }
- const QtViewPane* CEditorImpl::OpenView(QString sViewClassName, bool reuseOpened)
- {
- auto openMode = reuseOpened ? QtViewPane::OpenMode::None : QtViewPane::OpenMode::MultiplePanes;
- return QtViewPaneManager::instance()->OpenPane(sViewClassName, openMode);
- }
- QWidget* CEditorImpl::FindView(QString viewClassName)
- {
- return QtViewPaneManager::instance()->GetView(viewClassName);
- }
- // Intended to give a window focus only if it is currently open
- bool CEditorImpl::SetViewFocus(const char* sViewClassName)
- {
- QWidget* findWindow = FindView(sViewClassName);
- if (findWindow)
- {
- findWindow->setFocus(Qt::OtherFocusReason);
- return true;
- }
- return false;
- }
- bool CEditorImpl::CloseView(const char* sViewClassName)
- {
- return QtViewPaneManager::instance()->ClosePane(sViewClassName);
- }
- void CEditorImpl::CloseView(const GUID& classId)
- {
- IClassDesc* found = GetClassFactory()->FindClass(classId);
- if (found)
- {
- CloseView(found->ClassName().toUtf8().data());
- }
- }
- bool CEditorImpl::SelectColor(QColor& color, QWidget* parent)
- {
- const AZ::Color c = AzQtComponents::fromQColor(color);
- AzQtComponents::ColorPicker dlg(AzQtComponents::ColorPicker::Configuration::RGB, tr("Select Color"), parent);
- dlg.setCurrentColor(c);
- dlg.setSelectedColor(c);
- if (dlg.exec() == QDialog::Accepted)
- {
- color = AzQtComponents::toQColor(dlg.currentColor());
- return true;
- }
- return false;
- }
- void CEditorImpl::SetInGameMode(bool inGame)
- {
- if (IsInSimulationMode())
- {
- return;
- }
- if (m_pGameEngine)
- {
- m_pGameEngine->RequestSetGameMode(inGame);
- }
- }
- bool CEditorImpl::IsInGameMode()
- {
- if (m_pGameEngine)
- {
- return m_pGameEngine->IsInGameMode();
- }
- return false;
- }
- bool CEditorImpl::IsInSimulationMode()
- {
- if (m_pGameEngine)
- {
- return m_pGameEngine->GetSimulationMode();
- }
- return false;
- }
- bool CEditorImpl::IsInTestMode()
- {
- return CCryEditApp::instance()->IsInTestMode();
- }
- bool CEditorImpl::IsInConsolewMode()
- {
- return CCryEditApp::instance()->IsInConsoleMode();
- }
- bool CEditorImpl::IsInLevelLoadTestMode()
- {
- return CCryEditApp::instance()->IsInLevelLoadTestMode();
- }
- bool CEditorImpl::IsInPreviewMode()
- {
- return CCryEditApp::instance()->IsInPreviewMode();
- }
- static AZStd::string SafeGetStringFromDocument(rapidjson::Document& projectCfg, const char* memberName)
- {
- if (projectCfg.HasMember(memberName) && projectCfg[memberName].IsString())
- {
- return projectCfg[memberName].GetString();
- }
- return "";
- }
- AZStd::string CEditorImpl::LoadProjectIdFromProjectData()
- {
- const char* MissingProjectId = "";
- // get the full path of the project.json
- AZStd::string fullPath;
- AZStd::string relPath("project.json");
- bool fullPathFound = false;
- using namespace AzToolsFramework;
- AssetSystemRequestBus::BroadcastResult(fullPathFound, &AssetSystemRequestBus::Events::GetFullSourcePathFromRelativeProductPath, relPath, fullPath);
- if (!fullPathFound)
- {
- return MissingProjectId;
- }
- QFile file(fullPath.c_str());
- if (!file.open(QIODevice::ReadOnly))
- {
- return MissingProjectId;
- }
- // Read the project.json file using its full path
- QByteArray fileContents = file.readAll();
- file.close();
- rapidjson::Document projectCfg;
- projectCfg.Parse(fileContents);
- if (!projectCfg.IsObject())
- {
- return MissingProjectId;
- }
- AZStd::string projectId = SafeGetStringFromDocument(projectCfg, "project_id");
- // if we don't have a valid projectId by now, it's not happening
- if (projectId.empty() || projectId[0] == '\0')
- {
- return MissingProjectId;
- }
- // get the project Id and project name from the project.json file
- QString projectName(SafeGetStringFromDocument(projectCfg, "project_name").data());
- QFileInfo fileInfo(fullPath.c_str());
- QDir folderDirectory = fileInfo.dir();
- // get the project name from the folder directory
- QString editorProjectName = folderDirectory.dirName();
- // if the project name in the file doesn't match the directory name, it probably means that this is
- // a copied project, and not safe to put any plain text into the projectId string
- if (editorProjectName.compare(projectName, Qt::CaseInsensitive) != 0)
- {
- return projectId;
- }
- // get the project Id generated by using the project name from the folder directory
- QByteArray editorProjectNameUtf8 = editorProjectName.toUtf8();
- AZ::Uuid id = AZ::Uuid::CreateName(editorProjectNameUtf8.constData());
- // The projects that Open 3D Engine ships with had their project IDs hand-generated based on the name of the level.
- // Therefore, if the UUID from the project name is the same as the UUID in the file, it's one of our projects
- // and we can therefore send the name back, making it easier for Metrics to determine which level it was.
- // We are checking to see if this is a project we ship with Open 3D Engine, and therefore we can unobfuscate non-customer information.
- if (id != AZ::Uuid(projectId.data()))
- {
- return projectId;
- }
- QByteArray projectNameUtf8 = projectName.toUtf8();
- projectId += " [";
- projectId += projectNameUtf8.constData();
- projectId += "]";
- return projectId;
- }
- void CEditorImpl::DetectVersion()
- {
- #if defined(AZ_PLATFORM_WINDOWS)
- char exe[_MAX_PATH];
- DWORD dwHandle;
- UINT len;
- wchar_t ver[1024 * 8];
- AZ::Utils::GetExecutablePath(exe, _MAX_PATH);
- AZStd::wstring exeW;
- AZStd::to_wstring(exeW, exe);
- int verSize = GetFileVersionInfoSizeW(exeW.c_str(), &dwHandle);
- if (verSize > 0)
- {
- GetFileVersionInfoW(exeW.c_str(), dwHandle, 1024 * 8, ver);
- VS_FIXEDFILEINFO* vinfo;
- VerQueryValueW(ver, L"\\", (void**)&vinfo, &len);
- m_fileVersion.v[0] = vinfo->dwFileVersionLS & 0xFFFF;
- m_fileVersion.v[1] = vinfo->dwFileVersionLS >> 16;
- m_fileVersion.v[2] = vinfo->dwFileVersionMS & 0xFFFF;
- m_fileVersion.v[3] = vinfo->dwFileVersionMS >> 16;
- m_productVersion.v[0] = vinfo->dwProductVersionLS & 0xFFFF;
- m_productVersion.v[1] = vinfo->dwProductVersionLS >> 16;
- m_productVersion.v[2] = vinfo->dwProductVersionMS & 0xFFFF;
- m_productVersion.v[3] = vinfo->dwProductVersionMS >> 16;
- }
- #else
- // This requires the application version to be set using QCoreApplication::setApplicationVersion, which isn't done yet.
- const QString version = qApp->applicationVersion();
- if (!version.isEmpty())
- {
- QByteArray versionBytes = version.toUtf8();
- m_fileVersion.Set(versionBytes.data());
- m_productVersion.Set(versionBytes.data());
- }
- #endif
- }
- XmlNodeRef CEditorImpl::FindTemplate(const QString& templateName)
- {
- return m_templateRegistry.FindTemplate(templateName);
- }
- void CEditorImpl::AddTemplate(const QString& templateName, XmlNodeRef& tmpl)
- {
- m_templateRegistry.AddTemplate(templateName, tmpl);
- }
- bool CEditorImpl::ExecuteConsoleApp(const QString& CommandLine, QString& OutputText, [[maybe_unused]] bool bNoTimeOut, bool bShowWindow)
- {
- CLogFile::FormatLine("Executing console application '%s'", CommandLine.toUtf8().data());
- QProcess process;
- if (bShowWindow)
- {
- #if defined(AZ_PLATFORM_WINDOWS)
- process.start("cmd.exe", { QString("/C %1").arg(CommandLine) });
- #elif defined(AZ_PLATFORM_LINUX)
- //KDAB_TODO
- #elif defined(AZ_PLATFORM_MAC)
- process.start("/usr/bin/osascript", { QString("-e 'tell application \"Terminal\" to do script \"%1\"'").arg(QString(CommandLine).replace("\"", "\\\"")) });
- #else
- process.start("/usr/bin/csh", { QString("-c \"%1\"'").arg(QString(CommandLine).replace("\"", "\\\"")) } );
- #endif
- }
- else
- {
- process.start(CommandLine, QStringList());
- }
- if (!process.waitForStarted())
- {
- return false;
- }
- // Wait for the process to finish
- process.waitForFinished();
-
- OutputText += process.readAllStandardOutput();
- OutputText += process.readAllStandardError();
- return true;
- }
- void CEditorImpl::BeginUndo()
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->Begin();
- }
- }
- void CEditorImpl::RestoreUndo(bool undo)
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->Restore(undo);
- }
- }
- void CEditorImpl::AcceptUndo(const QString& name)
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->Accept(name);
- }
- }
- void CEditorImpl::CancelUndo()
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->Cancel();
- }
- }
- void CEditorImpl::SuperBeginUndo()
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->SuperBegin();
- }
- }
- void CEditorImpl::SuperAcceptUndo(const QString& name)
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->SuperAccept(name);
- }
- }
- void CEditorImpl::SuperCancelUndo()
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->SuperCancel();
- }
- }
- void CEditorImpl::SuspendUndo()
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->Suspend();
- }
- }
- void CEditorImpl::ResumeUndo()
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->Resume();
- }
- }
- void CEditorImpl::Undo()
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->Undo();
- }
- }
- void CEditorImpl::Redo()
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->Redo();
- }
- }
- bool CEditorImpl::IsUndoRecording()
- {
- if (m_pUndoManager)
- {
- return m_pUndoManager->IsUndoRecording();
- }
- return false;
- }
- bool CEditorImpl::IsUndoSuspended()
- {
- if (m_pUndoManager)
- {
- return m_pUndoManager->IsUndoSuspended();
- }
- return false;
- }
- void CEditorImpl::RecordUndo(IUndoObject* obj)
- {
- if (m_pUndoManager)
- {
- m_pUndoManager->RecordUndo(obj);
- }
- }
- bool CEditorImpl::FlushUndo(bool isShowMessage)
- {
- if (isShowMessage && m_pUndoManager && m_pUndoManager->IsHaveUndo() && QMessageBox::question(AzToolsFramework::GetActiveWindow(), QObject::tr("Flush Undo"), QObject::tr("After this operation undo will not be available! Are you sure you want to continue?")) != QMessageBox::Yes)
- {
- return false;
- }
- if (m_pUndoManager)
- {
- m_pUndoManager->Flush();
- }
- return true;
- }
- bool CEditorImpl::ClearLastUndoSteps(int steps)
- {
- if (!m_pUndoManager || !m_pUndoManager->IsHaveUndo())
- {
- return false;
- }
- m_pUndoManager->ClearUndoStack(steps);
- return true;
- }
- bool CEditorImpl::ClearRedoStack()
- {
- if (!m_pUndoManager || !m_pUndoManager->IsHaveRedo())
- {
- return false;
- }
- m_pUndoManager->ClearRedoStack();
- return true;
- }
- void CEditorImpl::SetConsoleVar(const char* var, float value)
- {
- ICVar* ivar = GetSystem()->GetIConsole()->GetCVar(var);
- if (ivar)
- {
- ivar->Set(value);
- }
- }
- float CEditorImpl::GetConsoleVar(const char* var)
- {
- ICVar* ivar = GetSystem()->GetIConsole()->GetCVar(var);
- if (ivar)
- {
- return ivar->GetFVal();
- }
- return 0;
- }
- CAnimationContext* CEditorImpl::GetAnimation()
- {
- return m_pAnimationContext;
- }
- CTrackViewSequenceManager* CEditorImpl::GetSequenceManager()
- {
- return m_pSequenceManager;
- }
- ITrackViewSequenceManager* CEditorImpl::GetSequenceManagerInterface()
- {
- return GetSequenceManager();
- }
- void CEditorImpl::RegisterDocListener(IDocListener* listener)
- {
- CCryEditDoc* doc = GetDocument();
- if (doc)
- {
- doc->RegisterListener(listener);
- }
- }
- void CEditorImpl::UnregisterDocListener(IDocListener* listener)
- {
- CCryEditDoc* doc = GetDocument();
- if (doc)
- {
- doc->UnregisterListener(listener);
- }
- }
- void CEditorImpl::StartLevelErrorReportRecording()
- {
- IErrorReport* errorReport = GetErrorReport();
- if (errorReport)
- {
- errorReport->Clear();
- errorReport->SetImmediateMode(false);
- errorReport->SetShowErrors(true);
- }
- }
- // Confetti Start: Leroy Sikkes
- void CEditorImpl::Notify(EEditorNotifyEvent event)
- {
- NotifyExcept(event, nullptr);
- }
- void CEditorImpl::NotifyExcept(EEditorNotifyEvent event, IEditorNotifyListener* listener)
- {
- if (m_bExiting)
- {
- return;
- }
- std::list<IEditorNotifyListener*>::iterator it = m_listeners.begin();
- while (it != m_listeners.end())
- {
- if (*it == listener)
- {
- it++;
- continue; // skip "except" listener
- }
- (*it++)->OnEditorNotifyEvent(event);
- }
- if (event == eNotify_OnInit)
- {
- REGISTER_COMMAND("py", CmdPy, 0, "Execute a Python code snippet.");
- }
- GetPluginManager()->NotifyPlugins(event);
- }
- // Confetti end: Leroy Sikkes
- void CEditorImpl::RegisterNotifyListener(IEditorNotifyListener* listener)
- {
- listener->m_bIsRegistered = true;
- stl::push_back_unique(m_listeners, listener);
- }
- void CEditorImpl::UnregisterNotifyListener(IEditorNotifyListener* listener)
- {
- m_listeners.remove(listener);
- listener->m_bIsRegistered = false;
- }
- ISourceControl* CEditorImpl::GetSourceControl()
- {
- AZStd::scoped_lock lock(m_pluginMutex);
- if (m_pSourceControl)
- {
- return m_pSourceControl;
- }
- IEditorClassFactory* classFactory = GetIEditor() ? GetIEditor()->GetClassFactory() : nullptr;
- if (classFactory)
- {
- std::vector<IClassDesc*> classes;
- classFactory->GetClassesBySystemID(ESYSTEM_CLASS_SCM_PROVIDER, classes);
- for (int i = 0; i < classes.size(); i++)
- {
- IClassDesc* pClass = classes[i];
- ISourceControl* pSCM = nullptr;
- HRESULT hRes = pClass->QueryInterface(__az_uuidof(ISourceControl), (void**)&pSCM);
- if (!FAILED(hRes) && pSCM)
- {
- m_pSourceControl = pSCM;
- return m_pSourceControl;
- }
- }
- }
- return nullptr;
- }
- bool CEditorImpl::IsSourceControlAvailable()
- {
- if ((gSettings.enableSourceControl) && (GetSourceControl()))
- {
- return true;
- }
- return false;
- }
- bool CEditorImpl::IsSourceControlConnected()
- {
- if ((gSettings.enableSourceControl) && (GetSourceControl()) && (GetSourceControl()->GetConnectivityState() == ISourceControl::Connected))
- {
- return true;
- }
- return false;
- }
- void CEditorImpl::SetMatEditMode(bool bIsMatEditMode)
- {
- m_bMatEditMode = bIsMatEditMode;
- }
- void CEditorImpl::ShowStatusText(bool bEnable)
- {
- m_bShowStatusText = bEnable;
- }
- void CEditorImpl::ReduceMemory()
- {
- GetIEditor()->GetUndoManager()->ClearRedoStack();
- GetIEditor()->GetUndoManager()->ClearUndoStack();
- GetIEditor()->GetObjectManager()->SendEvent(EVENT_FREE_GAME_DATA);
- #if defined(AZ_PLATFORM_WINDOWS)
- HANDLE hHeap = GetProcessHeap();
- if (hHeap)
- {
- uint64 maxsize = (uint64)HeapCompact(hHeap, 0);
- CryLogAlways("Max Free Memory Block = %I64d Kb", maxsize / 1024);
- }
- #endif
- }
- ESystemConfigPlatform CEditorImpl::GetEditorConfigPlatform() const
- {
- return m_pSystem->GetConfigPlatform();
- }
- void CEditorImpl::InitFinished()
- {
- if (!m_bInitialized)
- {
- m_bInitialized = true;
- Notify(eNotify_OnInit);
- // Let system wide listeners know about this as well.
- GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_EDITOR_ON_INIT, 0, 0);
- }
- }
- void CEditorImpl::ReloadTemplates()
- {
- m_templateRegistry.LoadTemplates("Editor");
- }
- void CEditorImpl::AddErrorMessage(const QString& text, const QString& caption)
- {
- if (!m_pErrorsDlg)
- {
- m_pErrorsDlg = new CErrorsDlg(GetEditorMainWindow());
- m_pErrorsDlg->show();
- }
- m_pErrorsDlg->AddMessage(text, caption);
- }
- void CEditorImpl::CmdPy(IConsoleCmdArgs* pArgs)
- {
- if (AzToolsFramework::EditorPythonRunnerRequestBus::HasHandlers())
- {
- // Execute the given script command.
- QString scriptCmd = pArgs->GetCommandLine();
- scriptCmd = scriptCmd.right(scriptCmd.length() - 2); // The part of the text after the 'py'
- scriptCmd = scriptCmd.trimmed();
- AzToolsFramework::EditorPythonRunnerRequestBus::Broadcast(&AzToolsFramework::EditorPythonRunnerRequestBus::Events::ExecuteByString, scriptCmd.toUtf8().data(), false);
- }
- else
- {
- AZ_Warning("python", false, "EditorPythonRunnerRequestBus has no handlers");
- }
- }
- void CEditorImpl::OnObjectContextMenuOpened(QMenu* pMenu, const CBaseObject* pObject)
- {
- for (auto it : m_objectContextMenuExtensions)
- {
- it(pMenu, pObject);
- }
- }
- void CEditorImpl::RegisterObjectContextMenuExtension(TContextMenuExtensionFunc func)
- {
- m_objectContextMenuExtensions.push_back(func);
- }
- // Vladimir@Conffx
- SSystemGlobalEnvironment* CEditorImpl::GetEnv()
- {
- assert(gEnv);
- return gEnv;
- }
- // Leroy@Conffx
- SEditorSettings* CEditorImpl::GetEditorSettings()
- {
- return &gSettings;
- }
- IImageUtil* CEditorImpl::GetImageUtil()
- {
- return m_pImageUtil;
- }
- QMimeData* CEditorImpl::CreateQMimeData() const
- {
- return new QMimeData();
- }
- void CEditorImpl::DestroyQMimeData(QMimeData* data) const
- {
- delete data;
- }
|