Added support for sound properties, labelled most MP1 sound properties

This commit is contained in:
parax0
2016-09-01 18:02:26 -06:00
parent 0929b20ba1
commit 2e1add84be
43 changed files with 221 additions and 106 deletions

View File

@@ -56,30 +56,38 @@ void CAudioManager::LoadAssets()
}
}
SSoundInfo CAudioManager::GetSoundInfo(u32 SoundID)
{
SSoundInfo Out;
Out.SoundID = SoundID;
Out.DefineID = mpAudioLookupTable->FindSoundDefineID(SoundID);
Out.pAudioGroup = nullptr;
if (Out.DefineID != 0xFFFF)
{
auto Iter = mSfxIdMap.find(Out.DefineID);
if (Iter != mSfxIdMap.end())
Out.pAudioGroup = Iter->second;
if (mpProject->Game() >= eEchoesDemo)
Out.Name = mpSfxNameList->StringByIndex(Out.DefineID);
}
return Out;
}
void CAudioManager::LogSoundInfo(u32 SoundID)
{
u16 DefineID = mpAudioLookupTable->FindSoundDefineID(SoundID);
SSoundInfo SoundInfo = GetSoundInfo(SoundID);
if (DefineID == -1)
Log::Write("Invalid sound");
else
if (SoundInfo.DefineID != 0xFFFF)
{
auto Iter = mSfxIdMap.find(DefineID);
if (mpProject->Game() >= eEchoesDemo)
Log::Write("Sound Name: " + SoundInfo.Name);
if (Iter != mSfxIdMap.end())
{
if (mpProject->Game() >= eEchoesDemo)
{
TString SoundName = mpSfxNameList->StringByIndex(DefineID);
Log::Write("Sound Name: " + SoundName);
}
CAudioGroup *pGroup = Iter->second;
Log::Write("Sound ID: " + TString::HexString(SoundID, 4));
Log::Write("Define ID: " + TString::HexString(DefineID, 4));
Log::Write("Audio Group: " + pGroup->Entry()->Name().ToUTF8());
Log::Write("");
}
Log::Write("Sound ID: " + TString::HexString(SoundInfo.SoundID, 4));
Log::Write("Define ID: " + TString::HexString(SoundInfo.DefineID, 4));
Log::Write("Audio Group: " + SoundInfo.pAudioGroup->Entry()->Name().ToUTF8());
Log::Write("");
}
}

View File

@@ -8,6 +8,14 @@
#include <algorithm>
#include <unordered_map>
struct SSoundInfo
{
CAudioGroup *pAudioGroup;
TString Name;
u32 SoundID;
u16 DefineID;
};
class CAudioManager
{
CGameProject *mpProject;
@@ -20,6 +28,7 @@ class CAudioManager
public:
CAudioManager(CGameProject *pProj);
void LoadAssets();
SSoundInfo GetSoundInfo(u32 SoundID);
void LogSoundInfo(u32 SoundID);
};

View File

@@ -16,7 +16,7 @@ public:
inline u16 FindSoundDefineID(u32 SoundID)
{
ASSERT(SoundID >= 0 && SoundID < mDefineIDs.size());
if (SoundID >= mDefineIDs.size()) return -1;
return mDefineIDs[SoundID];
}
};

View File

