From 0ca55875c77444a5d150b7ccf16db4feb48014fb Mon Sep 17 00:00:00 2001 From: polten0 Date: Tue, 15 Aug 2023 14:23:44 +0300 Subject: [PATCH] finishedFirstIterationOfLoginGUI --- DangerousD/Content/Content.mgcb | 20 +++-- DangerousD/Content/Font2.spritefont | 60 +++++++++++++ DangerousD/GameCore/GUI/LoginGUI.cs | 89 ++++++++++++++++++- DangerousD/GameCore/Managers/AppManager.cs | 5 +- .../UI/Base/DrawableTextedUiElement.cs | 6 +- MonogameLibrary/UI/Base/DrawableUIElement.cs | 4 +- 6 files changed, 171 insertions(+), 13 deletions(-) create mode 100644 DangerousD/Content/Font2.spritefont diff --git a/DangerousD/Content/Content.mgcb b/DangerousD/Content/Content.mgcb index a02f5aa..2c394eb 100644 --- a/DangerousD/Content/Content.mgcb +++ b/DangerousD/Content/Content.mgcb @@ -13,6 +13,20 @@ #---------------------------------- Content ---------------------------------# +#begin Font.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:Font.spritefont + +#begin Font2.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:Font2.spritefont + #begin wall.jpg /importer:TextureImporter /processor:TextureProcessor @@ -24,10 +38,4 @@ /processorParam:MakeSquare=False /processorParam:TextureFormat=Color /build:wall.jpg -#begin Font.spritefont -/importer:FontDescriptionImporter -/processor:FontDescriptionProcessor -/processorParam:PremultiplyAlpha=True -/processorParam:TextureFormat=Compressed -/build:Font.spritefont diff --git a/DangerousD/Content/Font2.spritefont b/DangerousD/Content/Font2.spritefont new file mode 100644 index 0000000..03b6450 --- /dev/null +++ b/DangerousD/Content/Font2.spritefont @@ -0,0 +1,60 @@ + + + + + + + Josefin Sans + + + 100 + + + 0 + + + true + + + + + + + + + + + + ~ + + + + diff --git a/DangerousD/GameCore/GUI/LoginGUI.cs b/DangerousD/GameCore/GUI/LoginGUI.cs index 311c480..16d64d4 100644 --- a/DangerousD/GameCore/GUI/LoginGUI.cs +++ b/DangerousD/GameCore/GUI/LoginGUI.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.Xna.Framework; using MonogameLibrary.UI.Elements; +using MonogameLibrary.UI.Enums; namespace DangerousD.GameCore.GUI { @@ -13,7 +14,93 @@ namespace DangerousD.GameCore.GUI { protected override void CreateUI() { - Elements.Add(new Label(Manager) { rectangle = new Rectangle(AppManager.Instance.resolution.X / 2, AppManager.Instance.resolution.Y / 2, 100, 50) }); + int screenWidth = AppManager.Instance.resolution.X; + int screenHeight = AppManager.Instance.resolution.Y; + + Elements.Add(new Label(Manager) { + rectangle = new Rectangle(screenWidth / 2 - 250, screenHeight / 6 - 50, 500, 100), + text = "Login", + scale = 0.8f, + fontColor = Color.White, + mainColor = Color.Transparent, + fontName = "font2" + }); + + // TextBox-ы + { + TextBox loginTextBox = new TextBox(Manager) + { + rectangle = new Rectangle(screenWidth / 2 - 125, screenHeight / 6 * 2 - 20, 250, 40), + text = "NickName", + scale = 0.16f, + fontColor = Color.Gray, + fontName = "font2", + textAligment = TextAligment.Left + }; + loginTextBox.TextChanged += input => { + if (loginTextBox.fontColor == Color.Gray) + { + loginTextBox.text = ""; loginTextBox.fontColor = Color.Black; + } + }; + + TextBox passwordTextBox = new TextBox(Manager) + { + rectangle = new Rectangle(screenWidth / 2 - 125, screenHeight / 6 * 3 - 40, 250, 40), + text = "Password", + scale = 0.16f, + fontColor = Color.Gray, + fontName = "font2", + textAligment = TextAligment.Left + }; + passwordTextBox.TextChanged += input => { + if (passwordTextBox.fontColor == Color.Gray) + { + passwordTextBox.text = ""; passwordTextBox.fontColor = Color.Black; + } + }; + } + + // Кнопки + { + Button logButton = new Button(Manager) { + rectangle = new Rectangle(screenWidth / 4 + 50, screenHeight / 6 * 4, 100, 50), + text = "LogIn", + scale = 0.2f, + fontColor = Color.Black, + fontName = "font2" + }; + logButton.LeftButtonPressed += () => { + AppManager.Instance.ChangeGameState(GameState.Lobby); + }; + + Button regButton = new Button(Manager) + { + rectangle = new Rectangle(screenWidth / 4 * 2 + 50, screenHeight / 6 * 4, 100, 50), + text = "Reg", + scale = 0.2f, + fontColor = Color.Black, + fontName = "font2" + }; + regButton.LeftButtonPressed += GoToRegWebServer; + + Button backButton = new Button(Manager) + { + rectangle = new Rectangle(screenWidth / 20, screenHeight / 15, 50, 50), + text = "<-", + scale = 0.3f, + fontColor = Color.Black, + fontName = "font2" + }; + backButton.LeftButtonPressed += () => { + AppManager.Instance.ChangeGameState(GameState.Menu); + }; + } + } + + private void GoToRegWebServer() + { + // TODO } } } diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 4c6ec74..0a162d5 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -35,13 +35,15 @@ namespace DangerousD.GameCore resolution = new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight); GameManager = new GameManager(); - gameState = GameState.Menu; + gameState = GameState.Login; MenuGUI = new MenuGUI(); + LoginGUI = new LoginGUI(); } protected override void Initialize() { MenuGUI.Initialize(GraphicsDevice); + LoginGUI.Initialize(GraphicsDevice); base.Initialize(); } @@ -49,6 +51,7 @@ namespace DangerousD.GameCore { _spriteBatch = new SpriteBatch(GraphicsDevice); MenuGUI.LoadContent(); + LoginGUI.LoadContent(); } protected override void Update(GameTime gameTime) diff --git a/MonogameLibrary/UI/Base/DrawableTextedUiElement.cs b/MonogameLibrary/UI/Base/DrawableTextedUiElement.cs index 2527ccc..0d64052 100644 --- a/MonogameLibrary/UI/Base/DrawableTextedUiElement.cs +++ b/MonogameLibrary/UI/Base/DrawableTextedUiElement.cs @@ -13,7 +13,7 @@ namespace MonogameLibrary.UI.Base public class DrawableTextedUiElement : DrawableUIElement { protected SpriteFont spriteFont; - protected string fontName; + public string fontName; public string text = ""; public float scale = 0.5f; public Color fontColor = Color.Black; @@ -57,11 +57,11 @@ namespace MonogameLibrary.UI.Base spriteBatch.DrawString(spriteFont, text, pos, fontColor, 0, Vector2.Zero, scale, SpriteEffects.None, 0); } - else if (textAligment == TextAligment.Center) + else if (textAligment == TextAligment.Left) { Vector2 pos = rectangle.Location.ToVector2(); pos.Y += (int)((rectangle.Height - measured.Y) / 2); - pos.X += (int)(2 * scale); + pos.X += (int)(2 * scale + rectangle.Width / 20); spriteBatch.DrawString(spriteFont, text, pos, fontColor, 0, Vector2.Zero, scale, SpriteEffects.None, 0); } diff --git a/MonogameLibrary/UI/Base/DrawableUIElement.cs b/MonogameLibrary/UI/Base/DrawableUIElement.cs index b751308..54a0db5 100644 --- a/MonogameLibrary/UI/Base/DrawableUIElement.cs +++ b/MonogameLibrary/UI/Base/DrawableUIElement.cs @@ -30,7 +30,7 @@ namespace MonogameLibrary.UI.Base if (textureName == "") { texture = new Texture2D(Manager.GraphicsDevice, 1, 1); - texture.SetData(new Color[] { Color.White }); + texture.SetData(new Color[] { mainColor }); } else { @@ -41,7 +41,7 @@ namespace MonogameLibrary.UI.Base catch { texture = new Texture2D(Manager.GraphicsDevice, 1, 1); - texture.SetData(new Color[] { Color.White }); + texture.SetData(new Color[] { mainColor }); } } }