AkSlider.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 "Components/Widget.h"
  17. #include "AkItemProperties.h"
  18. #include "AkSlider.generated.h"
  19. class AkSSlider;
  20. /** A delegate type invoked when the value of the slider changes. */
  21. DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FAkOnFloatValueChangedEvent, float, Value);
  22. /** A delegate type invoked when an item is being dragged. */
  23. DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnItemDropDetected, FGuid, ItemDroppedID);
  24. /** A delegate type invoked when a property is being dragged. */
  25. DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPropertyDropDetected, FString, PropertyDropped);
  26. /**
  27. * Structure for Wwise item details.
  28. */
  29. USTRUCT(BlueprintType)
  30. struct AKAUDIO_API FAkWwiseObjectDetails
  31. {
  32. GENERATED_BODY()
  33. /**
  34. * The name of the item to control
  35. */
  36. UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=ItemName, meta = (DisplayName = "Name"))
  37. FString ItemName;
  38. /**
  39. * The id of the item to control
  40. */
  41. UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = ItemPath, meta = (DisplayName = "Path"))
  42. FString ItemPath;
  43. /**
  44. * The id of the item to control
  45. */
  46. UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category =ItemId, meta = (DisplayName = "Id"))
  47. FString ItemId;
  48. };
  49. /**
  50. * Structure for Wwise items that are displayed in the UMG.
  51. */
  52. USTRUCT(BlueprintType)
  53. struct AKAUDIO_API FAkWwiseItemToControl //: public UObject
  54. {
  55. GENERATED_BODY()
  56. /**
  57. * The item to control
  58. */
  59. UPROPERTY(VisibleAnywhere, Category= ItemPicked, meta = (DisplayName = "Name"))
  60. FAkWwiseObjectDetails ItemPicked;
  61. UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=ItemPath, meta = (DisplayName = "Path"))
  62. FString ItemPath;
  63. };
  64. /*------------------------------------------------------------------------------------
  65. UAkSlider
  66. ------------------------------------------------------------------------------------*/
  67. /**
  68. * A simple widget that shows a sliding bar with a handle that allows you to control the value between 0..1.
  69. *
  70. * * No Children
  71. */
  72. UCLASS(config = Editor, defaultconfig)
  73. class AKAUDIO_API UAkSlider : public UWidget
  74. {
  75. GENERATED_BODY()
  76. public:
  77. UAkSlider(const FObjectInitializer& ObjectInitializer);
  78. /** The volume value to display. */
  79. UPROPERTY(EditAnywhere, Category=Appearance, meta=(ClampMin = "0", ClampMax = "1", UIMin = "0", UIMax = "1"))
  80. float Value = .0f;
  81. /** A bindable delegate to allow logic to drive the value of the widget */
  82. UPROPERTY()
  83. FGetFloat ValueDelegate;
  84. public:
  85. /** The progress bar style */
  86. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Style", meta=( DisplayName="Style" ))
  87. FSliderStyle WidgetStyle;
  88. /** The slider's orientation. */
  89. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Appearance)
  90. TEnumAsByte<EOrientation> Orientation = EOrientation::Orient_Horizontal;
  91. /** The color to draw the slider bar in. */
  92. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Appearance)
  93. FLinearColor SliderBarColor = FLinearColor(EForceInit::ForceInitToZero);
  94. /** The color to draw the slider handle in. */
  95. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Appearance)
  96. FLinearColor SliderHandleColor = FLinearColor(EForceInit::ForceInitToZero);
  97. /** Whether the slidable area should be indented to fit the handle. */
  98. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Appearance, AdvancedDisplay)
  99. bool IndentHandle = false;
  100. /** Whether the handle is interactive or fixed. */
  101. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Appearance, AdvancedDisplay)
  102. bool Locked = false;
  103. /** The amount to adjust the value by, when using a controller or keyboard */
  104. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Appearance, meta=( ClampMin="0", ClampMax="1", UIMin="0", UIMax="1"))
  105. float StepSize = .0f;
  106. /** Should the slider be focusable? */
  107. UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Interaction")
  108. bool IsFocusable = false;
  109. UPROPERTY(VisibleAnywhere, Category = "Audiokinetic|WAAPI|Slider", meta = (DisplayName = "Property to control"))
  110. FAkPropertyToControl ThePropertyToControl;
  111. UPROPERTY(Config, VisibleAnywhere, Category = "Audiokinetic|WAAPI|Slider", meta = (DisplayName = "Item to control"))
  112. FAkWwiseItemToControl ItemToControl;
  113. /** Called when the value is changed by slider or typing. */
  114. UPROPERTY(BlueprintAssignable, Category="Widget Event")
  115. FAkOnFloatValueChangedEvent OnValueChanged;
  116. /** Called when the item selection changes. */
  117. UPROPERTY(BlueprintAssignable, Category = "Widget Event")
  118. FOnItemDropDetected OnItemDropped;
  119. /** Called when the item selection changes. */
  120. UPROPERTY(BlueprintAssignable, Category = "Widget Event")
  121. FOnPropertyDropDetected OnPropertyDropped;
  122. public:
  123. /** Gets the current value of the slider. */
  124. UFUNCTION(BlueprintCallable, Category="Behavior")
  125. float GetValue() const;
  126. /** Sets the current value of the slider. */
  127. UFUNCTION(BlueprintCallable, Category="Behavior")
  128. void SetValue(float InValue);
  129. /** Sets if the slidable area should be indented to fit the handle */
  130. UFUNCTION(BlueprintCallable, Category="Behavior")
  131. void SetIndentHandle(bool InValue);
  132. /** Sets the handle to be interactive or fixed */
  133. UFUNCTION(BlueprintCallable, Category="Behavior")
  134. void SetLocked(bool InValue);
  135. /** Sets the amount to adjust the value by, when using a controller or keyboard */
  136. UFUNCTION(BlueprintCallable, Category="Behavior")
  137. void SetStepSize(float InValue);
  138. /** Sets the color of the slider bar */
  139. UFUNCTION(BlueprintCallable, Category="Appearance")
  140. void SetSliderBarColor(FLinearColor InValue);
  141. /** Sets the color of the handle bar */
  142. UFUNCTION(BlueprintCallable, Category="Appearance")
  143. void SetSliderHandleColor(FLinearColor InValue);
  144. /** Set the item id to the new one.
  145. * @param ItemId - value (new id) to set
  146. */
  147. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|WAAPI|Slider", meta = (Keywords = "Set Item Id"))
  148. void SetAkSliderItemId(const FGuid& ItemId);
  149. /** Returns the current item id.
  150. *
  151. * @return an id as GUID.
  152. */
  153. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|WAAPI|Slider", meta = (Keywords = "Get Item Id"))
  154. const FGuid GetAkSliderItemId() const;
  155. /** Set the item property to the new one.
  156. * @param ItemId - value (new id) to set
  157. */
  158. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|WAAPI|Slider", meta = (Keywords = "Set Item Property"))
  159. void SetAkSliderItemProperty(const FString& ItemProperty);
  160. /** Returns the current item property.
  161. *
  162. * @return a property as string.
  163. */
  164. UFUNCTION(BlueprintCallable, Category = "Audiokinetic|WAAPI|Slider", meta = (Keywords = "Get Item Property"))
  165. const FString GetAkSliderItemProperty() const;
  166. // UWidget interface
  167. virtual void SynchronizeProperties() override;
  168. // End of UWidget interface
  169. // UVisual interface
  170. virtual void ReleaseSlateResources(bool bReleaseChildren) override;
  171. // End of UVisual interface
  172. virtual void BeginDestroy() override;
  173. #if WITH_EDITOR
  174. virtual const FText GetPaletteCategory() override;
  175. #endif
  176. protected:
  177. uint64 SubscriptionId;
  178. /** Native Slate Widget */
  179. TSharedPtr<AkSSlider> MyAkSlider;
  180. // UWidget interface
  181. virtual TSharedRef<SWidget> RebuildWidget() override;
  182. // End of UWidget interface
  183. void HandleOnValueChanged(float InValue);
  184. /** Handles dropping of a wwise item onto the slider */
  185. FReply HandleDropped(const FGeometry& DropZoneGeometry, const FDragDropEvent& DragDropEvent);
  186. PROPERTY_BINDING_IMPLEMENTATION(float, Value);
  187. private:
  188. void SynchronizePropertyWithWwise();
  189. void UnsubscribePropertyChangedCallback();
  190. /** The minimum value the the slider could take */
  191. float minValue;
  192. /** The minimum value the the slider could take */
  193. float maxValue;
  194. };