Added tweak editor

This commit is contained in:
Aruki 2018-12-27 23:56:43 -07:00
parent 2c80e60b78
commit e8d3224088
15 changed files with 345 additions and 55 deletions

View File

@ -157,12 +157,23 @@ void CEditorApplication::EditResource(CResourceEntry *pEntry)
case EResourceType::StringTable:
pEd = new CStringEditor((CStringTable*) pRes, mpWorldEditor);
break;
case EResourceType::Tweaks:
{
CTweakEditor* pTweakEditor = mpWorldEditor->TweakEditor();
pTweakEditor->SetActiveTweakData( (CTweakData*) pRes );
pEd = pTweakEditor;
break;
}
}
if (pEd)
{
pEd->show();
mEditingMap[pEntry] = pEd;
if (pEntry->ResourceType() != EResourceType::Tweaks)
mEditingMap[pEntry] = pEd;
}
else if (pEntry->ResourceType() != EResourceType::Area)
UICommon::InfoMsg(mpWorldEditor, "Unsupported Resource", "This resource type is currently unsupported for editing.");
@ -308,7 +319,11 @@ void CEditorApplication::OnEditorClose()
}
mEditorWindows.removeOne(pEditor);
delete pEditor;
if (pEditor != mpWorldEditor->TweakEditor())
{
delete pEditor;
}
if (mpActiveProject)
{

108
src/Editor/CTweakEditor.cpp Normal file
View File

@ -0,0 +1,108 @@
#include "CTweakEditor.h"
#include "ui_CTweakEditor.h"
CTweakEditor::CTweakEditor(QWidget* pParent)
: IEditor(pParent)
, mpUI(new Ui::CTweakEditor)
, mCurrentTweakIndex(-1)
, mHasBeenShown(false)
{
mpUI->setupUi(this);
mpUI->TweakTabs->setExpanding(false);
SET_WINDOWTITLE_APPVARS("%APP_FULL_NAME% - Tweak Editor");
connect(mpUI->TweakTabs, SIGNAL(currentChanged(int)), this, SLOT(SetActiveTweakIndex(int)));
}
CTweakEditor::~CTweakEditor()
{
delete mpUI;
}
bool CTweakEditor::HasTweaks()
{
return !mTweakAssets.isEmpty();
}
void CTweakEditor::showEvent(QShowEvent* pEvent)
{
// Perform first-time UI initialization
// Property view cannot initialize correctly until first show due to window width not being configured
if (!mHasBeenShown)
{
mpUI->PropertyView->InitColumnWidths(0.6f, 0.3f);
mHasBeenShown = true;
}
IEditor::showEvent(pEvent);
}
void CTweakEditor::SetActiveTweakData(CTweakData* pTweakData)
{
for( int TweakIdx = 0; TweakIdx < mTweakAssets.size(); TweakIdx++ )
{
if (mTweakAssets[TweakIdx] == pTweakData)
{
SetActiveTweakIndex(TweakIdx);
break;
}
}
}
void CTweakEditor::SetActiveTweakIndex(int Index)
{
if( mCurrentTweakIndex != Index )
{
mCurrentTweakIndex = Index;
CTweakData* pTweakData = mTweakAssets[Index];
mpUI->PropertyView->SetIntrinsicProperties(pTweakData->TweakData());
mpUI->TweakTabs->blockSignals(true);
mpUI->TweakTabs->setCurrentIndex(Index);
mpUI->TweakTabs->blockSignals(false);
}
}
void CTweakEditor::OnProjectChanged(CGameProject* pNewProject)
{
// Close and clear tabs
mCurrentTweakIndex = -1;
mpUI->PropertyView->ClearProperties();
close();
mpUI->TweakTabs->blockSignals(true);
while (mpUI->TweakTabs->count() > 0)
{
mpUI->TweakTabs->removeTab(0);
}
mpUI->TweakTabs->blockSignals(false);
mTweakAssets.clear();
// Create tweak list
if (pNewProject != nullptr)
{
for (TResPtr<CTweakData> pTweakData : pNewProject->TweakManager()->TweakObjects())
{
mTweakAssets << pTweakData.RawPointer();
}
}
// Sort in alphabetical order and create tabs
if (!mTweakAssets.isEmpty())
{
qSort(mTweakAssets.begin(), mTweakAssets.end(), [](CTweakData* pLeft, CTweakData* pRight) -> bool {
return pLeft->Entry()->Name().ToUpper() < pRight->Entry()->Name().ToUpper();
});
foreach (CTweakData* pTweakData, mTweakAssets)
{
QString TweakName = TO_QSTRING( pTweakData->Entry()->Name() );
mpUI->TweakTabs->addTab(TweakName);
}
SetActiveTweakIndex(0);
}
}

39
src/Editor/CTweakEditor.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef CTWEAKEDITOR_H
#define CTWEAKEDITOR_H
#include "Editor/IEditor.h"
namespace Ui {
class CTweakEditor;
}
class CTweakEditor : public IEditor
{
Q_OBJECT
/** Qt UI */
Ui::CTweakEditor* mpUI;
/** List of editable tweak assets */
QVector<CTweakData*> mTweakAssets;
/** Whether the editor window has been shown before */
bool mHasBeenShown;
/** Index of tweak data currently being edited */
int mCurrentTweakIndex;
public:
explicit CTweakEditor(QWidget* pParent = 0);
~CTweakEditor();
bool HasTweaks();
virtual void showEvent(QShowEvent* pEvent) override;
public slots:
void SetActiveTweakData(CTweakData* pTweakData);
void SetActiveTweakIndex(int Index);
void OnProjectChanged(CGameProject* pNewProject);
};
#endif // CTWEAKEDITOR_H

120
src/Editor/CTweakEditor.ui Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CTweakEditor</class>
<widget class="QMainWindow" name="CTweakEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>452</width>
<height>644</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabBar" name="TweakTabs" native="true"/>
</item>
<item>
<widget class="CPropertyView" name="PropertyView">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="ToolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="ActionSave"/>
<addaction name="ActionSaveAndRepack"/>
</widget>
<action name="ActionSave">
<property name="icon">
<iconset resource="Icons.qrc">
<normaloff>:/icons/Save.png</normaloff>:/icons/Save.png</iconset>
</property>
<property name="text">
<string>Save</string>
</property>
<property name="toolTip">
<string>Save</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="ActionSaveAndRepack">
<property name="icon">
<iconset resource="Icons.qrc">
<normaloff>:/icons/SaveAndRepack_32px.png</normaloff>:/icons/SaveAndRepack_32px.png</iconset>
</property>
<property name="text">
<string>Save and Repack</string>
</property>
<property name="toolTip">
<string>Save and Repack</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>QTabBar</class>
<extends>QWidget</extends>
<header location="global">QTabBar</header>
<container>1</container>
</customwidget>
<customwidget>
<class>CPropertyView</class>
<extends>QTreeView</extends>
<header>Editor/PropertyEdit/CPropertyView.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="Icons.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -203,7 +203,8 @@ HEADERS += \
StringEditor/CStringEditor.h \
StringEditor/CStringListModel.h \
StringEditor/CStringDelegate.h \
CCustomDelegate.h
CCustomDelegate.h \
CTweakEditor.h
# Source Files
SOURCES += \
@ -282,7 +283,8 @@ SOURCES += \
StringEditor/CStringEditor.cpp \
StringEditor/CStringListModel.cpp \
IEditor.cpp \
StringEditor/CStringDelegate.cpp
StringEditor/CStringDelegate.cpp \
CTweakEditor.cpp
# UI Files
FORMS += \
@ -310,7 +312,8 @@ FORMS += \
CProgressDialog.ui \
Widgets/CSelectResourcePanel.ui \
CGeneratePropertyNamesDialog.ui \
StringEditor/CStringEditor.ui
StringEditor/CStringEditor.ui \
CTweakEditor.ui
# Codegen
CODEGEN_DIR = $$EXTERNALS_DIR/CodeGen

View File

@ -27,12 +27,12 @@
CPropertyDelegate::CPropertyDelegate(QObject *pParent /*= 0*/)
: QStyledItemDelegate(pParent)
, mpEditor(nullptr)
, mpModel(nullptr)
, mInRelayWidgetEdit(false)
, mEditInProgress(false)
, mRelaysBlocked(false)
{
mpEditor = gpEdApp->WorldEditor();
}
void CPropertyDelegate::SetPropertyModel(CPropertyModel *pModel)
@ -40,11 +40,6 @@ void CPropertyDelegate::SetPropertyModel(CPropertyModel *pModel)
mpModel = pModel;
}
void CPropertyDelegate::SetEditor(CWorldEditor *pEditor)
{
mpEditor = pEditor;
}
QWidget* CPropertyDelegate::createEditor(QWidget *pParent, const QStyleOptionViewItem& /*rkOption*/, const QModelIndex& rkIndex) const
{
if (!mpModel) return nullptr;

View File

@ -18,7 +18,6 @@ class CPropertyDelegate : public QStyledItemDelegate
public:
CPropertyDelegate(QObject *pParent = 0);
void SetPropertyModel(CPropertyModel *pModel);
void SetEditor(CWorldEditor *pEditor);
virtual QWidget* createEditor(QWidget *pParent, const QStyleOptionViewItem& rkOption, const QModelIndex& rkIndex) const;
virtual void setEditorData(QWidget *pEditor, const QModelIndex &rkIndex) const;

View File

@ -9,7 +9,6 @@
CPropertyView::CPropertyView(QWidget *pParent)
: QTreeView(pParent)
, mpEditor(nullptr)
, mpMenuProperty(nullptr)
{
mpModel = new CPropertyModel(this);
@ -40,6 +39,9 @@ CPropertyView::CPropertyView(QWidget *pParent)
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(CreateContextMenu(QPoint)));
connect(mpModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(SetPersistentEditors(QModelIndex)));
connect(mpModel, SIGNAL(PropertyModified(const QModelIndex&)), this, SLOT(OnPropertyModified(const QModelIndex&)));
mpEditor = gpEdApp->WorldEditor();
connect(mpEditor, SIGNAL(PropertyModified(CScriptObject*,IProperty*)), mpModel, SLOT(NotifyPropertyModified(CScriptObject*,IProperty*)));
}
void CPropertyView::setModel(QAbstractItemModel *pModel)
@ -84,11 +86,17 @@ bool CPropertyView::event(QEvent *pEvent)
else return QTreeView::event(pEvent);
}
void CPropertyView::SetEditor(CWorldEditor *pEditor)
void CPropertyView::InitColumnWidths(float NameColumnPercentage, float ValueColumnPercentage)
{
mpEditor = pEditor;
mpDelegate->SetEditor(pEditor);
connect(mpEditor, SIGNAL(PropertyModified(CScriptObject*,IProperty*)), mpModel, SLOT(NotifyPropertyModified(CScriptObject*,IProperty*)));
header()->resizeSection(0, width() * NameColumnPercentage);
header()->resizeSection(1, width() * ValueColumnPercentage);
header()->setSectionResizeMode(1, QHeaderView::Fixed);
}
void CPropertyView::ClearProperties()
{
mpObject = nullptr;
mpModel->ConfigureScript(nullptr, nullptr, nullptr);
}
void CPropertyView::SetIntrinsicProperties(CStructRef InProperties)

