Space Plunder
Loading...
Searching...
No Matches
UCommonSlider Class Reference

#include <CommonSlider.h>

Inheritance diagram for UCommonSlider:
UCommonWidgetBase

Public Member Functions

virtual bool Initialize () override
 
virtual void NativePreConstruct () override
 
virtual void NativeConstruct () override
 
float GetSliderValue () const
 
void SetSliderValue (const float Value)
 
void SetSliderMinMax (const float MinValue, const float MaxValue) const
 
- Public Member Functions inherited from UCommonWidgetBase
void PlaySlateSound (const FSlateSound &SlateSound) const
 

Public Attributes

FOnSliderValueChanged OnSliderValueChanged
 
bool bShowValue = true
 
bool bShowEditValue = false
 
bool bShowTitle = true
 
FText Title = FText::FromString("Title Text")
 

Protected Member Functions

virtual void Setup () override
 
- Protected Member Functions inherited from UCommonWidgetBase
void LogDebugError (const FString &Message) const
 
void LogDebugError (const FString &Message, const int32 Value) const
 
void LogDebugError (const FString &Message, const float Value) const
 
void LogDebugWarning (const FString &Message) const
 
void LogDebugWarning (const FString &Message, const int32 Value) const
 
void LogDebugWarning (const FString &Message, const float Value) const
 
void LogDebugMessage (const FString &Message, const bool bWarning=false, const bool bError=false) const
 
void LogDebugMessage (const FString &Message, const int32 Value, const bool bWarning=false, const bool bError=false) const
 
void LogDebugMessage (const FString &Message, const float Value, const bool bWarning=false, const bool bError=false) const
 
void LogDebugMessage (const FString &Message, const bool bValue, const bool bWarning, const bool bError) const
 
void LogOnScreenMessage (const int32 Key, const FString &Message, FColor Color=FColor::Green) const
 
void SetCategoryName (const FLogCategoryBase &Category)
 

Protected Attributes

USlider * Slider = nullptr
 
UTextBlock * TitleTextBlock = nullptr
 
UTextBlock * ValueTextBlock = nullptr
 
UEditableTextBox * EditableTextBox = nullptr
 
UButton * ValueInputButton = nullptr
 
UWidgetSwitcher * InputSwitcher = nullptr
 
- Protected Attributes inherited from UCommonWidgetBase
bool bDebuggingMode = false
 

Private Member Functions

void OnValueChanged (float Value)
 
void OnTextCommited (const FText &Text, ETextCommit::Type CommitMethod)
 
void OnTextChanged (const FText &Text)
 
void OnButtonPressed ()
 

Private Attributes

float SliderValue = 0.0
 

Member Function Documentation

◆ GetSliderValue()

float UCommonSlider::GetSliderValue ( ) const
inline
47{return SliderValue;};
float SliderValue
Definition CommonSlider.h:71

◆ Initialize()

bool UCommonSlider::Initialize ( )
overridevirtual
14{
15 const bool Success = Super::Initialize();
16 if(!Success) return false;
17 if (!ensure(Slider != nullptr)) return false;
18 if (!ensure(TitleTextBlock != nullptr)) return false;
19 if (!ensure(ValueTextBlock != nullptr)) return false;
20 if (!ensure(ValueInputButton != nullptr)) return false;
21 if (!ensure(EditableTextBox != nullptr)) return false;
22 if (!ensure(InputSwitcher != nullptr)) return false;
23 Slider->OnValueChanged.AddDynamic(this, &UCommonSlider::OnValueChanged);
24 EditableTextBox->OnTextCommitted.AddDynamic(this, &UCommonSlider::OnTextCommited);
25 EditableTextBox->OnTextChanged.AddDynamic(this, &UCommonSlider::OnTextChanged);
26 ValueInputButton->OnPressed.AddDynamic(this, &UCommonSlider::OnButtonPressed);
27 return true;
28}
void OnButtonPressed()
Definition CommonSlider.cpp:121
void OnTextChanged(const FText &Text)
Definition CommonSlider.cpp:92
UWidgetSwitcher * InputSwitcher
Definition CommonSlider.h:67
UTextBlock * TitleTextBlock
Definition CommonSlider.h:59
UButton * ValueInputButton
Definition CommonSlider.h:65
UEditableTextBox * EditableTextBox
Definition CommonSlider.h:63
void OnValueChanged(float Value)
Definition CommonSlider.cpp:68
USlider * Slider
Definition CommonSlider.h:57
UTextBlock * ValueTextBlock
Definition CommonSlider.h:61
void OnTextCommited(const FText &Text, ETextCommit::Type CommitMethod)
Definition CommonSlider.cpp:75

◆ NativeConstruct()

void UCommonSlider::NativeConstruct ( )
overridevirtual

Reimplemented from UCommonWidgetBase.

