// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "GameSettingFilterState.h" #include "GameSettingValueScalar.h" #include "Internationalization/Text.h" #include "Math/Range.h" #include "Misc/Optional.h" #include "Templates/Function.h" #include "Templates/SharedPointer.h" #include "UObject/UObjectGlobals.h" #include "GameSettingValueScalarDynamic.generated.h" class FGameSettingDataSource; class UObject; ////////////////////////////////////////////////////////////////////////// // UGameSettingValueScalarDynamic ////////////////////////////////////////////////////////////////////////// typedef TFunction FSettingScalarFormatFunction; UCLASS() class GAMESETTINGS_API UGameSettingValueScalarDynamic : public UGameSettingValueScalar { GENERATED_BODY() public: static FSettingScalarFormatFunction Raw; static FSettingScalarFormatFunction RawOneDecimal; static FSettingScalarFormatFunction RawTwoDecimals; static FSettingScalarFormatFunction ZeroToOnePercent; static FSettingScalarFormatFunction ZeroToOnePercent_OneDecimal; static FSettingScalarFormatFunction SourceAsPercent1; static FSettingScalarFormatFunction SourceAsPercent100; static FSettingScalarFormatFunction SourceAsInteger; private: static const FNumberFormattingOptions& GetOneDecimalFormattingOptions(); public: UGameSettingValueScalarDynamic(); /** UGameSettingValue */ virtual void Startup() override; virtual void StoreInitial() override; virtual void ResetToDefault() override; virtual void RestoreToInitial() override; /** UGameSettingValueScalar */ virtual TOptional GetDefaultValue() const override; virtual void SetValue(double Value, EGameSettingChangeReason Reason = EGameSettingChangeReason::Change) override; virtual double GetValue() const override; virtual TRange GetSourceRange() const override; virtual double GetSourceStep() const override; virtual FText GetFormattedText() const override; /** UGameSettingValueDiscreteDynamic */ void SetDynamicGetter(const TSharedRef& InGetter); void SetDynamicSetter(const TSharedRef& InSetter); void SetDefaultValue(double InValue); /** */ void SetDisplayFormat(FSettingScalarFormatFunction InDisplayFormat); /** */ void SetSourceRangeAndStep(const TRange& InRange, double InSourceStep); /** * The SetSourceRangeAndStep defines the actual range the numbers could move in, but often * the true minimum for the user is greater than the minimum source range, so for example, the range * of some slider might be 0..100, but you want to restrict the slider so that while it shows * a bar that travels from 0 to 100, the user can't set anything lower than some minimum, e.g. 1. * That is the Minimum Limit. */ void SetMinimumLimit(const TOptional& InMinimum); /** * The SetSourceRangeAndStep defines the actual range the numbers could move in, but rarely * the true maximum for the user is less than the maximum source range, so for example, the range * of some slider might be 0..100, but you want to restrict the slider so that while it shows * a bar that travels from 0 to 100, the user can't set anything lower than some maximum, e.g. 95. * That is the Maximum Limit. */ void SetMaximumLimit(const TOptional& InMaximum); protected: /** UGameSettingValue */ virtual void OnInitialized() override; void OnDataSourcesReady(); protected: TSharedPtr Getter; TSharedPtr Setter; TOptional DefaultValue; double InitialValue = 0; TRange SourceRange = TRange(0, 1); double SourceStep = 0.01; TOptional Minimum; TOptional Maximum; FSettingScalarFormatFunction DisplayFormat; };