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,123 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "EditorDefs.h"
#include "ButtonsPanel.h"
// Qt
#include <QGridLayout>
// Editor
#include "Controls/ToolButton.h"
/////////////////////////////////////////////////////////////////////////////
// CButtonsPanel dialog
CButtonsPanel::CButtonsPanel(QWidget* parent)
: QWidget(parent)
{
}
CButtonsPanel::~CButtonsPanel()
{
}
//////////////////////////////////////////////////////////////////////////
void CButtonsPanel::AddButton(const SButtonInfo& button)
{
SButton b;
b.info = button;
m_buttons.push_back(b);
}
//////////////////////////////////////////////////////////////////////////
void CButtonsPanel::AddButton(const QString& name, const QString& toolClass)
{
SButtonInfo bi;
bi.name = name;
bi.toolClassName = toolClass;
AddButton(bi);
}
//////////////////////////////////////////////////////////////////////////
void CButtonsPanel::AddButton(const QString& name, const QMetaObject* pToolClass)
{
SButtonInfo bi;
bi.name = name;
bi.pToolClass = pToolClass;
AddButton(bi);
}
//////////////////////////////////////////////////////////////////////////
void CButtonsPanel::ClearButtons()
{
auto buttons = layout()->findChildren<QEditorToolButton*>();
foreach(auto button, buttons)
{
layout()->removeWidget(button);
delete button;
}
m_buttons.clear();
}
void CButtonsPanel::UncheckAll()
{
for (auto& button : m_buttons)
{
button.pButton->SetSelected(false);
}
}
void CButtonsPanel::OnInitDialog()
{
auto layout = new QGridLayout(this);
setLayout(layout);
layout->setMargin(4);
layout->setHorizontalSpacing(4);
layout->setVerticalSpacing(1);
// Create Buttons.
int index = 0;
for (auto& button : m_buttons)
{
button.pButton = new QEditorToolButton(this);
button.pButton->setObjectName(button.info.name);
button.pButton->setText(button.info.name);
button.pButton->SetNeedDocument(button.info.bNeedDocument);
button.pButton->setToolTip(button.info.toolTip);
if (button.info.pToolClass)
{
button.pButton->SetToolClass(button.info.pToolClass, button.info.toolUserDataKey, (void*)button.info.toolUserData.c_str());
}
else if (!button.info.toolClassName.isEmpty())
{
button.pButton->SetToolName(button.info.toolClassName, button.info.toolUserDataKey, (void*)button.info.toolUserData.c_str());
}
layout->addWidget(button.pButton, index / 2, index % 2);
connect(button.pButton, &QEditorToolButton::clicked, this, [&]() { OnButtonPressed(button.info); });
++index;
}
}
void CButtonsPanel::EnableButton(const QString& buttonName, bool enable)
{
for (auto& button : m_buttons)
{
if (button.pButton->objectName() == buttonName)
{
button.pButton->setEnabled(enable);
}
}
}
#include <Dialogs/moc_ButtonsPanel.cpp>
@@ -0,0 +1,76 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_EDITOR_DIALOGS_BUTTONSPANEL_H
#define CRYINCLUDE_EDITOR_DIALOGS_BUTTONSPANEL_H
#pragma once
#if !defined(Q_MOC_RUN)
#include <QWidget>
#endif
class QEditorToolButton;
/////////////////////////////////////////////////////////////////////////////
// Panel with custom auto arranged buttons
class CButtonsPanel
: public QWidget
{
Q_OBJECT
public:
struct SButtonInfo
{
QString name;
QString toolClassName;
QString toolUserDataKey;
std::string toolUserData;
QString toolTip;
bool bNeedDocument;
const QMetaObject* pToolClass;
SButtonInfo()
: pToolClass(nullptr)
, bNeedDocument(true) {};
};
CButtonsPanel(QWidget* parent);
virtual ~CButtonsPanel();
virtual void AddButton(const SButtonInfo& button);
virtual void AddButton(const QString& name, const QString& toolClass);
virtual void AddButton(const QString& name, const QMetaObject* pToolClass);
virtual void EnableButton(const QString& buttonName, bool disable);
virtual void ClearButtons();
virtual void OnButtonPressed([[maybe_unused]] const SButtonInfo& button) {};
virtual void UncheckAll();
protected:
void ReleaseGuiButtons();
virtual void OnInitDialog();
//////////////////////////////////////////////////////////////////////////
struct SButton
{
SButtonInfo info;
QEditorToolButton* pButton;
SButton()
: pButton(nullptr) {};
};
std::vector<SButton> m_buttons;
};
#endif // CRYINCLUDE_EDITOR_DIALOGS_BUTTONSPANEL_H
@@ -0,0 +1,51 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "EditorDefs.h"
#include "DuplicatedObjectsHandlerDlg.h"
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
#include <Dialogs/ui_DuplicatedObjectsHandlerDlg.h>
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
CDuplicatedObjectsHandlerDlg::CDuplicatedObjectsHandlerDlg(const QString& msg, QWidget* pParent)
: QDialog(pParent)
, m_ui(new Ui::DuplicatedObjectsHandlerDlg)
{
m_ui->setupUi(this);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_ui->textBrowser->setPlainText(msg);
connect(m_ui->buttonOverride, &QPushButton::clicked, this, &CDuplicatedObjectsHandlerDlg::OnBnClickedOverrideBtn);
connect(m_ui->buttonCreateCopies, &QPushButton::clicked, this, &CDuplicatedObjectsHandlerDlg::OnBnClickedCreateCopiesBtn);
}
CDuplicatedObjectsHandlerDlg::~CDuplicatedObjectsHandlerDlg()
{
}
void CDuplicatedObjectsHandlerDlg::OnBnClickedOverrideBtn()
{
m_result = eResult_Override;
accept();
}
void CDuplicatedObjectsHandlerDlg::OnBnClickedCreateCopiesBtn()
{
m_result = eResult_CreateCopies;
accept();
}
#include <Dialogs/moc_DuplicatedObjectsHandlerDlg.cpp>
@@ -0,0 +1,57 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_EDITOR_DIALOGS_DUPLICATEDOBJECTSHANDLERDLG_H
#define CRYINCLUDE_EDITOR_DIALOGS_DUPLICATEDOBJECTSHANDLERDLG_H
#pragma once
#if !defined(Q_MOC_RUN)
#include <QDialog>
#endif
namespace Ui
{
class DuplicatedObjectsHandlerDlg;
}
class CDuplicatedObjectsHandlerDlg
: public QDialog
{
Q_OBJECT
public:
CDuplicatedObjectsHandlerDlg(const QString& msg, QWidget* pParent = nullptr);
virtual ~CDuplicatedObjectsHandlerDlg();
enum EResult
{
eResult_None,
eResult_Override,
eResult_CreateCopies
};
EResult GetResult() const
{
return m_result;
}
protected:
EResult m_result;
void OnBnClickedOverrideBtn();
void OnBnClickedCreateCopiesBtn();
QScopedPointer<Ui::DuplicatedObjectsHandlerDlg> m_ui;
};
#endif // CRYINCLUDE_EDITOR_DIALOGS_DUPLICATEDOBJECTSHANDLERDLG_H
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DuplicatedObjectsHandlerDlg</class>
<widget class="QDialog" name="DuplicatedObjectsHandlerDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>474</width>
<height>204</height>
</rect>
</property>
<property name="windowTitle">
<string>Duplicated Objects Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextBrowser" name="textBrowser">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<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="pushButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonOverride">
<property name="text">
<string>Override</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonCreateCopies">
<property name="text">
<string>Create Copies</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>DuplicatedObjectsHandlerDlg</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>258</x>
<y>183</y>
</hint>
<hint type="destinationlabel">
<x>190</x>
<y>184</y>
</hint>
</hints>
</connection>
</connections>
</ui>
+107
View File
@@ -0,0 +1,107 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#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>
+54
View File
@@ -0,0 +1,54 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// 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,79 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// 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;
}
//////////////////////////////////////////////////////////////////////////
@@ -0,0 +1,81 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// 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
@@ -0,0 +1,156 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#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
// 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;
const auto editorEnvStr = gSettings.strEditorEnv.toLocal8Bit();
AZStd::string editorScriptsPath = AZStd::string::format("@engroot@/%s", editorEnvStr.constData());
XmlNodeRef envNode = XmlHelpers::LoadXmlFromFile(editorScriptsPath.c_str());
if (envNode)
{
QString scriptPath;
int childrenCount = envNode->getChildCount();
for (int idx = 0; idx < childrenCount; ++idx)
{
XmlNodeRef child = envNode->getChild(idx);
if (child->haveAttr("scriptPath"))
{
scriptPath = child->getAttr("scriptPath");
scriptFolders.push_back(scriptPath);
}
}
}
ScanFolderForScripts(QString("@devroot@/%1/Editor/Scripts").arg(GetIEditor()->GetProjectName()), scriptFolders);
auto moduleCallback = [this, &scriptFolders](const AZ::ModuleData& moduleData) -> bool
{
if (moduleData.GetDynamicModuleHandle())
{
const AZ::OSString& modulePath = moduleData.GetDynamicModuleHandle()->GetFilename();
AZStd::string fileName;
AzFramework::StringFunc::Path::GetFileName(modulePath.c_str(), fileName);
AZStd::vector<AZStd::string> tokens;
AzFramework::StringFunc::Tokenize(fileName.c_str(), tokens, '.');
if (tokens.size() > 2 && tokens[0] == "Gem")
{
ScanFolderForScripts(QString("@engroot@/Gems/%1/Editor/Scripts").arg(tokens[1].c_str()), scriptFolders);
}
}
return true;
};
AZ::ModuleManagerRequestBus::Broadcast(&AZ::ModuleManagerRequestBus::Events::EnumerateModules, moduleCallback);
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))
{
QString workingDirectory = QDir::currentPath();
const QString scriptPath = QStringLiteral("%1/%2").arg(workingDirectory).arg(ui->treeView->GetPath(selectedItem));
using namespace AzToolsFramework;
EditorPythonRunnerRequestBus::Broadcast(&EditorPythonRunnerRequestBus::Events::ExecuteByFilename, scriptPath.toUtf8().constData());
}
}
#include <Dialogs/moc_PythonScriptsDialog.cpp>
@@ -0,0 +1,59 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#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>
@@ -0,0 +1,218 @@
/*
* 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 "NewEntityDialog.h"
// Qt
#include <QPushButton>
#include <QToolTip>
#include <QMessageBox>
// Editor
#include "Dialogs/QT/ui_NewEntityDialog.h"
NewEntityDialog::NewEntityDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::NewEntityDialog)
{
entityNameValidator = new EntityNameValidator(this);
ui->setupUi(this);
ui->entityName->setFocus();
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
connect(ui->entityName, SIGNAL(textChanged(QString)), this, SLOT(ValidateInput()));
connect(ui->categoryName, SIGNAL(textChanged(QString)), this, SLOT(ValidateInput()));
SetCategoryCompleterPath((Path::GetEditingGameDataFolder() + "/Scripts/Entities").c_str());
SetNameValidatorPath((Path::GetEditingGameDataFolder() + "/Entities").c_str());
}
NewEntityDialog::~NewEntityDialog()
{
SAFE_DELETE(entityNameValidator);
SAFE_DELETE(folderNameCompleter);
delete ui;
}
void NewEntityDialog::SetCategoryCompleterPath(CryStringT<char> path)
{
SAFE_DELETE(folderNameCompleter);
QDirIterator directoryIt(QString::fromLocal8Bit(path.c_str(), path.length()), QDir::NoDotAndDotDot | QDir::AllDirs, QDirIterator::Subdirectories);
baseDir = directoryIt.path() + "/";
QStringList dirs;
while (directoryIt.hasNext())
{
QString dir = directoryIt.next().remove(baseDir);
dirs.append(dir);
}
folderNameCompleter = new QCompleter(dirs);
folderNameCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
folderNameCompleter->setCaseSensitivity(Qt::CaseInsensitive);
ui->categoryName->setCompleter(folderNameCompleter);
}
void NewEntityDialog::SetNameValidatorPath(CryStringT<char> path)
{
QDir dir(QString::fromLocal8Bit(path.c_str(), path.length()));
nameBaseDir = dir.path() + "/";
}
void NewEntityDialog::ValidateInput()
{
int cursorPos = ui->entityName->cursorPosition();
QString text = ui->entityName->text();
bool validText = entityNameValidator->validate(text, cursorPos);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(validText);
}
void NewEntityDialog::accept()
{
if (ui->categoryName->text().isEmpty()
&& QMessageBox::question(this, "Are you sure?", "Create entity without category?", QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
{
return;
}
const char* devRoot = gEnv->pFileIO->GetAlias("@engroot@");
QString devRootPath(devRoot);
QFile entTemplateFile(devRootPath + "/Editor/NewEntityTemplate.ent_template");
QFile luaTemplateFile(devRootPath + "/Editor/NewEntityTemplate.lua_template");
QFile entDestFile(nameBaseDir + ui->entityName->text() + ".ent");
QFile luaDestFile(baseDir + ui->categoryName->text() + "/" + ui->entityName->text() + ".lua");
if (!entTemplateFile.exists() || !luaTemplateFile.exists())
{
QMessageBox::critical(this, tr("Missing Template Files"), tr("In order to create default entities the NewEntityTemplate.lua and NewEntityTemplate.ent template files must exist in the Templates folder!"));
return;
}
//generate the .ent file
QDir pathMaker(nameBaseDir);
pathMaker.mkpath(pathMaker.path());
QString entFileString;
if (!entTemplateFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
AZ_Warning("Editor", false, "Enable to open template file for ent : %s", entTemplateFile.fileName().toUtf8().constData());
return;
}
else
{
entFileString = entTemplateFile.readAll();
entTemplateFile.close();
}
entFileString.replace(QString("[CATEGORY_NAME]"), ui->categoryName->text());
entFileString.replace(QString("[ENTITY_NAME]"), ui->entityName->text());
if (!entDestFile.open(QIODevice::WriteOnly | QIODevice::Text))
{
AZ_Warning("Editor", false, "Enable to open destination file for ent : %s", entDestFile.fileName().toUtf8().constData());
return;
}
else
{
entDestFile.write(entFileString.toUtf8());
entDestFile.close();
}
//generate the .lua file
pathMaker.setPath(baseDir);
pathMaker.mkpath(ui->categoryName->text() + "/");
QString luaFileString;
if (!luaTemplateFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
AZ_Warning("Editor", false, "Enable to open template file for lua : %s", luaTemplateFile.fileName().toUtf8().constData());
return;
}
else
{
luaFileString = luaTemplateFile.readAll();
luaTemplateFile.close();
}
luaFileString.replace(QString("[ENTITY_NAME]"), ui->entityName->text());
if (!luaDestFile.open(QIODevice::WriteOnly | QIODevice::Text))
{
AZ_Warning("Editor", false, "Enable to open destination file for lua : %s", luaDestFile.fileName().toUtf8().constData());
return;
}
else
{
luaDestFile.write(luaFileString.toUtf8());
luaDestFile.close();
}
if (ui->openLuaCB->isChecked())
{
CFileUtil::EditTextFile(luaDestFile.fileName().toLocal8Bit().data());
}
QDialog::accept();
}
QValidator::State NewEntityDialog::EntityNameValidator::validate(QString& input, [[maybe_unused]] int& pos) const
{
if (!m_Parent)
{
return Invalid;
}
if (input.isEmpty())
{
return Invalid;
}
if (input.contains("/"))
{
return Invalid;
}
QString fileBaseName = m_Parent->ui->entityName->text();
// Characters
const char* notAllowedChars = ",^@=+{}[]~!?:&*\"|#%<>$\"'();`' ";
for (const char* c = notAllowedChars; *c; c++)
{
if (fileBaseName.contains(QLatin1Char(*c)))
{
const QChar qc = QLatin1Char(*c);
if (qc.isSpace())
{
QToolTip::showText(m_Parent->ui->entityName->mapToGlobal(QPoint()), tr("Name may not contain white space."), m_Parent->ui->entityName, m_Parent->ui->entityName->rect(), 2000);
}
else
{
QToolTip::showText(m_Parent->ui->entityName->mapToGlobal(QPoint()), tr("Invalid character \"%1\".").arg(qc), m_Parent->ui->entityName, m_Parent->ui->entityName->rect(), 2000);
}
return Invalid;
}
}
QString filename(m_Parent->nameBaseDir + m_Parent->ui->entityName->text() + ".ent");
QFile newFile(filename);
if (newFile.exists())
{
QToolTip::showText(m_Parent->ui->entityName->mapToGlobal(QPoint()), tr("Filename already exists!"), m_Parent->ui->entityName, m_Parent->ui->entityName->rect(), 2000);
return Invalid;
}
return Acceptable;
}
#include <Dialogs/QT/moc_NewEntityDialog.cpp>
@@ -0,0 +1,69 @@
/*
* 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.
*
*/
#ifndef NEWENTITYDIALOG_H
#define NEWENTITYDIALOG_H
#if !defined(Q_MOC_RUN)
#include <QDialog>
#include <QCompleter>
#include <QDirIterator>
#include <QStringListModel>
#include <QValidator>
#include <QEvent>
#include <QLineEdit>
#endif
namespace Ui {
class NewEntityDialog;
}
class NewEntityDialog
: public QDialog
{
Q_OBJECT
public:
explicit NewEntityDialog(QWidget* parent = 0);
~NewEntityDialog();
private:
Ui::NewEntityDialog* ui;
QString baseDir = "";
QString nameBaseDir = "";
QCompleter* folderNameCompleter = NULL;
void SetCategoryCompleterPath(CryStringT<char> path);
void SetNameValidatorPath(CryStringT<char> path);
virtual void accept();
class EntityNameValidator
: public QValidator
{
public:
explicit EntityNameValidator(NewEntityDialog* parent = 0)
: QValidator(parent)
, m_Parent(parent)
{
}
virtual State validate(QString& input, int& pos) const;
NewEntityDialog* m_Parent;
};
EntityNameValidator* entityNameValidator;
public slots:
void ValidateInput();
};
#endif // NEWENTITYDIALOG_H
@@ -0,0 +1,161 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NewEntityDialog</class>
<widget class="QDialog" name="NewEntityDialog">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>111</height>
</rect>
</property>
<property name="contextMenuPolicy">
<enum>Qt::PreventContextMenu</enum>
</property>
<property name="windowTitle">
<string>New Entity</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<property name="modal">
<bool>false</bool>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>70</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QLineEdit" name="entityName">
<property name="geometry">
<rect>
<x>110</x>
<y>10</y>
<width>281</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Entity Name:</string>
</property>
<property name="buddy">
<cstring>entityName</cstring>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Entity Category:</string>
</property>
<property name="buddy">
<cstring>categoryName</cstring>
</property>
</widget>
<widget class="QLineEdit" name="categoryName">
<property name="geometry">
<rect>
<x>110</x>
<y>40</y>
<width>281</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QCheckBox" name="openLuaCB">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>141</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Open Lua After Creating</string>
</property>
</widget>
</widget>
<tabstops>
<tabstop>entityName</tabstop>
<tabstop>categoryName</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>NewEntityDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>NewEntityDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>