AkPropertyToControlCustomization.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #if WITH_EDITOR
  16. #include "AkWaapiUMG/Components/AkPropertyToControlCustomization.h"
  17. #include "AkAudioDevice.h"
  18. #include "Framework/Application/SlateApplication.h"
  19. #include "Widgets/Images/SImage.h"
  20. #include "Widgets/Input/SButton.h"
  21. #include "DetailWidgetRow.h"
  22. #include "AkWaapiUMG/Components/SAkItemProperties.h"
  23. #include "AkAudioStyle.h"
  24. #if UE_5_0_OR_LATER
  25. #include "Framework/Docking/TabManager.h"
  26. #endif
  27. #define LOCTEXT_NAMESPACE "AkPropertyToControlCustomization"
  28. TSharedRef<IPropertyTypeCustomization> FAkPropertyToControlCustomization::MakeInstance()
  29. {
  30. return MakeShareable(new FAkPropertyToControlCustomization());
  31. }
  32. void FAkPropertyToControlCustomization::CustomizeHeader( TSharedRef<IPropertyHandle> StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
  33. {
  34. ItemPropertyHandle = StructPropertyHandle->GetChildHandle("ItemProperty");
  35. if(ItemPropertyHandle.IsValid())
  36. {
  37. TSharedPtr<SWidget> PickerWidget = nullptr;
  38. PickerWidget = SAssignNew(PickerButton, SButton)
  39. .ButtonStyle(FAkAudioStyle::Get(), "AudiokineticTools.HoverHintOnly" )
  40. .ToolTipText( LOCTEXT( "WwisePropertyToolTipText", "Choose a property") )
  41. .OnClicked(FOnClicked::CreateSP(this, &FAkPropertyToControlCustomization::OnPickContent, ItemPropertyHandle.ToSharedRef()))
  42. .ContentPadding(2.0f)
  43. .ForegroundColor( FSlateColor::UseForeground() )
  44. .IsFocusable(false)
  45. [
  46. SNew(SImage)
  47. .Image(FAkAudioStyle::GetBrush("AudiokineticTools.Button_EllipsisIcon"))
  48. .ColorAndOpacity(FSlateColor::UseForeground())
  49. ];
  50. HeaderRow.ValueContent()
  51. .MinDesiredWidth(125.0f)
  52. .MaxDesiredWidth(600.0f)
  53. [
  54. SNew(SHorizontalBox)
  55. + SHorizontalBox::Slot()
  56. .FillWidth(1.0f)
  57. .VAlign(VAlign_Center)
  58. [
  59. ItemPropertyHandle->CreatePropertyValueWidget()
  60. ]
  61. + SHorizontalBox::Slot()
  62. .AutoWidth()
  63. .Padding(FMargin(4.0f, 0.0f, 0.0f, 0.0f))
  64. .VAlign(VAlign_Center)
  65. [
  66. PickerWidget.ToSharedRef()
  67. ]
  68. ]
  69. .NameContent()
  70. [
  71. StructPropertyHandle->CreatePropertyNameWidget()
  72. ];
  73. }
  74. }
  75. void FAkPropertyToControlCustomization::CustomizeChildren( TSharedRef<IPropertyHandle> StructPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils )
  76. {
  77. }
  78. FReply FAkPropertyToControlCustomization::OnPickContent(TSharedRef<IPropertyHandle> PropertyHandle)
  79. {
  80. Window = SNew(SWindow)
  81. .Title(LOCTEXT("PropertyPickerWindowTitle", "Choose A Property"))
  82. .SizingRule(ESizingRule::UserSized)
  83. .AutoCenter(EAutoCenter::PreferredWorkArea)
  84. .ClientSize(FVector2D(350, 400));
  85. Window->SetContent(
  86. SNew(SBorder)
  87. [
  88. SNew(SAkItemProperties)
  89. .FocusSearchBoxWhenOpened(true)
  90. .SelectionMode(ESelectionMode::Single)
  91. .OnSelectionChanged(this, &FAkPropertyToControlCustomization::PropertySelectionChanged)
  92. ]
  93. );
  94. TSharedPtr<SWindow> RootWindow = FGlobalTabmanager::Get()->GetRootWindow();
  95. FSlateApplication::Get().AddWindowAsNativeChild(Window.ToSharedRef(), RootWindow.ToSharedRef());
  96. return FReply::Handled();
  97. }
  98. void FAkPropertyToControlCustomization::PropertySelectionChanged(TSharedPtr< FString > ItemProperty, ESelectInfo::Type SelectInfo)
  99. {
  100. if (ItemProperty.IsValid())
  101. {
  102. ItemPropertyHandle->SetValue(*ItemProperty.Get());
  103. Window->RequestDestroyWindow();
  104. }
  105. }
  106. #undef LOCTEXT_NAMESPACE
  107. #endif//WITH_EDITOR