From d05fdd1aa0999a959e6ab95f77fe9b2943c03d0c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 11 Nov 2015 15:02:58 +1100 Subject: [PATCH] Update entity names when default.png changes. --- ClassicalSharp/2D/Screens/ChatScreen.cs | 1 + ClassicalSharp/2D/Screens/FpsScreen.cs | 1 + ClassicalSharp/Entities/EntityList.cs | 14 ++++++++++++++ ClassicalSharp/Entities/Player.Rendering.cs | 14 ++++++++------ ClassicalSharp/Game/Game.cs | 3 ++- ClassicalSharp/TexturePack/TexturePackExtractor.cs | 4 +--- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs index 8adc4f13a..bac8436ee 100644 --- a/ClassicalSharp/2D/Screens/ChatScreen.cs +++ b/ClassicalSharp/2D/Screens/ChatScreen.cs @@ -164,6 +164,7 @@ namespace ClassicalSharp { } void ChatFontChanged( object sender, EventArgs e ) { + if( !game.Drawer2D.UseBitmappedChat ) return; Dispose(); Init(); } diff --git a/ClassicalSharp/2D/Screens/FpsScreen.cs b/ClassicalSharp/2D/Screens/FpsScreen.cs index b179cd4a8..2b62cfb8f 100644 --- a/ClassicalSharp/2D/Screens/FpsScreen.cs +++ b/ClassicalSharp/2D/Screens/FpsScreen.cs @@ -83,6 +83,7 @@ namespace ClassicalSharp { } void ChatFontChanged( object sender, EventArgs e ) { + if( !game.Drawer2D.UseBitmappedChat ) return; Dispose(); Init(); } diff --git a/ClassicalSharp/Entities/EntityList.cs b/ClassicalSharp/Entities/EntityList.cs index bff50d426..16a18b5de 100644 --- a/ClassicalSharp/Entities/EntityList.cs +++ b/ClassicalSharp/Entities/EntityList.cs @@ -8,6 +8,12 @@ namespace ClassicalSharp { public const int MaxCount = 256; public Player[] Players = new Player[MaxCount]; + public Game game; + + public EntityList( Game game ) { + this.game = game; + game.Events.ChatFontChanged += ChatFontChanged; + } /// Performs a tick call for all player entities contained in this list. public void Tick( double delta ) { @@ -42,6 +48,13 @@ namespace ClassicalSharp { api.AlphaTest = false; } + void ChatFontChanged( object sender, EventArgs e ) { + for( int i = 0; i < Players.Length; i++ ) { + if( Players[i] != null ) + Players[i].UpdateNameFont(); + } + } + /// Disposes of all player entities contained in this list. public void Dispose() { for( int i = 0; i < Players.Length; i++ ) { @@ -49,6 +62,7 @@ namespace ClassicalSharp { Players[i].Despawn(); } } + game.Events.ChatFontChanged -= ChatFontChanged; } public byte GetClosetPlayer( LocalPlayer localP ) { diff --git a/ClassicalSharp/Entities/Player.Rendering.cs b/ClassicalSharp/Entities/Player.Rendering.cs index c98a04af9..fc8b5a31c 100644 --- a/ClassicalSharp/Entities/Player.Rendering.cs +++ b/ClassicalSharp/Entities/Player.Rendering.cs @@ -7,27 +7,29 @@ namespace ClassicalSharp { partial class Player { - protected IGraphicsApi api; protected Texture nameTex; protected internal int PlayerTextureId = -1, MobTextureId = -1; internal bool RenderHat = true; public override void Despawn() { - if( api == null ) return; - api.DeleteTexture( ref PlayerTextureId ); - api.DeleteTexture( ref nameTex.ID ); + game.Graphics.DeleteTexture( ref PlayerTextureId ); + game.Graphics.DeleteTexture( ref nameTex.ID ); } protected void InitRenderingData() { - api = game.Graphics; - using( Font font = new Font( "Arial", 14 ) ) { DrawTextArgs args = new DrawTextArgs( DisplayName, font, true ); nameTex = game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ); } } + public void UpdateNameFont() { + game.Graphics.DeleteTexture( ref nameTex ); + InitRenderingData(); + } + protected void DrawName() { + IGraphicsApi api = game.Graphics; api.BindTexture( nameTex.ID ); float x1 = -nameTex.Width * 0.5f / 50f, y1 = nameTex.Height / 50f; diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index ff325eb0e..96630a128 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -22,7 +22,7 @@ namespace ClassicalSharp { public Map Map; public INetworkProcessor Network; - public EntityList Players = new EntityList(); + public EntityList Players; public CpeListInfo[] CpePlayersList = new CpeListInfo[256]; public LocalPlayer LocalPlayer; public Camera Camera; @@ -106,6 +106,7 @@ namespace ClassicalSharp { Graphics = new Direct3D9Api( this ); #endif Graphics.MakeGraphicsInfo(); + Players = new EntityList( this ); Options.Load(); ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 ); diff --git a/ClassicalSharp/TexturePack/TexturePackExtractor.cs b/ClassicalSharp/TexturePack/TexturePackExtractor.cs index 46099f4f6..816612a72 100644 --- a/ClassicalSharp/TexturePack/TexturePackExtractor.cs +++ b/ClassicalSharp/TexturePack/TexturePackExtractor.cs @@ -87,9 +87,7 @@ namespace ClassicalSharp.TexturePack { void SetFontBitmap( Game game, Stream stream ) { game.FontBitmap = new Bitmap( stream ); game.Drawer2D.SetFontBitmap( game.FontBitmap ); - - if( game.Drawer2D.UseBitmappedChat ) - game.Events.RaiseChatFontChanged(); + game.Events.RaiseChatFontChanged(); } void UpdateTexture( ref int texId, Stream stream, bool setSkinType ) {