Added interface for editing array properties in the property view

This commit is contained in:
parax0
2016-01-25 16:57:04 -07:00
parent 3b41415581
commit 9a24a34bc6
12 changed files with 185 additions and 48 deletions

View File

@@ -23,12 +23,6 @@ TIDString IProperty::IDString(bool FullPath) const
}
// ************ CPropertyStruct ************
CPropertyStruct::~CPropertyStruct()
{
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
delete *it;
}
IProperty* CPropertyStruct::PropertyByIndex(u32 index) const
{
return mProperties[index];
@@ -106,21 +100,21 @@ CPropertyStruct* CPropertyStruct::StructByIDString(const TIDString& rkStr) const
// ************ CArrayProperty ************
void CArrayProperty::Resize(u32 Size)
{
u32 OldSize = mSubStructs.size();
u32 OldSize = mProperties.size();
if (OldSize == Size) return;
if (Size < OldSize)
{
for (u32 i = mSubStructs.size() - 1; i >= Size; i--)
delete mSubStructs[i];
for (u32 i = mProperties.size() - 1; i >= Size; i--)
delete mProperties[i];
}
mSubStructs.resize(Size);
mProperties.resize(Size);
if (Size > OldSize)
{
for (u32 i = OldSize; i < Size; i++)
mSubStructs[i] = static_cast<CArrayTemplate*>(mpTemplate)->CreateSubStruct();
mProperties[i] = static_cast<CArrayTemplate*>(mpTemplate)->CreateSubStruct(this);
}
}
@@ -129,3 +123,8 @@ CStructTemplate* CArrayProperty::SubStructTemplate() const
// CArrayTemplate inherits from CStructTemplate. The template defines the substruct structure.
return static_cast<CStructTemplate*>(Template());
}
TString CArrayProperty::ElementName() const
{
return static_cast<CArrayTemplate*>(Template())->ElementName();
}

View File

@@ -92,12 +92,16 @@ typedef TTypedProperty<std::vector<u8>, eUnknownProperty, CUnknownValue>
class CPropertyStruct : public IProperty
{
friend class CScriptLoader;
protected:
std::vector<IProperty*> mProperties;
public:
CPropertyStruct(IPropertyTemplate *pTemp, CPropertyStruct *pParent)
: IProperty(pTemp, pParent) {}
~CPropertyStruct();
~CPropertyStruct() {
for (auto it = mProperties.begin(); it != mProperties.end(); it++)
delete *it;
}
EPropertyType Type() const { return eStructProperty; }
@@ -118,31 +122,23 @@ public:
/*
* CArrayProperty stores a repeated property struct.
*/
class CArrayProperty : public IProperty
class CArrayProperty : public CPropertyStruct
{
friend class CScriptLoader;
std::vector<CPropertyStruct*> mSubStructs;
public:
CArrayProperty(IPropertyTemplate *pTemp, CPropertyStruct *pParent)
: IProperty(pTemp, pParent) {}
~CArrayProperty() {
for (u32 iSub = 0; iSub < mSubStructs.size(); iSub++)
delete mSubStructs[iSub];
}
: CPropertyStruct(pTemp, pParent) {}
EPropertyType Type() const { return eArrayProperty; }
// Inline
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); }
inline void Reserve(u32 amount) { mProperties.reserve(amount); }
// Functions
void Resize(u32 Size);
CStructTemplate* SubStructTemplate() const;
TString ElementName() const;
};
#endif // IPROPERTY

View File

@@ -502,6 +502,7 @@ class CArrayTemplate : public CStructTemplate
{
friend class CTemplateLoader;
friend class CTemplateWriter;
TString mElementName;
public:
CArrayTemplate(u32 ID, CStructTemplate *pParent = 0)
@@ -518,14 +519,25 @@ public:
EPropertyType Type() const { return eArrayProperty; }
void SetParam(const TString& rkParamName, const TString& rkValue)
{
if (rkParamName == "element_name")
mElementName = rkValue;
else
CStructTemplate::SetParam(rkParamName, rkValue);
}
IProperty* InstantiateProperty(CPropertyStruct *pParent)
{
return new CArrayProperty(this, pParent);
}
CPropertyStruct* CreateSubStruct()
TString ElementName() const { return mElementName; }
void SetElementName(const TString& rkName) { mElementName = rkName; }
CPropertyStruct* CreateSubStruct(CArrayProperty *pArray)
{
return (CPropertyStruct*) CStructTemplate::InstantiateProperty(nullptr);
return (CPropertyStruct*) CStructTemplate::InstantiateProperty(pArray);
}
};