diff --git a/Source/UINavigation/Private/UINavSlider.cpp b/Source/UINavigation/Private/UINavSlider.cpp index 5b7402f4..ae520453 100644 --- a/Source/UINavigation/Private/UINavSlider.cpp +++ b/Source/UINavigation/Private/UINavSlider.cpp @@ -35,9 +35,11 @@ void UUINavSlider::NativeConstruct() } if (!Slider->OnValueChanged.IsBound()) Slider->OnValueChanged.AddDynamic(this, &UUINavSlider::HandleOnSliderValueChanged); - Slider->StepSize = Interval / (MaxValue - MinValue); - MaxOption = ((MaxValue - MinValue) / Interval); + Difference = MaxValue - MinValue; + Slider->StepSize = Interval / Difference; + + MaxOptionIndex = (Difference / Interval); HandleDefaultColor = Slider->SliderHandleColor; BarDefaultColor = Slider->SliderBarColor; @@ -46,13 +48,15 @@ void UUINavSlider::NativeConstruct() void UUINavSlider::Update() { - Slider->SetValue((float)OptionIndex / (float)MaxOption); + Slider->SetValue((float)OptionIndex / (float)MaxOptionIndex); FNumberFormattingOptions FormatOptions; FormatOptions.MaximumFractionalDigits = MaxDecimalDigits; FormatOptions.MinimumFractionalDigits = MinDecimalDigits; - float Value = MinValue + Slider->Value * MaxValue; + + float Value = MinValue + Slider->Value * Difference; FText ValueText = FText::AsNumber(Value, &FormatOptions); if (!bUseComma) ValueText = FText::FromString(ValueText.ToString().Replace(TEXT(","),TEXT("."))); + if (NavText != nullptr) NavText->SetText(ValueText); if (NavSpinBox != nullptr) NavSpinBox->SetValue(Value); } @@ -75,6 +79,7 @@ void UUINavSlider::NavigateLeft() { OptionIndex--; } + else if (bLoopOptions) OptionIndex = MaxOptionIndex; Update(); @@ -83,15 +88,11 @@ void UUINavSlider::NavigateLeft() void UUINavSlider::NavigateRight() { - if (OptionIndex < MaxOption) + if (OptionIndex < MaxOptionIndex) { OptionIndex++; } - else - { - OnNavigateRight(); - return; - } + else if (bLoopOptions) OptionIndex = 0; Update(); @@ -113,11 +114,11 @@ void UUINavSlider::HandleOnSpinBoxValueChanged(float InValue, ETextCommit::Type float UUINavSlider::IndexFromPercent(float Value) { float Div = Value / Slider->StepSize; - if (Div > MaxOption) Div = MaxOption; + if (Div > MaxOptionIndex) Div = MaxOptionIndex; int FlatDiv = (int)Div; float Decimal = Div - FlatDiv; - return Decimal < 0.5 ? FlatDiv : (FlatDiv + 1 <= MaxOption ? FlatDiv + 1 : MaxOption); + return Decimal < 0.5 ? FlatDiv : (FlatDiv + 1 <= MaxOptionIndex ? FlatDiv + 1 : MaxOptionIndex); } float UUINavSlider::IndexFromValue(float Value) diff --git a/Source/UINavigation/Public/UINavSlider.h b/Source/UINavigation/Public/UINavSlider.h index fac124d7..5349b047 100644 --- a/Source/UINavigation/Public/UINavSlider.h +++ b/Source/UINavigation/Public/UINavSlider.h @@ -43,13 +43,15 @@ class UINAVIGATION_API UUINavSlider : public UUINavHorizontalComponent int MinDecimalDigits = 0; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = UINavSlider, meta = (ClampMin="0")) bool bUseComma = false; - int MaxOption = 0; - FLinearColor HandleDefaultColor; - FLinearColor BarDefaultColor; - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = UINavSlider, meta = (ClampMin = "0")) + int MaxOptionIndex = 0; + float Difference = 0.0f; + + FLinearColor HandleDefaultColor = FColor::Black; + FLinearColor BarDefaultColor = FColor::Black; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = UINavSlider, meta = (ClampMin = "0")) FLinearColor HandleHoverColor; - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = UINavSlider, meta = (ClampMin = "0")) + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = UINavSlider, meta = (ClampMin = "0")) FLinearColor BarHoverColor; virtual void NativeConstruct() override; diff --git a/UINavigation.uplugin b/UINavigation.uplugin index e5ab8d45..83b8d76c 100644 --- a/UINavigation.uplugin +++ b/UINavigation.uplugin @@ -1,7 +1,7 @@ { "FileVersion": 3, "Version": 1, - "VersionName": "2.5.0", + "VersionName": "2.5.2", "FriendlyName": "UI Navigation", "Description": "A plugin that allows you to easily setup mouse, keyboard and controller navigation in UMG, among other things.", "Category": "Plugins",