Support for undoing property changes + tons of tweaks and fixes

This commit is contained in:
parax0
2016-01-31 01:11:32 -07:00
parent c7d448225c
commit cc054cf571
25 changed files with 467 additions and 192 deletions

View File

@@ -40,6 +40,7 @@ public:
virtual ~IProperty() {}
virtual EPropertyType Type() const = 0;
virtual TString ToString() const { return ""; }
virtual IPropertyValue* RawValue() { return nullptr; }
inline CPropertyStruct* Parent() const { return mpParent; }
@@ -68,6 +69,7 @@ public:
~TTypedProperty() {}
virtual EPropertyType Type() const { return TypeEnum; }
virtual TString ToString() const { return mValue.ToString(); }
virtual IPropertyValue* RawValue() { return &mValue; }
inline PropType Get() const { return mValue.Get(); }
inline void Set(PropType v) { mValue.Set(v); }
@@ -77,7 +79,7 @@ typedef TTypedProperty<char, eByteProperty, CByteValue>
typedef TTypedProperty<short, eShortProperty, CShortValue> TShortProperty;
typedef TTypedProperty<long, eLongProperty, CLongValue> TLongProperty;
typedef TTypedProperty<long, eEnumProperty, CLongValue> TEnumProperty;
typedef TTypedProperty<long, eBitfieldProperty, CLongValue> TBitfieldProperty;
typedef TTypedProperty<long, eBitfieldProperty, CHexLongValue> TBitfieldProperty;
typedef TTypedProperty<float, eFloatProperty, CFloatValue> TFloatProperty;
typedef TTypedProperty<TString, eStringProperty, CStringValue> TStringProperty;
typedef TTypedProperty<CVector3f, eVector3Property, CVector3Value> TVector3Property;

View File

