AkSettingsDetailsCustomization.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. #include "AkSettingsDetailsCustomization.h"
  16. #include "AkSettings.h"
  17. #include "AkUEFeatures.h"
  18. #include "DetailCategoryBuilder.h"
  19. #include "DetailLayoutBuilder.h"
  20. #include "DetailWidgetRow.h"
  21. #include "IStructureDetailsView.h"
  22. #include "Widgets/Input/SNumericEntryBox.h"
  23. #include "Widgets/Input/SButton.h"
  24. #include "Editor.h"
  25. #define LOCTEXT_NAMESPACE "AudiokineticTools"
  26. /** Dialog widget used to display function properties */
  27. class SDecayKeyEntryDialog : public SCompoundWidget
  28. {
  29. SLATE_BEGIN_ARGS(SDecayKeyEntryDialog) {}
  30. SLATE_END_ARGS()
  31. // We call this from a delegate that is called when the window has correctly been added to the slate application.
  32. // See FAkSettingsDetailsCustomization::InsertKeyModal.
  33. void FocusNumericEntryBox()
  34. {
  35. if (numberBox != nullptr)
  36. {
  37. FSlateApplication::Get().ClearAllUserFocus();
  38. FSlateApplication::Get().SetAllUserFocus(numberBox);
  39. FSlateApplication::Get().ClearKeyboardFocus();
  40. FSlateApplication::Get().SetKeyboardFocus(numberBox);
  41. }
  42. }
  43. void Construct(const FArguments& InArgs, TWeakPtr<SWindow> InParentWindow, float& decay)
  44. {
  45. bCommitted = false;
  46. ChildSlot
  47. [
  48. SNew(SVerticalBox)
  49. + SVerticalBox::Slot()
  50. .AutoHeight()
  51. [
  52. SNew(SBorder)
  53. .BorderImage(FAkAppStyle::Get().GetBrush("ToolPanel.GroupBorder"))
  54. .VAlign(VAlign_Center)
  55. .HAlign(HAlign_Center)
  56. [
  57. SNew(SVerticalBox)
  58. + SVerticalBox::Slot()
  59. .Padding(2.0f)
  60. .AutoHeight()
  61. [
  62. SAssignNew(numberBox, SNumericEntryBox<float>)
  63. .MinValue(0.0f)
  64. .MaxValue(100.0f)
  65. .Value_Lambda([&decay]() {return decay;})
  66. .OnValueCommitted_Lambda([this, InParentWindow, &decay](const float& value, ETextCommit::Type commitType)
  67. {
  68. if (commitType == ETextCommit::Type::OnCleared)
  69. decay = 0.0f;
  70. else
  71. decay = value;
  72. if (commitType == ETextCommit::OnEnter)
  73. {
  74. bCommitted = true;
  75. if (InParentWindow.IsValid())
  76. {
  77. InParentWindow.Pin()->RequestDestroyWindow();
  78. }
  79. }
  80. })
  81. .OnValueChanged_Lambda([&decay](const float& value)
  82. {
  83. decay = value;
  84. })
  85. ]
  86. + SVerticalBox::Slot()
  87. .Padding(2.0f)
  88. .AutoHeight()
  89. [
  90. SNew(SButton)
  91. .ForegroundColor(FLinearColor::White)
  92. .OnClicked_Lambda([this, InParentWindow, InArgs]()
  93. {
  94. if (InParentWindow.IsValid())
  95. {
  96. InParentWindow.Pin()->RequestDestroyWindow();
  97. }
  98. bCommitted = true;
  99. return FReply::Handled();
  100. })
  101. .ToolTipText(FText::FromString("Insert given key value"))
  102. [
  103. SNew(STextBlock)
  104. .TextStyle(FAkAppStyle::Get(), "FlatButton.DefaultTextStyle")
  105. .Text(FText::FromString("Insert"))
  106. ]
  107. ]
  108. ]
  109. ]
  110. ];
  111. }
  112. bool bCommitted = false;
  113. TSharedPtr<SNumericEntryBox<float>> numberBox = nullptr;
  114. };
  115. /** Dialog widget used to display function properties */
  116. class SClearWarningDialog : public SCompoundWidget
  117. {
  118. SLATE_BEGIN_ARGS(SClearWarningDialog) {}
  119. SLATE_END_ARGS()
  120. void Construct(const FArguments& InArgs, TWeakPtr<SWindow> InParentWindow)
  121. {
  122. bOKPressed = false;
  123. ChildSlot
  124. [
  125. SNew(SVerticalBox)
  126. + SVerticalBox::Slot()
  127. .AutoHeight()
  128. [
  129. SNew(SBorder)
  130. .BorderImage(FAkAppStyle::Get().GetBrush("ToolPanel.GroupBorder"))
  131. .VAlign(VAlign_Center)
  132. .HAlign(HAlign_Center)
  133. [
  134. SNew(SVerticalBox)
  135. + SVerticalBox::Slot()
  136. .Padding(2.0f)
  137. .AutoHeight()
  138. [
  139. SNew(STextBlock)
  140. .Text(FText::FromString("Warning: This will remove all aux bus values in the map. Do you want to continue?"))
  141. ]
  142. ]
  143. ]
  144. + SVerticalBox::Slot()
  145. .AutoHeight()
  146. [
  147. SNew(SBorder)
  148. .BorderImage(FAkAppStyle::Get().GetBrush("ToolPanel.GroupBorder"))
  149. .VAlign(VAlign_Center)
  150. .HAlign(HAlign_Center)
  151. [
  152. SNew(SHorizontalBox)
  153. + SHorizontalBox::Slot()
  154. .Padding(2.0f)
  155. .AutoWidth()
  156. [
  157. SNew(SButton)
  158. .ButtonStyle(FAkAppStyle::Get(), "FlatButton.Success")
  159. .ForegroundColor(FLinearColor::White)
  160. .OnClicked_Lambda([this, InParentWindow, InArgs]()
  161. {
  162. if (InParentWindow.IsValid())
  163. {
  164. InParentWindow.Pin()->RequestDestroyWindow();
  165. }
  166. bOKPressed = true;
  167. return FReply::Handled();
  168. })
  169. .ToolTipText(FText::FromString("Clear aux bus assignment map"))
  170. [
  171. SNew(STextBlock)
  172. .TextStyle(FAkAppStyle::Get(), "FlatButton.DefaultTextStyle")
  173. .Text(FText::FromString("Clear"))
  174. ]
  175. ]
  176. + SHorizontalBox::Slot()
  177. .Padding(2.0f)
  178. .AutoWidth()
  179. [
  180. SNew(SButton)
  181. .ButtonStyle(FAkAppStyle::Get(), "FlatButton.Default")
  182. .ForegroundColor(FLinearColor::White)
  183. .OnClicked_Lambda([this, InParentWindow, InArgs]()
  184. {
  185. if (InParentWindow.IsValid())
  186. {
  187. InParentWindow.Pin()->RequestDestroyWindow();
  188. }
  189. return FReply::Handled();
  190. })
  191. .ToolTipText(FText::FromString("Cancel"))
  192. [
  193. SNew(STextBlock)
  194. .TextStyle(FAkAppStyle::Get(), "FlatButton.DefaultTextStyle")
  195. .Text(FText::FromString("Cancel"))
  196. ]
  197. ]
  198. ]
  199. ]
  200. ];
  201. }
  202. bool bOKPressed;
  203. };
  204. TSharedRef<IDetailCustomization> FAkSettingsDetailsCustomization::MakeInstance()
  205. {
  206. return MakeShareable(new FAkSettingsDetailsCustomization);
  207. }
  208. void FAkSettingsDetailsCustomization::CustomizeDetails(IDetailLayoutBuilder& DetailLayout)
  209. {
  210. IDetailCategoryBuilder& CategoryBuilder = DetailLayout.EditCategory("Reverb Assignment Map", FText::GetEmpty(), ECategoryPriority::Uncommon);
  211. CategoryBuilder.AddCustomRow(FText::FromString("Clear Map")).WholeRowContent()
  212. [
  213. SNew(SVerticalBox)
  214. + SVerticalBox::Slot().AutoHeight().Padding(2)
  215. [
  216. SNew(SHorizontalBox)
  217. + SHorizontalBox::Slot().AutoWidth()
  218. [
  219. SNew(SButton)
  220. .Text(FText::FromString("Clear Map"))
  221. .ToolTipText(FText::FromString("Clear all of the entries in the map"))
  222. .OnClicked_Raw(this, &FAkSettingsDetailsCustomization::ClearAkSettingsRoomDecayAuxBusMap)
  223. ]
  224. + SHorizontalBox::Slot().FillWidth(8)
  225. ]
  226. + SVerticalBox::Slot().AutoHeight().Padding(2)
  227. [
  228. SNew(SHorizontalBox)
  229. + SHorizontalBox::Slot().AutoWidth()
  230. [
  231. SNew(SButton)
  232. .Text(FText::FromString("Insert Decay Key"))
  233. .OnClicked_Raw(this, &FAkSettingsDetailsCustomization::InsertKeyModal)
  234. ]
  235. + SHorizontalBox::Slot().FillWidth(8)
  236. ]
  237. ];
  238. TArray<TSharedRef<IPropertyHandle>> Properties;
  239. CategoryBuilder.GetDefaultProperties(Properties);
  240. for (TSharedRef<IPropertyHandle> Property : Properties)
  241. {
  242. CategoryBuilder.AddProperty(Property);
  243. }
  244. }
  245. FReply FAkSettingsDetailsCustomization::ClearAkSettingsRoomDecayAuxBusMap()
  246. {
  247. // pop up a dialog to input params to the function
  248. TSharedRef<SWindow> Window = SNew(SWindow)
  249. .Title(FText::FromString("Clear aux bus assignment map?"))
  250. .ScreenPosition(FSlateApplication::Get().GetCursorPos())
  251. .AutoCenter(EAutoCenter::None)
  252. .SizingRule(ESizingRule::Autosized)
  253. .SupportsMinimize(false)
  254. .SupportsMaximize(false);
  255. TSharedPtr<SClearWarningDialog> Dialog;
  256. Window->SetContent(SAssignNew(Dialog, SClearWarningDialog, Window));
  257. GEditor->EditorAddModalWindow(Window);
  258. if (Dialog->bOKPressed)
  259. {
  260. UAkSettings* AkSettings = GetMutableDefault<UAkSettings>();
  261. if (AkSettings != nullptr)
  262. AkSettings->ClearAkRoomDecayAuxBusMap();
  263. }
  264. return FReply::Handled();
  265. }
  266. FReply FAkSettingsDetailsCustomization::InsertKeyModal()
  267. {
  268. // pop up a dialog to input params to the function
  269. TSharedRef<SWindow> Window = SNew(SWindow)
  270. .Title(FText::FromString("Insert Decay Key"))
  271. .ScreenPosition(FSlateApplication::Get().GetCursorPos())
  272. .AutoCenter(EAutoCenter::None)
  273. .SizingRule(ESizingRule::Autosized)
  274. .SupportsMinimize(false)
  275. .SupportsMaximize(false);
  276. float decay = 0.0f;
  277. TSharedPtr<SDecayKeyEntryDialog> Dialog;
  278. Window->SetContent(SAssignNew(Dialog, SDecayKeyEntryDialog, Window, decay));
  279. // In order to give focus to the textbox in SDecayKeyEntryDialog when the dialog is created,
  280. // we need to wait until the window has been added to the slate application. If we try to focus the
  281. // text box during the construction of the dialog, the window will not be found in the slate application's
  282. // list of top level windows, and the text box will not be focused.
  283. // To achieve this, we need to set up a delegate to call after the modal window has been added to the slate application.
  284. FModalWindowStackStarted modalWindowCallback;
  285. modalWindowCallback.BindLambda([&Dialog]()
  286. {
  287. if (Dialog.IsValid())
  288. Dialog->FocusNumericEntryBox();
  289. });
  290. FSlateApplication::Get().SetModalWindowStackStartedDelegate(modalWindowCallback);
  291. // During this call, the ModalWindowStackStartedDelegate will be called.
  292. GEditor->EditorAddModalWindow(Window);
  293. // Clear the ModalWindowStackStartedDelegate.
  294. FSlateApplication::Get().SetModalWindowStackStartedDelegate(nullptr);
  295. if (Dialog->bCommitted)
  296. {
  297. UAkSettings* AkSettings = GetMutableDefault<UAkSettings>();
  298. if (AkSettings != nullptr)
  299. AkSettings->InsertDecayKeyValue(decay);
  300. }
  301. return FReply::Handled();
  302. }
  303. #undef LOCTEXT_NAMESPACE