mirror of
https://github.com/AxioDL/PrimeWorldEditor.git
synced 2025-12-18 09:25:31 +00:00
Notify script nodes when their properties are modified
This commit is contained in:
@@ -31,11 +31,10 @@ CScriptObject::~CScriptObject()
|
||||
mpActive = mpTemplate->FindActive(mpProperties);
|
||||
mpLightParameters = mpTemplate->FindLightParameters(mpProperties);
|
||||
mHasInGameModel = mpTemplate->HasInGameModel(mpProperties);
|
||||
mVolumeShape = mpTemplate->VolumeShape(this);
|
||||
mVolumeScale = mpTemplate->VolumeScale(this);
|
||||
EvaluateDisplayModel();
|
||||
EvaluateBillboard();
|
||||
EvaluateCollisionModel();
|
||||
EvaluateVolume();
|
||||
}
|
||||
|
||||
void CScriptObject::EvaluateDisplayModel()
|
||||
@@ -53,6 +52,23 @@ void CScriptObject::EvaluateCollisionModel()
|
||||
mpCollision = mpTemplate->FindCollision(mpProperties);
|
||||
}
|
||||
|
||||
void CScriptObject::EvaluateVolume()
|
||||
{
|
||||
mVolumeShape = mpTemplate->VolumeShape(this);
|
||||
mVolumeScale = mpTemplate->VolumeScale(this);
|
||||
}
|
||||
|
||||
bool CScriptObject::IsEditorProperty(IProperty *pProp)
|
||||
{
|
||||
return ( (pProp == mpInstanceName) ||
|
||||
(pProp == mpPosition) ||
|
||||
(pProp == mpRotation) ||
|
||||
(pProp == mpScale) ||
|
||||
(pProp == mpActive) ||
|
||||
(pProp->Parent() == mpLightParameters)
|
||||
);
|
||||
}
|
||||
|
||||
// ************ GETTERS ************
|
||||
IProperty* CScriptObject::PropertyByIndex(u32 index) const
|
||||
{
|
||||
|
||||
@@ -48,6 +48,8 @@ public:
|
||||
void EvaluateDisplayModel();
|
||||
void EvaluateBillboard();
|
||||
void EvaluateCollisionModel();
|
||||
void EvaluateVolume();
|
||||
bool IsEditorProperty(IProperty *pProp);
|
||||
|
||||
CScriptTemplate* Template() const;
|
||||
CMasterTemplate* MasterTemplate() const;
|
||||
|
||||
@@ -283,6 +283,13 @@ public:
|
||||
mAcceptedExtensions = rkExtensions;
|
||||
}
|
||||
|
||||
bool AcceptsExtension(const TString& rkExtension)
|
||||
{
|
||||
for (auto it = mAcceptedExtensions.begin(); it != mAcceptedExtensions.end(); it++)
|
||||
if (*it == rkExtension) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
const TStringList& Extensions() const
|
||||
{
|
||||
return mAcceptedExtensions;
|
||||
@@ -404,10 +411,16 @@ class CBitfieldTemplate : public TLongTemplate
|
||||
|
||||
public:
|
||||
CBitfieldTemplate(u32 ID, CStructTemplate *pParent = 0)
|
||||
: TLongTemplate(ID, pParent) {}
|
||||
: TLongTemplate(ID, pParent)
|
||||
{
|
||||
mDefaultValue.SetHexStringOutput(true);
|
||||
}
|
||||
|
||||
CBitfieldTemplate(u32 ID, const TString& rkName, ECookPreference CookPreference, CStructTemplate *pParent = 0)
|
||||
: TLongTemplate(ID, rkName, CookPreference, pParent) {}
|
||||
: TLongTemplate(ID, rkName, CookPreference, pParent)
|
||||
{
|
||||
mDefaultValue.SetHexStringOutput(true);
|
||||
}
|
||||
|
||||
virtual EPropertyType Type() const { return eBitfieldProperty; }
|
||||
virtual bool CanHaveDefault() const { return true; }
|
||||
|
||||
@@ -28,6 +28,7 @@ CScriptNode::CScriptNode(CScene *pScene, CSceneNode *pParent, CScriptObject *pOb
|
||||
CScriptTemplate *pTemp = Template();
|
||||
|
||||
// Determine transform
|
||||
mHasValidPosition = pTemp->HasPosition();
|
||||
mPosition = mpInstance->Position();
|
||||
mRotation = CQuaternion::FromEuler(mpInstance->Rotation());
|
||||
mScale = mpInstance->Scale();
|
||||
@@ -41,36 +42,15 @@ CScriptNode::CScriptNode(CScene *pScene, CSceneNode *pParent, CScriptObject *pOb
|
||||
mpCollisionNode->SetCollision(mpInstance->GetCollision());
|
||||
|
||||
// Create preview volume node
|
||||
mHasValidPosition = pTemp->HasPosition();
|
||||
mpVolumePreviewNode = new CModelNode(pScene, this, nullptr);
|
||||
|
||||
if (pTemp->ScaleType() == CScriptTemplate::eScaleVolume)
|
||||
{
|
||||
EVolumeShape shape = mpInstance->VolumeShape();
|
||||
TResPtr<CModel> pVolumeModel = nullptr;
|
||||
|
||||
switch (shape)
|
||||
{
|
||||
case eAxisAlignedBoxShape:
|
||||
case eBoxShape:
|
||||
pVolumeModel = gResCache.GetResource("../resources/VolumeBox.cmdl");
|
||||
break;
|
||||
|
||||
case eEllipsoidShape:
|
||||
pVolumeModel = gResCache.GetResource("../resources/VolumeSphere.cmdl");
|
||||
break;
|
||||
|
||||
case eCylinderShape:
|
||||
pVolumeModel = gResCache.GetResource("../resources/VolumeCylinder.cmdl");
|
||||
break;
|
||||
}
|
||||
|
||||
mHasVolumePreview = (pVolumeModel != nullptr);
|
||||
UpdatePreviewVolume();
|
||||
|
||||
if (mHasVolumePreview)
|
||||
{
|
||||
mpVolumePreviewNode = new CModelNode(pScene, this, pVolumeModel);
|
||||
mpVolumePreviewNode->SetInheritance(true, (shape != eAxisAlignedBoxShape), true);
|
||||
mpVolumePreviewNode->SetScale(mpInstance->VolumeScale());
|
||||
mpVolumePreviewNode->SetInheritance(true, (mpInstance->VolumeShape() != eAxisAlignedBoxShape), true);
|
||||
mpVolumePreviewNode->ForceAlphaEnabled(true);
|
||||
}
|
||||
}
|
||||
@@ -395,6 +375,89 @@ CColor CScriptNode::TintColor(const SViewInfo &ViewInfo) const
|
||||
return BaseColor;
|
||||
}
|
||||
|
||||
void CScriptNode::PropertyModified(IProperty *pProp)
|
||||
{
|
||||
// Update volume
|
||||
if ( (pProp->Type() == eBoolProperty) || (pProp->Type() == eByteProperty) || (pProp->Type() == eShortProperty) ||
|
||||
(pProp->Type() == eLongProperty) || (pProp->Type() == eEnumProperty) )
|
||||
{
|
||||
mpInstance->EvaluateVolume();
|
||||
UpdatePreviewVolume();
|
||||
}
|
||||
|
||||
// Update resources
|
||||
if (pProp->Type() == eCharacterProperty)
|
||||
{
|
||||
mpInstance->EvaluateDisplayModel();
|
||||
mpActiveModel = mpInstance->GetDisplayModel();
|
||||
}
|
||||
else if (pProp->Type() == eFileProperty)
|
||||
{
|
||||
CFileTemplate *pFile = static_cast<CFileTemplate*>(pProp->Template());
|
||||
|
||||
if (pFile->AcceptsExtension("CMDL") || pFile->AcceptsExtension("ANCS") || pFile->AcceptsExtension("CHAR"))
|
||||
{
|
||||
mpInstance->EvaluateDisplayModel();
|
||||
mpActiveModel = mpInstance->GetDisplayModel();
|
||||
}
|
||||
else if (pFile->AcceptsExtension("TXTR"))
|
||||
{
|
||||
mpInstance->EvaluateBillboard();
|
||||
mpBillboard = mpInstance->GetBillboard();
|
||||
}
|
||||
else if (pFile->AcceptsExtension("DCLN"))
|
||||
{
|
||||
mpInstance->EvaluateCollisionModel();
|
||||
mpCollisionNode->SetCollision(mpInstance->GetCollision());
|
||||
}
|
||||
}
|
||||
|
||||
// Update other editor properties
|
||||
if (mpInstance->IsEditorProperty(pProp))
|
||||
{
|
||||
SetName("[" + mpInstance->Template()->Name() + "] " + mpInstance->InstanceName());
|
||||
mPosition = mpInstance->Position();
|
||||
mRotation = CQuaternion::FromEuler(mpInstance->Rotation());
|
||||
mScale = mpInstance->Scale();
|
||||
MarkTransformChanged();
|
||||
|
||||
SetLightLayerIndex(mpLightParameters->LightLayerIndex());
|
||||
}
|
||||
|
||||
// Update script extra
|
||||
if (mpExtra) mpExtra->PropertyModified(pProp);
|
||||
}
|
||||
|
||||
void CScriptNode::UpdatePreviewVolume()
|
||||
{
|
||||
EVolumeShape Shape = mpInstance->VolumeShape();
|
||||
TResPtr<CModel> pVolumeModel = nullptr;
|
||||
|
||||
switch (Shape)
|
||||
{
|
||||
case eAxisAlignedBoxShape:
|
||||
case eBoxShape:
|
||||
pVolumeModel = gResCache.GetResource("../resources/VolumeBox.cmdl");
|
||||
break;
|
||||
|
||||
case eEllipsoidShape:
|
||||
pVolumeModel = gResCache.GetResource("../resources/VolumeSphere.cmdl");
|
||||
break;
|
||||
|
||||
case eCylinderShape:
|
||||
pVolumeModel = gResCache.GetResource("../resources/VolumeCylinder.cmdl");
|
||||
break;
|
||||
}
|
||||
|
||||
mHasVolumePreview = (pVolumeModel != nullptr);
|
||||
|
||||
if (mHasVolumePreview)
|
||||
{
|
||||
mpVolumePreviewNode->SetModel(pVolumeModel);
|
||||
mpVolumePreviewNode->SetScale(mpInstance->VolumeScale());
|
||||
}
|
||||
}
|
||||
|
||||
void CScriptNode::GeneratePosition()
|
||||
{
|
||||
if (!mHasValidPosition)
|
||||
|
||||
@@ -38,6 +38,8 @@ public:
|
||||
CColor TintColor(const SViewInfo &ViewInfo) const;
|
||||
CColor WireframeColor() const;
|
||||
|
||||
void PropertyModified(IProperty *pProp);
|
||||
void UpdatePreviewVolume();
|
||||
void GeneratePosition();
|
||||
CScriptObject* Object() const;
|
||||
CScriptTemplate* Template() const;
|
||||
|
||||
Reference in New Issue
Block a user