Documentation for the Unreal C++ Plugin
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"
20#include "Story/StoryManager.h"
21#include "ButtonWidget.generated.h"
22
23UENUM()
24enum class ButtonType
25{
28};
29
30class UButtonWidget;
31
33DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FClickEventPtrDelegate, FText, ButtonName, int32, UID);
34DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FClickEventSelfPtrDelegate, UButtonWidget*, ButtonObj);
39UCLASS()
40class PIXOCORE_API UButtonWidget : public UUserWidget
41{
43
44public:
45#if WITH_EDITOR
46 virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) override;
47#endif // WITH_EDITOR
48
49 virtual void NativeOnInitialized() override;
50
51 virtual void NativePreConstruct() override;
52
53 UFUNCTION(BlueprintCallable)
54 void SetButtonName(const FText& Name);
55
56 UFUNCTION(BlueprintCallable)
57 const FText& GetButtonName();
58
63 UFUNCTION(BlueprintCallable)
64 virtual void ChangeButtonState(const bool bState);
65
70 UFUNCTION(BlueprintCallable)
71 bool GetState() const { return bCurrentState; } ;
72
73 ButtonType GetType() const { return Type; };
74
78 void RefreshWidgetStyle();
79
83
84 UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
85 void OnHintActivated(bool Activate);
86
87private:
92 void SwitchButtonColor(const bool bState);
93
94 UFUNCTION()
95 void ButtonReleased();
96 UFUNCTION()
97 void ButtonHovered();
98 UFUNCTION()
99 void OnUnHovered();
100 UFUNCTION()
101 void OnPressed();
102
103 UFUNCTION()
104 void NewStep(FStoryStep NewStep, bool IsForward);
105 UFUNCTION()
107 UFUNCTION()
108 void StoryLoaded();
109
110#pragma region Variables
111public:
112 UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Delegate")
113 FClickEventDelegate OnClickEventDelegate;
114
115 UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Delegate")
116 FClickEventPtrDelegate OnClickEventPtrDelegate;
117
118 UPROPERTY(BlueprintAssignable, BlueprintCallable, Category = "Delegate")
119 FClickEventSelfPtrDelegate OnClickEventSelfPtrDelegate;
120
121 UPROPERTY(BlueprintReadWrite)
123
124 UPROPERTY(BlueprintReadWrite)
126
127 UPROPERTY(BlueprintReadWrite)
128 FText ActiveStep;
129
130 UPROPERTY(BlueprintReadWrite)
131 FText ActiveSubStep;
132
133 UPROPERTY(BlueprintReadWrite)
135
136protected:
137 UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
138 UBorder* ButtonHighlight;
139
140 UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
141 UBorder* ButtonBounds;
142
143 UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
144 UButton* Button;
145
146 UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
147 UTextBlock* BtnName;
148
149 UPROPERTY(EditAnywhere, BlueprintReadWrite)
150 float ButtonBoundsWidth = 2.f;
152 UPROPERTY(EditAnywhere, BlueprintReadWrite)
153 FLinearColor ButtonBoundsColor = FLinearColor::Black;
154
155 UPROPERTY(EditAnywhere, BlueprintReadWrite)
156 float ButtonNameFontSize = 18.f;
157
158 UPROPERTY(EditAnywhere, BlueprintReadWrite)
159 FText ButtonName = FText::FromString(TEXT("Text"));
160
161 UPROPERTY(EditAnywhere, BlueprintReadWrite)
162 FLinearColor ButtonNameColor = FLinearColor::White;
163
164 UPROPERTY(EditAnywhere, BlueprintReadWrite)
165 FLinearColor DefaultButtonColor = FLinearColor(0.91f, 0.22f, 0.0f, 1.0f);
166
167 UPROPERTY(EditAnywhere, BlueprintReadWrite)
168 FLinearColor SelectedButtonColor = FLinearColor(0.25f, 0.6f, 0.0f, 1.0f);
169
170 UPROPERTY(EditAnywhere, BlueprintReadWrite)
171 FLinearColor DefaultHoveredButtonColor = FLinearColor(0.25f, 0.6f, 0.0f, 1.0f);
172
173 UPROPERTY(EditAnywhere, BlueprintReadWrite)
174 FLinearColor SelectedHoveredButtonColor = FLinearColor(0.25f, 0.6f, 0.0f, 1.0f);
175
176 UPROPERTY(EditAnywhere, BlueprintReadWrite)
177 FLinearColor PressedButtonColor = FLinearColor(0.25f, 0.6f, 0.0f, 1.0f);
178
179 UPROPERTY(EditAnywhere, BlueprintReadWrite)
180 USoundBase* SelectSound;
181
182 UPROPERTY(EditAnywhere, BlueprintReadWrite)
183 USoundBase* HoverSound;
184
185 UPROPERTY(EditAnywhere, BlueprintReadWrite)
186 bool bIsSelectable = true;
187
190 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
191 UWidgetAnimation* ButtonHighlightAnimation;
192
193 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
194 bool bIsPulsationHighlight = false;
196 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
197 float HighlightAnimationSpeed = 1.f;
198
199 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
200 TArray<FText> HighlightActiveSteps;
201
202 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
203 TArray<FText> HighlightActiveSubSteps;
204
205 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
206 float ButtonHighlightWidth = 0.f;
207
208 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
209 FLinearColor ButtonHighlightColor = FLinearColor(0.25f, 0.6f, 0.0f, 0.f);
210
211 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Highlight")
213
214private:
215 bool bCurrentState;
216
217#pragma endregion Variables
218};
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)