DangerousD/DangerousD/GameCore/GUI/DeathGUI.cs
2023-08-18 12:39:06 +03:00

45 lines
No EOL
2.2 KiB
C#

using DangerousD.GameCore.Managers;
using Microsoft.Xna.Framework;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements;
using System.Diagnostics;
using System.Runtime.Serialization;
namespace DangerousD.GameCore.GUI;
internal class DeathGUI : AbstractGui
{
protected override void CreateUI()
{
int wigth = AppManager.Instance.inGameResolution.X;
int height = AppManager.Instance.inGameResolution.Y;
float scaler = AppManager.Instance.resolution.Y / (float)AppManager.Instance.inGameHUDHelperResolution.Y;
var menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, wigth, height), textureName = "deathBackground" };
Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content);
Elements.Add(new Label(Manager) { rectangle = new Rectangle((wigth - 50) / 2, (height - 50) / 2 - 80, 50, 50), text = "You died", mainColor = Color.Transparent, scale = 0.7f, fontName = "ButtonFont", fontColor = Color.White });
Elements.Add(new Label(Manager) { rectangle = new Rectangle((wigth - 50) / 2, (height - 50) / 2, 50, 50), text = $"Score: {0}", mainColor = Color.Transparent, scale = 0.7f, fontName = "ButtonFont", fontColor = Color.White });
var butMenu = new ButtonText(Manager) { rectangle = new Rectangle((wigth - 300) / 2, (height - 50) / 2 + 80, 300, 50), text = "Back to menu", scale = 0.7f, fontName = "ButtonFont" };
Elements.Add(butMenu);
butMenu.LeftButtonPressed += () =>
{
AppManager.Instance.ChangeGameState(GameState.Menu);
};
foreach (var item in Elements)
{
item.rectangle.X = (int)(scaler * item.rectangle.X);
item.rectangle.Y = (int)(scaler * item.rectangle.Y);
item.rectangle.Width = (int)(scaler * item.rectangle.Width);
item.rectangle.Height = (int)(scaler * item.rectangle.Height);
if (item is DrawableTextedUiElement)
{
(item as DrawableTextedUiElement).scale *= scaler;
}
}
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
}