mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-11 22:44:19 +00:00
Added AnimationParameters property type, decreased contents margins for struct properties in the modify tab, other minor fixes/cleanup
This commit is contained in:
237
UI/WAnimParamsEditor.cpp
Normal file
237
UI/WAnimParamsEditor.cpp
Normal file
@@ -0,0 +1,237 @@
|
||||
#include "WAnimParamsEditor.h"
|
||||
#include <Core/CResCache.h>
|
||||
#include <Resource/CAnimSet.h>
|
||||
|
||||
WAnimParamsEditor::WAnimParamsEditor(QWidget *pParent)
|
||||
: QWidget(pParent),
|
||||
mpGroupBox(new QGroupBox("Animation Parameters", this)),
|
||||
mpGroupLayout(nullptr),
|
||||
mpSelector(nullptr),
|
||||
mpCharComboBox(nullptr)
|
||||
{
|
||||
for (u32 iBox = 0; iBox < 4; iBox++)
|
||||
mpSpinBoxes[iBox] = nullptr;
|
||||
|
||||
for (u32 iLabel = 0; iLabel < 5; iLabel++) {
|
||||
mpLabels[iLabel] = nullptr;
|
||||
mpValueLayouts[iLabel] = nullptr;
|
||||
}
|
||||
|
||||
QVBoxLayout *pLayout = new QVBoxLayout(this);
|
||||
pLayout->addWidget(mpGroupBox);
|
||||
pLayout->setContentsMargins(0,0,0,0);
|
||||
setLayout(pLayout);
|
||||
}
|
||||
|
||||
WAnimParamsEditor::WAnimParamsEditor(const CAnimationParameters& params, QWidget *pParent)
|
||||
: QWidget(pParent),
|
||||
mpGroupBox(new QGroupBox("Animation Parameters", this)),
|
||||
mpGroupLayout(nullptr),
|
||||
mpSelector(nullptr),
|
||||
mpCharComboBox(nullptr)
|
||||
{
|
||||
for (u32 iBox = 0; iBox < 4; iBox++)
|
||||
mpSpinBoxes[iBox] = nullptr;
|
||||
|
||||
for (u32 iLabel = 0; iLabel < 5; iLabel++) {
|
||||
mpLabels[iLabel] = nullptr;
|
||||
mpValueLayouts[iLabel] = nullptr;
|
||||
}
|
||||
|
||||
QVBoxLayout *pLayout = new QVBoxLayout(this);
|
||||
pLayout->addWidget(mpGroupBox);
|
||||
pLayout->setContentsMargins(0,0,0,0);
|
||||
setLayout(pLayout);
|
||||
|
||||
mParams = params;
|
||||
SetupUI();
|
||||
}
|
||||
|
||||
WAnimParamsEditor::~WAnimParamsEditor()
|
||||
{
|
||||
}
|
||||
|
||||
void WAnimParamsEditor::SetTitle(const QString& title)
|
||||
{
|
||||
mpGroupBox->setTitle(title);
|
||||
}
|
||||
|
||||
void WAnimParamsEditor::SetParameters(const CAnimationParameters& params)
|
||||
{
|
||||
mParams = params;
|
||||
SetupUI();
|
||||
}
|
||||
|
||||
// ************ PRIVATE SLOTS ************
|
||||
void WAnimParamsEditor::OnResourceChanged(QString path)
|
||||
{
|
||||
CResource *pRes = gResCache.GetResource(path.toStdString());
|
||||
if (pRes->Type() != eAnimSet) pRes = nullptr;
|
||||
|
||||
mParams.SetResource(pRes);
|
||||
emit ParametersChanged(mParams);
|
||||
}
|
||||
|
||||
void WAnimParamsEditor::OnCharacterChanged(int index)
|
||||
{
|
||||
mParams.SetNodeIndex(index);
|
||||
emit ParametersChanged(mParams);
|
||||
}
|
||||
|
||||
void WAnimParamsEditor::OnUnknownChanged()
|
||||
{
|
||||
for (u32 iBox = 0; iBox < 4; iBox++)
|
||||
if (mpSpinBoxes[iBox])
|
||||
mParams.SetUnknown(iBox, mpSpinBoxes[iBox]->value());
|
||||
emit ParametersChanged(mParams);
|
||||
}
|
||||
|
||||
// ************ PRIVATE ************
|
||||
void WAnimParamsEditor::SetupUI()
|
||||
{
|
||||
// Clean existing layout
|
||||
if (!mLayoutWidgets.isEmpty())
|
||||
{
|
||||
foreach (QObject *pObject, mLayoutWidgets)
|
||||
delete pObject;
|
||||
|
||||
mpSelector = nullptr;
|
||||
mpCharComboBox = nullptr;
|
||||
|
||||
for (u32 iBox = 0; iBox < 4; iBox++)
|
||||
mpSpinBoxes[iBox] = nullptr;
|
||||
|
||||
for (u32 iLabel = 0; iLabel < 5; iLabel++) {
|
||||
mpLabels[iLabel] = nullptr;
|
||||
mpValueLayouts[iLabel] = nullptr;
|
||||
}
|
||||
|
||||
mLayoutWidgets.clear();
|
||||
}
|
||||
|
||||
delete mpGroupLayout;
|
||||
mpGroupLayout = new QVBoxLayout(mpGroupBox);
|
||||
mpGroupLayout->setContentsMargins(5,5,5,5);
|
||||
mpGroupBox->setLayout(mpGroupLayout);
|
||||
|
||||
// Create resource selector
|
||||
mpLabels[0] = new QLabel(mParams.Version() <= eEchoes ? "AnimSet" : "Character");
|
||||
mpSelector = new WResourceSelector(this);
|
||||
mpSelector->SetAllowedExtensions(mParams.Version() <= eEchoes ? "ANCS" : "CHAR");
|
||||
mpSelector->AdjustPreviewToParent(true);
|
||||
mpSelector->SetResource(mParams.Resource());
|
||||
|
||||
mpValueLayouts[0] = new QHBoxLayout(this);
|
||||
mpValueLayouts[0]->addWidget(mpLabels[0], 0);
|
||||
mpValueLayouts[0]->addWidget(mpSelector, 1);
|
||||
mpValueLayouts[0]->setSpacing(5);
|
||||
mpGroupLayout->addLayout(mpValueLayouts[0]);
|
||||
|
||||
mLayoutWidgets << mpLabels[0] << mpSelector << mpValueLayouts[0];
|
||||
connect(mpSelector, SIGNAL(ResourceChanged(QString)), this, SLOT(OnResourceChanged(QString)));
|
||||
|
||||
// Create MP1/2 widgets
|
||||
if (mParams.Version() <= eEchoes)
|
||||
{
|
||||
// Create character select combo box
|
||||
mpCharComboBox = new QComboBox(this);
|
||||
CAnimSet *pSet = static_cast<CAnimSet*>(mParams.Resource());
|
||||
|
||||
for (u32 iChar = 0; iChar < pSet->getNodeCount(); iChar++)
|
||||
mpCharComboBox->addItem(QString::fromStdString(pSet->getNodeName(iChar)));
|
||||
|
||||
mpCharComboBox->setCurrentIndex(mParams.CharacterIndex());
|
||||
mpLabels[1] = new QLabel("Character", this);
|
||||
|
||||
// Create unknown spin box
|
||||
mpSpinBoxes[0] = new WIntegralSpinBox(this);
|
||||
mpSpinBoxes[0]->setRange(-2147483648, 2147483647);
|
||||
mpSpinBoxes[0]->setFocusPolicy(Qt::StrongFocus);
|
||||
mpSpinBoxes[0]->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
mpSpinBoxes[0]->setValue(mParams.Unknown(0));
|
||||
mpLabels[2] = new QLabel("Unknown", this);
|
||||
|
||||
// Create layouts
|
||||
mpValueLayouts[1] = new QHBoxLayout(this);
|
||||
mpValueLayouts[1]->addWidget(mpLabels[1], 0);
|
||||
mpValueLayouts[1]->addWidget(mpCharComboBox, 1);
|
||||
mpValueLayouts[1]->setSpacing(5);
|
||||
|
||||
mpValueLayouts[2] = new QHBoxLayout(this);
|
||||
mpValueLayouts[2]->addWidget(mpLabels[2], 0);
|
||||
mpValueLayouts[2]->addWidget(mpSpinBoxes[0], 1);
|
||||
mpValueLayouts[2]->setSpacing(5);
|
||||
|
||||
mpGroupLayout->addLayout(mpValueLayouts[1]);
|
||||
mpGroupLayout->addLayout(mpValueLayouts[2]);
|
||||
|
||||
// Finish UI
|
||||
mLayoutWidgets << mpLabels[1] << mpCharComboBox << mpLabels[2] << mpSpinBoxes[0] << mpValueLayouts[1] << mpValueLayouts[2];
|
||||
connect(mpCharComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OnCharacterChanged(int)));
|
||||
connect(mpSpinBoxes[0], SIGNAL(valueChanged(int)), this, SLOT(OnUnknownChanged()));
|
||||
}
|
||||
|
||||
// Create MP3 widgets
|
||||
else if (mParams.Version() <= eCorruption)
|
||||
{
|
||||
// Create unknown spin box
|
||||
mpSpinBoxes[0] = new WIntegralSpinBox(this);
|
||||
mpSpinBoxes[0]->setRange(-2147483648, 2147483647);
|
||||
mpSpinBoxes[0]->setFocusPolicy(Qt::StrongFocus);
|
||||
mpSpinBoxes[0]->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
mpSpinBoxes[0]->setValue(mParams.Unknown(0));
|
||||
mpLabels[1] = new QLabel("Unknown", this);
|
||||
|
||||
// Create layouts
|
||||
mpValueLayouts[1] = new QHBoxLayout(this);
|
||||
mpValueLayouts[1]->addWidget(mpLabels[1], 0);
|
||||
mpValueLayouts[1]->addWidget(mpSpinBoxes[0], 1);
|
||||
mpValueLayouts[1]->setSpacing(5);
|
||||
mpGroupLayout->addLayout(mpValueLayouts[1]);
|
||||
|
||||
// Finish UI
|
||||
mLayoutWidgets << mpLabels[1] << mpSpinBoxes[0] << mpValueLayouts[1];
|
||||
connect(mpSpinBoxes[0], SIGNAL(valueChanged(int)), this, SLOT(OnUnknownChanged()));
|
||||
}
|
||||
|
||||
// Create DKCR widgets
|
||||
else if (mParams.Version() == eReturns)
|
||||
{
|
||||
// Create unknown spin box A
|
||||
mpSpinBoxes[0] = new WIntegralSpinBox(this);
|
||||
mpSpinBoxes[0]->setRange(0, 255);
|
||||
mpSpinBoxes[0]->setFocusPolicy(Qt::StrongFocus);
|
||||
mpSpinBoxes[0]->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
mpSpinBoxes[0]->setValue(mParams.Unknown(0));
|
||||
mpLabels[1] = new QLabel("Unknown", this);
|
||||
|
||||
mpValueLayouts[1] = new QHBoxLayout(this);
|
||||
mpValueLayouts[1]->addWidget(mpLabels[1], 0);
|
||||
mpValueLayouts[1]->addWidget(mpSpinBoxes[0], 1);
|
||||
mpValueLayouts[1]->setSpacing(5);
|
||||
mpGroupLayout->addLayout(mpValueLayouts[1]);
|
||||
|
||||
mLayoutWidgets << mpLabels[1] << mpSpinBoxes[0] << mpValueLayouts[1];
|
||||
connect(mpSpinBoxes[0], SIGNAL(valueChanged(int)), this, SLOT(OnUnknownChanged()));
|
||||
|
||||
// Create unknown spin box B/C/D
|
||||
for (u32 iBox = 1; iBox < 4; iBox++)
|
||||
{
|
||||
mpSpinBoxes[iBox] = new WIntegralSpinBox(this);
|
||||
mpSpinBoxes[iBox]->setRange(-2147483648, 2147483647);
|
||||
mpSpinBoxes[iBox]->setFocusPolicy(Qt::StrongFocus);
|
||||
mpSpinBoxes[iBox]->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
mpSpinBoxes[iBox]->setValue(mParams.Unknown(iBox));
|
||||
mpLabels[iBox+1] = new QLabel("Unknown", this);
|
||||
|
||||
mpValueLayouts[iBox+1] = new QHBoxLayout(this);
|
||||
mpValueLayouts[iBox+1]->addWidget(mpLabels[iBox+1], 0);
|
||||
mpValueLayouts[iBox+1]->addWidget(mpSpinBoxes[iBox], 1);
|
||||
mpValueLayouts[iBox+1]->setSpacing(5);
|
||||
mpGroupLayout->addLayout(mpValueLayouts[iBox+1]);
|
||||
|
||||
mLayoutWidgets << mpLabels[iBox+1] << mpSpinBoxes[iBox] << mpValueLayouts[iBox+1];
|
||||
connect(mpSpinBoxes[iBox], SIGNAL(valueChanged(int)), this, SLOT(OnUnknownChanged()));
|
||||
}
|
||||
}
|
||||
}
|
||||
50
UI/WAnimParamsEditor.h
Normal file
50
UI/WAnimParamsEditor.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef WANIMPARAMSEDITOR_H
|
||||
#define WANIMPARAMSEDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QComboBox>
|
||||
#include <QGroupBox>
|
||||
#include <QSpinBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QVector>
|
||||
|
||||
#include "WIntegralSpinBox.h"
|
||||
#include "WResourceSelector.h"
|
||||
#include <Resource/CAnimationParameters.h>
|
||||
|
||||
class WAnimParamsEditor : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
CAnimationParameters mParams;
|
||||
|
||||
QGroupBox *mpGroupBox;
|
||||
QVBoxLayout *mpGroupLayout;
|
||||
|
||||
QHBoxLayout *mpValueLayouts[5];
|
||||
QLabel *mpLabels[5];
|
||||
WResourceSelector *mpSelector;
|
||||
QComboBox *mpCharComboBox;
|
||||
WIntegralSpinBox *mpSpinBoxes[4];
|
||||
QVector<QObject*> mLayoutWidgets;
|
||||
|
||||
public:
|
||||
WAnimParamsEditor(QWidget *pParent = 0);
|
||||
WAnimParamsEditor(const CAnimationParameters& params, QWidget *pParent = 0);
|
||||
~WAnimParamsEditor();
|
||||
void SetTitle(const QString& title);
|
||||
void SetParameters(const CAnimationParameters& params);
|
||||
|
||||
signals:
|
||||
void ParametersChanged(const CAnimationParameters& params);
|
||||
|
||||
private slots:
|
||||
void OnResourceChanged(QString path);
|
||||
void OnCharacterChanged(int index);
|
||||
void OnUnknownChanged();
|
||||
|
||||
private:
|
||||
void SetupUI();
|
||||
};
|
||||
|
||||
#endif // WANIMPARAMSEDITOR_H
|
||||
@@ -4,12 +4,16 @@
|
||||
#include "WResourceSelector.h"
|
||||
#include "WColorPicker.h"
|
||||
#include "WVectorEditor.h"
|
||||
#include "WAnimParamsEditor.h"
|
||||
#include <Resource/CAnimSet.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QSpinBox>
|
||||
#include <QComboBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QLineEdit>
|
||||
#include <QGroupBox>
|
||||
#include <QFontMetrics>
|
||||
#include <QGroupBox>
|
||||
#include <QLineEdit>
|
||||
#include <QSpinBox>
|
||||
|
||||
static const QString gskNullProperty = "[NULL]";
|
||||
static const QString gskUnsupportedType = "Invalid property type";
|
||||
@@ -218,9 +222,10 @@ void WPropertyEditor::CreateEditor()
|
||||
case eStructProperty:
|
||||
{
|
||||
CPropertyStruct *pStructCast = static_cast<CPropertyStruct*>(mpProperty);
|
||||
QGroupBox *pGroupBox = new QGroupBox(this);
|
||||
|
||||
QGroupBox *pGroupBox = new QGroupBox(this);
|
||||
QVBoxLayout *pStructLayout = new QVBoxLayout(pGroupBox);
|
||||
pStructLayout->setContentsMargins(5,5,5,5);
|
||||
pGroupBox->setLayout(pStructLayout);
|
||||
pGroupBox->setTitle(QString::fromStdString(pStructCast->Name()));
|
||||
mUI.PropertyName->hide();
|
||||
@@ -235,6 +240,20 @@ void WPropertyEditor::CreateEditor()
|
||||
break;
|
||||
}
|
||||
|
||||
// AnimParams - WAnimParamsEditor
|
||||
case eAnimParamsProperty:
|
||||
{
|
||||
CAnimParamsProperty *pAnimCast = static_cast<CAnimParamsProperty*>(mpProperty);
|
||||
CAnimationParameters params = pAnimCast->Get();
|
||||
|
||||
WAnimParamsEditor *pEditor = new WAnimParamsEditor(params, this);
|
||||
pEditor->SetTitle(QString::fromStdString(pAnimCast->Name()));
|
||||
|
||||
mUI.PropertyName->hide();
|
||||
mUI.EditorWidget = pEditor;
|
||||
break;
|
||||
}
|
||||
|
||||
// Invalid
|
||||
case eInvalidProperty:
|
||||
default:
|
||||
@@ -243,7 +262,9 @@ void WPropertyEditor::CreateEditor()
|
||||
}
|
||||
|
||||
// For some reason setting a minimum size on group boxes flattens it...
|
||||
if ((mpProperty->Type() != eStructProperty) && (mpProperty->Type() != eVector3Property))
|
||||
if ((mpProperty->Type() != eStructProperty) &&
|
||||
(mpProperty->Type() != eVector3Property) &&
|
||||
(mpProperty->Type() != eAnimParamsProperty))
|
||||
{
|
||||
mUI.EditorWidget->setMinimumHeight(21);
|
||||
mUI.EditorWidget->setMaximumHeight(21);
|
||||
@@ -361,6 +382,14 @@ void WPropertyEditor::UpdateEditor()
|
||||
break;
|
||||
}
|
||||
|
||||
case eAnimParamsProperty:
|
||||
{
|
||||
CAnimParamsProperty *pAnimCast = static_cast<CAnimParamsProperty*>(mpProperty);
|
||||
WAnimParamsEditor *pEditor = static_cast<WAnimParamsEditor*>(mUI.EditorWidget);
|
||||
pEditor->SetParameters(pAnimCast->Get());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user