refactor: moved font loading to label
This commit is contained in:
		
							
								
								
									
										2
									
								
								Engine
									
									
									
									
									
								
							
							
								
								
								
								
								
							
						
						
									
										2
									
								
								Engine
									
									
									
									
									
								
							 Submodule Engine updated: ad365dc722...37aca44e45
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
using Microsoft.Xna.Framework;
 | 
					using Microsoft.Xna.Framework.Content;
 | 
				
			||||||
using Microsoft.Xna.Framework.Graphics;
 | 
					using Microsoft.Xna.Framework.Graphics;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using Syntriax.Engine.Core;
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
@@ -6,9 +6,10 @@ using Syntriax.Engine.Integration.MonoGame;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace Pong.Behaviours;
 | 
					namespace Pong.Behaviours;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Label : Behaviour2D, IDrawableSprite
 | 
					public class Label : Behaviour2D, IDrawableSprite, ILoadContent
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public SpriteFont? Font { get; set; } = null;
 | 
					    public SpriteFont? Font { get; set; } = null;
 | 
				
			||||||
 | 
					    public ColorRGBA Color { get; set; } = new ColorRGBA(255, 255, 255, 255);
 | 
				
			||||||
    public int Size { get; set; } = 16;
 | 
					    public int Size { get; set; } = 16;
 | 
				
			||||||
    public string Text { get; set; } = string.Empty;
 | 
					    public string Text { get; set; } = string.Empty;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -17,7 +18,12 @@ public class Label : Behaviour2D, IDrawableSprite
 | 
				
			|||||||
        if (Font is null)
 | 
					        if (Font is null)
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        spriteBatch.DrawString(Font, Text, Transform.Position, Color.White, Transform.Rotation, Vector2D.One * .5f, Transform.Scale.Magnitude, SpriteEffects.None, 0f);
 | 
					        spriteBatch.DrawString(Font, Text, Transform.Position, Color.ToPreMultipliedColor(), Transform.Rotation, Vector2D.One * .5f, Transform.Scale.Magnitude, SpriteEffects.None, 0f);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void LoadContent(ContentManager content)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        Font ??= content.Load<SpriteFont>("UbuntuMono");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Label() { }
 | 
					    public Label() { }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,8 @@
 | 
				
			|||||||
using Microsoft.Xna.Framework.Content;
 | 
					 | 
				
			||||||
using Microsoft.Xna.Framework.Graphics;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
using Syntriax.Engine.Core;
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
using Syntriax.Engine.Integration.MonoGame;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Pong.Behaviours;
 | 
					namespace Pong.Behaviours;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ScoreLabel(bool IsLeft) : Label, IFirstFrameUpdate, ILoadContent
 | 
					public class ScoreLabel(bool IsLeft) : Label, IFirstFrameUpdate
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public readonly bool IsLeft = IsLeft;
 | 
					    public readonly bool IsLeft = IsLeft;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -22,11 +18,6 @@ public class ScoreLabel(bool IsLeft) : Label, IFirstFrameUpdate, ILoadContent
 | 
				
			|||||||
        UpdateScores(pongManager);
 | 
					        UpdateScores(pongManager);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void LoadContent(ContentManager content)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        Font = content.Load<SpriteFont>("UbuntuMono");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    private void UpdateScores(PongManager pongManager)
 | 
					    private void UpdateScores(PongManager pongManager)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (IsLeft)
 | 
					        if (IsLeft)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user