Implemented new property editor, CPropertyView

This commit is contained in:
parax0
2016-01-22 13:53:57 -07:00
parent 26485b1151
commit 38942988d5
42 changed files with 1828 additions and 1248 deletions

View File

@@ -12,7 +12,7 @@ CScriptObject::CScriptObject(CGameArea *pArea, CScriptLayer *pLayer, CScriptTemp
, mHasInGameModel(false)
{
mpTemplate->AddObject(this);
mpProperties = (CPropertyStruct*) pTemplate->BaseStruct()->InstantiateProperty();
mpProperties = (CPropertyStruct*) pTemplate->BaseStruct()->InstantiateProperty(nullptr);
}
CScriptObject::~CScriptObject()

View File

@@ -233,7 +233,7 @@ CModel* CScriptTemplate::FindDisplayModel(CPropertyStruct *pProperties)
else if (pProp->Type() == eCharacterProperty)
{
TAnimParamsProperty *pParams = static_cast<TAnimParamsProperty*>(pProp);
TCharacterProperty *pParams = static_cast<TCharacterProperty*>(pProp);
pRes = pParams->Get().GetCurrentModel(it->ForceNodeIndex);
}
}
@@ -332,7 +332,7 @@ bool CScriptTemplate::HasInGameModel(CPropertyStruct *pProperties)
else if (pProp->Type() == eCharacterProperty)
{
TAnimParamsProperty *pParams = static_cast<TAnimParamsProperty*>(pProp);
TCharacterProperty *pParams = static_cast<TCharacterProperty*>(pProp);
pRes = pParams->Get().GetCurrentModel(it->ForceNodeIndex);
}

View File

@@ -2,21 +2,26 @@
#include "IPropertyTemplate.h"
// ************ IProperty ************
IPropertyTemplate* IProperty::Template()
IPropertyTemplate* IProperty::Template() const
{
return mpTemplate;
}
TString IProperty::Name()
TString IProperty::Name() const
{
return mpTemplate->Name();
}
u32 IProperty::ID()
u32 IProperty::ID() const
{
return mpTemplate->PropertyID();
}
TIDString IProperty::IDString(bool FullPath) const
{
return mpTemplate->IDString(FullPath);
}
// ************ CPropertyStruct ************
CPropertyStruct::~CPropertyStruct()
{
@@ -24,12 +29,12 @@ CPropertyStruct::~CPropertyStruct()
delete *it;
}
IProperty* CPropertyStruct::PropertyByIndex(u32 index)
IProperty* CPropertyStruct::PropertyByIndex(u32 index) const
{
return mProperties[index];
}
IProperty* CPropertyStruct::PropertyByID(u32 ID)
IProperty* CPropertyStruct::PropertyByID(u32 ID) const
{
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
{
@@ -39,7 +44,7 @@ IProperty* CPropertyStruct::PropertyByID(u32 ID)
return nullptr;
}
IProperty* CPropertyStruct::PropertyByIDString(const TIDString& rkStr)
IProperty* CPropertyStruct::PropertyByIDString(const TIDString& rkStr) const
{
// Resolve namespace
u32 NSStart = rkStr.IndexOf(":");
@@ -68,7 +73,7 @@ IProperty* CPropertyStruct::PropertyByIDString(const TIDString& rkStr)
}
}
CPropertyStruct* CPropertyStruct::StructByIndex(u32 index)
CPropertyStruct* CPropertyStruct::StructByIndex(u32 index) const
{
IProperty *pProp = PropertyByIndex(index);
@@ -78,7 +83,7 @@ CPropertyStruct* CPropertyStruct::StructByIndex(u32 index)
return nullptr;
}
CPropertyStruct* CPropertyStruct::StructByID(u32 ID)
CPropertyStruct* CPropertyStruct::StructByID(u32 ID) const
{
IProperty *pProp = PropertyByID(ID);
@@ -88,7 +93,7 @@ CPropertyStruct* CPropertyStruct::StructByID(u32 ID)
return nullptr;
}
CPropertyStruct* CPropertyStruct::StructByIDString(const TIDString& rkStr)
CPropertyStruct* CPropertyStruct::StructByIDString(const TIDString& rkStr) const
{
IProperty *pProp = PropertyByIDString(rkStr);
@@ -119,8 +124,8 @@ void CArrayProperty::Resize(u32 Size)
}
}
CStructTemplate* CArrayProperty::SubStructTemplate()
CStructTemplate* CArrayProperty::SubStructTemplate() const
{
// CArrayTemplate inherits from CStructTemplate. It defines the substruct structure.
// CArrayTemplate inherits from CStructTemplate. The template defines the substruct structure.
return static_cast<CStructTemplate*>(Template());
}

View File

