SAkItemProperties.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. SAkItemProperties.cpp
  17. ------------------------------------------------------------------------------------*/
  18. /*------------------------------------------------------------------------------------
  19. includes.
  20. ------------------------------------------------------------------------------------*/
  21. #include "AkWaapiUMG/Components/SAkItemProperties.h"
  22. #include "AkAudioDevice.h"
  23. #include "Widgets/Input/SSearchBox.h"
  24. #include "Layout/WidgetPath.h"
  25. #include "Misc/ScopedSlowTask.h"
  26. #include "AkAudioStyle.h"
  27. #include "Framework/Application/SlateApplication.h"
  28. /*------------------------------------------------------------------------------------
  29. Defines
  30. ------------------------------------------------------------------------------------*/
  31. #define LOCTEXT_NAMESPACE "AkAudio"
  32. /*------------------------------------------------------------------------------------
  33. Statics and Globals
  34. ------------------------------------------------------------------------------------*/
  35. namespace SAkItemProperties_Helpers
  36. {
  37. static const FString FullPropertiesList[] =
  38. {
  39. #if AK_WWISESDK_VERSION_MAJOR >= 2018
  40. TEXT("CenterPercentage"),
  41. #endif
  42. #if AK_WWISESDK_VERSION_MAJOR <= 2017
  43. TEXT("DivergenceCenter"),
  44. #endif
  45. TEXT("GameAuxSendHPF"),
  46. TEXT("GameAuxSendLPF"),
  47. TEXT("GameAuxSendVolume"),
  48. TEXT("HdrActiveRange"),
  49. TEXT("HdrEnvelopeSensitivity"),
  50. TEXT("Highpass"),
  51. TEXT("InitialDelay"),
  52. TEXT("LoopCount"),
  53. TEXT("Lowpass"),
  54. TEXT("MakeUpGain"),
  55. TEXT("MaxSoundPerInstance"),
  56. TEXT("MidiChannelFilter"),
  57. TEXT("MidiKeyFilterMax"),
  58. TEXT("MidiKeyFilterMin"),
  59. TEXT("MidiTrackingRootNote"),
  60. TEXT("MidiTransposition"),
  61. TEXT("MidiVelocityFilterMax"),
  62. TEXT("MidiVelocityFilterMin"),
  63. TEXT("MidiVelocityOffset"),
  64. #if AK_WWISESDK_VERSION_MAJOR <= 2017
  65. TEXT("MotionLowpass"),
  66. TEXT("MotionVolume"),
  67. #endif
  68. TEXT("OutputBusHighpass"),
  69. TEXT("OutputBusLowpass"),
  70. TEXT("OutputBusVolume"),
  71. TEXT("Pitch"),
  72. TEXT("PreFetchLength"),
  73. TEXT("Priority"),
  74. TEXT("PriorityDistanceOffset"),
  75. #if AK_WWISESDK_VERSION_MAJOR >= 2018
  76. TEXT("SpeakerPanning3DSpatializationMix"),
  77. #endif
  78. TEXT("UserAuxSendVolume0"),
  79. TEXT("UserAuxSendVolume1"),
  80. TEXT("UserAuxSendVolume2"),
  81. TEXT("UserAuxSendVolume3"),
  82. TEXT("Volume"),
  83. TEXT("Weight")
  84. };
  85. enum { FullPropertiesListSize = sizeof(FullPropertiesList) / sizeof(*FullPropertiesList) };
  86. }
  87. /*------------------------------------------------------------------------------------
  88. Helpers
  89. ------------------------------------------------------------------------------------*/
  90. /*------------------------------------------------------------------------------------
  91. Implementation
  92. ------------------------------------------------------------------------------------*/
  93. SAkItemProperties::SAkItemProperties()
  94. {}
  95. SAkItemProperties::~SAkItemProperties()
  96. {}
  97. void SAkItemProperties::Construct(const FArguments& InArgs)
  98. {
  99. OnDragDetected = InArgs._OnDragDetected;
  100. OnSelectionChanged = InArgs._OnSelectionChanged;
  101. if (InArgs._FocusSearchBoxWhenOpened)
  102. {
  103. RegisterActiveTimer(0.f, FWidgetActiveTimerDelegate::CreateSP(this, &SAkItemProperties::SetFocusPostConstruct));
  104. }
  105. SearchBoxFilter = MakeShareable( new StringFilter( StringFilter::FItemToStringArray::CreateSP( this, &SAkItemProperties::PopulateSearchStrings ) ) );
  106. SearchBoxFilter->OnChanged().AddSP( this, &SAkItemProperties::FilterUpdated );
  107. ChildSlot
  108. [
  109. SNew(SBorder)
  110. .Padding(4)
  111. .BorderImage(FAkAudioStyle::GetBrush("AudiokineticTools.GroupBorder"))
  112. [
  113. SNew(SVerticalBox)
  114. // Search
  115. + SVerticalBox::Slot()
  116. .AutoHeight()
  117. .Padding(0, 1, 0, 3)
  118. [
  119. SNew(SHorizontalBox)
  120. + SHorizontalBox::Slot()
  121. .AutoWidth()
  122. [
  123. InArgs._SearchContent.Widget
  124. ]
  125. + SHorizontalBox::Slot()
  126. .FillWidth(1.0f)
  127. [
  128. SAssignNew(SearchBoxPtr,SSearchBox)
  129. .HintText( LOCTEXT( "PropertiesSearchHint", "Search an item property" ) )
  130. .ToolTipText(LOCTEXT("PropertiesSearchTooltip", "Type here to search for a property"))
  131. .OnTextChanged( this, &SAkItemProperties::OnSearchBoxChanged )
  132. .SelectAllTextWhenFocused(false)
  133. .DelayChangeNotificationsWhileTyping(true)
  134. ]
  135. ]
  136. // Tree
  137. +SVerticalBox::Slot()
  138. .FillHeight(1.f)
  139. [
  140. SAssignNew(ListViewPtr, SListView< TSharedPtr<FString> >)
  141. .ListItemsSource(&PropertiesList)
  142. .OnGenerateRow( this, &SAkItemProperties::GenerateRow )
  143. .ItemHeight(18)
  144. .SelectionMode(InArgs._SelectionMode)
  145. .OnSelectionChanged(this, &SAkItemProperties::ListSelectionChanged)
  146. .ClearSelectionOnClick(false)
  147. ]
  148. ]
  149. ];
  150. for (const auto& Property : SAkItemProperties_Helpers::FullPropertiesList)
  151. {
  152. PropertiesList.Add(MakeShareable(new FString(Property)));
  153. }
  154. ListViewPtr->RequestListRefresh();
  155. }
  156. TSharedRef<ITableRow> SAkItemProperties::GenerateRow( TSharedPtr<FString> ItemProperty, const TSharedRef<STableViewBase>& OwnerTable )
  157. {
  158. check(ItemProperty.IsValid());
  159. TSharedPtr<ITableRow> NewRow = SNew(STableRow< TSharedPtr<FString> >, OwnerTable)
  160. .OnDragDetected(this, &SAkItemProperties::HandleOnDragDetected)
  161. [
  162. SNew(STextBlock)
  163. .Text(FText::FromString(*ItemProperty.Get()))
  164. .HighlightText(SearchBoxFilter.Get(), &StringFilter::GetRawFilterText)
  165. ];
  166. return NewRow.ToSharedRef();
  167. }
  168. FReply SAkItemProperties::HandleOnDragDetected(const FGeometry& Geometry, const FPointerEvent& MouseEvent)
  169. {
  170. // Refresh the contents
  171. if(OnDragDetected.IsBound())
  172. return OnDragDetected.Execute(Geometry,MouseEvent);
  173. return FReply::Unhandled();
  174. }
  175. void SAkItemProperties::PopulateSearchStrings( const FString& PropertyName, OUT TArray< FString >& OutSearchStrings ) const
  176. {
  177. OutSearchStrings.Add( PropertyName );
  178. }
  179. void SAkItemProperties::OnSearchBoxChanged( const FText& InSearchText )
  180. {
  181. SearchBoxFilter->SetRawFilterText( InSearchText );
  182. }
  183. void SAkItemProperties::FilterUpdated()
  184. {
  185. FScopedSlowTask SlowTask(2.f, LOCTEXT("AK_PopulatingPicker", "Populating Properties Picker..."));
  186. SlowTask.MakeDialog();
  187. PropertiesList.Empty(SAkItemProperties_Helpers::FullPropertiesListSize);
  188. const FString& FilterString = SearchBoxFilter->GetRawFilterText().ToString();
  189. if (FilterString.IsEmpty())
  190. {
  191. for (const auto& Property : SAkItemProperties_Helpers::FullPropertiesList)
  192. {
  193. PropertiesList.Add(MakeShareable(new FString(Property)));
  194. }
  195. }
  196. else
  197. {
  198. for (const auto& Property : SAkItemProperties_Helpers::FullPropertiesList)
  199. {
  200. if (Property.Contains(FilterString))
  201. {
  202. PropertiesList.Add(MakeShareable(new FString(Property)));
  203. }
  204. }
  205. }
  206. ListViewPtr->RequestListRefresh();
  207. }
  208. void SAkItemProperties::ListSelectionChanged( TSharedPtr< FString > ItemProperty, ESelectInfo::Type /*SelectInfo*/ )
  209. {
  210. if (OnSelectionChanged.IsBound())
  211. OnSelectionChanged.Execute(ItemProperty, ESelectInfo::OnMouseClick);
  212. }
  213. const TArray<TSharedPtr<FString>> SAkItemProperties::GetSelectedProperties() const
  214. {
  215. return ListViewPtr->GetSelectedItems();
  216. }
  217. const FString SAkItemProperties::GetSearchText() const
  218. {
  219. return SearchBoxFilter->GetRawFilterText().ToString();
  220. }
  221. const void SAkItemProperties::SetSearchText(const FString& newText)
  222. {
  223. SearchBoxPtr->SetText(FText::FromString(newText));
  224. }
  225. EActiveTimerReturnType SAkItemProperties::SetFocusPostConstruct(double InCurrentTime, float InDeltaTime)
  226. {
  227. FWidgetPath WidgetToFocusPath;
  228. FSlateApplication::Get().GeneratePathToWidgetUnchecked(SearchBoxPtr.ToSharedRef(), WidgetToFocusPath);
  229. FSlateApplication::Get().SetKeyboardFocus(WidgetToFocusPath, EFocusCause::SetDirectly);
  230. return EActiveTimerReturnType::Stop;
  231. }
  232. #undef LOCTEXT_NAMESPACE