View File

@ -26,7 +26,8 @@ public:
CPropertyView(QWidget *pParent = 0);
void setModel(QAbstractItemModel *pModel);
bool event(QEvent *pEvent);
void SetEditor(CWorldEditor *pEditor);
void InitColumnWidths(float NameColumnPercentage, float ValueColumnPercentage);
void ClearProperties();
void SetIntrinsicProperties(CStructRef InProperties);
void SetInstance(CScriptObject *pObj);
void UpdateEditorProperties(const QModelIndex& rkParent);

View File

@ -39,6 +39,7 @@ CWorldEditor::CWorldEditor(QWidget *parent)
, mpWorld(nullptr)
, mpLinkDialog(new CLinkDialog(this, this))
, mpGeneratePropertyNamesDialog(new CGeneratePropertyNamesDialog(this))
, mpTweakEditor(new CTweakEditor(this))
, mIsMakingLink(false)
, mpNewLinkSender(nullptr)
, mpNewLinkReceiver(nullptr)
@ -170,8 +171,9 @@ CWorldEditor::CWorldEditor(QWidget *parent)
connect(ui->ActionLink, SIGNAL(toggled(bool)), this, SLOT(OnLinkButtonToggled(bool)));
connect(ui->ActionUnlink, SIGNAL(triggered()), this, SLOT(OnUnlinkClicked()));
connect(ui->ActionEditTweaks, SIGNAL(triggered()), mpTweakEditor, SLOT(show()));
connect(ui->ActionEditLayers, SIGNAL(triggered()), this, SLOT(EditLayers()));
connect(ui->ActionGeneratePropertyNames, SIGNAL(triggered()), this, SLOT(GeneratePropertyNames()));
connect(ui->ActionGeneratePropertyNames, SIGNAL(triggered()), mpGeneratePropertyNamesDialog, SLOT(show()));
connect(ui->ActionDrawWorld, SIGNAL(triggered()), this, SLOT(ToggleDrawWorld()));
connect(ui->ActionDrawObjects, SIGNAL(triggered()), this, SLOT(ToggleDrawObjects()));
@ -190,7 +192,7 @@ CWorldEditor::CWorldEditor(QWidget *parent)
connect(ui->ActionBloom, SIGNAL(triggered()), this, SLOT(SetBloom()));
connect(ui->ActionIncrementGizmo, SIGNAL(triggered()), this, SLOT(IncrementGizmo()));
connect(ui->ActionDecrementGizmo, SIGNAL(triggered()), this, SLOT(DecrementGizmo()));
connect(ui->ActionCollisionRenderSettings, SIGNAL(triggered()), this, SLOT(EditCollisionRenderSettings()));
connect(ui->ActionCollisionRenderSettings, SIGNAL(triggered()), mpCollisionDialog, SLOT(show()));
connect(ui->ActionAbout, SIGNAL(triggered(bool)), this, SLOT(About()));
}
@ -509,6 +511,12 @@ void CWorldEditor::OnActiveProjectChanged(CGameProject *pProj)
ResetCamera();
UpdateWindowTitle();
// Update tweak editor
// We update this here to ensure we can update the menu item correctly without risking
// that this function runs before the tweak editor has a chance to update its tweak list.
mpTweakEditor->OnProjectChanged(pProj);
ui->ActionEditTweaks->setEnabled( mpTweakEditor->HasTweaks() );
// Default bloom to Fake Bloom for Metroid Prime 3; disable for other games
bool AllowBloom = (CurrentGame() == EGame::CorruptionProto || CurrentGame() == EGame::Corruption);
AllowBloom ? SetFakeBloom() : SetNoBloom();
@ -1319,11 +1327,6 @@ void CWorldEditor::DecrementGizmo()
mGizmo.DecrementSize();
}
void CWorldEditor::EditCollisionRenderSettings()
{
mpCollisionDialog->show();
}
void CWorldEditor::EditLayers()
{
// Launch layer editor
@ -1331,9 +1334,3 @@ void CWorldEditor::EditLayers()
Editor.SetArea(mpArea);
Editor.exec();
}
void CWorldEditor::GeneratePropertyNames()
{
// Launch property name generation dialog
mpGeneratePropertyNamesDialog->show();
}

