AkItemProperties.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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/AkItemProperties.h"
  19. #include "AkAudioDevice.h"
  20. #include "Widgets/Input/SButton.h"
  21. #include "Framework/MultiBox/MultiBoxBuilder.h"
  22. #include "AkWaapiUMG/Components/WwisePropertyDragDropOp.h"
  23. #include "AkWaapiSlate/Widgets/Input/AkSSlider.h"
  24. #include "AkAudioStyle.h"
  25. /*------------------------------------------------------------------------------------
  26. Defines
  27. ------------------------------------------------------------------------------------*/
  28. #define LOCTEXT_NAMESPACE "AkWaapiUMG"
  29. /*------------------------------------------------------------------------------------
  30. UAkItemPropertiesConv
  31. ------------------------------------------------------------------------------------*/
  32. UAkItemPropertiesConv::UAkItemPropertiesConv(const class FObjectInitializer& ObjectInitializer)
  33. : Super(ObjectInitializer)
  34. {
  35. // Property initialization
  36. }
  37. FString UAkItemPropertiesConv::Conv_FAkPropertyToControlToString(const FAkPropertyToControl& INAkPropertyToControl)
  38. {
  39. return INAkPropertyToControl.ItemProperty;
  40. }
  41. FText UAkItemPropertiesConv::Conv_FAkPropertyToControlToText(const FAkPropertyToControl& INAkPropertyToControl)
  42. {
  43. return FText::FromString(*INAkPropertyToControl.ItemProperty);
  44. }
  45. /*------------------------------------------------------------------------------------
  46. Implementation
  47. ------------------------------------------------------------------------------------*/
  48. /////////////////////////////////////////////////////
  49. // UAkItemProperties
  50. UAkItemProperties::UAkItemProperties(const FObjectInitializer& ObjectInitializer)
  51. : Super(ObjectInitializer)
  52. {
  53. AkSSlider::FArguments Defaults;
  54. }
  55. TSharedRef<SWidget> UAkItemProperties::RebuildWidget()
  56. {
  57. bool autoFocus = GetWorld()->WorldType != EWorldType::Game &&
  58. GetWorld()->WorldType != EWorldType::PIE &&
  59. GetWorld()->WorldType != EWorldType::GamePreview;
  60. return
  61. SNew(SBorder)
  62. .BorderImage(FAkAudioStyle::GetBrush("AudiokineticTools.GroupBorder"))
  63. .Padding(FMargin(0.0f, 3.0f))
  64. .BorderBackgroundColor(FLinearColor(.6, .6, .6, 1.0f))
  65. [
  66. SNew(SVerticalBox)
  67. + SVerticalBox::Slot()
  68. .AutoHeight()
  69. [
  70. SNew(SHorizontalBox)
  71. + SHorizontalBox::Slot()
  72. .Padding(FMargin(10.0f, 0.0f, 0.0f, 0.0f))
  73. .AutoWidth()
  74. .VAlign(VAlign_Center)
  75. [
  76. SAssignNew(PropertyTextBlock, STextBlock)
  77. .IsEnabled(true)
  78. .ToolTipText(LOCTEXT("editable_Tooltip", "Property Name"))
  79. .MinDesiredWidth(300.f)
  80. .Text(FText::FromString(TEXT("Choose a property")))
  81. ]
  82. ]
  83. + SVerticalBox::Slot()
  84. [
  85. SAssignNew(WwiseProperties, SAkItemProperties)
  86. .FocusSearchBoxWhenOpened(autoFocus)
  87. .SelectionMode(ESelectionMode::Single)
  88. .OnSelectionChanged(FOnSelectionChanged::CreateUObject(this, &UAkItemProperties::PropertySelectionChanged))
  89. .OnDragDetected(FOnDragDetected::CreateUObject(this, &UAkItemProperties::HandleOnDragDetected))
  90. ]
  91. ];
  92. }
  93. void UAkItemProperties::PropertySelectionChanged(TSharedPtr< FString > PropertySelected, ESelectInfo::Type SelectInfo)
  94. {
  95. if (PropertySelected.IsValid())
  96. {
  97. const auto& PropertyString = *PropertySelected.Get();
  98. PropertyTextBlock->SetText(FText::FromString(PropertyString));
  99. if (OnSelectionChanged.IsBound())
  100. {
  101. OnSelectionChanged.Broadcast(PropertyString);
  102. }
  103. }
  104. }
  105. FReply UAkItemProperties::HandleOnDragDetected(const FGeometry& Geometry, const FPointerEvent& MouseEvent)
  106. {
  107. if (MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton) && WwiseProperties.IsValid())
  108. {
  109. const TArray<TSharedPtr<FString>>& PropertySelected = WwiseProperties->GetSelectedProperties();
  110. if (PropertySelected.Num() == 1)
  111. {
  112. if(OnPropertyDragged.IsBound())
  113. {
  114. OnPropertyDragged.Broadcast(*PropertySelected[0].Get());
  115. }
  116. TSharedRef<FWwisePropertyDragDropOp> Operation = FWwisePropertyDragDropOp::New(PropertySelected);
  117. return FReply::Handled().BeginDragDrop(Operation);
  118. }
  119. }
  120. return FReply::Unhandled();
  121. }
  122. FString UAkItemProperties::GetSelectedProperty() const
  123. {
  124. return *WwiseProperties->GetSelectedProperties()[0];
  125. }
  126. FString UAkItemProperties::GetSearchText() const
  127. {
  128. return WwiseProperties->GetSearchText();
  129. }
  130. void UAkItemProperties::SetSearchText(const FString& newText)
  131. {
  132. WwiseProperties->SetSearchText(newText);
  133. }
  134. void UAkItemProperties::ReleaseSlateResources(bool bReleaseChildren)
  135. {
  136. Super::ReleaseSlateResources(bReleaseChildren);
  137. PropertyTextBlock.Reset();
  138. WwiseProperties.Reset();
  139. }
  140. #if WITH_EDITOR
  141. const FText UAkItemProperties::GetPaletteCategory()
  142. {
  143. return LOCTEXT("Wwise", "Wwise");
  144. }
  145. #endif
  146. //
  147. /////////////////////////////////////////////////////
  148. #undef LOCTEXT_NAMESPACE