steam-deck-tools/PowerControl/Options/FPSLimit.cs
maniman303 3252e799cb PowerControl: Base Profiles Implementation (#38)
Small refactor of menu with options

Fix protection error on menuwithoptions

Make profiles controller non static

Dynamicall set and load options

Use IsOSDForeground when retriveing current game name

Better alt-tab functionality

Get rid off thread.sleep

Merged #38
2023-01-09 20:32:05 +01:00

59 lines
1.9 KiB
C#

using CommonHelpers;
using PowerControl.Helpers;
namespace PowerControl.Options
{
public static class FPSLimit
{
public static Menu.MenuItemWithOptions Instance = new Menu.MenuItemWithOptions()
{
Name = "FPS Limit",
PersistentKey = "FPSLimit",
ApplyDelay = 500,
ResetValue = () => { return "Off"; },
OptionsValues = delegate ()
{
var refreshRate = DisplayResolutionController.GetRefreshRate();
return new string[]
{
(refreshRate / 4).ToString(),
(refreshRate / 2).ToString(),
refreshRate.ToString(),
"Off"
};
},
CurrentValue = delegate ()
{
try
{
RTSS.LoadProfile();
if (RTSS.GetProfileProperty("FramerateLimit", out int framerate))
return (framerate == 0) ? "Off" : framerate.ToString();
}
catch { }
return null;
},
ApplyValue = (selected) =>
{
try
{
int framerate = 0;
if (selected != "Off")
framerate = int.Parse(selected);
RTSS.LoadProfile();
if (!RTSS.SetProfileProperty("FramerateLimit", framerate))
return null;
if (!RTSS.GetProfileProperty("FramerateLimit", out framerate))
return null;
RTSS.SaveProfile();
RTSS.UpdateProfiles();
return (framerate == 0) ? "Off" : framerate.ToString();
}
catch { }
return null;
}
};
}
}