AkWwiseTreeSelector.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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/AkWwiseTreeSelector.h"
  19. #include "AkAudioDevice.h"
  20. #include "Widgets/Input/SButton.h"
  21. #include "Framework/MultiBox/MultiBoxBuilder.h"
  22. #include "Framework/Docking/TabManager.h"
  23. #include "Framework/Application/SlateApplication.h"
  24. #include "AkWaapiUMG/Components/WwiseUmgDragDropOp.h"
  25. #include "AkWaapiSlate/Widgets/Input/AkSSlider.h"
  26. /*------------------------------------------------------------------------------------
  27. Defines
  28. ------------------------------------------------------------------------------------*/
  29. #define LOCTEXT_NAMESPACE "AkWaapiUMG"
  30. /*------------------------------------------------------------------------------------
  31. Implementation
  32. ------------------------------------------------------------------------------------*/
  33. /////////////////////////////////////////////////////
  34. // UAkWwiseTreeSelector
  35. UAkWwiseTreeSelector::UAkWwiseTreeSelector(const FObjectInitializer& ObjectInitializer)
  36. : Super(ObjectInitializer)
  37. {
  38. AkSSlider::FArguments Defaults;
  39. }
  40. TSharedRef<SWidget> UAkWwiseTreeSelector::RebuildWidget()
  41. {
  42. TSharedPtr<SWidget> PickerWidget = nullptr;
  43. PickerWidget = SAssignNew(PickerButton, SButton)
  44. .ButtonStyle(FAkAudioStyle::Get(), "AudiokineticTools.HoverHintOnly")
  45. .ToolTipText(LOCTEXT("WwiseItemToolTipText", "Choose a Wwise Item"))
  46. .OnClicked(FOnClicked::CreateUObject(this, &UAkWwiseTreeSelector::HandleButtonClicked))
  47. .ContentPadding(2.0f)
  48. .ForegroundColor(FSlateColor::UseForeground())
  49. .IsFocusable(true)
  50. [
  51. SNew(SImage)
  52. .Image(FAkAudioStyle::GetBrush("AudiokineticTools.Button_EllipsisIcon"))
  53. .ColorAndOpacity(FSlateColor::UseForeground())
  54. ];
  55. return
  56. SNew(SBorder)
  57. .BorderImage(FAkAudioStyle::GetBrush("AudiokineticTools.GroupBorder"))
  58. .Padding(FMargin(0.0f, 3.0f))
  59. .BorderBackgroundColor(FLinearColor(.6, .6, .6, 1.0f))
  60. [
  61. SNew(SHorizontalBox)
  62. + SHorizontalBox::Slot()
  63. .Padding(FMargin(10.0f, 0.0f, 0.0f, 0.0f))
  64. .AutoWidth()
  65. .VAlign(VAlign_Center)
  66. [
  67. SAssignNew(ItemTextBlock, STextBlock)
  68. .IsEnabled(true)
  69. .ToolTipText(LOCTEXT("editable_Tooltip", "Item Name"))
  70. .MinDesiredWidth(300.f)
  71. .Text(FText::FromString(TEXT("Choose an item from the Wwise tree")))
  72. ]
  73. + SHorizontalBox::Slot()
  74. .Padding(FMargin(0.0f, 0.0f, 10.0f, 0.0f))
  75. .VAlign(VAlign_Center)
  76. .HAlign(HAlign_Right)
  77. [
  78. PickerWidget.ToSharedRef()
  79. ]
  80. ];
  81. }
  82. FReply UAkWwiseTreeSelector::HandleButtonClicked()
  83. {
  84. TSharedRef<SWindow> Window = SNew(SWindow)
  85. .Title(LOCTEXT("PropertyPickerWindowTitle", "Choose A Wwise Item"))
  86. .SizingRule(ESizingRule::UserSized)
  87. .AutoCenter(EAutoCenter::PreferredWorkArea)
  88. .ClientSize(FVector2D(350, 400));
  89. Window->SetContent(
  90. SNew(SBorder)
  91. [
  92. SAssignNew(WaapiPicker, SWaapiPicker)
  93. .RestrictContextMenu(true)
  94. .FocusSearchBoxWhenOpened(true)
  95. .SelectionMode(ESelectionMode::Single)
  96. .OnSelectionChanged(FOnSelectionChanged::CreateUObject(this, &UAkWwiseTreeSelector::TreeSelectionChanged))
  97. .OnDragDetected(FOnDragDetected::CreateUObject(this, &UAkWwiseTreeSelector::HandleOnDragDetected))
  98. ]
  99. );
  100. #if WITH_EDITOR
  101. TSharedPtr<SWindow> RootWindow = FGlobalTabmanager::Get()->GetRootWindow();
  102. FSlateApplication::Get().AddWindowAsNativeChild(Window, RootWindow.ToSharedRef());
  103. #endif//WITH_EDITOR
  104. return FReply::Handled();
  105. }
  106. void UAkWwiseTreeSelector::SynchronizeProperties()
  107. {
  108. Super::SynchronizeProperties();
  109. }
  110. void UAkWwiseTreeSelector::ReleaseSlateResources(bool bReleaseChildren)
  111. {
  112. Super::ReleaseSlateResources(bReleaseChildren);
  113. ItemTextBlock.Reset();
  114. WaapiPicker.Reset();
  115. PickerButton.Reset();
  116. PickerMenu.Reset();
  117. }
  118. void UAkWwiseTreeSelector::TreeSelectionChanged(TSharedPtr< FWwiseTreeItem > TreeItem, ESelectInfo::Type SelectInfo)
  119. {
  120. if (TreeItem.IsValid())
  121. {
  122. ItemTextBlock->SetText(FText::FromString(TreeItem->DisplayName));
  123. if (OnSelectionChanged.IsBound())
  124. {
  125. OnSelectionChanged.Broadcast(TreeItem->ItemId);
  126. }
  127. }
  128. }
  129. FReply UAkWwiseTreeSelector::HandleOnDragDetected(const FGeometry& Geometry, const FPointerEvent& MouseEvent)
  130. {
  131. if (MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton) && WaapiPicker.IsValid())
  132. {
  133. const TArray<TSharedPtr<FWwiseTreeItem>>& ItemsSelected = WaapiPicker->GetSelectedItems();
  134. if (ItemsSelected.Num() == 1)
  135. {
  136. if (OnItemDragged.IsBound())
  137. {
  138. OnItemDragged.Broadcast(ItemsSelected[0]->ItemId, ItemsSelected[0]->DisplayName);
  139. }
  140. return FReply::Handled().BeginDragDrop(FWwiseUmgDragDropOp::New(ItemsSelected));
  141. }
  142. }
  143. return FReply::Unhandled();
  144. }
  145. #if WITH_EDITOR
  146. const FText UAkWwiseTreeSelector::GetPaletteCategory()
  147. {
  148. return LOCTEXT("Wwise", "Wwise");
  149. }
  150. #endif
  151. //
  152. /////////////////////////////////////////////////////
  153. #undef LOCTEXT_NAMESPACE