SWwiseBrowserTreeView.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #include "SWwiseBrowserTreeView.h"
  16. #include "AkAudioStyle.h"
  17. #include "AkSettings.h"
  18. #include "WwiseUEFeatures.h"
  19. #include "IAudiokineticTools.h"
  20. #include "SWwiseBrowser.h"
  21. #include "SlateOptMacros.h"
  22. #include "WwiseBrowser/WwiseAssetDragDropOp.h"
  23. #if UE_5_0_OR_LATER
  24. #include "WwiseUEFeatures.h"
  25. #endif
  26. BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
  27. FReply HandleOnDragDetected(const FGeometry& Geometry, const FPointerEvent& MouseEvent, TWeakPtr<SWwiseBrowserTreeView> Table)
  28. {
  29. if (!MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton))
  30. {
  31. return FReply::Unhandled();
  32. }
  33. auto TablePtr = Table.Pin();
  34. TArray<FWwiseTreeItemPtr> SelectedItems;
  35. if (TablePtr.IsValid() && MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton))
  36. {
  37. SelectedItems = TablePtr->GetSelectedItems();
  38. if (SelectedItems.Num() == 0)
  39. {
  40. return FReply::Unhandled();
  41. }
  42. }
  43. UE_LOG(LogAudiokineticTools, Verbose, TEXT("SWwiseBrowser::OnDragDetected: User drag operation started."));
  44. auto AkSettings = GetMutableDefault<UAkSettings>();
  45. const FString DefaultPath = AkSettings->DefaultAssetCreationPath;
  46. TArray<WwiseBrowserHelpers::WwiseBrowserAssetPayload> DragAssets;
  47. TSet<FGuid> SeenGuids;
  48. bool bAllItemsCanBeCreated = true;
  49. for (auto& WwiseTreeItem : SelectedItems)
  50. {
  51. if (!WwiseTreeItem->ItemId.IsValid() && !WwiseTreeItem->IsFolder())
  52. {
  53. UE_LOG(LogAudiokineticTools, Error, TEXT("Cannot drag selected Wwise asset: %s does not have a valid ID"), *(WwiseTreeItem->FolderPath));
  54. continue;
  55. }
  56. if (!WwiseBrowserHelpers::CanCreateAsset(WwiseTreeItem))
  57. {
  58. bAllItemsCanBeCreated = false;
  59. }
  60. WwiseBrowserHelpers::FindOrCreateAssetsRecursive(WwiseTreeItem, DragAssets,SeenGuids, WwiseBrowserHelpers::EAssetCreationMode::Transient);
  61. }
  62. if (DragAssets.Num() == 0 && bAllItemsCanBeCreated)
  63. {
  64. UE_LOG(LogAudiokineticTools, Error, TEXT("Failed to find or create Wwise asset '%s'%s in Browser operation"),
  65. *(SelectedItems[0]->FolderPath), SelectedItems.Num() > 1 ? TEXT(" and others"): TEXT(""));
  66. return FReply::Unhandled();
  67. }
  68. return FReply::Handled().BeginDragDrop(FWwiseAssetDragDropOp::New(DragAssets));
  69. }
  70. void SWwiseBrowserTreeView::Construct(const FArguments& InArgs, TSharedRef<SWwiseBrowser> Owner)
  71. {
  72. WwiseBrowserWeak = Owner;
  73. STreeView::Construct(InArgs);
  74. }
  75. void SWwiseBrowserTreeView::SetSelectedItems(TArray<TSharedPtr<FWwiseTreeItem>> Items)
  76. {
  77. SelectedItems.Reset();
  78. for(auto Item : Items)
  79. {
  80. SelectedItems.Add(Item);
  81. }
  82. if (OnSelectionChanged.IsBound() && SelectedItems.Num() > 0)
  83. {
  84. NullableItemType SelectedItem = (*typename TItemSet::TIterator(SelectedItems));
  85. OnSelectionChanged.ExecuteIfBound(SelectedItem, ESelectInfo::Direct);
  86. }
  87. }
  88. TSharedRef<SWidget> SWwiseBrowserTreeRow::GenerateWidgetForColumn(const FName& InColumnId)
  89. {
  90. auto ItemPtr = Item.Pin();
  91. if (!ItemPtr.IsValid())
  92. {
  93. return SNullWidget::NullWidget;
  94. }
  95. auto WwiseBrowser = WwiseBrowserWeak.Pin();
  96. check(WwiseBrowser.IsValid());
  97. // Create the widget for this item
  98. TSharedRef<SWidget> NewItemWidget = SNullWidget::NullWidget;
  99. auto Column = WwiseBrowser->GetColumns().FindRef(InColumnId);
  100. if (Column.IsValid())
  101. {
  102. NewItemWidget = Column->ConstructRowWidget(ItemPtr.ToSharedRef(), *this);
  103. }
  104. if( InColumnId == WwiseBrowserHelpers::WwiseBrowserColumnId)
  105. {
  106. // The first column gets the tree expansion arrow for this row
  107. return SNew(SBox)
  108. .MinDesiredHeight(20)
  109. [
  110. SNew( SHorizontalBox )
  111. +SHorizontalBox::Slot()
  112. .AutoWidth()
  113. .Padding(6, 0, 0, 0)
  114. [
  115. SNew( SExpanderArrow, SharedThis(this) ).IndentAmount(12)
  116. ]
  117. +SHorizontalBox::Slot()
  118. .FillWidth(1.0f)
  119. [
  120. NewItemWidget
  121. ]
  122. ];
  123. }
  124. else
  125. {
  126. // Other columns just get widget content -- no expansion arrow needed
  127. return NewItemWidget;
  128. }
  129. }
  130. void SWwiseBrowserTreeRow::Construct(
  131. const FArguments& InArgs,
  132. const TSharedRef<SWwiseBrowserTreeView>& BrowserTreeView,
  133. TSharedRef<SWwiseBrowser> WwiseBrowser)
  134. {
  135. Item = InArgs._Item->AsShared();
  136. WwiseBrowserWeak = WwiseBrowser;
  137. auto Args = FSuperRowType::FArguments();
  138. Args.OnDragDetected_Static(HandleOnDragDetected, TWeakPtr<SWwiseBrowserTreeView>(BrowserTreeView));
  139. auto ItemPtr = Item.Pin();
  140. auto WwiseBrowserPtr = WwiseBrowserWeak.Pin();
  141. SetVisibility(ItemPtr->IsVisible ? EVisibility::Visible : EVisibility::Collapsed);
  142. if (!WwiseBrowserPtr.IsValid())
  143. {
  144. UE_LOG(LogAudiokineticTools, Error, TEXT("Wwise Browser is invalid."));
  145. return;
  146. }
  147. if (!ItemPtr.IsValid())
  148. {
  149. UE_LOG(LogAudiokineticTools, Error, TEXT("Wwise Item is invalid."));
  150. return;
  151. }
  152. SMultiColumnTableRow<FWwiseTreeItemPtr>::Construct(Args, BrowserTreeView);
  153. }
  154. END_SLATE_FUNCTION_BUILD_OPTIMIZATION