AkWwiseTree.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. includes.
  17. ------------------------------------------------------------------------------------*/
  18. #include "AkWaapiUMG/Components/AkWwiseTree.h"
  19. #include "AkAudioDevice.h"
  20. #include "Widgets/Input/SButton.h"
  21. #include "Framework/MultiBox/MultiBoxBuilder.h"
  22. #include "AkWaapiUMG/Components/WwiseUmgDragDropOp.h"
  23. #include "AkWaapiSlate/Widgets/Input/AkSSlider.h"
  24. /*------------------------------------------------------------------------------------
  25. Defines
  26. ------------------------------------------------------------------------------------*/
  27. #define LOCTEXT_NAMESPACE "AkWaapiUMG"
  28. /*------------------------------------------------------------------------------------
  29. Implementation
  30. ------------------------------------------------------------------------------------*/
  31. /////////////////////////////////////////////////////
  32. // UAkWwiseTree
  33. UAkWwiseTree::UAkWwiseTree(const FObjectInitializer& ObjectInitializer)
  34. : Super(ObjectInitializer)
  35. {
  36. }
  37. TSharedRef<SWidget> UAkWwiseTree::RebuildWidget()
  38. {
  39. bool autoFocus = GetWorld()->WorldType != EWorldType::Game &&
  40. GetWorld()->WorldType != EWorldType::PIE &&
  41. GetWorld()->WorldType != EWorldType::GamePreview;
  42. return
  43. SNew(SBorder)
  44. .BorderImage(FAkAudioStyle::GetBrush("AudiokineticTools.GroupBorder"))
  45. .Padding(FMargin(0.0f, 3.0f))
  46. .BorderBackgroundColor(FLinearColor(.6, .6, .6, 1.0f))
  47. [
  48. SNew(SVerticalBox)
  49. + SVerticalBox::Slot()
  50. .AutoHeight()
  51. [
  52. SNew(SHorizontalBox)
  53. + SHorizontalBox::Slot()
  54. .Padding(FMargin(10.0f, 0.0f, 0.0f, 0.0f))
  55. .AutoWidth()
  56. .VAlign(VAlign_Center)
  57. [
  58. SAssignNew(ItemTextBlock, STextBlock)
  59. .IsEnabled(true)
  60. .ToolTipText(LOCTEXT("editable_Tooltip", "Item Name"))
  61. .MinDesiredWidth(300.f)
  62. .Text(FText::FromString(TEXT("Choose an item from the Wwise tree")))
  63. ]
  64. ]
  65. + SVerticalBox::Slot()
  66. [
  67. SAssignNew(WaapiPicker, SWaapiPicker)
  68. .RestrictContextMenu(true)
  69. .FocusSearchBoxWhenOpened(autoFocus)
  70. .SelectionMode(ESelectionMode::Single)
  71. .OnSelectionChanged(FOnSelectionChanged::CreateUObject(this, &UAkWwiseTree::TreeSelectionChanged))
  72. .OnDragDetected(FOnDragDetected::CreateUObject(this, &UAkWwiseTree::HandleOnDragDetected))
  73. ]
  74. ];
  75. }
  76. void UAkWwiseTree::SynchronizeProperties()
  77. {
  78. Super::SynchronizeProperties();
  79. }
  80. void UAkWwiseTree::ReleaseSlateResources(bool bReleaseChildren)
  81. {
  82. Super::ReleaseSlateResources(bReleaseChildren);
  83. WaapiPicker.Reset();
  84. }
  85. void UAkWwiseTree::TreeSelectionChanged(TSharedPtr< FWwiseTreeItem > TreeItem, ESelectInfo::Type SelectInfo)
  86. {
  87. if (TreeItem.IsValid())
  88. {
  89. ItemTextBlock->SetText(FText::FromString(TreeItem->DisplayName));
  90. if (OnSelectionChanged.IsBound())
  91. {
  92. OnSelectionChanged.Broadcast(TreeItem->ItemId);
  93. }
  94. }
  95. }
  96. FReply UAkWwiseTree::HandleOnDragDetected(const FGeometry& Geometry, const FPointerEvent& MouseEvent)
  97. {
  98. if (MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton) && WaapiPicker.IsValid())
  99. {
  100. const TArray<TSharedPtr<FWwiseTreeItem>>& ItemsSelected = WaapiPicker->GetSelectedItems();
  101. if (ItemsSelected.Num() == 1)
  102. {
  103. if(OnItemDragged.IsBound())
  104. {
  105. OnItemDragged.Broadcast(ItemsSelected[0]->ItemId, ItemsSelected[0]->DisplayName);
  106. }
  107. return FReply::Handled().BeginDragDrop(FWwiseUmgDragDropOp::New(ItemsSelected));
  108. }
  109. }
  110. return FReply::Unhandled();
  111. }
  112. FAkWwiseObjectDetails UAkWwiseTree::GetSelectedItem() const
  113. {
  114. const TArray<TSharedPtr<FWwiseTreeItem>> selectedItems = WaapiPicker->GetSelectedItems();
  115. FAkWwiseObjectDetails itemObjectDetails = FAkWwiseObjectDetails();
  116. if (selectedItems.Num())
  117. {
  118. TSharedPtr<FWwiseTreeItem> itemSelected = selectedItems[0];
  119. itemObjectDetails.ItemId = itemSelected->ItemId.ToString(EGuidFormats::DigitsWithHyphensInBraces);
  120. itemObjectDetails.ItemName = itemSelected->DisplayName;
  121. itemObjectDetails.ItemPath = itemSelected->FolderPath;
  122. }
  123. return itemObjectDetails;
  124. }
  125. FString UAkWwiseTree::GetSearchText() const
  126. {
  127. return WaapiPicker->GetSearchText();
  128. }
  129. void UAkWwiseTree::SetSearchText(const FString& newText)
  130. {
  131. WaapiPicker->SetSearchText(newText);
  132. }
  133. #if WITH_EDITOR
  134. const FText UAkWwiseTree::GetPaletteCategory()
  135. {
  136. return LOCTEXT("Wwise", "Wwise");
  137. }
  138. #endif
  139. //
  140. /////////////////////////////////////////////////////
  141. #undef LOCTEXT_NAMESPACE