AkItemBoolProperties.cpp 5.8 KB

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