View File

@ -6,6 +6,7 @@
#include "CLinkDialog.h"
#include "CPoiMapSidebar.h"
#include "CScriptEditSidebar.h"
#include "CTweakEditor.h"
#include "CWorldInfoSidebar.h"
#include "Editor/INodeEditor.h"
#include "Editor/CGeneratePropertyNamesDialog.h"
@ -47,31 +48,32 @@ class CWorldEditor : public INodeEditor
Q_OBJECT
static const int mskMaxRecentProjects = 10;
Ui::CWorldEditor *ui;
QMenu *mpOpenRecentMenu;
QAction *mRecentProjectsActions[ mskMaxRecentProjects ];
Ui::CWorldEditor* ui;
QMenu* mpOpenRecentMenu;
QAction* mRecentProjectsActions[ mskMaxRecentProjects ];
TResPtr<CWorld> mpWorld;
TResPtr<CGameArea> mpArea;
CCollisionRenderSettingsDialog *mpCollisionDialog;
CLinkDialog *mpLinkDialog;
CCollisionRenderSettingsDialog* mpCollisionDialog;
CLinkDialog* mpLinkDialog;
CGeneratePropertyNamesDialog* mpGeneratePropertyNamesDialog;
CTweakEditor* mpTweakEditor;
bool mIsMakingLink;
CScriptObject *mpNewLinkSender;
CScriptObject *mpNewLinkReceiver;
CScriptObject* mpNewLinkSender;
CScriptObject* mpNewLinkReceiver;
// Sidebars
QVBoxLayout *mpRightSidebarLayout;
CWorldEditorSidebar *mpCurSidebar;
QVBoxLayout* mpRightSidebarLayout;
CWorldEditorSidebar* mpCurSidebar;
QButtonGroup *mpEditModeButtonGroup;
CWorldInfoSidebar *mpWorldInfoSidebar;
CScriptEditSidebar *mpScriptSidebar;
CPoiMapSidebar *mpPoiMapSidebar;
QButtonGroup* mpEditModeButtonGroup;
CWorldInfoSidebar* mpWorldInfoSidebar;
CScriptEditSidebar* mpScriptSidebar;
CPoiMapSidebar* mpPoiMapSidebar;
QAction *mpPoiMapAction;
QAction* mpPoiMapAction;
public:
explicit CWorldEditor(QWidget *parent = 0);
@ -86,6 +88,7 @@ public:
inline EGame CurrentGame() const { return gpEdApp->CurrentGame(); }
inline CLinkDialog* LinkDialog() const { return mpLinkDialog; }
inline CGeneratePropertyNamesDialog* NameGeneratorDialog() const { return mpGeneratePropertyNamesDialog; }
inline CTweakEditor* TweakEditor() { return mpTweakEditor; }
CResourceBrowser* ResourceBrowser() const;
CSceneViewport* Viewport() const;
@ -167,9 +170,7 @@ private slots:
void SetBloom();
void IncrementGizmo();
void DecrementGizmo();
void EditCollisionRenderSettings();
void EditLayers();
void GeneratePropertyNames();
signals:
void MapChanged(CWorld *pNewWorld, CGameArea *pNewArea);

