Fries
425bf2ad27
i added more to the main menu, as it has a settings menu now, that stores its files with json. i also changed the font to atkinson hyperlegible and made a BaseMenu class that takes care of the screen scaling for menus. i also refactored the project folder structure to make it more organized.
43 lines
991 B
C#
43 lines
991 B
C#
using Godot;
|
|
|
|
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);
|
|
}
|
|
}
|