@@ -338,13 +338,11 @@ public:
CEnumTemplate(u32 ID, CStructTemplate *pParent = 0)
: TLongTemplate(ID, pParent)
{
mDefaultValue.SetHexStringOutput(true);
}
CEnumTemplate(u32 ID, const TString& rkName, ECookPreference CookPreference, CStructTemplate *pParent = 0)
: TLongTemplate(ID, rkName, CookPreference, pParent)
{
mDefaultValue.SetHexStringOutput(true);
}
virtual EPropertyType Type() const { return eEnumProperty; }
@@ -393,7 +391,7 @@ public:
// CBitfieldTemplate - Property template for bitfields, which can have multiple
// distinct boolean parameters packed into one property.
class CBitfieldTemplate : public TLongTemplate
class CBitfieldTemplate : public TTypedPropertyTemplate<u32, eBitfieldProperty, CHexLongValue>
{
friend class CTemplateLoader;
friend class CTemplateWriter;
@@ -411,15 +409,13 @@ class CBitfieldTemplate : public TLongTemplate
public:
CBitfieldTemplate(u32 ID, CStructTemplate *pParent = 0)
: TLongTemplate(ID, pParent)
: TTypedPropertyTemplate(ID, pParent)
{
mDefaultValue.SetHexStringOutput(true);
}
CBitfieldTemplate(u32 ID, const TString& rkName, ECookPreference CookPreference, CStructTemplate *pParent = 0)
: TLongTemplate(ID, rkName, CookPreference, pParent)
: TTypedPropertyTemplate(ID, rkName, CookPreference, pParent)
{
mDefaultValue.SetHexStringOutput(true);
}
virtual EPropertyType Type() const { return eBitfieldProperty; }

View File

@@ -17,6 +17,9 @@ class IPropertyValue
public:
virtual TString ToString() const = 0;
virtual void FromString(const TString& rkString) = 0;
virtual IPropertyValue* Clone() const = 0;
virtual void Copy(IPropertyValue *pValue) = 0;
virtual bool Matches(IPropertyValue *pValue) const = 0;
};
template<typename PropType>
@@ -28,8 +31,20 @@ protected:
public:
TTypedPropertyValue() {}
TTypedPropertyValue(PropType Val)
: mValue(Val) {}
TTypedPropertyValue(PropType rkVal)
: mValue(rkVal) {}
virtual void Copy(IPropertyValue *pValue)
{
TTypedPropertyValue *pOther = static_cast<TTypedPropertyValue*>(pValue);
mValue = pOther->mValue;
}
virtual bool Matches(IPropertyValue *pValue) const
{
TTypedPropertyValue *pOther = static_cast<TTypedPropertyValue*>(pValue);
return (mValue == pOther->mValue);
}
PropType Get() const
{
@@ -69,6 +84,11 @@ public:
{
mValue = (rkString == "true");
}
IPropertyValue* Clone() const
{
return new CBoolValue(mValue);
}
};
class CByteValue : public TTypedPropertyValue<s8>
@@ -87,6 +107,11 @@ public:
u32 base = (rkString.StartsWith("0x") ? 16 : 10);
mValue = (s8) rkString.ToInt32(base);
}
IPropertyValue* Clone() const
{
return new CByteValue(mValue);
}
};
class CShortValue : public TTypedPropertyValue<s16>
@@ -105,28 +130,22 @@ public:
u32 base = (rkString.StartsWith("0x") ? 16 : 10);
mValue = (s16) rkString.ToInt32(base);
}
IPropertyValue* Clone() const
{
return new CShortValue(mValue);
}
};
class CLongValue : public TTypedPropertyValue<s32>
{
protected:
bool mShouldOutputHex;
public:
CLongValue() { mShouldOutputHex = false; mValue = 0; }
CLongValue(s32 Val) { mShouldOutputHex = false; mValue = Val; }
void SetHexStringOutput(bool enable)
{
mShouldOutputHex = enable;
}
CLongValue() { mValue = 0; }
CLongValue(s32 Val) { mValue = Val; }
TString ToString() const
{
if (mShouldOutputHex)
return TString::HexString((u32) mValue, true, true, 8);
else
return TString::FromInt32(mValue, 0, 10);
return TString::FromInt32(mValue, 0, 10);
}
void FromString(const TString& rkString)
@@ -134,6 +153,34 @@ public:
u32 base = (rkString.StartsWith("0x") ? 16 : 10);
mValue = (s32) rkString.ToInt32(base);
}
IPropertyValue* Clone() const
{
return new CLongValue(mValue);
}
};
class CHexLongValue : public TTypedPropertyValue<u32>
{
public:
CHexLongValue() { mValue = 0; }
CHexLongValue(u32 Val) { mValue = Val; }
TString ToString() const
{
return TString::HexString(mValue, true, true, 8);
}
void FromString(const TString& rkString)
{
u32 base = (rkString.StartsWith("0x") ? 16 : 10);
mValue = (s32) rkString.ToInt32(base);
}
IPropertyValue* Clone() const
{
return new CHexLongValue(mValue);
}
};
class CFloatValue : public TTypedPropertyValue<float>
@@ -151,6 +198,11 @@ public:
{
mValue = rkString.ToFloat();
}
IPropertyValue* Clone() const
{
return new CFloatValue(mValue);
}
};
class CStringValue : public TTypedPropertyValue<TString>
@@ -169,6 +221,11 @@ public:
{
mValue = rkString;
}
IPropertyValue* Clone() const
{
return new CStringValue(mValue);
}
};
class CColorValue : public TTypedPropertyValue<CColor>
@@ -207,6 +264,11 @@ public:
pPtr++;
}
}
IPropertyValue* Clone() const
{
return new CColorValue(mValue);
}
};
class CVector3Value : public TTypedPropertyValue<CVector3f>
@@ -243,15 +305,26 @@ public:
pPtr++;
}
}
IPropertyValue* Clone() const
{
return new CVector3Value(mValue);
}
};
class CCharacterValue : public TTypedPropertyValue<CAnimationParameters>
{
public:
CCharacterValue() {}
CCharacterValue(const CAnimationParameters& rkParams) { mValue = rkParams; }
TString ToString() const { return ""; }
void FromString(const TString&) { }
IPropertyValue* Clone() const
{
return new CCharacterValue(mValue);
}
};
class CFileValue : public TTypedPropertyValue<CResourceInfo>
@@ -262,15 +335,26 @@ public:
TString ToString() const { return ""; }
void FromString(const TString&) { }
IPropertyValue* Clone() const
{
return new CFileValue(mValue);
}
};
class CUnknownValue : public TTypedPropertyValue<std::vector<u8>>
{
public:
CUnknownValue();
CUnknownValue(const std::vector<u8>& rkVec) { mValue = rkVec; }
TString ToString() const { return ""; }
void FromString(const TString&) {}
IPropertyValue* Clone() const
{
return new CUnknownValue(mValue);
}
};
#endif // IPROPERTYVALUE_H