View File

@ -338,6 +338,7 @@
<property name="title">
<string>Tools</string>
</property>
<addaction name="ActionEditTweaks"/>
<addaction name="ActionEditLayers"/>
<addaction name="ActionGeneratePropertyNames"/>
</widget>
@ -785,6 +786,14 @@
<string>About</string>
</property>
</action>
<action name="ActionEditTweaks">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Edit Tweaks</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -16,14 +16,9 @@ WModifyTab::WModifyTab(CWorldEditor *pEditor, QWidget *pParent)
, mIsPicking(false)
{
ui->setupUi(this);
ui->PropertyView->InitColumnWidths(0.3f, 0.3f);
mpWorldEditor = pEditor;
ui->PropertyView->SetEditor(mpWorldEditor);
int PropViewWidth = ui->PropertyView->width();
ui->PropertyView->header()->resizeSection(0, PropViewWidth * 0.3);
ui->PropertyView->header()->resizeSection(1, PropViewWidth * 0.3);
ui->PropertyView->header()->setSectionResizeMode(1, QHeaderView::Fixed);
mpInLinkModel = new CLinkModel(this);
mpInLinkModel->SetConnectionType(ELinkType::Incoming);

View File

@ -461,7 +461,7 @@
</Element>
<Element Type="Array" ID="0x99">
<Name>ScanSpeeds</Name>
<ItemArchetype Type="Int" ID="0x0">
<ItemArchetype Type="Float" ID="0x0">
<Name>ScanSpeed</Name>
</ItemArchetype>
</Element>

View File

@ -5,7 +5,7 @@
<Atomic>true</Atomic>
<SubProperties>
<Element Type="Float" ID="0x0">
<Name>CoolDown</Name>
<Name>Cooldown</Name>
</Element>
<Element Type="Struct" ID="0x1" Archetype="ShotParam">
<Name>NormalDamage</Name>