graphic settings wip 2
This commit is contained in:
parent
fbd5dddcc9
commit
07f34a7c6b
@ -105,6 +105,38 @@ FWorldDilationChangedDelegate& UCommonFunctions::GetWorldDilationChangedDelegate
|
|||||||
return SlowMotion::worldDilationChangedDelegate;
|
return SlowMotion::worldDilationChangedDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FString UCommonFunctions::IntPointToString(const FIntPoint& in)
|
||||||
|
{
|
||||||
|
FString result = FString::Printf(TEXT("%sx%s"), *FString::FromInt(in.X), *FString::FromInt(in.Y));
|
||||||
|
return MoveTemp(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
FIntPoint UCommonFunctions::StringToIntPoint(const FString& in)
|
||||||
|
{
|
||||||
|
FIntPoint result;
|
||||||
|
|
||||||
|
const FRegexPattern rgxP(FRegexPattern(TEXT("[0-9]+")));
|
||||||
|
FRegexMatcher rgx = FRegexMatcher(rgxP, in);
|
||||||
|
if(rgx.FindNext())
|
||||||
|
result.X = FCString::Atoi(*in.Mid(rgx.GetMatchBeginning(), rgx.GetMatchEnding() - rgx.GetMatchBeginning()));
|
||||||
|
if(rgx.FindNext())
|
||||||
|
result.Y = FCString::Atoi(*in.Mid(rgx.GetMatchBeginning(), rgx.GetMatchEnding() - rgx.GetMatchBeginning()));
|
||||||
|
|
||||||
|
return MoveTemp(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 UCommonFunctions::GreatestCommonDivisor(int32 a, int32 b)
|
||||||
|
{
|
||||||
|
int32 temp;
|
||||||
|
while(b != 0)
|
||||||
|
{
|
||||||
|
temp = b;
|
||||||
|
b = a % b;
|
||||||
|
a = temp;
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
void UCommonFunctions::SlowMotionTick()
|
void UCommonFunctions::SlowMotionTick()
|
||||||
{
|
{
|
||||||
const UWorld* world = UCustomGameInstance::Get()->GetWorld();
|
const UWorld* world = UCustomGameInstance::Get()->GetWorld();
|
||||||
|
@ -44,6 +44,18 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintPure, Category = TypeCasts)
|
||||||
|
static FString IntPointToString(const FIntPoint& in);
|
||||||
|
UFUNCTION(BlueprintPure, Category = TypeCasts)
|
||||||
|
static FIntPoint StringToIntPoint(const FString& in);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintPure, Category = Math)
|
||||||
|
static int32 GreatestCommonDivisor(int32 a, int32 b);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure)
|
UFUNCTION(BlueprintPure)
|
||||||
static TArray<int32> GetRandomIntArray(int32 size = 16, int32 min = 0, int32 max = 16);
|
static TArray<int32> GetRandomIntArray(int32 size = 16, int32 min = 0, int32 max = 16);
|
||||||
|
|
||||||
|
@ -23,16 +23,16 @@ UCustomGameSettings::UCustomGameSettings(const FObjectInitializer& ObjectInitial
|
|||||||
bUseMotionBlur = false;
|
bUseMotionBlur = false;
|
||||||
bShowFps = false;
|
bShowFps = false;
|
||||||
|
|
||||||
/** Game */
|
|
||||||
fMouseSensetivity = GetDefaultMouseSensetivity();
|
|
||||||
bMouseInverted = GetDefaultMouseInverted();
|
|
||||||
|
|
||||||
/** Audio */
|
/** Audio */
|
||||||
fMasterVolume = GetDefaultMasterVolume();
|
fMasterVolume = GetDefaultMasterVolume();
|
||||||
fMusicVolume = GetDefaultMusicVolume();
|
fMusicVolume = GetDefaultMusicVolume();
|
||||||
fEffectsVolume = GetDefaultEffectsVolume();
|
fEffectsVolume = GetDefaultEffectsVolume();
|
||||||
fVoicesVolume = GetDefaultVoicesVolume();
|
fVoicesVolume = GetDefaultVoicesVolume();
|
||||||
fMenuVolume = GetDefaultMenuVolume();
|
fMenuVolume = GetDefaultMenuVolume();
|
||||||
|
|
||||||
|
/** Game */
|
||||||
|
fMouseSensetivity = GetDefaultMouseSensetivity();
|
||||||
|
bMouseInverted = GetDefaultMouseInverted();
|
||||||
}
|
}
|
||||||
|
|
||||||
UCustomGameSettings* UCustomGameSettings::Get()
|
UCustomGameSettings* UCustomGameSettings::Get()
|
||||||
@ -42,45 +42,24 @@ UCustomGameSettings* UCustomGameSettings::Get()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Game */
|
|
||||||
float UCustomGameSettings::GetDefaultMouseSensetivity() const
|
|
||||||
{
|
|
||||||
return fDefaultMouseSensetivity;
|
|
||||||
}
|
|
||||||
float UCustomGameSettings::GetMouseSensetivity() const
|
|
||||||
{
|
|
||||||
return fMouseSensetivity;
|
|
||||||
}
|
|
||||||
void UCustomGameSettings::SetMouseSensetivity(float value)
|
|
||||||
{
|
|
||||||
fMouseSensetivity = FMath::Clamp(value, 0.1f, 2.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UCustomGameSettings::GetDefaultMouseInverted() const
|
|
||||||
{
|
|
||||||
return bDefaultMouseInverted;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Audio */
|
/** Audio */
|
||||||
float UCustomGameSettings::GetDefaultMasterVolume() const
|
inline float UCustomGameSettings::GetDefaultMasterVolume() const
|
||||||
{
|
{
|
||||||
return fDefaultMasterVolume;
|
return fDefaultMasterVolume;
|
||||||
}
|
}
|
||||||
float UCustomGameSettings::GetDefaultMusicVolume() const
|
inline float UCustomGameSettings::GetDefaultMusicVolume() const
|
||||||
{
|
{
|
||||||
return fDefaultMusicVolume;
|
return fDefaultMusicVolume;
|
||||||
}
|
}
|
||||||
float UCustomGameSettings::GetDefaultEffectsVolume() const
|
inline float UCustomGameSettings::GetDefaultEffectsVolume() const
|
||||||
{
|
{
|
||||||
return fDefaultEffectsVolume;
|
return fDefaultEffectsVolume;
|
||||||
}
|
}
|
||||||
float UCustomGameSettings::GetDefaultVoicesVolume() const
|
inline float UCustomGameSettings::GetDefaultVoicesVolume() const
|
||||||
{
|
{
|
||||||
return fDefaultVoicesVolume;
|
return fDefaultVoicesVolume;
|
||||||
}
|
}
|
||||||
float UCustomGameSettings::GetDefaultMenuVolume() const
|
inline float UCustomGameSettings::GetDefaultMenuVolume() const
|
||||||
{
|
{
|
||||||
return fDefaultMenuVolume;
|
return fDefaultMenuVolume;
|
||||||
}
|
}
|
||||||
@ -126,3 +105,22 @@ void UCustomGameSettings::SetMenuVolume(float value)
|
|||||||
{
|
{
|
||||||
fMenuVolume = FMath::Clamp(value, 0.0f, 1.0f);
|
fMenuVolume = FMath::Clamp(value, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Game */
|
||||||
|
inline float UCustomGameSettings::GetDefaultMouseSensetivity() const
|
||||||
|
{
|
||||||
|
return fDefaultMouseSensetivity;
|
||||||
|
}
|
||||||
|
float UCustomGameSettings::GetMouseSensetivity() const
|
||||||
|
{
|
||||||
|
return fMouseSensetivity;
|
||||||
|
}
|
||||||
|
void UCustomGameSettings::SetMouseSensetivity(float value)
|
||||||
|
{
|
||||||
|
fMouseSensetivity = FMath::Clamp(value, 0.1f, 2.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool UCustomGameSettings::GetDefaultMouseInverted() const
|
||||||
|
{
|
||||||
|
return bDefaultMouseInverted;
|
||||||
|
}
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
static UCustomGameSettings* Get();
|
static UCustomGameSettings* Get();
|
||||||
|
|
||||||
|
|
||||||
|
/** Graphics */
|
||||||
UPROPERTY(Config, BlueprintReadWrite)
|
UPROPERTY(Config, BlueprintReadWrite)
|
||||||
bool bUseMotionBlur;
|
bool bUseMotionBlur;
|
||||||
|
|
||||||
@ -32,40 +32,20 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Game */
|
|
||||||
UFUNCTION(BlueprintPure, Category = Settings)
|
|
||||||
float GetDefaultMouseSensetivity() const;
|
|
||||||
/** Returns mouse sensetivity multiplier in [0.1 - 2.0] */
|
|
||||||
UFUNCTION(BlueprintPure, Category = Settings)
|
|
||||||
float GetMouseSensetivity() const;
|
|
||||||
/**
|
|
||||||
* Sets mouse sensetivity multiplier
|
|
||||||
* @param value [0.1 - 2.0]
|
|
||||||
*/
|
|
||||||
UFUNCTION(BlueprintCallable, Category = Settings)
|
|
||||||
void SetMouseSensetivity(float value);
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure, Category = Settings)
|
|
||||||
bool GetDefaultMouseInverted() const;
|
|
||||||
UPROPERTY(Config, BlueprintReadWrite)
|
|
||||||
bool bMouseInverted;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Audio
|
* Audio
|
||||||
* All values are clamped in [0.0 - 1.0]
|
* All values are clamped in [0.0 - 1.0]
|
||||||
*/
|
*/
|
||||||
UFUNCTION(BlueprintPure, Category = Settings)
|
UFUNCTION(BlueprintPure, Category = Settings)
|
||||||
float GetDefaultMasterVolume() const; // UFUNCTION doesn't support constexpr functions
|
LOST_EDGE_API inline float GetDefaultMasterVolume() const; // UFUNCTION doesn't support constexpr functions
|
||||||
UFUNCTION(BlueprintPure, Category = Settings)
|
UFUNCTION(BlueprintPure, Category = Settings)
|
||||||
float GetDefaultMusicVolume() const; // UFUNCTION doesn't support constexpr functions
|
LOST_EDGE_API inline float GetDefaultMusicVolume() const; // UFUNCTION doesn't support constexpr functions
|
||||||
UFUNCTION(BlueprintPure, Category = Settings)
|
UFUNCTION(BlueprintPure, Category = Settings)
|
||||||
float GetDefaultEffectsVolume() const; // UFUNCTION doesn't support constexpr functions
|
LOST_EDGE_API inline float GetDefaultEffectsVolume() const; // UFUNCTION doesn't support constexpr functions
|
||||||
UFUNCTION(BlueprintPure, Category = Settings)
|
UFUNCTION(BlueprintPure, Category = Settings)
|
||||||
float GetDefaultVoicesVolume() const; // UFUNCTION doesn't support constexpr functions
|
LOST_EDGE_API inline float GetDefaultVoicesVolume() const; // UFUNCTION doesn't support constexpr functions
|
||||||
UFUNCTION(BlueprintPure, Category = Settings)
|
UFUNCTION(BlueprintPure, Category = Settings)
|
||||||
float GetDefaultMenuVolume() const; // UFUNCTION doesn't support constexpr functions
|
LOST_EDGE_API inline float GetDefaultMenuVolume() const; // UFUNCTION doesn't support constexpr functions
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure, Category = Settings)
|
UFUNCTION(BlueprintPure, Category = Settings)
|
||||||
float GetMasterVolume() const;
|
float GetMasterVolume() const;
|
||||||
@ -89,6 +69,28 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable, Category = Settings)
|
UFUNCTION(BlueprintCallable, Category = Settings)
|
||||||
void SetMenuVolume(float value);
|
void SetMenuVolume(float value);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Game */
|
||||||
|
UFUNCTION(BlueprintPure, Category = Settings)
|
||||||
|
LOST_EDGE_API inline float GetDefaultMouseSensetivity() const;
|
||||||
|
/** Returns mouse sensetivity multiplier in [0.1 - 2.0] */
|
||||||
|
UFUNCTION(BlueprintPure, Category = Settings)
|
||||||
|
float GetMouseSensetivity() const;
|
||||||
|
/**
|
||||||
|
* Sets mouse sensetivity multiplier
|
||||||
|
* @param value [0.1 - 2.0]
|
||||||
|
*/
|
||||||
|
UFUNCTION(BlueprintCallable, Category = Settings)
|
||||||
|
void SetMouseSensetivity(float value);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintPure, Category = Settings)
|
||||||
|
LOST_EDGE_API inline bool GetDefaultMouseInverted() const;
|
||||||
|
UPROPERTY(Config, BlueprintReadWrite)
|
||||||
|
bool bMouseInverted;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UPROPERTY(Config)
|
UPROPERTY(Config)
|
||||||
float fMouseSensetivity;
|
float fMouseSensetivity;
|
||||||
|
@ -4,34 +4,294 @@
|
|||||||
|
|
||||||
#include "GenericPlatform/GenericApplication.h"
|
#include "GenericPlatform/GenericApplication.h"
|
||||||
|
|
||||||
|
#include "CommonFunctions.h"
|
||||||
|
#include "CustomGameSettings.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const FIntPoint ipDefaultWindowPosition = { 0, 0 };
|
||||||
|
constexpr int32 iDefaultMonitorId = 0;
|
||||||
|
const FIntPoint ipDefaultResolution = { 1920, 1080 };
|
||||||
|
constexpr float fDefaultResolutionScale = 1.0f;
|
||||||
|
constexpr int32 iDefaultFrameRateLimit = 120;
|
||||||
|
}
|
||||||
|
|
||||||
|
FIntPoint UGraphicsSettingsHelper::GetDefaultWindowPosition([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
return ipDefaultWindowPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
FIntPoint UGraphicsSettingsHelper::GetWindowPosition([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
if(GEngine && GEngine->GameViewport)
|
||||||
|
{
|
||||||
|
if(auto window = GEngine->GameViewport->GetWindow())
|
||||||
|
{
|
||||||
|
auto pos = window->GetPositionInScreen();
|
||||||
|
return { (int32)pos.X, (int32)pos.Y };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetDefaultWindowPosition(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UGraphicsSettingsHelper::SetWindowPosition([[maybe_unused]] UCustomGameSettings* settings, const FIntPoint& pos)
|
||||||
|
{
|
||||||
|
if(settings && GEngine && GEngine->GameViewport)
|
||||||
|
{
|
||||||
|
if(auto window = GEngine->GameViewport->GetWindow())
|
||||||
|
{
|
||||||
|
window->MoveWindowTo(pos);
|
||||||
|
settings->SetWindowPosition(pos.X, pos.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 UGraphicsSettingsHelper::GetDefaultMonitorId([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
return iDefaultMonitorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 UGraphicsSettingsHelper::GetMonitorId([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
int32 currentWidth = 0;
|
||||||
|
if(GEngine && GEngine->GameViewport)
|
||||||
|
currentWidth = GEngine->GameViewport->GetWindow()->GetPositionInScreen().X;
|
||||||
|
|
||||||
|
auto monitors = GetAvailableMonitors();
|
||||||
|
|
||||||
|
int32 i = 0;
|
||||||
|
for(; i < monitors.Num(); ++i)
|
||||||
|
{
|
||||||
|
if(currentWidth <= monitors[i].NativeWidth)
|
||||||
|
return i;
|
||||||
|
else
|
||||||
|
currentWidth -= monitors[i].NativeWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetDefaultMonitorId(settings);
|
||||||
|
}
|
||||||
|
|
||||||
int32 UGraphicsSettingsHelper::GetPrimaryMonitorId()
|
int32 UGraphicsSettingsHelper::GetPrimaryMonitorId()
|
||||||
{
|
{
|
||||||
FDisplayMetrics FDM;
|
auto monitors = GetAvailableMonitors();
|
||||||
FDisplayMetrics::GetMonitorsInfo(FDM);
|
for(int32 i = 0; i < monitors.Num(); i++)
|
||||||
TArray<FMonitorInfo> buffer;
|
|
||||||
for(const FMonitorInfo& i : FDM.MonitorInfo)
|
|
||||||
{
|
|
||||||
buffer.Add(FMonitorInfo(i.Name, i.ID, i.NativeWidth, i.NativeHeight,
|
|
||||||
FPlatformRectangle(i.DisplayRect.Left, i.DisplayRect.Top, i.DisplayRect.Right, i.DisplayRect.Bottom),
|
|
||||||
FPlatformRectangle(i.WorkArea.Left, i.WorkArea.Top, i.WorkArea.Right, i.WorkArea.Bottom),
|
|
||||||
i.bIsPrimary, i.DPI));
|
|
||||||
}
|
|
||||||
monitors = buffer;
|
|
||||||
TArray<FMonitorInfo> monitors = GetAvailableMonitors();
|
|
||||||
for(int i = 0; i < monitors.Num(); i++)
|
|
||||||
if(monitors[i].bIsPrimary)
|
if(monitors[i].bIsPrimary)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
|
return GetDefaultMonitorId(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 UGraphicsSettingsHelper::GetCurrentMonitorId()
|
TArray<FString> UGraphicsSettingsHelper::GetAvailableMonitorsNames()
|
||||||
{
|
{
|
||||||
return int32();
|
TArray<FString> names;
|
||||||
|
auto monitors = GetAvailableMonitors();
|
||||||
|
for(auto& m : monitors)
|
||||||
|
names.Add(m.ID);
|
||||||
|
|
||||||
|
return MoveTemp(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TArray<FMonitorInfo> UGraphicsSettingsHelper::GetAvailableMonitors()
|
TArray<FMonitorInfo> UGraphicsSettingsHelper::GetAvailableMonitors()
|
||||||
//{
|
{
|
||||||
// return TArray<FMonitorInfo>();
|
FDisplayMetrics FDM;
|
||||||
//}
|
FDisplayMetrics::RebuildDisplayMetrics(FDM);
|
||||||
|
return MoveTemp(FDM.MonitorInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UGraphicsSettingsHelper::SetMonitor(UCustomGameSettings* settings, const int32 id)
|
||||||
|
{
|
||||||
|
auto monitors = GetAvailableMonitors();
|
||||||
|
if(id >= monitors.Num())
|
||||||
|
return;
|
||||||
|
|
||||||
|
int32 windowNewX = 0.0f;
|
||||||
|
for(int32 i = 0; i < id; ++i)
|
||||||
|
windowNewX += monitors[i].NativeWidth;
|
||||||
|
|
||||||
|
FIntPoint currentRes = GEngine->GameViewport->Viewport->GetSizeXY();
|
||||||
|
FIntPoint nativeRes = FIntPoint{ monitors[id].NativeWidth, monitors[id].NativeHeight };
|
||||||
|
|
||||||
|
SetWindowPosition(settings, FIntPoint{
|
||||||
|
(nativeRes.X - currentRes.X) / 2 + windowNewX,
|
||||||
|
(nativeRes.Y - currentRes.Y) / 2
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
FIntPoint UGraphicsSettingsHelper::GetDefaultResolution([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
return ipDefaultResolution;
|
||||||
|
}
|
||||||
|
|
||||||
|
FIntPoint UGraphicsSettingsHelper::GetResolution([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
if(GEngine
|
||||||
|
&& GEngine->GameViewport
|
||||||
|
&& GEngine->GameViewport->Viewport)
|
||||||
|
return GEngine->GameViewport->Viewport->GetSizeXY();
|
||||||
|
|
||||||
|
return GetNativeResolutionByMonitorId(GetMonitorId(settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
FIntPoint UGraphicsSettingsHelper::GetNativeResolutionByMonitorId(const int32 id)
|
||||||
|
{
|
||||||
|
auto monitors = GetAvailableMonitors();
|
||||||
|
if(id < monitors.Num())
|
||||||
|
return { monitors[id].NativeWidth, monitors[id].NativeHeight };
|
||||||
|
|
||||||
|
return GetDefaultResolution(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
TArray<FResolutionAndRefreshRates> UGraphicsSettingsHelper::GetAllAvailableResolutionsAndRefreshRates()
|
||||||
|
{
|
||||||
|
TArray<FScreenResolutionRHI> buffer;
|
||||||
|
if(!RHIGetAvailableResolutions(buffer, false) || buffer.Num() == 0)
|
||||||
|
return { {GetResolution(nullptr), {GetDefaultFrameRateLimit(nullptr)}} };
|
||||||
|
|
||||||
|
TArray<FResolutionAndRefreshRates> result = {};
|
||||||
|
int32 lastWidth = 0;
|
||||||
|
int32 lastHeight = 0;
|
||||||
|
for(auto& i : buffer)
|
||||||
|
{
|
||||||
|
if(lastWidth != i.Width || lastHeight != i.Height)
|
||||||
|
{
|
||||||
|
result.Add({ {static_cast<int32>(i.Width), static_cast<int32>(i.Height)}, {static_cast<int32>(i.RefreshRate)} });
|
||||||
|
lastHeight = i.Height;
|
||||||
|
lastWidth = i.Width;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result[result.Num() - 1].refreshRates.Add(static_cast<int32>(i.RefreshRate));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MoveTemp(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
TArray<FIntPoint> UGraphicsSettingsHelper::GetAllAvailableResolutions()
|
||||||
|
{
|
||||||
|
TArray<FScreenResolutionRHI> buffer;
|
||||||
|
if(!RHIGetAvailableResolutions(buffer, false) || buffer.Num() == 0)
|
||||||
|
return { {GetResolution(nullptr), {GetDefaultFrameRateLimit(nullptr)}} };
|
||||||
|
|
||||||
|
TArray<FIntPoint> result;
|
||||||
|
int32 lastWidth = 0;
|
||||||
|
int32 lastHeight = 0;
|
||||||
|
for(auto& i : buffer)
|
||||||
|
{
|
||||||
|
if(lastWidth != i.Width || lastHeight != i.Height)
|
||||||
|
{
|
||||||
|
result.Add({ static_cast<int32>(i.Width), static_cast<int32>(i.Height) });
|
||||||
|
lastHeight = i.Height;
|
||||||
|
lastWidth = i.Width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MoveTemp(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
TArray<FIntPoint> UGraphicsSettingsHelper::GetAvailableResolutionsByMonitorId(const int32 id)
|
||||||
|
{
|
||||||
|
TArray<FIntPoint> result;
|
||||||
|
|
||||||
|
FIntPoint nativeRes = GetNativeResolutionByMonitorId(id);
|
||||||
|
for(auto& i : GetAllAvailableResolutions())
|
||||||
|
{
|
||||||
|
if(i.X > nativeRes.X && i.Y > nativeRes.Y)
|
||||||
|
continue;
|
||||||
|
result.Add(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return MoveTemp(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
TArray<FIntPoint> UGraphicsSettingsHelper::FilterResolutionsViaAspectRatio(const TArray<FIntPoint>& resolutions, const FIntPoint& aspectRatio)
|
||||||
|
{
|
||||||
|
TArray<FIntPoint> result;
|
||||||
|
|
||||||
|
for(FIntPoint i : resolutions)
|
||||||
|
if(i.X % aspectRatio.X == 0 && i.Y % aspectRatio.Y == 0)
|
||||||
|
result.Add(i);
|
||||||
|
|
||||||
|
return MoveTemp(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UGraphicsSettingsHelper::SetResolution(UCustomGameSettings* settings, const FIntPoint& resolution)
|
||||||
|
{
|
||||||
|
if(!settings)
|
||||||
|
return;
|
||||||
|
|
||||||
|
settings->bUseDynamicResolution = true;
|
||||||
|
settings->SetScreenResolution(resolution);
|
||||||
|
}
|
||||||
|
|
||||||
|
float UGraphicsSettingsHelper::GetDefaultResolutionScale([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
return fDefaultResolutionScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
float UGraphicsSettingsHelper::GetResolutionScale([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
if(auto settings = UCustomGameSettings::Get())
|
||||||
|
return settings->GetResolutionScaleNormalized();
|
||||||
|
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UGraphicsSettingsHelper::SetResolutionScale(UCustomGameSettings* settings, const float resolutionScale)
|
||||||
|
{
|
||||||
|
if(!settings)
|
||||||
|
return;
|
||||||
|
|
||||||
|
settings->SetResolutionScaleNormalized(resolutionScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 UGraphicsSettingsHelper::GetDefaultFrameRateLimit([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
return iDefaultFrameRateLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
TArray<int32> UGraphicsSettingsHelper::GetAvailableFrameRateLimitsForResolution(const FIntPoint& resolution)
|
||||||
|
{
|
||||||
|
auto resAndRates = GetAllAvailableResolutionsAndRefreshRates();
|
||||||
|
for(auto& i : resAndRates)
|
||||||
|
if(i.resolution == resolution)
|
||||||
|
return MoveTemp(i.refreshRates);
|
||||||
|
|
||||||
|
return { GetDefaultFrameRateLimit(nullptr) };
|
||||||
|
}
|
||||||
|
|
||||||
|
FIntPoint UGraphicsSettingsHelper::GetDefaultAspectRatio([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
return GetAspectRatioFromResolution(GetDefaultResolution(settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
FIntPoint UGraphicsSettingsHelper::GetAspectRatio([[maybe_unused]] UCustomGameSettings* settings)
|
||||||
|
{
|
||||||
|
return GetAspectRatioFromResolution(GetResolution(settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
FIntPoint UGraphicsSettingsHelper::GetAspectRatioFromResolution(const FIntPoint& resolution)
|
||||||
|
{
|
||||||
|
int32 gcd = UCommonFunctions::GreatestCommonDivisor(resolution.X, resolution.Y);
|
||||||
|
return { resolution.X / gcd, resolution.Y / gcd };
|
||||||
|
}
|
||||||
|
|
||||||
|
FIntPoint UGraphicsSettingsHelper::GetAspectRatioOfMonitor(const int32 monitor)
|
||||||
|
{
|
||||||
|
return GetAspectRatioFromResolution(GetNativeResolutionByMonitorId(monitor));
|
||||||
|
}
|
||||||
|
|
||||||
|
TArray<FIntPoint> UGraphicsSettingsHelper::GetAvailableAspectRatiousOfMonitor(const int32 monitor)
|
||||||
|
{
|
||||||
|
TArray<FIntPoint> resolutions = GetAvailableResolutionsByMonitorId(monitor);
|
||||||
|
if(resolutions.Num() == 0)
|
||||||
|
return { GetAspectRatio(nullptr) };
|
||||||
|
|
||||||
|
TSet<FIntPoint> aspects;
|
||||||
|
for(auto& i : resolutions)
|
||||||
|
aspects.Add(GetAspectRatioFromResolution(i));
|
||||||
|
return aspects.Array();
|
||||||
|
}
|
||||||
|
|
||||||
void UGraphicsSettingsHelper::SetMonitor(int32 id)
|
|
||||||
{}
|
|
||||||
|
@ -6,18 +6,108 @@
|
|||||||
|
|
||||||
#include "GraphicsSettingsHelper.generated.h"
|
#include "GraphicsSettingsHelper.generated.h"
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType, Category = "Settings|Graphics|Structs")
|
||||||
|
struct FResolutionAndRefreshRates
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
FIntPoint resolution;
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
TArray<int32> refreshRates;
|
||||||
|
};
|
||||||
|
|
||||||
|
UENUM(BlueprintType, Category = "Settings|Graphics|Enums")
|
||||||
|
enum class EDisplayMode : uint8
|
||||||
|
{
|
||||||
|
Fullscreen = 0,
|
||||||
|
Borderless = 1,
|
||||||
|
Windowed = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper for trivial and complex graphic settings.
|
||||||
|
* Most of functions work without settings pointer. It is there just for Blueprint call convinience.
|
||||||
|
* Helps with window position, monitor selection, resolution, resolution scale, frame rate limit, aspect ratio,
|
||||||
|
* display mode and gamma.
|
||||||
|
*/
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class UGraphicsSettingsHelper : public UBlueprintFunctionLibrary
|
class UGraphicsSettingsHelper : public UBlueprintFunctionLibrary
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UFUNCTION(BlueprintPure, Category = GraphicsSettingsHelper)
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Window")
|
||||||
|
static FIntPoint GetDefaultWindowPosition(class UCustomGameSettings* settings); // inline functions need API macro, but API macro with static inline function results in "no definition"
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Window")
|
||||||
|
static FIntPoint GetWindowPosition(class UCustomGameSettings* settings);
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Settings|Graphics|Window")
|
||||||
|
static void SetWindowPosition(class UCustomGameSettings* settings, const FIntPoint& pos);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Monitor")
|
||||||
|
static int32 GetDefaultMonitorId(class UCustomGameSettings* settings);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Monitor")
|
||||||
|
static int32 GetMonitorId(class UCustomGameSettings* settings);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Monitor")
|
||||||
static int32 GetPrimaryMonitorId();
|
static int32 GetPrimaryMonitorId();
|
||||||
UFUNCTION(BlueprintPure, Category = GraphicsSettingsHelper)
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Monitor")
|
||||||
static int32 GetCurrentMonitorId();
|
static TArray<FString> GetAvailableMonitorsNames();
|
||||||
//UFUNCTION(BlueprintPure, Category = GraphicsSettingsHelper)
|
static TArray<FMonitorInfo> GetAvailableMonitors();
|
||||||
//static TArray<FMonitorInfo> GetAvailableMonitors();
|
UFUNCTION(BlueprintCallable, Category = "Settings|Graphics|Monitor")
|
||||||
UFUNCTION(BlueprintCallable, Category = GraphicsSettingsHelper)
|
static void SetMonitor(class UCustomGameSettings* settings, const int32 id);
|
||||||
static void SetMonitor(int32 id);
|
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Resolution")
|
||||||
|
static FIntPoint GetDefaultResolution(class UCustomGameSettings* settings);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Resolution")
|
||||||
|
static FIntPoint GetResolution(class UCustomGameSettings* settings);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Resolution")
|
||||||
|
static FIntPoint GetNativeResolutionByMonitorId(const int32 id);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics")
|
||||||
|
static TArray<FResolutionAndRefreshRates> GetAllAvailableResolutionsAndRefreshRates();
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Resolution")
|
||||||
|
static TArray<FIntPoint> GetAllAvailableResolutions();
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Resolution")
|
||||||
|
static TArray<FIntPoint> GetAvailableResolutionsByMonitorId(const int32 id);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Resolution")
|
||||||
|
static TArray<FIntPoint> FilterResolutionsViaAspectRatio(const TArray<FIntPoint>& resolutions, const FIntPoint& aspectRatio);
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Settings|Graphics|Resolution")
|
||||||
|
static void SetResolution(class UCustomGameSettings* settings, const FIntPoint& resolution);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Resolution Scale")
|
||||||
|
static float GetDefaultResolutionScale(class UCustomGameSettings* settings);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Resolution Scale")
|
||||||
|
static float GetResolutionScale(class UCustomGameSettings* settings);
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "Settings|Graphics|Resolution Scale")
|
||||||
|
static void SetResolutionScale(class UCustomGameSettings* settings, const float resolutionScale);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Frame Rate Limit")
|
||||||
|
static int32 GetDefaultFrameRateLimit(class UCustomGameSettings* settings);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Frame Rate Limit")
|
||||||
|
static TArray<int32> GetAvailableFrameRateLimitsForResolution(const FIntPoint& resolution);
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Aspect Ratio")
|
||||||
|
static FIntPoint GetDefaultAspectRatio(class UCustomGameSettings* settings);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Aspect Ratio")
|
||||||
|
static FIntPoint GetAspectRatio(class UCustomGameSettings* settings);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Aspect Ratio")
|
||||||
|
static FIntPoint GetAspectRatioFromResolution(const FIntPoint& resolution);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Aspect Ratio")
|
||||||
|
static FIntPoint GetAspectRatioOfMonitor(const int32 monitor);
|
||||||
|
UFUNCTION(BlueprintPure, Category = "Settings|Graphics|Aspect Ratio")
|
||||||
|
static TArray<FIntPoint> GetAvailableAspectRatiousOfMonitor(const int32 monitor);
|
||||||
|
|
||||||
|
//UFUNCTION(BlueprintPure, Category = "Settings Video|Display Mode")
|
||||||
|
//static EDisplayMode StringToDisplayMode(FString in);
|
||||||
|
//UFUNCTION(BlueprintPure, Category = "Settings Video|Display Mode")
|
||||||
|
//static FString DisplayModeToString(EDisplayMode mode);
|
||||||
|
//UFUNCTION(BlueprintPure, Category = "Settings Video|Display Mode")
|
||||||
|
//static void IntToDisplayMode(int in, EDisplayMode& mode);
|
||||||
|
//UFUNCTION(BlueprintPure, Category = "Settings Video|Display Mode")
|
||||||
|
//static void DisplayModeToInt(EDisplayMode mode, int& out);
|
||||||
|
//UFUNCTION(BlueprintPure, Category = "Settings Video|Display Mode")
|
||||||
|
//static void GetCurrentDisplayMode(EDisplayMode& mode);
|
||||||
|
//UFUNCTION(BlueprintCallable, Category = "Settings Video|Display Mode")
|
||||||
|
//static void SetDisplayMode(EDisplayMode mode);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user