git mv Code\Sandbox\Editor Code/Editor

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
Esteban Papp
2021-06-29 12:41:59 -07:00
parent 9f0bbf3b74
commit e34e36cb35
1415 changed files with 0 additions and 0 deletions
+102
View File
@@ -0,0 +1,102 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "EditorDefs.h"
#include "ErrorsDlg.h"
// Qt
#include <QClipboard>
#include <QStyle>
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
#include <Dialogs/ui_ErrorsDlg.h>
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
CErrorsDlg::CErrorsDlg(QWidget* pParent /*=NULL*/)
: QDialog(pParent)
, ui(new Ui::CErrorsDlg)
{
ui->setupUi(this);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_bFirstMessage = true;
OnInitDialog();
connect(ui->m_buttonCopyErrors, &QPushButton::clicked, this, &CErrorsDlg::OnCopyErrors);
connect(ui->m_buttonClearErrors, &QPushButton::clicked, this, &CErrorsDlg::OnClearErrors);
connect(ui->m_buttonCancel, &QPushButton::clicked, this, &CErrorsDlg::OnCancel);
}
CErrorsDlg::~CErrorsDlg()
{
}
void CErrorsDlg::OnInitDialog()
{
auto icon = style()->standardIcon(QStyle::SP_MessageBoxCritical);
ui->m_errorIconCtrl->setPixmap(icon.pixmap(ui->m_errorIconCtrl->width()));
}
void CErrorsDlg::AddMessage(const QString& text, const QString& caption)
{
// At the load time this dialog is frozen, cause there is no message loop in progress.
// We need to dispatch messages before showing a window if it was closed by user.
if (!isVisible())
{
show();
}
ui->m_richEdit->moveCursor(QTextCursor::End);
auto textCursor = ui->m_richEdit->textCursor();
if (m_bFirstMessage)
{
m_bFirstMessage = false;
}
else
{
textCursor.insertText("\n\n");
}
QTextCharFormat format;
format.setFontWeight(QFont::Bold);
textCursor.setCharFormat(format);
textCursor.insertText(caption + "\n");
format.setFontWeight(QFont::Normal);
// Show message in a dialog
textCursor.setCharFormat(format);
textCursor.insertText(text);
}
void CErrorsDlg::OnCancel()
{
hide();
}
void CErrorsDlg::OnCopyErrors()
{
QString text = ui->m_richEdit->toPlainText();
QApplication::clipboard()->setText(text);
}
void CErrorsDlg::OnClearErrors()
{
m_bFirstMessage = true;
ui->m_richEdit->clear();
}
#include <Dialogs/moc_ErrorsDlg.cpp>
+49
View File
@@ -0,0 +1,49 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : Modeless dialog for list of errors.
// To avoid interuption on start Editor time and on load level time.
// Using: To add messages from any part of CryEngine you can use this style:
// gEnv->pSystem->ShowMessage("Text", "Caption", MB_OK);
#ifndef CRYINCLUDE_EDITOR_DIALOGS_ERRORSDLG_H
#define CRYINCLUDE_EDITOR_DIALOGS_ERRORSDLG_H
#pragma once
#if !defined(Q_MOC_RUN)
#include <QDialog>
#endif
namespace Ui {
class CErrorsDlg;
}
class CErrorsDlg
: public QDialog
{
Q_OBJECT
public:
CErrorsDlg(QWidget* pParent = nullptr);
virtual ~CErrorsDlg();
void AddMessage(const QString& text, const QString& caption);
protected:
void OnCancel();
void OnInitDialog();
void OnCopyErrors();
void OnClearErrors();
private:
bool m_bFirstMessage;
QScopedPointer<Ui::CErrorsDlg> ui;
};
#endif // CRYINCLUDE_EDITOR_DIALOGS_ERRORSDLG_H
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CErrorsDlg</class>
<widget class="QDialog" name="CErrorsDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>520</width>
<height>367</height>
</rect>
</property>
<property name="windowTitle">
<string>Level Errors</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>16</number>
</property>
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item>
<widget class="QLabel" name="m_errorIconCtrl">
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>This is a list of errors you need to fix before saving your work. Otherwise it can corrupt the level data.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextEdit" name="m_richEdit">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="text" stdset="0">
<string/>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="m_buttonCopyErrors">
<property name="text">
<string>Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_buttonClearErrors">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="m_buttonCancel">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,74 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : These are helper classes for containing the data from the
// generic overwrite dialog
#include "EditorDefs.h"
#include "UserOptions.h"
//////////////////////////////////////////////////////////////////////////
CUserOptions::CUserOptionsReferenceCountHelper::CUserOptionsReferenceCountHelper(CUserOptions& roUserOptions)
: m_roReferencedUserOptionsObject(roUserOptions)
{
m_roReferencedUserOptionsObject.IncRef();
}
//////////////////////////////////////////////////////////////////////////
CUserOptions::CUserOptionsReferenceCountHelper::~CUserOptionsReferenceCountHelper()
{
m_roReferencedUserOptionsObject.DecRef();
}
//////////////////////////////////////////////////////////////////////////
CUserOptions::CUserOptions()
{
m_boToAll = false;
m_nCurrentOption = ENotSet;
}
//////////////////////////////////////////////////////////////////////////
bool CUserOptions::IsOptionValid()
{
return m_nCurrentOption != ENotSet;
}
//////////////////////////////////////////////////////////////////////////
int CUserOptions::GetOption()
{
return m_nCurrentOption;
}
//////////////////////////////////////////////////////////////////////////
bool CUserOptions::IsOptionToAll()
{
return m_boToAll;
}
//////////////////////////////////////////////////////////////////////////
void CUserOptions::SetOption(int nNewOption, bool boToAll)
{
m_nCurrentOption = nNewOption;
m_boToAll = boToAll;
}
//////////////////////////////////////////////////////////////////////////
int CUserOptions::DecRef()
{
if (m_nNumberOfReferences >= 1)
{
--m_nNumberOfReferences;
if (m_nNumberOfReferences == 0)
{
SetOption(CUserOptions::ENotSet, false);
}
}
return m_nNumberOfReferences;
}
//////////////////////////////////////////////////////////////////////////
int CUserOptions::IncRef()
{
++m_nNumberOfReferences;
return m_nNumberOfReferences;
}
//////////////////////////////////////////////////////////////////////////
+76
View File
@@ -0,0 +1,76 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
// Description : These are helper classes for containing the data from the
// generic overwrite dialog.
#ifndef CRYINCLUDE_EDITOR_DIALOGS_GENERIC_USEROPTIONS_H
#define CRYINCLUDE_EDITOR_DIALOGS_GENERIC_USEROPTIONS_H
#pragma once
// Small helper class.
// Hint: have one for files and other for directories.
// Hint: used a CUserOptionsReferenceCountHelper to automatically control the reference counts
// of any CUserOptions variable: usefull for recursion when you don't want to use
// only static variables. See example in FileUtill.cpp, function CopyTree.
class CUserOptions
{
//////////////////////////////////////////////////////////////////////////
// Types & typedefs
public:
enum EOption
{
ENotSet,
EYes = 6,
ENo = 7,
ECancel = 2,
};
class CUserOptionsReferenceCountHelper
{
public:
CUserOptionsReferenceCountHelper(CUserOptions& roUserOptions);
virtual ~CUserOptionsReferenceCountHelper();
protected:
CUserOptions& m_roReferencedUserOptionsObject;
};
protected:
private:
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Methods
public:
CUserOptions();
bool IsOptionValid();
int GetOption();
bool IsOptionToAll();
void SetOption(int nNewOption, bool boToAll);
int DecRef();
int IncRef();
protected:
private:
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Data
public:
protected:
int m_nCurrentOption;
bool m_boToAll;
int m_nNumberOfReferences;
private:
//////////////////////////////////////////////////////////////////////////
};
#endif // CRYINCLUDE_EDITOR_DIALOGS_GENERIC_USEROPTIONS_H
+174
View File
@@ -0,0 +1,174 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include "EditorDefs.h"
#include "PythonScriptsDialog.h"
// AzCore
#include <AzCore/Module/Module.h> // for AZ::ModuleData
#include <AzCore/Module/ModuleManagerBus.h> // for AZ::ModuleManagerRequestBus
#include <AzCore/Module/DynamicModuleHandle.h> // for AZ::DynamicModuleHandle
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/Utils/Utils.h>
// AzToolsFramework
#include <AzToolsFramework/API/ViewPaneOptions.h> // for AzToolsFramework::ViewPaneOptions
#include <AzToolsFramework/API/EditorPythonRunnerRequestsBus.h> // for AzToolsFramework::EditorPythonRunnerRequestBus
#include <AzToolsFramework/API/ToolsApplicationAPI.h>
// AzQtComponents
#include <AzQtComponents/Components/Widgets/LineEdit.h>
// Editor
#include "Settings.h"
#include "LyViewPaneNames.h"
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
#include <Dialogs/ui_PythonScriptsDialog.h>
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
//////////////////////////////////////////////////////////////////////////
namespace
{
// File name extension for python files
const QString s_kPythonFileNameSpec = "*.py";
// Tree root element name
const QString s_kRootElementName = "Python Scripts";
}
//////////////////////////////////////////////////////////////////////////
void CPythonScriptsDialog::RegisterViewClass()
{
if (AzToolsFramework::EditorPythonRunnerRequestBus::HasHandlers())
{
AzToolsFramework::ViewPaneOptions options;
options.canHaveMultipleInstances = true;
AzToolsFramework::RegisterViewPane<CPythonScriptsDialog>("Python Scripts", LyViewPane::CategoryOther, options);
}
}
//////////////////////////////////////////////////////////////////////////
CPythonScriptsDialog::CPythonScriptsDialog(QWidget* parent)
: QWidget(parent)
, ui(new Ui::CPythonScriptsDialog)
{
ui->setupUi(this);
AzQtComponents::LineEdit::applySearchStyle(ui->searchField);
QStringList scriptFolders;
auto engineScriptPath = AZ::IO::FixedMaxPath(AZ::Utils::GetEnginePath()) / "Assets" / "Editor" / "Scripts";
scriptFolders.push_back(engineScriptPath.c_str());
AZ::IO::FixedMaxPathString projectPath = AZ::Utils::GetProjectPath();
ScanFolderForScripts(QString("%1/Editor/Scripts").arg(projectPath.c_str()), scriptFolders);
struct GetGemSourcePathsVisitor
: AZ::SettingsRegistryInterface::Visitor
{
GetGemSourcePathsVisitor(AZ::SettingsRegistryInterface& settingsRegistry)
: m_settingsRegistry(settingsRegistry)
{}
void Visit(AZStd::string_view path, AZStd::string_view, AZ::SettingsRegistryInterface::Type,
AZStd::string_view value) override
{
AZStd::string_view jsonSourcePathPointer{ path };
// Remove the array index from the path and check if the JSON path ends with "/SourcePaths"
AZ::StringFunc::TokenizeLast(jsonSourcePathPointer, "/");
if (jsonSourcePathPointer.ends_with("/SourcePaths"))
{
AZ::IO::Path newSourcePath = jsonSourcePathPointer;
// Resolve any file aliases first - Do not use ResolvePath() as that assumes
// any relative path is underneath the @assets@ alias
if (auto fileIoBase = AZ::IO::FileIOBase::GetInstance(); fileIoBase != nullptr)
{
AZ::IO::FixedMaxPath replacedAliasPath;
if (fileIoBase->ReplaceAlias(replacedAliasPath, value))
{
newSourcePath = AZ::IO::PathView(replacedAliasPath);
}
}
// The current assumption is that the gem source path is the relative to the engine root
AZ::IO::Path engineRootPath;
m_settingsRegistry.Get(engineRootPath.Native(), AZ::SettingsRegistryMergeUtils::FilePathKey_EngineRootFolder);
newSourcePath = (engineRootPath / newSourcePath).LexicallyNormal();
if (auto gemSourcePathIter = AZStd::find(m_gemSourcePaths.begin(), m_gemSourcePaths.end(), newSourcePath);
gemSourcePathIter == m_gemSourcePaths.end())
{
m_gemSourcePaths.emplace_back(AZStd::move(newSourcePath));
}
}
}
AZStd::vector<AZ::IO::Path> m_gemSourcePaths;
private:
AZ::SettingsRegistryInterface& m_settingsRegistry;
};
if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
{
GetGemSourcePathsVisitor visitor{ *settingsRegistry };
constexpr auto gemListKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::OrganizationRootKey)
+ "/Gems";
settingsRegistry->Visit(visitor, gemListKey);
for (const AZ::IO::Path& gemSourcePath : visitor.m_gemSourcePaths)
{
ScanFolderForScripts(QString("%1/Editor/Scripts").arg(gemSourcePath.c_str()), scriptFolders);
}
}
ui->treeView->init(scriptFolders, s_kPythonFileNameSpec, s_kRootElementName, false, false);
QObject::connect(ui->treeView, &CFolderTreeCtrl::ItemDoubleClicked, this, &CPythonScriptsDialog::OnExecute);
QObject::connect(ui->executeButton, &QPushButton::clicked, this, &CPythonScriptsDialog::OnExecute);
QObject::connect(ui->searchField, &QLineEdit::textChanged, ui->treeView, &CFolderTreeCtrl::SetSearchFilter);
}
//////////////////////////////////////////////////////////////////////////
void CPythonScriptsDialog::ScanFolderForScripts(QString path, QStringList& scriptFolders) const
{
char resolvedPath[AZ_MAX_PATH_LEN] = { 0 };
if (AZ::IO::FileIOBase::GetDirectInstance()->ResolvePath(path.toLocal8Bit().constData(), resolvedPath, AZ_MAX_PATH_LEN))
{
if (AZ::IO::SystemFile::Exists(resolvedPath))
{
scriptFolders.push_back(path);
}
}
}
//////////////////////////////////////////////////////////////////////////
CPythonScriptsDialog::~CPythonScriptsDialog()
{
}
//////////////////////////////////////////////////////////////////////////
void CPythonScriptsDialog::OnExecute()
{
QList<QStandardItem*> selectedItems = ui->treeView->GetSelectedItems();
QStandardItem* selectedItem = selectedItems.empty() ? nullptr : selectedItems.first();
if (selectedItem == NULL)
{
return;
}
if (ui->treeView->IsFile(selectedItem))
{
auto scriptPath = AZ::IO::FixedMaxPath(AZ::Utils::GetEnginePath()) / ui->treeView->GetPath(selectedItem).toUtf8().constData();
using namespace AzToolsFramework;
EditorPythonRunnerRequestBus::Broadcast(&EditorPythonRunnerRequestBus::Events::ExecuteByFilename, scriptPath.Native());
}
}
#include <Dialogs/moc_PythonScriptsDialog.cpp>
+54
View File
@@ -0,0 +1,54 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#ifndef CRYINCLUDE_EDITOR_DIALOGS_PYTHONSCRIPTSDIALOG_H
#define CRYINCLUDE_EDITOR_DIALOGS_PYTHONSCRIPTSDIALOG_H
#pragma once
#if !defined(Q_MOC_RUN)
#include <QWidget>
#include <QScopedPointer>
#endif
namespace Ui {
class CPythonScriptsDialog;
}
class CPythonScriptsDialog
: public QWidget
{
Q_OBJECT
public:
explicit CPythonScriptsDialog(QWidget* parent = nullptr);
~CPythonScriptsDialog();
static const GUID& GetClassID()
{
// {C61C9C4C-CFED-47C4-8FE1-79069D0284E1}
static const GUID guid = {
0xc61c9c4c, 0xcfed, 0x47c4, { 0x8f, 0xe1, 0x79, 0x6, 0x9d, 0x2, 0x84, 0xe1 }
};
return guid;
}
static void RegisterViewClass();
private slots:
void OnExecute();
protected:
void ScanFolderForScripts(QString path, QStringList& scriptFolders) const;
private:
QScopedPointer<Ui::CPythonScriptsDialog> ui;
};
#endif // CRYINCLUDE_EDITOR_DIALOGS_PYTHONSCRIPTSDIALOG_H
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CPythonScriptsDialog</class>
<widget class="QWidget" name="CPythonScriptsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>416</width>
<height>336</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="CFolderTreeCtrl" name="treeView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="executeButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Execute</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="searchField">
<property name="placeholderText">
<string>Search...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>CFolderTreeCtrl</class>
<extends>QTreeView</extends>
<header>Controls/FolderTreeCtrl.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>