A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
ButtonWidget.h
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
3/*
4 * Improve ButtonWidget
5 * - added button highlight
6 * - some properties can be editable outside (ButtonNameFontSize, ButtonBoundsWidth, ButtonBoundsColor...)
7 * - integration of highlight with HintManager (HintManager->OnHintActivated)
8 * - the change of properties displayed in the blueprint
9 * - integration of highlight with StoryManager (StoryManager->OnNewStep, StoryManager->OnNewSubStep, StoryManager->OnStoryLoaded)
10*/
11
12#pragma once
13
14#include "CoreMinimal.h"
15#include "Blueprint/UserWidget.h"
16#include "Components/Border.h"
17#include "Components/Button.h"
18#include "Components/TextBlock.h"
19#include "ButtonWidget.generated.h"
20
21UENUM()
22enum class ButtonType
23{
26};
27
28class UButtonWidget;
29
31DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FClickEventPtrDelegate, FText, ButtonName, int32, UID);
32DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FClickEventSelfPtrDelegate, UButtonWidget*, ButtonObj);
37UCLASS()
38class PIXOCORE_API UButtonWidget : public UUserWidget
39{
41
42public:
43#if WITH_EDITOR
44 virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) override;
45#endif // WITH_EDITOR
46
47 virtual void NativeOnInitialized() override;
48
49 virtual void NativePreConstruct() override;
50
51 UFUNCTION(BlueprintCallable)
52 void SetButtonName(const FText& Name);
53
54 UFUNCTION(BlueprintCallable)
55 const FText& GetButtonName();
56
61 UFUNCTION(BlueprintCallable)
62 virtual void ChangeButtonState(const bool bState);
63
68 UFUNCTION(BlueprintCallable)
69 bool GetState() const { return bCurrentState; } ;
70
71 ButtonType GetType() const { return Type; };
72
76 void RefreshWidgetStyle();
77
81
82 UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
83 void OnHintActivated(bool Activate);
84
85private:
90 void SwitchButtonColor(const bool bState);
91
92 UFUNCTION()
93 void ButtonReleased();
94 UFUNCTION()
95 void ButtonHovered();
96 UFUNCTION()
97 void OnUnHovered();
98 UFUNCTION()
99 void OnPressed();
100
101 UFUNCTION()
102 void NewStep(FStoryStep NewStep, bool IsForward);
103 UFUNCTION()
105 UFUNCTION()
106 void StoryLoaded();
107
108#pragma region Variables
109public:
110 UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Delegate")
111 FClickEventDelegate OnClickEventDelegate;
112
113 UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Delegate")
114 FClickEventPtrDelegate OnClickEventPtrDelegate;
115
116 UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Delegate")
117 FClickEventSelfPtrDelegate OnClickEventSelfPtrDelegate;
118
119 UPROPERTY(BlueprintReadWrite)
121
122 UPROPERTY(BlueprintReadWrite)
124
125 UPROPERTY(BlueprintReadWrite)
127
128 UPROPERTY(BlueprintReadWrite)
130
131 UPROPERTY(BlueprintReadWrite)
133
134protected:
135 UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
136 UBorder* ButtonHighlight;
137
138 UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
139 UBorder* ButtonBounds;
140
141 UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
142 UButton* Button;
143
144 UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
145 UTextBlock* BtnName;
146
147 UPROPERTY(EditAnywhere, BlueprintReadWrite)
148 float ButtonBoundsWidth = 2.f;
150 UPROPERTY(EditAnywhere, BlueprintReadWrite)
151 FLinearColor ButtonBoundsColor = FLinearColor::Black;
152
153 UPROPERTY(EditAnywhere, BlueprintReadWrite)
154 float ButtonNameFontSize = 18.f;
155
156 UPROPERTY(EditAnywhere, BlueprintReadWrite)
157 FText ButtonName = FText::FromString(TEXT("Text"));
158
159 UPROPERTY(EditAnywhere, BlueprintReadWrite)
160 FLinearColor ButtonNameColor = FLinearColor::White;
161
162 UPROPERTY(EditAnywhere, BlueprintReadWrite)
163 FLinearColor DefaultButtonColor = FLinearColor(0.91f, 0.22f, 0.0f, 1.0f);
164
165 UPROPERTY(EditAnywhere, BlueprintReadWrite)
166 FLinearColor SelectedButtonColor = FLinearColor(0.25f, 0.6f, 0.0f, 1.0f);
167
168 UPROPERTY(EditAnywhere, BlueprintReadWrite)
169 FLinearColor DefaultHoveredButtonColor = FLinearColor(0.25f, 0.6f, 0.0f, 1.0f);
170
171 UPROPERTY(EditAnywhere, BlueprintReadWrite)
172 FLinearColor SelectedHoveredButtonColor = FLinearColor(0.25f, 0.6f, 0.0f, 1.0f);
173
174 UPROPERTY(EditAnywhere, BlueprintReadWrite)
175 FLinearColor PressedButtonColor = FLinearColor(0.25f, 0.6f, 0.0f, 1.0f);
176
177 UPROPERTY(EditAnywhere, BlueprintReadWrite)
178 USoundBase* SelectSound;
179
180 UPROPERTY(EditAnywhere, BlueprintReadWrite)
181 USoundBase* HoverSound;
182
183 UPROPERTY(EditAnywhere, BlueprintReadWrite)
184 bool bIsSelectable = true;
185
186 ButtonType Type;
188 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
189 UWidgetAnimation* ButtonHighlightAnimation;
190
191 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
192 bool bIsPulsationHighlight = false;
194 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
195 float HighlightAnimationSpeed = 1.f;
196
197 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
199
200 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
202
203 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
204 float ButtonHighlightWidth = 0.f;
205
206 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
207 FLinearColor ButtonHighlightColor = FLinearColor(0.25f, 0.6f, 0.0f, 0.f);
208
209 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
211
212private:
213 bool bCurrentState;
214
215#pragma endregion Variables
216};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FClickEventDelegate, FText, ButtonName)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FClickEventPtrDelegate, FText, ButtonName, int32, UID)
ButtonType
UENUM()
Custom widget class representing a button.
UHintManager * HintManager
UPROPERTY(BlueprintReadWrite)
bool bWidgetActiveOnStep
UPROPERTY(BlueprintReadWrite)
void ActivateButtonPulsationHighlight()
virtual void ChangeButtonState(const bool bState)
Changes the state of the button .
float HighlightAnimationSpeed
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
void NewStep(FStoryStep NewStep, bool IsForward)
UFUNCTION()
FText ActiveStep
UPROPERTY(BlueprintReadWrite)
ButtonType GetType() const
bool bIsPulsationHighlight
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
FLinearColor ButtonNameColor
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UBorder * ButtonHighlight
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
FLinearColor SelectedHoveredButtonColor
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ButtonType Type
void ButtonHovered()
UFUNCTION()
bool bIsSelectable
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float ButtonHighlightWidth
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
virtual void NativePreConstruct() override
float ButtonBoundsWidth
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UStoryManager * StoryManager
UPROPERTY(BlueprintReadWrite)
FClickEventPtrDelegate OnClickEventPtrDelegate
UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Delegate")
FLinearColor ButtonBoundsColor
UPROPERTY(EditAnywhere, BlueprintReadWrite)
void StoryLoaded()
UFUNCTION()
FLinearColor DefaultButtonColor
UPROPERTY(EditAnywhere, BlueprintReadWrite)
virtual void NativeOnInitialized() override
bool GetState() const
Gets the state of the button.
TArray< FText > HighlightActiveSteps
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
void SetButtonName(const FText &Name)
UFUNCTION(BlueprintCallable)
TArray< FText > HighlightActiveSubSteps
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
bool ActivateHighlightOnEachActiveStep
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
FClickEventDelegate OnClickEventDelegate
UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Delegate")
FLinearColor DefaultHoveredButtonColor
UPROPERTY(EditAnywhere, BlueprintReadWrite)
void NewSubStep(FStoryStep NewSubStep)
UFUNCTION()
UWidgetAnimation * ButtonHighlightAnimation
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
void ButtonReleased()
UFUNCTION()
void OnPressed()
UFUNCTION()
USoundBase * HoverSound
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText ActiveSubStep
UPROPERTY(BlueprintReadWrite)
FLinearColor PressedButtonColor
UPROPERTY(EditAnywhere, BlueprintReadWrite)
void ActivateButtonHighlight()
FClickEventSelfPtrDelegate OnClickEventSelfPtrDelegate
UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Delegate")
UBorder * ButtonBounds
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
void OnHintActivated(bool Activate)
UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
const FText & GetButtonName()
UFUNCTION(BlueprintCallable)
USoundBase * SelectSound
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UTextBlock * BtnName
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
float ButtonNameFontSize
UPROPERTY(EditAnywhere, BlueprintReadWrite)
void DeactivateButtonHighlight()
void OnUnHovered()
UFUNCTION()
FLinearColor ButtonHighlightColor
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
FText ButtonName
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UButton * Button
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
FLinearColor SelectedButtonColor
UPROPERTY(EditAnywhere, BlueprintReadWrite)
void SwitchButtonColor(const bool bState)
Switches the button color based on the state.
void RefreshWidgetStyle()
Refreshes the visual style of the button widget.
Manager that provides functionality for managing hint activation events.
Definition HintManager.h:19
Manager that provides handling story-related operations and data.
USTRUCT(BlueprintType)