Added TPropCast property casting function, added support for clean/dirty state in the world editor + check for unsaved changes when the window is closed

This commit is contained in:
parax0
2016-02-01 16:42:12 -07:00
parent 6669dd4367
commit 1a07a9c083
34 changed files with 242 additions and 163 deletions

View File

@@ -16,36 +16,18 @@ CDamageableTriggerExtra::CDamageableTriggerExtra(CScriptObject *pInstance, CScen
CPropertyStruct *pBaseStruct = pInstance->Properties();
// Fetch render side
mpRenderSideProp = (TEnumProperty*) pBaseStruct->PropertyByIndex(0x5);
if (mpRenderSideProp && mpRenderSideProp->Type() != eEnumProperty)
mpRenderSideProp = nullptr;
mpRenderSideProp = TPropCast<TEnumProperty>(pBaseStruct->PropertyByIndex(0x5));
if (mpRenderSideProp) PropertyModified(mpRenderSideProp);
// Fetch scale
mpSizeProp = (TVector3Property*) pBaseStruct->PropertyByIndex(0x2);
if (mpSizeProp && mpSizeProp->Type() != eVector3Property)
mpSizeProp = nullptr;
if (mpSizeProp) PropertyModified (mpSizeProp);
mpSizeProp = TPropCast<TVector3Property>(pBaseStruct->PropertyByIndex(0x2));
if (mpSizeProp) PropertyModified(mpSizeProp);
// Fetch textures
for (u32 iTex = 0; iTex < 3; iTex++)
{
mpTextureProps[iTex] = (TFileProperty*) pBaseStruct->PropertyByIndex(0x6 + iTex);
if (mpTextureProps[iTex])
{
if (mpTextureProps[iTex]->Type() == eFileProperty)
PropertyModified(mpTextureProps[iTex]);
else
mpTextureProps[iTex] = nullptr;
}
else
mpTextures[iTex] = nullptr;
mpTextureProps[iTex] = TPropCast<TFileProperty>(pBaseStruct->PropertyByIndex(0x6 + iTex));
if (mpTextureProps[iTex]) PropertyModified(mpTextureProps[iTex]);
}
}
@@ -147,6 +129,12 @@ void CDamageableTriggerExtra::UpdatePlaneTransform()
MarkTransformChanged();
}
void CDamageableTriggerExtra::OnTransformed()
{
mPlaneSize = mpSizeProp->Get();
UpdatePlaneTransform();
}
void CDamageableTriggerExtra::PropertyModified(IProperty *pProperty)
{
if (pProperty == mpRenderSideProp)
@@ -209,7 +197,7 @@ void CDamageableTriggerExtra::Draw(FRenderOptions Options, int /*ComponentIndex*
// Note: The plane the game renders this onto is 5x4.5, which is why we divide the tex coords by this value
CVector2f TexUL(0.f, mCoordScale.y / 4.5f);
CVector2f TexUR(mCoordScale.x / 5.f, mCoordScale.y / 4.5f);
CVector2f TexUR(mCoordScale.x / 5.f, mCoordScale.y / 4.5f);
CVector2f TexBR(mCoordScale.x / 5.f, 0.f);
CVector2f TexBL(0.f, 0.f);
CDrawUtil::DrawSquare(TexUL, TexUR, TexBR, TexBL);

View File

@@ -35,6 +35,7 @@ public:
~CDamageableTriggerExtra();
void CreateMaterial();
void UpdatePlaneTransform();
void OnTransformed();
void PropertyModified(IProperty *pProperty);
bool ShouldDrawNormalAssets();
void AddToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo);

View File

@@ -9,31 +9,19 @@ CDoorExtra::CDoorExtra(CScriptObject *pInstance, CScene *pScene, CSceneNode *pPa
{
CPropertyStruct *pBaseStruct = pInstance->Properties();
mpShieldModelProp = (TFileProperty*) pBaseStruct->PropertyByID(0xB20CC271);
if (mpShieldModelProp && (mpShieldModelProp->Type() != eFileProperty))
mpShieldModelProp = nullptr;
if (mpShieldModelProp)
PropertyModified(mpShieldModelProp);
mpShieldModelProp = TPropCast<TFileProperty>(pBaseStruct->PropertyByID(0xB20CC271));
if (mpShieldModelProp) PropertyModified(mpShieldModelProp);
if (mGame >= eEchoes)
{
mpShieldColorProp = (TColorProperty*) pBaseStruct->PropertyByID(0x47B4E863);
if (mpShieldColorProp && (mpShieldColorProp->Type() != eColorProperty))
mpShieldColorProp = nullptr;
if (mpShieldColorProp)
PropertyModified(mpShieldColorProp);
mpShieldColorProp = TPropCast<TColorProperty>(pBaseStruct->PropertyByID(0x47B4E863));
if (mpShieldColorProp) PropertyModified(mpShieldColorProp);
}
else
{
mpDisabledProp = (TBoolProperty*) pBaseStruct->PropertyByID(0xDEE730F5);
if (mpDisabledProp && (mpDisabledProp->Type() != eBoolProperty))
mpDisabledProp = nullptr;
if (mpDisabledProp)
PropertyModified(mpDisabledProp);
mpDisabledProp = TPropCast<TBoolProperty>(pBaseStruct->PropertyByID(0xDEE730F5));
if (mpDisabledProp) PropertyModified(mpDisabledProp);
}
}

View File

@@ -11,32 +11,9 @@ CPointOfInterestExtra::CPointOfInterestExtra(CScriptObject *pInstance, CScene *p
// Fetch scan data property
CPropertyStruct *pBaseProp = pInstance->Properties();
switch (mGame)
{
case ePrimeDemo:
case ePrime:
mpScanProperty = (TFileProperty*) pBaseProp->PropertyByIDString("0x04:0x00");
break;
case eEchoesDemo:
case eEchoes:
case eCorruptionProto:
case eCorruption:
mpScanProperty = (TFileProperty*) pBaseProp->PropertyByIDString("0xBDBEC295:0xB94E9BE7");
break;
default:
mpScanProperty = nullptr;
break;
}
if (mpScanProperty)
{
if (mpScanProperty->Type() == eFileProperty)
PropertyModified(mpScanProperty);
else
mpScanProperty = nullptr;
}
if (mGame <= ePrime) mpScanProperty = TPropCast<TFileProperty>(pBaseProp->PropertyByIDString("0x04:0x00"));
else mpScanProperty = (TFileProperty*) pBaseProp->PropertyByIDString("0xBDBEC295:0xB94E9BE7");
if (mpScanProperty) PropertyModified(mpScanProperty);
}
void CPointOfInterestExtra::PropertyModified(IProperty* pProperty)

View File

@@ -11,16 +11,16 @@ CRadiusSphereExtra::CRadiusSphereExtra(CScriptObject *pInstance, CScene *pScene,
switch (mObjectType)
{
case 0x63: // Repulsor (MP1)
mpRadius = (TFloatProperty*) pInstance->Properties()->PropertyByID(0x3);
mpRadius = TPropCast<TFloatProperty>(pInstance->Properties()->PropertyByID(0x3));
break;
case 0x68: // RadialDamage (MP1)
mpRadius = (TFloatProperty*) pInstance->Properties()->PropertyByID(0x4);
mpRadius = TPropCast<TFloatProperty>(pInstance->Properties()->PropertyByID(0x4));
break;
case 0x5245504C: // "REPL" Repulsor (MP2/MP3)
case 0x52414444: // "RADD" RadialDamage (MP2/MP3/DKCR)
mpRadius = (TFloatProperty*) pInstance->Properties()->PropertyByID(0x78C507EB);
mpRadius = TPropCast<TFloatProperty>(pInstance->Properties()->PropertyByID(0x78C507EB));
break;
}
}

View File

@@ -12,21 +12,10 @@ CSpacePirateExtra::CSpacePirateExtra(CScriptObject *pInstance, CScene *pScene, C
if (pVulns && pVulns->Type() == eStructProperty)
{
mpPowerVuln = (TLongProperty*) pVulns->PropertyByID(0x0);
if (mpPowerVuln && mpPowerVuln->Type() != eLongProperty && mpPowerVuln->Type() != eEnumProperty)
mpPowerVuln = nullptr;
mpWaveVuln = (TLongProperty*) pVulns->PropertyByID(0x2);
if (mpWaveVuln && mpWaveVuln->Type() != eLongProperty && mpWaveVuln->Type() != eEnumProperty)
mpWaveVuln = nullptr;
mpIceVuln = (TLongProperty*) pVulns->PropertyByID(0x1);
if (mpIceVuln && mpIceVuln->Type() != eLongProperty && mpIceVuln->Type() != eEnumProperty)
mpIceVuln = nullptr;
mpPlasmaVuln = (TLongProperty*) pVulns->PropertyByID(0x3);
if (mpPlasmaVuln && mpPlasmaVuln->Type() != eLongProperty && mpPlasmaVuln->Type() != eEnumProperty)
mpPlasmaVuln = nullptr;
mpPowerVuln = TPropCast<TEnumProperty>(pVulns->PropertyByID(0x0));
mpWaveVuln = TPropCast<TEnumProperty>(pVulns->PropertyByID(0x2));
mpIceVuln = TPropCast<TEnumProperty>(pVulns->PropertyByID(0x1));
mpPlasmaVuln = TPropCast<TEnumProperty>(pVulns->PropertyByID(0x3));
}
}

View File

@@ -7,10 +7,10 @@
class CSpacePirateExtra : public CScriptExtra
{
// Render beam troopers with the correct color
TLongProperty *mpPowerVuln;
TLongProperty *mpWaveVuln;
TLongProperty *mpIceVuln;
TLongProperty *mpPlasmaVuln;
TEnumProperty *mpPowerVuln;
TEnumProperty *mpWaveVuln;
TEnumProperty *mpIceVuln;
TEnumProperty *mpPlasmaVuln;
public:
explicit CSpacePirateExtra(CScriptObject *pInstance, CScene *pScene, CSceneNode *pParent = 0);