@@ -86,6 +86,13 @@ void CScriptCooker::WriteProperty(IProperty *pProp, bool InSingleStruct)
break;
}
case eSoundProperty:
{
TSoundProperty *pSoundCast = static_cast<TSoundProperty*>(pProp);
mpSCLY->WriteLong(pSoundCast->Get());
break;
}
case eAssetProperty:
{
TAssetProperty *pAssetCast = static_cast<TAssetProperty*>(pProp);

View File

@@ -106,6 +106,13 @@ void CScriptLoader::ReadProperty(IProperty *pProp, u32 Size, IInputStream& rSCLY
break;
}
case eSoundProperty:
{
TSoundProperty *pSoundCast = static_cast<TSoundProperty*>(pProp);
pSoundCast->Set(rSCLY.ReadLong());
break;
}
case eAssetProperty:
{
TAssetProperty *pAssetCast = static_cast<TAssetProperty*>(pProp);

View File

@@ -190,6 +190,7 @@ IPropertyTemplate* CTemplateLoader::CreateProperty(u32 ID, EPropertyType Type, c
case eStringProperty: pOut = CREATE_PROP_TEMP(TStringTemplate); break;
case eVector3Property: pOut = CREATE_PROP_TEMP(TVector3Template); break;
case eColorProperty: pOut = CREATE_PROP_TEMP(TColorTemplate); break;
case eSoundProperty: pOut = CREATE_PROP_TEMP(TSoundTemplate); break;
case eAssetProperty: pOut = CREATE_PROP_TEMP(CAssetTemplate); break;
case eCharacterProperty: pOut = CREATE_PROP_TEMP(TCharacterTemplate); break;
case eMayaSplineProperty: pOut = CREATE_PROP_TEMP(TMayaSplineTemplate); break;

View File

@@ -15,6 +15,7 @@ enum EPropertyType
eStringProperty,
eVector3Property,
eColorProperty,
eSoundProperty,
eAssetProperty,
eStructProperty,
eArrayProperty,

View File

@@ -22,8 +22,6 @@ typedef TString TIDString;
*/
class IProperty
{
friend class CScriptLoader;
protected:
class CPropertyStruct *mpParent;
CScriptObject *mpInstance;
@@ -78,7 +76,6 @@ public:
template <typename ValueType, EPropertyType TypeEnum, class ValueClass>
class TTypedProperty : public IProperty
{
friend class CScriptLoader;
ValueClass mValue;
public:
TTypedProperty(IPropertyTemplate *pTemp, CScriptObject *pInstance, CPropertyStruct *pParent)
@@ -124,7 +121,7 @@ typedef TTypedProperty<CColor, eColorProperty, CColorValue>
typedef TTypedProperty<std::vector<u8>, eUnknownProperty, CUnknownValue> TUnknownProperty;
/*
* TStringProperty, TAssetProperty, and TCharacterProperty get little subclasses in order to override some virtual functions.
* TStringProperty, TSoundProperty, TAssetProperty, and TCharacterProperty get little subclasses in order to override some virtual functions.
*/
#define IMPLEMENT_PROPERTY_CTORS(ClassName, ValueType) \
ClassName(IPropertyTemplate *pTemp, CScriptObject *pInstance, CPropertyStruct *pParent) \
@@ -142,6 +139,15 @@ public:
virtual bool ShouldCook() { return true; }
};
class TSoundProperty : public TTypedProperty<u32, eSoundProperty, CSoundValue>
{
public:
IMPLEMENT_PROPERTY_CTORS(TSoundProperty, u32)
IMPLEMENT_PROPERTY_CLONE(TSoundProperty)
virtual bool MatchesDefault() { return Get() == -1; }
virtual bool ShouldCook() { return MatchesDefault(); }
};
class TAssetProperty : public TTypedProperty<CAssetID, eAssetProperty, CAssetValue>
{
public:

View File

@@ -229,6 +229,7 @@ TString PropEnumToPropString(EPropertyType Prop)
case eStringProperty: return "string";
case eColorProperty: return "color";
case eVector3Property: return "vector3f";
case eSoundProperty: return "sound";
case eAssetProperty: return "asset";
case eStructProperty: return "struct";
case eArrayProperty: return "array";
@@ -255,6 +256,7 @@ EPropertyType PropStringToPropEnum(TString Prop)
if (Prop == "string") return eStringProperty;
if (Prop == "color") return eColorProperty;
if (Prop == "vector3f") return eVector3Property;
if (Prop == "sound") return eSoundProperty;
if (Prop == "asset") return eAssetProperty;
if (Prop == "struct") return eStructProperty;
if (Prop == "array") return eArrayProperty;

View File

@@ -308,7 +308,7 @@ typedef TNumericalPropertyTemplate<float, eFloatProperty, CFloatValue>
typedef TTypedPropertyTemplate<CVector3f, eVector3Property, CVector3Value, true> TVector3Template;
typedef TTypedPropertyTemplate<CColor, eColorProperty, CColorValue, true> TColorTemplate;
// TCharacterTemplate, TStringTemplate, and TMayaSplineTemplate get their own subclasses so they can reimplement a couple functions
// TCharacterTemplate, TSoundTemplate, TStringTemplate, and TMayaSplineTemplate get their own subclasses so they can reimplement a couple functions
class TCharacterTemplate : public TTypedPropertyTemplate<CAnimationParameters, eCharacterProperty, CCharacterValue, false>
{
friend class CTemplateLoader;
@@ -327,6 +327,24 @@ public:
}
};
class TSoundTemplate : public TTypedPropertyTemplate<u32, eSoundProperty, CSoundValue, false>
{
friend class CTemplateLoader;
friend class CTemplateWriter;
public:
TSoundTemplate(u32 ID, CScriptTemplate *pScript, CMasterTemplate *pMaster, CStructTemplate *pParent = 0)
: TTypedPropertyTemplate(ID, pScript, pMaster, pParent) {}
TSoundTemplate(u32 ID, const TString& rkName, ECookPreference CookPreference, CScriptTemplate *pScript, CMasterTemplate *pMaster, CStructTemplate *pParent = 0)
: TTypedPropertyTemplate(ID, rkName, CookPreference, pScript, pMaster, pParent) {}
IProperty* InstantiateProperty(CScriptObject *pInstance, CPropertyStruct *pParent)
{
return new TSoundProperty(this, pInstance, pParent, -1);
}
};
class TStringTemplate : public TTypedPropertyTemplate<TString, eStringProperty, CStringValue, false>
{
friend class CTemplateLoader;

View File

@@ -342,6 +342,21 @@ public:
}
};
class CSoundValue : public TTypedPropertyValue<u32>
{
public:
CSoundValue() {}
CSoundValue(u32 SoundID) { mValue = SoundID; }
TString ToString() const { return TString::FromInt32(mValue, 0, 10); }
void FromString(const TString& rkString) { mValue = rkString.ToInt32(10); }
IPropertyValue* Clone() const
{
return new CSoundValue(mValue);
}
};
class CAssetValue : public TTypedPropertyValue<CAssetID>
{
public:

View File

@@ -104,6 +104,16 @@ QWidget* CPropertyDelegate::createEditor(QWidget *pParent, const QStyleOptionVie
break;
}
case eSoundProperty:
{
WIntegralSpinBox *pSpinBox = new WIntegralSpinBox(pParent);
pSpinBox->setMinimum(-1);
pSpinBox->setMaximum(0xFFFF);
CONNECT_RELAY(pSpinBox, rkIndex, valueChanged(int))
pOut = pSpinBox;
break;
}
case eStringProperty:
{
QLineEdit *pLineEdit = new QLineEdit(pParent);
@@ -237,6 +247,7 @@ void CPropertyDelegate::setEditorData(QWidget *pEditor, const QModelIndex &rkInd
}
case eLongProperty:
case eSoundProperty:
{
WIntegralSpinBox *pSpinBox = static_cast<WIntegralSpinBox*>(pEditor);
@@ -406,6 +417,7 @@ void CPropertyDelegate::setModelData(QWidget *pEditor, QAbstractItemModel* /*pMo
}
case eLongProperty:
case eSoundProperty:
{
WIntegralSpinBox *pSpinBox = static_cast<WIntegralSpinBox*>(pEditor);
TLongProperty *pLong = static_cast<TLongProperty*>(pProp);

View File

@@ -1,5 +1,6 @@
#include "CPropertyModel.h"
#include "Editor/UICommon.h"
#include <Core/GameProject/CGameProject.h>
#include <Core/Resource/Script/IProperty.h>
#include <Core/Resource/Script/IPropertyTemplate.h>
#include <QFont>
@@ -289,6 +290,34 @@ QVariant CPropertyModel::data(const QModelIndex& rkIndex, int Role) const
case eVector3Property:
return "(" + TO_QSTRING(pProp->ToString()) + ")";
// Display the AGSC/sound name for sounds
case eSoundProperty:
{
TSoundProperty *pSound = static_cast<TSoundProperty*>(pProp);
u32 SoundID = pSound->Get();
if (SoundID == -1) return "[None]";
CGameProject *pProj = CGameProject::ActiveProject();
SSoundInfo SoundInfo = pProj->AudioManager()->GetSoundInfo(SoundID);
QString Out = QString::number(SoundID);
if (SoundInfo.DefineID == -1)
return Out + " [INVALID]";
// Always display define ID. Display sound name if we have one, otherwise display AGSC ID.
Out += " [" + TO_QSTRING( TString::HexString(SoundInfo.DefineID, 4) );
QString AudioGroupName = (SoundInfo.pAudioGroup ? TO_QSTRING(SoundInfo.pAudioGroup->Entry()->Name()) : "NO AUDIO GROUP");
QString Name = (!SoundInfo.Name.IsEmpty() ? TO_QSTRING(SoundInfo.Name) : AudioGroupName);
Out += " " + Name + "]";
// If we have a sound name and this is a tooltip, add a second line with the AGSC name
if (Role == Qt::ToolTipRole && !SoundInfo.Name.IsEmpty())
Out += "\n" + AudioGroupName;
return Out;
}
// Display character name for characters
case eCharacterProperty:
return TO_QSTRING(static_cast<TCharacterProperty*>(pProp)->Get().GetCurrentCharacterName());