WwiseTreeItem.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. /*------------------------------------------------------------------------------------
  16. WwiseTreeItem.h
  17. ------------------------------------------------------------------------------------*/
  18. #pragma once
  19. #include "AkAudioType.h"
  20. #include "AssetRegistry/AssetData.h"
  21. #include "Engine/GameEngine.h"
  22. #include "Widgets/Views/STableRow.h"
  23. #include "WwiseItemType.h"
  24. #if WITH_EDITORONLY_DATA
  25. #include "Wwise/Metadata/WwiseMetadataBasicReference.h"
  26. #endif
  27. /*------------------------------------------------------------------------------------
  28. WwiseTreeItem
  29. ------------------------------------------------------------------------------------*/
  30. struct AKAUDIO_API FWwiseTreeItem : public TSharedFromThis<FWwiseTreeItem>
  31. {
  32. private:
  33. TArray< TSharedPtr<FWwiseTreeItem> > m_Children;
  34. public:
  35. /** Name to display */
  36. FString DisplayName;
  37. /** The path of the tree item including the name */
  38. FString FolderPath;
  39. /** Type of the item */
  40. EWwiseItemType::Type ItemType = EWwiseItemType::None;
  41. /** Id of the item */
  42. FGuid ItemId;
  43. /** ShortId of the item*/
  44. uint32 ShortId = 0;
  45. /** The children of this tree item */
  46. const TArray< TSharedPtr<FWwiseTreeItem> > GetChildren() { return m_Children; }
  47. TArray< TSharedPtr<FWwiseTreeItem> >* GetChildrenMutable() { return &m_Children; }
  48. /** The number of children of this tree item requested from Wwise*/
  49. uint32_t ChildCountInWwise = 0;
  50. /** The parent folder for this item */
  51. TWeakPtr<FWwiseTreeItem> Parent;
  52. /** The row in the tree view associated to this item */
  53. TWeakPtr<ITableRow> TreeRow;
  54. /** Should this item be visible? */
  55. bool IsVisible = true;
  56. /** The Assets associated with the Tree Item*/
  57. TArray<FAssetData> Assets;
  58. /** The name of the UAsset referenced by this item. If there are more than one, takes the first one found*/
  59. FName UAssetName;
  60. /** The name of the item in the Wwise project*/
  61. FString WaapiName;
  62. #if WITH_EDITORONLY_DATA
  63. /** Reference to the item in the Wwise Project database */
  64. TSharedPtr<FWwiseMetadataBasicReference> WwiseItemRef;
  65. #endif
  66. /** Is this item active in the currently opened project? */
  67. bool bWaapiRefExists = false;
  68. /** Is this item in the same path in Wwise and the SoundBanks? */
  69. bool bSameLocation = true;
  70. bool IsExpanded = false;
  71. bool UEAssetExists() const;
  72. bool WwiseBankRefExists() const;
  73. bool WaapiRefExists() const;
  74. bool IsRenamedInWwise() const;
  75. bool IsDeletedInWwise() const;
  76. bool IsNotInWwiseOrSoundBank() const;
  77. bool IsNewInWwise() const;
  78. bool IsMovedInWwise() const;
  79. bool IsSoundBankUpToDate() const;
  80. bool IsRenamedInSoundBank() const;
  81. bool IsUAssetMissing() const;
  82. bool IsUAssetOrphaned() const;
  83. bool IsNotInSoundBankOrUnreal() const;
  84. bool IsUAssetUpToDate() const;
  85. bool HasUniqueUAsset() const;
  86. bool HasMultipleUAssets() const;
  87. bool IsUAssetOutOfDate() const;
  88. bool IsItemUpToDate() const;
  89. bool IsFolder() const;
  90. bool IsAuxBus() const;
  91. bool ShouldDisplayInfo() const;
  92. bool IsRootItem() const;
  93. TSharedPtr<FWwiseTreeItem> GetRoot();
  94. void SetWaapiRef(bool bExistsInWaapi);
  95. FString GetSwitchAssetName() const;
  96. const FString GetDefaultAssetName() const;
  97. /** Constructor */
  98. FWwiseTreeItem(FString InDisplayName, FString InFolderPath, TSharedPtr<FWwiseTreeItem> InParent, EWwiseItemType::Type InItemType, const FGuid& InItemId)
  99. : DisplayName(MoveTemp(InDisplayName))
  100. , FolderPath(MoveTemp(InFolderPath))
  101. , ItemType(MoveTemp(InItemType))
  102. , ItemId(InItemId)
  103. , ChildCountInWwise(m_Children.Num())
  104. , Parent(MoveTemp(InParent))
  105. {
  106. }
  107. #if WITH_EDITORONLY_DATA
  108. FWwiseTreeItem(const FWwiseMetadataBasicReference& ItemRef, TSharedPtr<FWwiseTreeItem> InParent, EWwiseItemType::Type InItemType)
  109. : ItemType(InItemType)
  110. , ChildCountInWwise(m_Children.Num())
  111. , Parent(MoveTemp(InParent))
  112. {
  113. WwiseItemRef = MakeShared<FWwiseMetadataBasicReference>(ItemRef.Id, ItemRef.Name, ItemRef.ObjectPath, ItemRef.GUID);
  114. ItemId = WwiseItemRef->GUID;
  115. DisplayName = WwiseItemRef->Name.ToString();
  116. FolderPath = WwiseItemRef->ObjectPath.ToString();
  117. }
  118. #endif
  119. void AddChild(TSharedPtr<FWwiseTreeItem> Child);
  120. void AddChildren(TArray<TSharedPtr<FWwiseTreeItem>> Children);
  121. void EmptyChildren();
  122. void RemoveChild(const FGuid& childGuid);
  123. void RemoveChild(const TSharedPtr< FWwiseTreeItem> child);
  124. void RemoveChildren(const TArray<TSharedPtr<FWwiseTreeItem>> Children);
  125. /** Returns true if this item is a child of the specified item */
  126. bool IsChildOf(const FWwiseTreeItem& InParent);
  127. bool IsBrowserType() const;
  128. bool IsOfType(const TArray<EWwiseItemType::Type>& Types) const;
  129. bool IsNotOfType(const TArray<EWwiseItemType::Type>& Types) const;
  130. /** Returns the child item by name or NULL if the child does not exist */
  131. TSharedPtr<FWwiseTreeItem> GetChild(const FString& InChildName);
  132. /** Returns the child item by name or NULL if the child does not exist */
  133. TSharedPtr<FWwiseTreeItem> GetChild(const FGuid& InGuid, const AkUInt32 InShortId, const FString& InChildName);
  134. /** Finds the child who's path matches the one specified */
  135. TSharedPtr<FWwiseTreeItem> FindItemRecursive(const FString& InFullPath);
  136. /** Finds the child who's Guid matches the one specified */
  137. TSharedPtr<FWwiseTreeItem> FindItemRecursive(const TSharedPtr<FWwiseTreeItem>& InItem);
  138. struct FCompareWwiseTreeItem
  139. {
  140. template<typename CT>
  141. inline int StringCompareLogical(const CT* pA1, const CT* pA2) const
  142. {
  143. if (pA1 && pA2)
  144. {
  145. while (*pA1)
  146. {
  147. if (!*pA2)
  148. {
  149. // We've iterated through all the characters of the RHS but
  150. // there are characters left on the LHS
  151. return 1;
  152. }
  153. else if (TChar<CT>::IsDigit(*pA1))
  154. {
  155. // LHS is a digit but RHS is not
  156. if (!TChar<CT>::IsDigit(*pA2))
  157. return -1;
  158. // Both sides are digits, parse the numbers and compare them
  159. CT* pEnd1 = nullptr;
  160. CT* pEnd2 = nullptr;
  161. const auto i1 = TCString<CT>::Strtoi(pA1, &pEnd1, 10);
  162. const auto i2 = TCString<CT>::Strtoi(pA2, &pEnd2, 10);
  163. if (i1 < i2)
  164. return -1;
  165. else if (i1 > i2)
  166. return 1;
  167. pA1 = pEnd1;
  168. pA2 = pEnd2;
  169. }
  170. else if (TChar<CT>::IsDigit(*pA2))
  171. {
  172. // LHS is not a digit but RHS is
  173. return 1;
  174. }
  175. else
  176. {
  177. // Neither side is a digit, do a case-insensitive comparison
  178. int diff = TChar<CT>::ToLower(*pA1) - TChar<CT>::ToLower(*pA2);
  179. if (diff > 0)
  180. return 1;
  181. else if (diff < 0)
  182. return -1;
  183. ++pA1;
  184. ++pA2;
  185. }
  186. }
  187. if (*pA2)
  188. {
  189. // We've iterated through all the characters of the LHS but
  190. // there are characters left on the RHS
  191. return -1;
  192. }
  193. }
  194. return 0;
  195. }
  196. FORCEINLINE bool operator()( TSharedPtr<FWwiseTreeItem> A, TSharedPtr<FWwiseTreeItem> B ) const
  197. {
  198. // Items are sorted like so:
  199. // 1- Physical folders, sorted alphabetically
  200. // 1- WorkUnits, sorted alphabetically
  201. // 2- Virtual folders, sorted alphabetically
  202. // 3- Normal items, sorted alphabetically
  203. if( A->ItemType == B->ItemType)
  204. {
  205. return StringCompareLogical(*A->DisplayName, *B->DisplayName) < 0;
  206. }
  207. else if( A->ItemType == EWwiseItemType::PhysicalFolder )
  208. {
  209. return true;
  210. }
  211. else if( B->ItemType == EWwiseItemType::PhysicalFolder )
  212. {
  213. return false;
  214. }
  215. else if( A->ItemType == EWwiseItemType::StandaloneWorkUnit || A->ItemType == EWwiseItemType::NestedWorkUnit )
  216. {
  217. return true;
  218. }
  219. else if( B->ItemType == EWwiseItemType::StandaloneWorkUnit || B->ItemType == EWwiseItemType::NestedWorkUnit )
  220. {
  221. return false;
  222. }
  223. else if( A->ItemType == EWwiseItemType::Folder )
  224. {
  225. return true;
  226. }
  227. else if( B->ItemType == EWwiseItemType::Folder )
  228. {
  229. return false;
  230. }
  231. else
  232. {
  233. return true;
  234. }
  235. }
  236. };
  237. /** Sort the children by name */
  238. void SortChildren();
  239. };