Fries
9fdf16c557
i added a vsync option to the settings that lets you pick a vsync option that maps to the engines vsync enum. so you can either enable, disable it, turn it to adapt mode, or mailbox mode.
39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
namespace Pong.Scripts.Managers.UI;
|
|
|
|
public partial class BaseMenu : VBoxContainer
|
|
{
|
|
private SettingsManager _settingsManager;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
_settingsManager = GetNode<SettingsManager>("/root/SettingsManager");
|
|
_settingsManager.SettingsChanged += SettingsChanged;
|
|
GetTree().Root.SizeChanged += AdaptUiToGameResolution;
|
|
AdaptUiToGameResolution();
|
|
}
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
GetTree().Root.SizeChanged -= AdaptUiToGameResolution;
|
|
_settingsManager.SettingsChanged -= SettingsChanged;
|
|
}
|
|
|
|
/// <summary>
|
|
/// method that fires when the settings get changed.
|
|
/// </summary>
|
|
private void SettingsChanged()
|
|
{
|
|
AdaptUiToGameResolution();
|
|
DisplayServer.WindowSetVsyncMode((DisplayServer.VSyncMode)_settingsManager.SettingsData.VSync);
|
|
}
|
|
|
|
/// <summary>
|
|
/// change the size of the UI container to the current resolution of the game.
|
|
/// </summary>
|
|
private void AdaptUiToGameResolution()
|
|
{
|
|
var scale = _settingsManager.SettingsData.Scale;
|
|
Size = (Vector2)DisplayServer.WindowGetSize() / scale;
|
|
Scale = new Vector2(scale, scale);
|
|
}
|
|
}
|