36{
37 Super::NativeConstruct();
38 if(Title.IsEmpty())
39 {
40 TitleTextBlock->SetVisibility(ESlateVisibility::Collapsed);
41 }
42 SliderValue = Slider->GetValue();
43}
FText Title
Definition CommonSlider.h:45

◆ NativePreConstruct()

void UCommonSlider::NativePreConstruct ( )
overridevirtual

Reimplemented from UCommonWidgetBase.

31{
32 Super::NativePreConstruct();
33}

◆ OnButtonPressed()

void UCommonSlider::OnButtonPressed ( )
private
122{
123 InputSwitcher->SetActiveWidget(EditableTextBox);
124 EditableTextBox->SetKeyboardFocus();
125}

◆ OnTextChanged()

void UCommonSlider::OnTextChanged ( const FText & Text)
private
93{
94 const FText PreviousNumber = FText::AsNumber(SliderValue);
95 FString NewNumber;
96 float NewNumberFloat = 0.0f;
97 for(const auto Char : Text.ToString().GetCharArray())
98 {
99 FString StringCharacter = FString::Chr(Char);
100 if(StringCharacter.IsEmpty()){continue;}
101 float Number = 0;
102 if(FDefaultValueHelper::ParseFloat(StringCharacter, Number) && StringCharacter.ToLower() != "f" && StringCharacter.ToLower() != "e")
103 {
104 NewNumber.Append(StringCharacter);
105 }
106 }
107 if(FDefaultValueHelper::ParseFloat(NewNumber, NewNumberFloat))
108 {
109 EditableTextBox->SetText(FText::FromString(NewNumber));
110 }
111 else if(NewNumber.IsEmpty())
112 {
113 EditableTextBox->SetText(FText::FromString("0"));
114 }
115 else
116 {
117 EditableTextBox->SetText(PreviousNumber);
118 }
119}

◆ OnTextCommited()

void UCommonSlider::OnTextCommited ( const FText & Text,
ETextCommit::Type CommitMethod )
private
76{
77 if(CommitMethod == ETextCommit::OnEnter)
78 {
79 InputSwitcher->SetActiveWidget(ValueTextBlock);
80 float NewNumber = 0.0f;
81 if(FDefaultValueHelper::ParseFloat(Text.ToString(), NewNumber))
82 {
83 SetSliderValue(NewNumber);
84 }
85 else
86 {
88 }
89 }
90}
void SetSliderValue(const float Value)
Definition CommonSlider.cpp:45

◆ OnValueChanged()

void UCommonSlider::OnValueChanged ( float Value)
private
69{
70 SliderValue = Value;
71 ValueTextBlock->SetText(FText::AsNumber(Value));
72 OnSliderValueChanged.Broadcast(Value);
73}
FOnSliderValueChanged OnSliderValueChanged
Definition CommonSlider.h:30

◆ SetSliderMinMax()

void UCommonSlider::SetSliderMinMax ( const float MinValue,
const float MaxValue ) const
53{
54 Slider->SetMinValue(MinValue);
55 Slider->SetMaxValue(MaxValue);
56}

◆ SetSliderValue()

void UCommonSlider::SetSliderValue ( const float Value)
46{
47 Slider->SetValue(Value);
48 OnValueChanged(Value);
49 OnSliderValueChanged.Broadcast(Value);
50}

◆ Setup()

void UCommonSlider::Setup ( )
overrideprotectedvirtual

Reimplemented from UCommonWidgetBase.

59{
60 Super::Setup();
61 // ToggleWidgetVisibility(ValueTextBlock, bShowValue);
62 // ToggleWidgetVisibility(TitleTextBlock, bShowTitle);
63 // ToggleWidgetVisibility(EditableTextBox, bShowEditValue);
64 TitleTextBlock->SetText(Title);
65 ValueTextBlock->SetText(FText::AsNumber(Slider->GetValue()));
66}

Member Data Documentation

◆ bShowEditValue

bool UCommonSlider::bShowEditValue = false

◆ bShowTitle

bool UCommonSlider::bShowTitle = true

◆ bShowValue

bool UCommonSlider::bShowValue = true

◆ EditableTextBox

UEditableTextBox* UCommonSlider::EditableTextBox = nullptr
protected

◆ InputSwitcher

UWidgetSwitcher* UCommonSlider::InputSwitcher = nullptr
protected

◆ OnSliderValueChanged

FOnSliderValueChanged UCommonSlider::OnSliderValueChanged

◆ Slider

USlider* UCommonSlider::Slider = nullptr
protected

◆ SliderValue

float UCommonSlider::SliderValue = 0.0
private

◆ Title

FText UCommonSlider::Title = FText::FromString("Title Text")

◆ TitleTextBlock

UTextBlock* UCommonSlider::TitleTextBlock = nullptr
protected

◆ ValueInputButton

UButton* UCommonSlider::ValueInputButton = nullptr
protected

◆ ValueTextBlock

UTextBlock* UCommonSlider::ValueTextBlock = nullptr
protected

The documentation for this class was generated from the following files: