Pong/Scripts/Managers/UI/BaseMenu.cs
Fries 604d79e654 the paddle can now scale to the resolution
i added a GameArea class which makes it easier to operate on in coordinates bounds with the GameCoordinate struct wrapper which does calculations for me. the GameArea class also has a normalization system which is how the ScalingManager can teleport items in bounds to relatively the same place when resized.

it took quite a while to get the paddle to teleport. looks like im supposed to modify the position inside IntegrateForces instead of PhysicsProcess which is my mistake.
2023-05-23 00:21:54 -07:00

41 lines
977 B
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 += AdaptUiToGameResolution;
GetTree().Root.SizeChanged += AdaptUiToGameResolution;
AdaptUiToGameResolution();
EnterTree();
}
public override void _ExitTree()
{
GetTree().Root.SizeChanged -= AdaptUiToGameResolution;
_settingsManager.SettingsChanged -= AdaptUiToGameResolution;
ExitTree();
}
protected virtual void EnterTree()
{
}
protected virtual void ExitTree()
{
}
/// <summary>
/// change the size of the UI container to the current resolution of the game.
/// </summary>
protected void AdaptUiToGameResolution()
{
var scale = _settingsManager.SettingsData.Scale;
Size = (Vector2)DisplayServer.WindowGetSize() / scale;
Scale = new Vector2(scale, scale);
}
}