@@ -25,16 +25,29 @@ typedef TString TIDString;
class IProperty
{
friend class CScriptLoader;
protected:
IPropertyTemplate *mpTemplate;
public:
IProperty(IPropertyTemplate *pTemp) : mpTemplate(pTemp) {}
virtual ~IProperty() {}
virtual EPropertyType Type() = 0;
IPropertyTemplate* Template();
TString Name();
u32 ID();
protected:
class CPropertyStruct *mpParent;
IPropertyTemplate *mpTemplate;
public:
IProperty(IPropertyTemplate *pTemp, CPropertyStruct *pParent)
: mpParent(pParent)
, mpTemplate(pTemp)
{
}
virtual ~IProperty() {}
virtual EPropertyType Type() const = 0;
virtual TString ToString() const { return ""; }
inline CPropertyStruct* Parent() const { return mpParent; }
// These functions can't be in the header to avoid circular includes with IPropertyTemplate.h
IPropertyTemplate* Template() const;
TString Name() const;
u32 ID() const;
TIDString IDString(bool FullPath) const;
};
/*
@@ -46,15 +59,17 @@ class TTypedProperty : public IProperty
friend class CScriptLoader;
ValueClass mValue;
public:
TTypedProperty(IPropertyTemplate *pTemp)
: IProperty(pTemp) {}
TTypedProperty(IPropertyTemplate *pTemp, CPropertyStruct *pParent)
: IProperty(pTemp, pParent) {}
TTypedProperty(IPropertyTemplate *pTemp, PropType v)
: IProperty(pTemp), mValue(v) {}
~TTypedProperty() {}
inline EPropertyType Type() { return TypeEnum; }
inline PropType Get() { return mValue.Get(); }
virtual EPropertyType Type() const { return TypeEnum; }
virtual TString ToString() const { return mValue.ToString(); }
inline PropType Get() const { return mValue.Get(); }
inline void Set(PropType v) { mValue.Set(v); }
};
typedef TTypedProperty<bool, eBoolProperty, CBoolValue> TBoolProperty;
@@ -68,7 +83,7 @@ typedef TTypedProperty<TString, eStringProperty, CStringValue>
typedef TTypedProperty<CVector3f, eVector3Property, CVector3Value> TVector3Property;
typedef TTypedProperty<CColor, eColorProperty, CColorValue> TColorProperty;
typedef TTypedProperty<CResourceInfo, eFileProperty, CFileValue> TFileProperty;
typedef TTypedProperty<CAnimationParameters, eCharacterProperty, CCharacterValue> TAnimParamsProperty;
typedef TTypedProperty<CAnimationParameters, eCharacterProperty, CCharacterValue> TCharacterProperty;
typedef TTypedProperty<std::vector<u8>, eUnknownProperty, CUnknownValue> TUnknownProperty;
/*
@@ -79,25 +94,25 @@ class CPropertyStruct : public IProperty
friend class CScriptLoader;
std::vector<IProperty*> mProperties;
public:
CPropertyStruct(IPropertyTemplate *pTemp)
: IProperty(pTemp) {}
CPropertyStruct(IPropertyTemplate *pTemp, CPropertyStruct *pParent)
: IProperty(pTemp, pParent) {}
~CPropertyStruct();
EPropertyType Type() { return eStructProperty; }
EPropertyType Type() const { return eStructProperty; }
// Inline
inline u32 Count() { return mProperties.size(); }
inline u32 Count() const { return mProperties.size(); }
inline void AddSubProperty(IProperty *pProp) { mProperties.push_back(pProp); }
inline IProperty* operator[](u32 index) { return mProperties[index]; }
// Functions
IProperty* PropertyByIndex(u32 index);
IProperty* PropertyByID(u32 ID);
IProperty* PropertyByIDString(const TIDString& rkStr);
CPropertyStruct* StructByIndex(u32 index);
CPropertyStruct* StructByID(u32 ID);
CPropertyStruct* StructByIDString(const TIDString& rkStr);
IProperty* PropertyByIndex(u32 index) const;
IProperty* PropertyByID(u32 ID) const;
IProperty* PropertyByIDString(const TIDString& rkStr) const;
CPropertyStruct* StructByIndex(u32 index) const;
CPropertyStruct* StructByID(u32 ID) const;
CPropertyStruct* StructByIDString(const TIDString& rkStr) const;
};
/*
@@ -109,20 +124,25 @@ class CArrayProperty : public IProperty
std::vector<CPropertyStruct*> mSubStructs;
public:
CArrayProperty(IPropertyTemplate *pTemp)
: IProperty(pTemp) {}
CArrayProperty(IPropertyTemplate *pTemp, CPropertyStruct *pParent)
: IProperty(pTemp, pParent) {}
EPropertyType Type() { return eArrayProperty; }
~CArrayProperty() {
for (u32 iSub = 0; iSub < mSubStructs.size(); iSub++)
delete mSubStructs[iSub];
}
EPropertyType Type() const { return eArrayProperty; }
// Inline
inline u32 Count() { return mSubStructs.size(); }
inline u32 Count() const { return mSubStructs.size(); }
inline void Reserve(u32 amount) { mSubStructs.reserve(amount); }
inline CPropertyStruct* ElementByIndex(u32 index) { return mSubStructs[index]; }
inline CPropertyStruct* operator[](u32 index) { return ElementByIndex(index); }
// Functions
void Resize(u32 Size);
CStructTemplate* SubStructTemplate();
CStructTemplate* SubStructTemplate() const;
};
#endif // IPROPERTY

View File

@@ -66,9 +66,11 @@ public:
{
if (rkParamName == "should_cook")
{
if (rkValue == "always")
TString lValue = rkValue.ToLower();
if (lValue == "always")
mCookPreference = eAlwaysCook;
else if (rkValue == "never")
else if (lValue == "never")
mCookPreference = eNeverCook;
else
mCookPreference = eNoCookPreference;
@@ -78,7 +80,7 @@ public:
mDescription = rkValue;
}
virtual IProperty* InstantiateProperty() = 0;
virtual IProperty* InstantiateProperty(CPropertyStruct *pParent) = 0;
inline TString Name() const
{
@@ -152,14 +154,14 @@ public:
IPropertyTemplate::SetParam(rkParamName, rkValue);
if (rkParamName == "default")
mDefaultValue.FromString(rkValue);
mDefaultValue.FromString(rkValue.ToLower());
}
virtual IProperty* InstantiateProperty()
virtual IProperty* InstantiateProperty(CPropertyStruct *pParent)
{
typedef TTypedProperty<PropType, PropTypeEnum, ValueClass> TPropertyType;
TPropertyType *pOut = new TPropertyType(this);
TPropertyType *pOut = new TPropertyType(this, pParent);
pOut->Set(GetDefaultValue());
return pOut;
}
@@ -215,7 +217,7 @@ public:
if (rkParamName == "range")
{
TStringList Components = rkValue.Split(", ");
TStringList Components = rkValue.ToLower().Split(", ");
if (Components.size() == 2)
{
@@ -271,9 +273,9 @@ public:
virtual bool CanHaveDefault() const { return false; }
virtual bool IsNumerical() const { return false; }
IProperty* InstantiateProperty()
IProperty* InstantiateProperty(CPropertyStruct *pParent)
{
return new TFileProperty(this);
return new TFileProperty(this, pParent);
}
void SetAllowedExtensions(const TStringList& rkExtensions)
@@ -342,9 +344,9 @@ public:
virtual bool CanHaveDefault() const { return true; }
virtual bool IsNumerical() const { return false; }
virtual IProperty* InstantiateProperty()
virtual IProperty* InstantiateProperty(CPropertyStruct *pParent)
{
TEnumProperty *pEnum = new TEnumProperty(this);
TEnumProperty *pEnum = new TEnumProperty(this, pParent);
u32 Index = EnumeratorIndex(GetDefaultValue());
pEnum->Set(Index);
return pEnum;
@@ -411,9 +413,9 @@ public:
virtual bool CanHaveDefault() const { return true; }
virtual bool IsNumerical() const { return false; }
virtual IProperty* InstantiateProperty()
virtual IProperty* InstantiateProperty(CPropertyStruct *pParent)
{
TBitfieldProperty *pBitfield = new TBitfieldProperty(this);
TBitfieldProperty *pBitfield = new TBitfieldProperty(this, pParent);
pBitfield->Set(GetDefaultValue());
return pBitfield;
}
@@ -466,13 +468,13 @@ public:
bool CanHaveDefault() const { return false; }
bool IsNumerical() const { return false; }
IProperty* InstantiateProperty()
IProperty* InstantiateProperty(CPropertyStruct *pParent)
{
CPropertyStruct *pStruct = new CPropertyStruct(this);
CPropertyStruct *pStruct = new CPropertyStruct(this, pParent);
for (u32 iSub = 0; iSub < mSubProperties.size(); iSub++)
{
IProperty *pSubProp = mSubProperties[iSub]->InstantiateProperty();
IProperty *pSubProp = mSubProperties[iSub]->InstantiateProperty(pStruct);
pStruct->AddSubProperty(pSubProp);
}
@@ -516,14 +518,14 @@ public:
EPropertyType Type() const { return eArrayProperty; }
IProperty* InstantiateProperty()
IProperty* InstantiateProperty(CPropertyStruct *pParent)
{
return new CArrayProperty(this);
return new CArrayProperty(this, pParent);
}
CPropertyStruct* CreateSubStruct()
{
return (CPropertyStruct*) CStructTemplate::InstantiateProperty();
return (CPropertyStruct*) CStructTemplate::InstantiateProperty(nullptr);
}
};