AkCheckBox.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. #pragma once
  16. #include "CoreMinimal.h"
  17. #include "UObject/ObjectMacros.h"
  18. #include "Styling/SlateTypes.h"
  19. #include "Widgets/SWidget.h"
  20. #include "Components/ContentWidget.h"
  21. #include "AkSlider.h"
  22. #include "Widgets/SCompoundWidget.h"
  23. #include "AkItemBoolProperties.h"
  24. #include "AkCheckBox.generated.h"
  25. class SCheckBox;
  26. class USlateBrushAsset;
  27. class USlateWidgetStyleAsset;
  28. DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam( FAkOnCheckBoxComponentStateChanged, bool, bIsChecked );
  29. /** A delegate type invoked when an item is being dragged. */
  30. DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnWwiseItemDropDetected, FGuid, ItemDroppedID);
  31. /** A delegate type invoked when a property is being dragged. */
  32. DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnBoolPropertyDropDetected, FString, PropertyDropped);
  33. /**
  34. * The checkbox widget allows you to display a toggled state of 'unchecked', 'checked' and
  35. * 'indeterminable. You can use the checkbox for a classic checkbox, or as a toggle button,
  36. * or as radio buttons.
  37. *
  38. * * Single Child
  39. * * Toggle
  40. */
  41. UCLASS(config = Editor, defaultconfig)
  42. class AKAUDIO_API UAkCheckBox : public UContentWidget, public SCompoundWidget
  43. {
  44. GENERATED_BODY()
  45. public:
  46. UAkCheckBox(const FObjectInitializer& ObjectInitializer);
  47. /** Whether the check box is currently in a checked state */
  48. UPROPERTY(EditAnywhere, Category=Appearance)
  49. ECheckBoxState CheckedState = ECheckBoxState::Undetermined;
  50. /** A bindable delegate for the IsChecked. */
  51. UPROPERTY()
  52. FGetCheckBoxState CheckedStateDelegate;
  53. public:
  54. /** The checkbox bar style */
  55. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Style", meta=( DisplayName="Style" ))
  56. FCheckBoxStyle WidgetStyle;
  57. /** How the content of the toggle button should align within the given space */
  58. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Appearance)
  59. TEnumAsByte<EHorizontalAlignment> HorizontalAlignment = EHorizontalAlignment::HAlign_Left;
  60. /** Sometimes a button should only be mouse-clickable and never keyboard focusable. */
  61. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Interaction")
  62. bool IsFocusable = false;
  63. UPROPERTY(EditAnywhere, Category = "Audiokinetic|WAAPI|Checkbox", meta = (DisplayName = "Property to control"))
  64. FAkBoolPropertyToControl ThePropertyToControl;
  65. UPROPERTY(Config, VisibleAnywhere, Category = "Audiokinetic|WAAPI|Checkbox", meta = (DisplayName = "Item to control"))
  66. FAkWwiseItemToControl ItemToControl;
  67. public:
  68. /** Called when the checked state has changed */
  69. UPROPERTY(BlueprintAssignable, Category="CheckBox|Event")
  70. FAkOnCheckBoxComponentStateChanged AkOnCheckStateChanged;
  71. /** Called when the item selection changes. */
  72. UPROPERTY(BlueprintAssignable, Category = "Widget Event")
  73. FOnWwiseItemDropDetected OnItemDropped;
  74. /** Called when the item selection changes. */
  75. UPROPERTY(BlueprintAssignable, Category = "Widget Event")
  76. FOnBoolPropertyDropDetected OnPropertyDropped;
  77. public:
  78. /** Returns true if this button is currently pressed */
  79. UFUNCTION(BlueprintCallable, Category="Widget")
  80. bool IsPressed() const;
  81. /** Returns true if the checkbox is currently checked */
  82. UFUNCTION(BlueprintCallable, Category="Widget")
  83. bool IsChecked() const;
  84. /** @return the full current checked state. */
  85. UFUNCTION(BlueprintCallable, Category="Widget")
  86. ECheckBoxState GetCheckedState() const;
  87. /** Sets the checked state. */
  88. UFUNCTION(BlueprintCallable, Category="Widget")
  89. void SetIsChecked(bool InIsChecked);
  90. /** Sets the checked state. */
  91. UFUNCTION(BlueprintCallable, Category="Widget")
  92. void SetCheckedState(ECheckBoxState InCheckedState);
  93. /** Set the item id to the new one.
  94. * @param ItemId - value (new id) to set
  95. */
  96. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|WAAPI|Checkbox", meta = (Keywords = "Set Item Id"))
  97. void SetAkItemId(const FGuid& ItemId);
  98. /** Returns the current item id.
  99. *
  100. * @return an id as GUID.
  101. */
  102. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|WAAPI|Checkbox", meta = (Keywords = "Get Item Id"))
  103. const FGuid GetAkItemId() const;
  104. /** Set the item property to the new one.
  105. * @param ItemId - value (new id) to set
  106. */
  107. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|WAAPI|Checkbox", meta = (Keywords = "Set Item Property"))
  108. void SetAkBoolProperty(const FString& ItemProperty);
  109. /** Returns the current item property.
  110. *
  111. * @return a property as string.
  112. */
  113. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|WAAPI|Checkbox", meta = (Keywords = "Get Item Property"))
  114. const FString GetAkProperty() const;
  115. public:
  116. //~ Begin UWidget Interface
  117. virtual void SynchronizeProperties() override;
  118. //~ End UWidget Interface
  119. //~ Begin UVisual Interface
  120. virtual void ReleaseSlateResources(bool bReleaseChildren) override;
  121. //~ End UVisual Interface
  122. virtual void BeginDestroy() override;
  123. #if WITH_EDITOR
  124. virtual const FText GetPaletteCategory() override;
  125. #endif
  126. /**
  127. * Called when the user is dropping something onto a widget; terminates drag and drop.
  128. *
  129. * @param MyGeometry The geometry of the widget receiving the event.
  130. * @param DragDropEvent The drag and drop event.
  131. *
  132. * @return A reply that indicated whether this event was handled.
  133. */
  134. FReply OnDropHandler(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent);
  135. protected:
  136. // UPanelWidget
  137. virtual void OnSlotAdded(UPanelSlot* Slot) override;
  138. virtual void OnSlotRemoved(UPanelSlot* Slot) override;
  139. // End UPanelWidget
  140. protected:
  141. //~ Begin UWidget Interface
  142. virtual TSharedRef<SWidget> RebuildWidget() override;
  143. //~ End UWidget Interface
  144. void SlateOnCheckStateChangedCallback(ECheckBoxState NewState);
  145. private:
  146. void SetAkItemControlled(const FString& Item);
  147. FText GetAkItemControlled();
  148. FText GetAkBoolProperty() const;
  149. void SynchronizePropertyWithWwise();
  150. protected:
  151. TSharedPtr<SCheckBox> MyCheckbox;
  152. FString ItemControlled;
  153. FString IdItemToControl;
  154. FString BoolPropertyToControl;
  155. uint64 SubscriptionId = 0;
  156. uint64 SubscriptionIdNameChanged = 0;
  157. PROPERTY_BINDING_IMPLEMENTATION(ECheckBoxState, CheckedState);
  158. };