AkWaapiFieldNames.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. AkWaapiFieldNames.cpp
  17. ------------------------------------------------------------------------------------*/
  18. /*------------------------------------------------------------------------------------
  19. includes.
  20. ------------------------------------------------------------------------------------*/
  21. #include "AkWaapiBlueprints/AkWaapiFieldNames.h"
  22. #include "AkAudioDevice.h"
  23. #include "Widgets/Input/SSearchBox.h"
  24. #include "Misc/ScopedSlowTask.h"
  25. #include "Framework/Application/SlateApplication.h"
  26. #include "AkAudioStyle.h"
  27. /*------------------------------------------------------------------------------------
  28. Defines
  29. ------------------------------------------------------------------------------------*/
  30. #define LOCTEXT_NAMESPACE "AkAudio"
  31. /*------------------------------------------------------------------------------------
  32. Statics and Globals
  33. ------------------------------------------------------------------------------------*/
  34. namespace SAkWaapiFieldNames_Helpers
  35. {
  36. static const FString FullFieldNamesList[] =
  37. {
  38. TEXT("id"),
  39. TEXT("return"),
  40. TEXT("path"),
  41. TEXT("filePath"),
  42. TEXT("from"),
  43. TEXT("name"),
  44. TEXT("type"),
  45. TEXT("children"),
  46. TEXT("childrenCount"),
  47. TEXT("ancestors"),
  48. TEXT("descendants"),
  49. TEXT("workunit:type"),
  50. TEXT("Folder"),
  51. TEXT("PhysicalFolder"),
  52. TEXT("search"),
  53. TEXT("parent"),
  54. TEXT("select"),
  55. TEXT("transform"),
  56. TEXT("object"),
  57. TEXT("objects"),
  58. TEXT("value"),
  59. TEXT("command"),
  60. TEXT("transport"),
  61. TEXT("action"),
  62. TEXT("play"),
  63. TEXT("stop"),
  64. TEXT("stopped"),
  65. TEXT("displayName"),
  66. TEXT("Delete Items"),
  67. TEXT("Drag Drop Items"),
  68. TEXT("Undo"),
  69. TEXT("Redo"),
  70. TEXT("state"),
  71. TEXT("ofType"),
  72. TEXT("Project"),
  73. TEXT("property"),
  74. TEXT("Volume"),
  75. TEXT("newName"),
  76. TEXT("oldName"),
  77. TEXT("new"),
  78. TEXT("classId"),
  79. TEXT("FindInProjectExplorerSyncGroup1")
  80. };
  81. enum { FullFieldNamesListSize = sizeof(FullFieldNamesList) / sizeof(*FullFieldNamesList) };
  82. }
  83. /*------------------------------------------------------------------------------------
  84. Helpers
  85. ------------------------------------------------------------------------------------*/
  86. /*------------------------------------------------------------------------------------
  87. USAkWaapiFieldNamesConv
  88. ------------------------------------------------------------------------------------*/
  89. USAkWaapiFieldNamesConv::USAkWaapiFieldNamesConv(const class FObjectInitializer& ObjectInitializer)
  90. : Super(ObjectInitializer)
  91. {
  92. // Property initialization
  93. }
  94. FString USAkWaapiFieldNamesConv::Conv_FAkWaapiFieldNamesToString(const FAkWaapiFieldNames& INAkWaapiFieldNames)
  95. {
  96. return INAkWaapiFieldNames.FieldName;
  97. }
  98. FText USAkWaapiFieldNamesConv::Conv_FAkWaapiFieldNamesToText(const FAkWaapiFieldNames& INAkWaapiFieldNames)
  99. {
  100. return FText::FromString(*INAkWaapiFieldNames.FieldName);
  101. }
  102. /*------------------------------------------------------------------------------------
  103. SAkWaapiFieldNames
  104. ------------------------------------------------------------------------------------*/
  105. SAkWaapiFieldNames::SAkWaapiFieldNames()
  106. {}
  107. SAkWaapiFieldNames::~SAkWaapiFieldNames()
  108. {}
  109. void SAkWaapiFieldNames::Construct(const FArguments& InArgs)
  110. {
  111. OnDragDetected = InArgs._OnDragDetected;
  112. OnSelectionChanged = InArgs._OnSelectionChanged;
  113. if (InArgs._FocusSearchBoxWhenOpened)
  114. {
  115. RegisterActiveTimer(0.f, FWidgetActiveTimerDelegate::CreateSP(this, &SAkWaapiFieldNames::SetFocusPostConstruct));
  116. }
  117. SearchBoxFilter = MakeShareable(new StringFilter(StringFilter::FItemToStringArray::CreateSP(this, &SAkWaapiFieldNames::PopulateSearchStrings)));
  118. SearchBoxFilter->OnChanged().AddSP(this, &SAkWaapiFieldNames::FilterUpdated);
  119. ChildSlot
  120. [
  121. SNew(SBorder)
  122. .Padding(4)
  123. .BorderImage(FAkAudioStyle::GetBrush("AudiokineticTools.GroupBorder"))
  124. [
  125. SNew(SVerticalBox)
  126. // Search
  127. + SVerticalBox::Slot()
  128. .AutoHeight()
  129. .Padding(0, 1, 0, 3)
  130. [
  131. SNew(SHorizontalBox)
  132. + SHorizontalBox::Slot()
  133. .AutoWidth()
  134. [
  135. InArgs._SearchContent.Widget
  136. ]
  137. + SHorizontalBox::Slot()
  138. .FillWidth(1.0f)
  139. [
  140. SAssignNew(SearchBoxPtr, SSearchBox)
  141. .HintText(LOCTEXT("FieldNameSearchHint", "Search a Field Name"))
  142. .ToolTipText(LOCTEXT("FieldNameSearchTooltip", "Type here to search for a Field Name"))
  143. .OnTextChanged(SearchBoxFilter.Get(), &StringFilter::SetRawFilterText)
  144. .SelectAllTextWhenFocused(false)
  145. .DelayChangeNotificationsWhileTyping(true)
  146. ]
  147. ]
  148. // Tree
  149. + SVerticalBox::Slot()
  150. .FillHeight(1.f)
  151. [
  152. SAssignNew(ListViewPtr, SListView< TSharedPtr<FString> >)
  153. .ListItemsSource(&FieldNamesList)
  154. .OnGenerateRow(this, &SAkWaapiFieldNames::GenerateRow)
  155. .ItemHeight(18)
  156. .SelectionMode(InArgs._SelectionMode)
  157. .OnSelectionChanged(this, &SAkWaapiFieldNames::ListSelectionChanged)
  158. .ClearSelectionOnClick(false)
  159. ]
  160. ]
  161. ];
  162. for (const auto& FieldName : SAkWaapiFieldNames_Helpers::FullFieldNamesList)
  163. {
  164. FieldNamesList.Add(MakeShareable(new FString(FieldName)));
  165. }
  166. FieldNamesList.Sort([](TSharedPtr< FString > Firststr, TSharedPtr< FString > Secondstr) { return *Firststr.Get() < *Secondstr.Get(); });
  167. ListViewPtr->RequestListRefresh();
  168. }
  169. TSharedRef<ITableRow> SAkWaapiFieldNames::GenerateRow(TSharedPtr<FString> in_FieldName, const TSharedRef<STableViewBase>& OwnerTable)
  170. {
  171. check(in_FieldName.IsValid());
  172. TSharedPtr<ITableRow> NewRow = SNew(STableRow< TSharedPtr<FString> >, OwnerTable)
  173. [
  174. SNew(STextBlock)
  175. .Text(FText::FromString(*in_FieldName.Get()))
  176. .HighlightText(SearchBoxFilter.Get(), &StringFilter::GetRawFilterText)
  177. ];
  178. return NewRow.ToSharedRef();
  179. }
  180. void SAkWaapiFieldNames::PopulateSearchStrings(const FString& in_FieldName, OUT TArray< FString >& OutSearchStrings) const
  181. {
  182. OutSearchStrings.Add(in_FieldName);
  183. }
  184. void SAkWaapiFieldNames::FilterUpdated()
  185. {
  186. FScopedSlowTask SlowTask(2.f, LOCTEXT("AK_PopulatingPicker", "Populating FieldName Picker..."));
  187. SlowTask.MakeDialog();
  188. FieldNamesList.Empty(SAkWaapiFieldNames_Helpers::FullFieldNamesListSize);
  189. FString FilterString = SearchBoxFilter->GetRawFilterText().ToString();
  190. if (FilterString.IsEmpty())
  191. {
  192. for (const auto& FieldName : SAkWaapiFieldNames_Helpers::FullFieldNamesList)
  193. {
  194. FieldNamesList.Add(MakeShareable(new FString(FieldName)));
  195. }
  196. }
  197. else
  198. {
  199. for (const auto& FieldName : SAkWaapiFieldNames_Helpers::FullFieldNamesList)
  200. {
  201. if (FieldName.Contains(FilterString))
  202. {
  203. FieldNamesList.Add(MakeShareable(new FString(FieldName)));
  204. }
  205. }
  206. }
  207. FieldNamesList.Sort([](TSharedPtr< FString > Firststr, TSharedPtr< FString > Secondstr) { return *Firststr.Get() < *Secondstr.Get(); });
  208. ListViewPtr->RequestListRefresh();
  209. }
  210. void SAkWaapiFieldNames::ListSelectionChanged(TSharedPtr< FString > in_FieldName, ESelectInfo::Type /*SelectInfo*/)
  211. {
  212. if (OnSelectionChanged.IsBound())
  213. OnSelectionChanged.Execute(in_FieldName, ESelectInfo::OnMouseClick);
  214. }
  215. const TArray<TSharedPtr<FString>> SAkWaapiFieldNames::GetSelectedFieldNames() const
  216. {
  217. return ListViewPtr->GetSelectedItems();
  218. }
  219. EActiveTimerReturnType SAkWaapiFieldNames::SetFocusPostConstruct(double InCurrentTime, float InDeltaTime)
  220. {
  221. FWidgetPath WidgetToFocusPath;
  222. FSlateApplication::Get().GeneratePathToWidgetUnchecked(SearchBoxPtr.ToSharedRef(), WidgetToFocusPath);
  223. FSlateApplication::Get().SetKeyboardFocus(WidgetToFocusPath, EFocusCause::SetDirectly);
  224. return EActiveTimerReturnType::Stop;
  225. }
  226. #undef LOCTEXT_NAMESPACE