Fixed array property display on UI (they still can't be resized)

This commit is contained in:
Aruki
2018-07-09 03:54:19 -06:00
parent 4faadbda61
commit 641cf81dd8
14 changed files with 123 additions and 45 deletions

View File

@@ -213,7 +213,7 @@ void CScriptCooker::WriteProperty(IOutputStream& rOut, IPropertyNew* pProperty,
for (u32 ElementIdx = 0; ElementIdx < pArray->ArrayCount(pData); ElementIdx++)
{
mpArrayItemData = pArray->ItemPointer(pData, ElementIdx);
WriteProperty(rOut, pArray->ArchetypeProperty(), true);
WriteProperty(rOut, pArray->ItemArchetype(), true);
}
mpArrayItemData = pOldItemData;

View File

@@ -219,7 +219,7 @@ void CScriptLoader::ReadProperty(IPropertyNew *pProp, u32 Size, IInputStream& rS
// Make sure the array archetype is atomic... non-atomic array archetypes is not supported
// because arrays can only have one possible archetype so having property IDs here wouldn't make sense
ASSERT(pArray->ArchetypeProperty()->IsAtomic());
ASSERT(pArray->ItemArchetype()->IsAtomic());
for (int ElementIdx = 0; ElementIdx < Count; ElementIdx++)
{
@@ -236,7 +236,7 @@ void CScriptLoader::ReadProperty(IPropertyNew *pProp, u32 Size, IInputStream& rS
* things to make this cleaner
*/
mpArrayItemData = pArray->ItemPointer(pData, ElementIdx);
ReadProperty(pArray->ArchetypeProperty(), 0, rSCLY);
ReadProperty(pArray->ItemArchetype(), 0, rSCLY);
}
mpArrayItemData = pOldArrayItemData;

View File

@@ -333,18 +333,22 @@ IPropertyNew* CTemplateLoader::LoadProperty(XMLElement* pElem, CScriptTemplate*
{
CArrayProperty* pArray = TPropCast<CArrayProperty>(pProp);
if (pArray->mpArchetype != nullptr)
if (pArray->mpItemArchetype != nullptr)
{
ASSERT(pArray->mpArchetype->Type() == EPropertyTypeNew::Struct);
pStruct = TPropCast<CStructPropertyNew>(pArray->mpArchetype);
ASSERT(pArray->mpItemArchetype->Type() == EPropertyTypeNew::Struct);
pStruct = TPropCast<CStructPropertyNew>(pArray->mpItemArchetype);
}
else
{
pArray->mpArchetype = IPropertyNew::Create(EPropertyTypeNew::Struct, pArray, mpMaster, pScript, false);
pStruct = TPropCast<CStructPropertyNew>(pArray->mpArchetype);
pArray->mpItemArchetype = IPropertyNew::Create(EPropertyTypeNew::Struct, pArray, mpMaster, pScript, false);
pStruct = TPropCast<CStructPropertyNew>(pArray->mpItemArchetype);
pStruct->mFlags = EPropertyFlag::IsAtomic | EPropertyFlag::IsArrayArchetype;
}
pStruct = TPropCast<CStructPropertyNew>(pArray->mpArchetype);
XMLElement* pItemNameElem = pElem->FirstChildElement("element_name");
if (pItemNameElem)
pStruct->mName = pItemNameElem->GetText();
}
// Load parameter overrides

View File

@@ -152,10 +152,8 @@ TString IPropertyNew::GetTemplateFileName()
void* IPropertyNew::RawValuePtr(void* pData) const
{
// For array archetypes, the caller needs to provide the pointer to the correct array item
if (IsArrayArchetype())
return pData;
void* pBasePtr = (mpPointerParent ? mpPointerParent->GetChildDataPointer(pData) : pData);
// Array archetypes can't store their index in the array so it's impossible to determine the correct pointer.
void* pBasePtr = (mpPointerParent && !IsArrayArchetype() ? mpPointerParent->GetChildDataPointer(pData) : pData);
void* pValuePtr = ((char*)pBasePtr + mOffset);
return pValuePtr;
}

View File

@@ -72,6 +72,7 @@ inline const char* PropEnumToHashableTypeName(EPropertyTypeNew Type)
{
switch (Type)
{
// these names are required to generate accurate property ID hashes
case EPropertyTypeNew::Bool: return "bool";
case EPropertyTypeNew::Int: return "int";
case EPropertyTypeNew::Float: return "float";
@@ -85,6 +86,14 @@ inline const char* PropEnumToHashableTypeName(EPropertyTypeNew Type)
case EPropertyTypeNew::Sound: return "sound";
case EPropertyTypeNew::Spline: return "spline";
case EPropertyTypeNew::Guid: return "guid";
// unknown hashable types - used in hashes but these names are inaccurate
case EPropertyTypeNew::Animation: return "animation"; // hashable but real name unknown
case EPropertyTypeNew::Sequence: return "sequence";
// non hashable types - not used in ID hashes but still displayed on the UI
case EPropertyTypeNew::Byte: return "byte";
case EPropertyTypeNew::Short: return "short";
case EPropertyTypeNew::Array: return "array";
// fallback
default: return "";
}
}

View File

@@ -17,6 +17,11 @@ public:
{
Value(pData).Serialize(Arc);
}
virtual const char* HashableTypeName() const
{
return (Game() <= eEchoes ? "AnimationSet" : "CharacterAnimationSet");
}
};
#endif // CANIMATIONSETPROPERTY_H

View File

@@ -22,7 +22,9 @@ struct SScriptArray
/** @todo proper support of default values for arrays (this would be used for prefabs) */
class CArrayProperty : public TTypedPropertyNew<int, EPropertyTypeNew::Array>
{
friend class IPropertyNew;
friend class CTemplateLoader;
/** This class inherits from TTypedPropertyNew<int> in order to expose the array
* count value (the first member of SScriptArray). Outside users can edit this
* value and we respond by updating the allocated space, handling item destruction
@@ -42,6 +44,12 @@ class CArrayProperty : public TTypedPropertyNew<int, EPropertyTypeNew::Array>
return rArray.size() / ItemSize();
}
protected:
CArrayProperty()
: TTypedPropertyNew()
, mpItemArchetype(nullptr)
{}
public:
virtual u32 DataSize() const
{
@@ -110,7 +118,7 @@ public:
if (Arc.ParamBegin("ArrayElement"))
{
void* pItemData = ItemPointer(pData, ItemIdx);
mpArchetype->SerializeValue(pItemData, Arc);
mpItemArchetype->SerializeValue(pItemData, Arc);
Arc.ParamEnd();
}
}
@@ -148,6 +156,7 @@ public:
u32 NewSize = NewCount * ItemSize();
rArray.Array.resize(NewSize);
rArray.Count = NewCount;
// Handle construction of new elements
if (NewCount > OldCount)
@@ -163,7 +172,7 @@ public:
void* ItemPointer(void* pPropertyData, u32 ItemIndex) const
{
ASSERT(ArrayCount(pPropertyData) > ItemIndex);
ASSERT(_InternalArrayCount(pPropertyData) > ItemIndex);
std::vector<char>& rArray = _GetInternalArray(pPropertyData).Array;
u32 MyItemSize = ItemSize();
ASSERT(rArray.size() >= (MyItemSize * (ItemIndex+1)));
@@ -178,7 +187,7 @@ public:
}
/** Accessors */
IPropertyNew* ArchetypeProperty() const { return mpArchetype; }
IPropertyNew* ItemArchetype() const { return mpItemArchetype; }
};
#endif // CARRAYPROPERTY_H

View File

@@ -18,7 +18,7 @@ public:
Arc.SerializePrimitive( (u8&) ValueRef(pData) );
}
virtual TString ValueAsString(void* pData)
virtual TString ValueAsString(void* pData) const
{
return TString::FromInt32( (s32) Value(pData), 0, 10 );
}

View File

@@ -18,7 +18,7 @@ public:
Arc.SerializePrimitive( (u16&) ValueRef(pData) );
}
virtual TString ValueAsString(void* pData)
virtual TString ValueAsString(void* pData) const
{
return TString::FromInt32( (s32) Value(pData), 0, 10 );
}

View File

@@ -81,12 +81,10 @@ public:
virtual const char* HashableTypeName() const
{
ASSERT(IsArchetype() || mpArchetype != nullptr);
if (IsArchetype())
if (IsArchetype() || !mpArchetype)
return *mName;
else
return *mpArchetype->Name();
return mpArchetype->HashableTypeName();
}
#if 0