diff --git a/ClassicalSharp/2D/Drawing/GdiPlusDrawerFont.cs b/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.Text.cs similarity index 88% rename from ClassicalSharp/2D/Drawing/GdiPlusDrawerFont.cs rename to ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.Text.cs index a06485851..d672660a9 100644 --- a/ClassicalSharp/2D/Drawing/GdiPlusDrawerFont.cs +++ b/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.Text.cs @@ -5,13 +5,14 @@ using ClassicalSharp.GraphicsAPI; namespace ClassicalSharp { - public sealed class GdiPlusDrawerFont : GdiPlusDrawer2D { + public sealed partial class GdiPlusDrawer2D { StringFormat format; Bitmap measuringBmp; Graphics measuringGraphics; - public GdiPlusDrawerFont( IGraphicsApi graphics ) : base( graphics ) { + public GdiPlusDrawer2D( IGraphicsApi graphics ) { + this.graphics = graphics; format = StringFormat.GenericTypographic; format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; format.Trimming = StringTrimming.None; @@ -62,7 +63,7 @@ namespace ClassicalSharp { format.Trimming = StringTrimming.None; } - public override Size MeasureSize( ref DrawTextArgs args ) { + public override Size MeasureSize( ref DrawTextArgs args ) { GetTextParts( args.Text ); SizeF total = SizeF.Empty; for( int i = 0; i < parts.Count; i++ ) { @@ -77,8 +78,7 @@ namespace ClassicalSharp { return Size.Ceiling( total ); } - public override void DisposeInstance() { - base.DisposeInstance(); + void DisposeText() { measuringGraphics.Dispose(); measuringBmp.Dispose(); } diff --git a/ClassicalSharp/2D/Drawing/GdiPlusDrawerMCFont.cs b/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.TextMC.cs similarity index 84% rename from ClassicalSharp/2D/Drawing/GdiPlusDrawerMCFont.cs rename to ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.TextMC.cs index 2761aa415..7c6b5f521 100644 --- a/ClassicalSharp/2D/Drawing/GdiPlusDrawerMCFont.cs +++ b/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.TextMC.cs @@ -4,7 +4,7 @@ using ClassicalSharp.GraphicsAPI; namespace ClassicalSharp { - public unsafe sealed class GdiPlusDrawerMCFont : GdiPlusDrawer2D { + public unsafe sealed partial class GdiPlusDrawer2D { // NOTE: This drawer is still a big work in progress and not close to done // TODO: italic and bold @@ -13,10 +13,7 @@ namespace ClassicalSharp { int boxSize; const int italicSize = 8; - public GdiPlusDrawerMCFont( IGraphicsApi graphics ) : base( graphics ) { - } - - public void SetFontBitmap( Bitmap bmp ) { + public override void SetFontBitmap( Bitmap bmp ) { fontBmp = bmp; boxSize = fontBmp.Width / 16; fontPixels = new FastBitmap( fontBmp, true ); @@ -45,7 +42,7 @@ namespace ClassicalSharp { widths[i] = 0; } - public override void DrawText( ref DrawTextArgs args, int x, int y ) { + public override void DrawBitmappedText( ref DrawTextArgs args, int x, int y ) { if( !args.SkipPartsCheck ) GetTextParts( args.Text ); @@ -106,11 +103,7 @@ namespace ClassicalSharp { } } - public override void DrawClippedText( ref DrawTextArgs args, int x, int y, float maxWidth, float maxHeight ) { - throw new NotImplementedException( "Clipped text not implemented yet with minecraft font" ); - } - - public override Size MeasureSize( ref DrawTextArgs args ) { + public override Size MeasureBitmappedSize( ref DrawTextArgs args ) { GetTextParts( args.Text ); float point = args.Font.Size; Size total = new Size( 0, PtToPx( point, boxSize ) ); @@ -149,8 +142,7 @@ namespace ClassicalSharp { return (int)Math.Ceiling( (value / boxSize) * point / 72f * 96f ); } - public override void DisposeInstance() { - base.DisposeInstance(); + void DisposeBitmappedText() { fontPixels.Dispose(); fontBmp.Dispose(); } diff --git a/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.cs b/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.cs index f0a67b004..3c70d38fc 100644 --- a/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.cs +++ b/ClassicalSharp/2D/Drawing/GdiPlusDrawer2D.cs @@ -3,19 +3,14 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; -using ClassicalSharp.GraphicsAPI; namespace ClassicalSharp { - public abstract class GdiPlusDrawer2D : IDrawer2D { + public sealed partial class GdiPlusDrawer2D : IDrawer2D { - Dictionary brushCache = new Dictionary( 16 ); - - protected Graphics g; - protected Bitmap curBmp; - public GdiPlusDrawer2D( IGraphicsApi graphics ) { - this.graphics = graphics; - } + Dictionary brushCache = new Dictionary( 16 ); + Graphics g; + Bitmap curBmp; public override void SetBitmap( Bitmap bmp ) { if( g != null ) { @@ -87,17 +82,19 @@ namespace ClassicalSharp { } public override void DisposeInstance() { - foreach( var pair in brushCache ) { + foreach( var pair in brushCache ) pair.Value.Dispose(); - } + + DisposeText(); + DisposeBitmappedText(); } - protected SolidBrush GetOrCreateBrush( Color color ) { + SolidBrush GetOrCreateBrush( Color color ) { int key = color.ToArgb(); SolidBrush brush; - if( brushCache.TryGetValue( key, out brush ) ) { + if( brushCache.TryGetValue( key, out brush ) ) return brush; - } + brush = new SolidBrush( color ); brushCache[key] = brush; return brush; diff --git a/ClassicalSharp/2D/Drawing/IDrawer2D.cs b/ClassicalSharp/2D/Drawing/IDrawer2D.cs index cc80da7f4..8fc6e79a1 100644 --- a/ClassicalSharp/2D/Drawing/IDrawer2D.cs +++ b/ClassicalSharp/2D/Drawing/IDrawer2D.cs @@ -16,14 +16,6 @@ namespace ClassicalSharp { /// Sets the underlying bitmap that drawing operations will be performed on. public abstract void SetBitmap( Bitmap bmp ); - /// Draws a string using the specified arguments and fonts at the - /// specified coordinates in the currently bound bitmap. - public abstract void DrawText( ref DrawTextArgs args, int x, int y ); - - /// Draws a string using the specified arguments and fonts at the - /// specified coordinates in the currently bound bitmap, clipping if necessary. - public abstract void DrawClippedText( ref DrawTextArgs args, int x, int y, float maxWidth, float maxHeight ); - /// Draws a 2D flat rectangle of the specified dimensions at the /// specified coordinates in the currently bound bitmap. public abstract void DrawRect( FastColour colour, int x, int y, int width, int height ); @@ -55,30 +47,85 @@ namespace ClassicalSharp { src = newBmp; } + + /// Draws a string using the specified arguments and font at the + /// specified coordinates in the currently bound bitmap. + public abstract void DrawText( ref DrawTextArgs args, int x, int y ); + + /// Draws a string using the specified arguments and fonts at the + /// specified coordinates in the currently bound bitmap, clipping if necessary. + public abstract void DrawClippedText( ref DrawTextArgs args, int x, int y, float maxWidth, float maxHeight ); + + /// Draws a string using the specified arguments and the current bitmapped font at the + /// specified coordinates in the currently bound bitmap. + public abstract void DrawBitmappedText( ref DrawTextArgs args, int x, int y ); + + /// Draws a string using the specified arguments, using the specified font or + /// the current bitmapped font depending on the 'useFont' argument, at the + /// specified coordinates in the currently bound bitmap. + public void DrawChatText( bool useFont, ref DrawTextArgs args, int windowX, int windowY ) { + if( useFont ) + DrawText( ref args, windowX, windowY ); + else + DrawBitmappedText( ref args, windowX, windowY ); + } + /// Returns the size of a bitmap needed to contain the specified text with the given arguments. public abstract Size MeasureSize( ref DrawTextArgs args ); - /// Disposes of all native resources used by this class. - /// You will no longer be able to perform measuring or drawing calls after this. - public abstract void DisposeInstance(); + /// Returns the size of a bitmap needed to contain the specified text with the given arguments, + /// when drawn with the current bitmapped font. + public abstract Size MeasureBitmappedSize( ref DrawTextArgs args ); + + /// Returns the size of a bitmap needed to contain the specified text with the given arguments, + /// when drawn with the specified font or the current bitmapped font depending on the 'useFont' argument. + public Size MeasureChatSize( bool useFont, ref DrawTextArgs args ) { + return useFont ? MeasureSize( ref args ) : + MeasureBitmappedSize( ref args ); + } + + /// Sets the bitmap that contains the bitmapped font characters as an atlas. + public abstract void SetFontBitmap( Bitmap bmp ); /// Draws the specified string from the arguments into a new bitmap, - /// them creates a 2D texture with origin at the specified window coordinates. + /// then creates a 2D texture with origin at the specified window coordinates. public Texture MakeTextTexture( ref DrawTextArgs args, int windowX, int windowY ) { Size size = MeasureSize( ref args ); if( parts.Count == 0 ) return new Texture( -1, windowX, windowY, 0, 0, 1, 1 ); - + return MakeTextureImpl( size, ref args, windowX, windowY, false ); + } + + /// Draws the specified string from the arguments into a new bitmap, + /// using the current bitmap font, then creates a 2D texture with origin at the + /// specified window coordinates. + public Texture MakeBitmappedTextTexture( ref DrawTextArgs args, int windowX, int windowY ) { + Size size = MeasureBitmappedSize( ref args ); + if( parts.Count == 0 ) + return new Texture( -1, windowX, windowY, 0, 0, 1, 1 ); + return MakeTextureImpl( size, ref args, windowX, windowY, true ); + } + + Texture MakeTextureImpl( Size size, ref DrawTextArgs args, + int windowX, int windowY, bool bitmapped ) { using( Bitmap bmp = CreatePow2Bitmap( size ) ) { SetBitmap( bmp ); args.SkipPartsCheck = true; - DrawText( ref args, 0, 0 ); + if( !bitmapped ) + DrawText( ref args, 0, 0 ); + else + DrawBitmappedText( ref args, 0, 0 ); Dispose(); return Make2DTexture( bmp, size, windowX, windowY ); } } + + /// Disposes of all native resources used by this class. + /// You will no longer be able to perform measuring or drawing calls after this. + public abstract void DisposeInstance(); + /// Creates a 2D texture with origin at the specified window coordinates. public Texture Make2DTexture( Bitmap bmp, Size used, int windowX, int windowY ) { int texId = graphics.CreateTexture( bmp ); diff --git a/ClassicalSharp/2D/Screens/FpsScreen.cs b/ClassicalSharp/2D/Screens/FpsScreen.cs index 0e9df844f..73a961c10 100644 --- a/ClassicalSharp/2D/Screens/FpsScreen.cs +++ b/ClassicalSharp/2D/Screens/FpsScreen.cs @@ -6,15 +6,13 @@ namespace ClassicalSharp { public class FpsScreen : Screen { - readonly Font font, posFont; + Font font, posFont; StringBuffer text; public FpsScreen( Game game ) : base( game ) { - font = new Font( "Arial", 13 ); - posFont = new Font( "Arial", 12, FontStyle.Italic ); text = new StringBuffer( 96 ); } - + TextWidget fpsTextWidget, hackStatesWidget; Texture posTexture; public override void Render( double delta ) { @@ -56,18 +54,22 @@ namespace ClassicalSharp { } public override void Init() { - fpsTextWidget = new TextWidget( game, font ); + font = new Font( "Arial", 13 ); + posFont = new Font( "Arial", 12, FontStyle.Italic ); + game.Events.ChatFontChanged += ChatFontChanged; + + fpsTextWidget = new ChatTextWidget( game, font ); fpsTextWidget.XOffset = 2; fpsTextWidget.YOffset = 2; fpsTextWidget.Init(); fpsTextWidget.SetText( "FPS: no data yet" ); MakePosTextWidget(); - hackStatesWidget = new TextWidget( game, posFont ); + hackStatesWidget = new ChatTextWidget( game, posFont ); hackStatesWidget.XOffset = 2; hackStatesWidget.YOffset = fpsTextWidget.Height + posHeight + 2; hackStatesWidget.Init(); - UpdateHackState( true ); + UpdateHackState( true ); } public override void Dispose() { @@ -75,6 +77,12 @@ namespace ClassicalSharp { posFont.Dispose(); fpsTextWidget.Dispose(); graphicsApi.DeleteTexture( ref posTexture ); + game.Events.ChatFontChanged -= ChatFontChanged; + } + + void ChatFontChanged( object sender, EventArgs e ) { + Dispose(); + Init(); } public override void OnResize( int oldWidth, int oldHeight, int width, int height ) { @@ -122,23 +130,23 @@ namespace ClassicalSharp { DrawTextArgs args = new DrawTextArgs( "", posFont, true ); for( int i = 0; i < possibleChars.Length; i++ ) { args.Text = new String( possibleChars[i], 1 ); - widths[i] = game.Drawer2D.MeasureSize( ref args ).Width; + widths[i] = game.Drawer2D.MeasureChatSize( game.UseArial, ref args ).Width; } using( IDrawer2D drawer = game.Drawer2D ) { args.Text = "Feet pos: "; - Size size = game.Drawer2D.MeasureSize( ref args ); + Size size = game.Drawer2D.MeasureChatSize( game.UseArial, ref args ); baseWidth = size.Width; size.Width += 16 * possibleChars.Length; posHeight = size.Height; using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) { drawer.SetBitmap( bmp ); - drawer.DrawText( ref args, 0, 0 ); + drawer.DrawChatText( game.UseArial, ref args, 0, 0 ); for( int i = 0; i < possibleChars.Length; i++ ) { args.Text = new String( possibleChars[i], 1 ); - drawer.DrawText( ref args, baseWidth + 16 * i, 0 ); + drawer.DrawChatText( game.UseArial, ref args, baseWidth + 16 * i, 0 ); } int y = fpsTextWidget.Height + 2; @@ -150,7 +158,6 @@ namespace ClassicalSharp { } } - void AddChar( int charIndex, ref int index ) { int width = widths[charIndex]; TextureRec xy = new TextureRec( curX, posTexture.Y1, width, posTexture.Height ); diff --git a/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs b/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs new file mode 100644 index 000000000..7a542a207 --- /dev/null +++ b/ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs @@ -0,0 +1,46 @@ +using System; +using System.Drawing; + +namespace ClassicalSharp { + + /// Draws text to the screen, uses the given font when the user has specified 'use arial' in options, + /// otherwise draws text using the bitmapped font in default.png + public sealed class ChatTextWidget : TextWidget { + + public ChatTextWidget( Game game, Font font ) : base( game, font ) { + } + + public static ChatTextWidget Create( Game game, int x, int y, string text, Anchor horizontal, Anchor vertical, Font font ) { + ChatTextWidget widget = new ChatTextWidget( game, font ); + widget.Init(); + widget.HorizontalAnchor = horizontal; widget.VerticalAnchor = vertical; + widget.XOffset = x; widget.YOffset = y; + widget.SetText( text ); + return widget; + } + + public override void Init() { + DrawTextArgs args = new DrawTextArgs( "I", font, true ); + defaultHeight = game.Drawer2D.MeasureChatSize( game.UseArial, ref args ).Height; + Height = defaultHeight; + } + + public override void SetText( string text ) { + graphicsApi.DeleteTexture( ref texture ); + if( String.IsNullOrEmpty( text ) ) { + texture = new Texture(); + Height = defaultHeight; + } else { + DrawTextArgs args = new DrawTextArgs( text, font, true ); + if( game.UseArial ) + texture = game.Drawer2D.MakeTextTexture( ref args, 0, 0 ); + else + texture = game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ); + X = texture.X1 = CalcOffset( game.Width, texture.Width, XOffset, HorizontalAnchor ); + Y = texture.Y1 = CalcOffset( game.Height, texture.Height, YOffset, VerticalAnchor ); + Height = texture.Height; + } + Width = texture.Width; + } + } +} \ No newline at end of file diff --git a/ClassicalSharp/2D/Widgets/TextGroupWidget.cs b/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.cs similarity index 100% rename from ClassicalSharp/2D/Widgets/TextGroupWidget.cs rename to ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.cs diff --git a/ClassicalSharp/2D/Widgets/TextInputWidget.cs b/ClassicalSharp/2D/Widgets/Chat/TextInputWidget.cs similarity index 100% rename from ClassicalSharp/2D/Widgets/TextInputWidget.cs rename to ClassicalSharp/2D/Widgets/Chat/TextInputWidget.cs diff --git a/ClassicalSharp/2D/Widgets/Menu/MenuInputWidget.cs b/ClassicalSharp/2D/Widgets/Menu/MenuInputWidget.cs index c1e7ddfbd..0b26c6d33 100644 --- a/ClassicalSharp/2D/Widgets/Menu/MenuInputWidget.cs +++ b/ClassicalSharp/2D/Widgets/Menu/MenuInputWidget.cs @@ -40,7 +40,7 @@ namespace ClassicalSharp { public MenuInputValidator Validator; double accumulator; - public override void Render( double delta ) { + public override void Render( double delta ) { chatInputTexture.Render( graphicsApi ); if( (accumulator % 1) >= 0.5 ) chatCaretTexture.Render( graphicsApi ); @@ -57,7 +57,7 @@ namespace ClassicalSharp { chatInputText.Append( 0, value ); DrawTextArgs args = new DrawTextArgs( value, font, false ); Size textSize = game.Drawer2D.MeasureSize( ref args ); - Size size = new Size( Math.Max( textSize.Width, DesiredMaxWidth ), + Size size = new Size( Math.Max( textSize.Width, DesiredMaxWidth ), Math.Max( textSize.Height, DesiredMaxHeight ) ); using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) { @@ -69,10 +69,12 @@ namespace ClassicalSharp { args.Text = Validator.Range; args.SkipPartsCheck = false; - Size hintSize = drawer.MeasureSize( ref args ); + Size hintSize = drawer.MeasureSize( ref args ); args.SkipPartsCheck = true; - drawer.DrawText( ref args, size.Width - hintSize.Width, 0 ); + int hintX = size.Width - hintSize.Width; + if( textSize.Width < hintX ) + drawer.DrawText( ref args, hintX, 0 ); chatInputTexture = drawer.Make2DTexture( bmp, size, 0, 0 ); } } @@ -114,7 +116,7 @@ namespace ClassicalSharp { public override bool HandlesKeyPress( char key ) { if( chatInputText.Length < 64 && !IsInvalidChar( key ) ) { - if( !Validator.IsValidChar( key ) ) return true; + if( !Validator.IsValidChar( key ) ) return true; chatInputText.Append( chatInputText.Length, key ); if( !Validator.IsValidString( chatInputText.GetString() ) ) { diff --git a/ClassicalSharp/2D/Widgets/TextWidget.cs b/ClassicalSharp/2D/Widgets/TextWidget.cs index fc963d4b9..6c5414b17 100644 --- a/ClassicalSharp/2D/Widgets/TextWidget.cs +++ b/ClassicalSharp/2D/Widgets/TextWidget.cs @@ -1,10 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Drawing; +using System; +using System.Drawing; namespace ClassicalSharp { - public sealed class TextWidget : Widget { + public class TextWidget : Widget { public TextWidget( Game game, Font font ) : base( game ) { this.font = font; @@ -21,10 +20,10 @@ namespace ClassicalSharp { return widget; } - Texture texture; + protected Texture texture; public int XOffset = 0, YOffset = 0; - int defaultHeight; - readonly Font font; + protected int defaultHeight; + protected readonly Font font; public override void Init() { DrawTextArgs args = new DrawTextArgs( "I", font, true ); @@ -32,7 +31,7 @@ namespace ClassicalSharp { Height = defaultHeight; } - public void SetText( string text ) { + public virtual void SetText( string text ) { graphicsApi.DeleteTexture( ref texture ); if( String.IsNullOrEmpty( text ) ) { texture = new Texture(); @@ -48,9 +47,8 @@ namespace ClassicalSharp { } public override void Render( double delta ) { - if( texture.IsValid ) { + if( texture.IsValid ) texture.Render( graphicsApi ); - } } public override void Dispose() { @@ -58,12 +56,9 @@ namespace ClassicalSharp { } public override void MoveTo( int newX, int newY ) { - int deltaX = newX - X; - int deltaY = newY - Y; - texture.X1 += deltaX; - texture.Y1 += deltaY; - X = newX; - Y = newY; + int diffX = newX - X, diffY = newY - Y; + texture.X1 += diffX; texture.Y1 += diffY; + X = newX; Y = newY; } } } \ No newline at end of file diff --git a/ClassicalSharp/Blocks/BlockInfo.Atlas.cs b/ClassicalSharp/Blocks/BlockInfo.Atlas.cs index 2268f9298..c54781e62 100644 --- a/ClassicalSharp/Blocks/BlockInfo.Atlas.cs +++ b/ClassicalSharp/Blocks/BlockInfo.Atlas.cs @@ -2,6 +2,7 @@ namespace ClassicalSharp { + /// Stores various properties about the blocks in Minecraft Classic. public partial class BlockInfo { internal int[] textures = new int[BlocksCount * TileSide.Sides]; diff --git a/ClassicalSharp/Blocks/BlockInfo.Culling.cs b/ClassicalSharp/Blocks/BlockInfo.Culling.cs index 4e1e042d7..ef5b4e63c 100644 --- a/ClassicalSharp/Blocks/BlockInfo.Culling.cs +++ b/ClassicalSharp/Blocks/BlockInfo.Culling.cs @@ -2,6 +2,7 @@ namespace ClassicalSharp { + /// Stores various properties about the blocks in Minecraft Classic. public partial class BlockInfo { bool[] hidden = new bool[BlocksCount * BlocksCount * TileSide.Sides]; @@ -34,6 +35,8 @@ namespace ClassicalSharp { hidden[( tile * BlocksCount + block ) * TileSide.Sides + tileSide] = value; } + /// Returns whether the face at the given face of the tile + /// should be drawn with the neighbour 'block' present on the other side of the face. public bool IsFaceHidden( byte tile, byte block, int tileSide ) { return hidden[( tile * BlocksCount + block ) * TileSide.Sides + tileSide]; } diff --git a/ClassicalSharp/Blocks/BlockInfo.cs b/ClassicalSharp/Blocks/BlockInfo.cs index 20317fcbd..ff5406a31 100644 --- a/ClassicalSharp/Blocks/BlockInfo.cs +++ b/ClassicalSharp/Blocks/BlockInfo.cs @@ -32,10 +32,13 @@ namespace ClassicalSharp { /// Gets whether the given block blocks sunlight. public bool[] BlocksLight = new bool[BlocksCount]; + /// Gets whether the given block should draw all it faces with a full white colour component. public bool[] FullBright = new bool[BlocksCount]; public string[] Name = new string[BlocksCount]; + /// Gets the custom fog colour that should be used when the player is standing within this block. + /// Note that this is only used for exponential fog mode. public FastColour[] FogColour = new FastColour[BlocksCount]; public float[] FogDensity = new float[BlocksCount]; @@ -83,18 +86,18 @@ namespace ClassicalSharp { SetBlockHeight( Block.Slab, 8/16f ); SetBlockHeight( Block.CobblestoneSlab, 8/16f ); - SetBlockHeight( Block.Snow, 2/16f ); - MarkTranslucent( Block.StillWater ); MarkTranslucent( Block.Water ); + SetBlockHeight( Block.Snow, 2/16f ); + MarkTranslucent( Block.StillWater ); MarkTranslucent( Block.Water ); MarkTranslucent( Block.Ice ); - MarkTransparent( Block.Glass, false ); MarkTransparent( Block.Leaves, false ); - MarkTransparent( Block.Slab, true ); MarkTransparent( Block.Snow, true ); + MarkTransparent( Block.Glass, false ); MarkTransparent( Block.Leaves, false ); + MarkTransparent( Block.Slab, true ); MarkTransparent( Block.Snow, true ); MarkTransparent( Block.CobblestoneSlab, true ); - MarkSprite( Block.Rose ); MarkSprite( Block.Sapling ); - MarkSprite( Block.Dandelion ); MarkSprite( Block.BrownMushroom ); - MarkSprite( Block.RedMushroom ); MarkSprite( Block.Rope ); + MarkSprite( Block.Rose ); MarkSprite( Block.Sapling ); + MarkSprite( Block.Dandelion ); MarkSprite( Block.BrownMushroom ); + MarkSprite( Block.RedMushroom ); MarkSprite( Block.Rope ); MarkSprite( Block.Fire ); SetIsLiquid( Block.StillWater ); SetIsLiquid( Block.Water ); - SetIsLiquid( Block.StillLava ); SetIsLiquid( Block.Lava ); + SetIsLiquid( Block.StillLava ); SetIsLiquid( Block.Lava ); SetFullBright( Block.Lava, true ); SetFullBright( Block.StillLava, true ); SetFullBright( Block.Magma, true ); SetFullBright( Block.Fire, true ); diff --git a/ClassicalSharp/ClassicalSharp.csproj b/ClassicalSharp/ClassicalSharp.csproj index 251a2fac9..d5518f3f5 100644 --- a/ClassicalSharp/ClassicalSharp.csproj +++ b/ClassicalSharp/ClassicalSharp.csproj @@ -75,8 +75,8 @@ - - + + @@ -103,14 +103,15 @@ + + + - - @@ -230,6 +231,7 @@ + diff --git a/ClassicalSharp/Entities/Player.cs b/ClassicalSharp/Entities/Player.cs index d58148bbe..b98497ff6 100644 --- a/ClassicalSharp/Entities/Player.cs +++ b/ClassicalSharp/Entities/Player.cs @@ -1,7 +1,7 @@ -using System; -using System.Drawing; -using ClassicalSharp.Network; -using OpenTK; +using System; +using System.Drawing; +using ClassicalSharp.Network; +using OpenTK; namespace ClassicalSharp { diff --git a/ClassicalSharp/Game/Events.cs b/ClassicalSharp/Game/Events.cs index 01838816c..80c6cc0a6 100644 --- a/ClassicalSharp/Game/Events.cs +++ b/ClassicalSharp/Game/Events.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace ClassicalSharp { @@ -66,6 +66,11 @@ namespace ClassicalSharp { public event EventHandler ChatReceived; internal void RaiseChatReceived( string text, CpeMessage type ) { chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); } + /// Raised when the user changes chat font to arial or back to bitmapped font, + /// also raised when the bitmapped font changes. + public event EventHandler ChatFontChanged; + internal void RaiseChatFontChanged( bool arial ) { fontArgs.UseArial = arial; Raise( ChatFontChanged, fontArgs ); } + // Cache event instances so we don't create needless new objects. @@ -73,6 +78,7 @@ namespace ClassicalSharp { MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs(); EnvVarEventArgs envArgs = new EnvVarEventArgs(); ChatEventArgs chatArgs = new ChatEventArgs(); + ChatFontChangedEventArgs fontArgs = new ChatFontChangedEventArgs(); void Raise( EventHandler handler ) { if( handler != null ) { @@ -94,21 +100,33 @@ namespace ClassicalSharp { public sealed class ChatEventArgs : EventArgs { + /// Where this chat message should appear on the screen. public CpeMessage Type; + /// Raw text of the message (including colour codes), + /// with code page 437 indices converted to their unicode representations. public string Text; } public sealed class MapLoadingEventArgs : EventArgs { + /// Percentage of the map that has been fully decompressed by the client. public int Progress; } public sealed class EnvVarEventArgs : EventArgs { + /// Map environment variable that was changed. public EnvVar Var; } + public sealed class ChatFontChangedEventArgs : EventArgs { + + /// true if chat should be drawn using arial, + /// false if it should be drawn using the current bitmapped font. + public bool UseArial; + } + public enum EnvVar { SidesBlock, EdgeBlock, diff --git a/ClassicalSharp/Game/Game.cs b/ClassicalSharp/Game/Game.cs index 38b0e5a7c..0b9ccab5f 100644 --- a/ClassicalSharp/Game/Game.cs +++ b/ClassicalSharp/Game/Game.cs @@ -74,6 +74,7 @@ namespace ClassicalSharp { internal int CloudsTextureId, RainTextureId, SnowTextureId; internal bool screenshotRequested; public Bitmap FontBitmap; + public bool UseArial = false; void LoadAtlas( Bitmap bmp ) { TerrainAtlas1D.Dispose(); @@ -108,7 +109,7 @@ namespace ClassicalSharp { ModelCache = new ModelCache( this ); ModelCache.InitCache(); AsyncDownloader = new AsyncDownloader( skinServer ); - Drawer2D = new GdiPlusDrawerFont( Graphics ); + Drawer2D = new GdiPlusDrawer2D( Graphics ); TerrainAtlas1D = new TerrainAtlas1D( Graphics ); TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D ); diff --git a/ClassicalSharp/Game/InputHandler.cs b/ClassicalSharp/Game/InputHandler.cs index ece0b03ca..52d351cd7 100644 --- a/ClassicalSharp/Game/InputHandler.cs +++ b/ClassicalSharp/Game/InputHandler.cs @@ -268,6 +268,13 @@ namespace ClassicalSharp { Key key = e.Key; if( SimulateMouse( key, true ) ) return; + // TODO: this is a temp debug statement + // NOTE: this is a temp debug statement + if( key == Key.F8 ) { + game.UseArial = !game.UseArial; + game.Events.RaiseChatFontChanged( game.UseArial ); + return; + } if( key == Key.F4 && (game.IsKeyDown( Key.AltLeft ) || game.IsKeyDown( Key.AltRight )) ) { game.Exit(); } else if( key == Keys[KeyBinding.Screenshot] ) { diff --git a/ClassicalSharp/TexturePack/TexturePackExtractor.cs b/ClassicalSharp/TexturePack/TexturePackExtractor.cs index 9367d95a4..f8c998959 100644 --- a/ClassicalSharp/TexturePack/TexturePackExtractor.cs +++ b/ClassicalSharp/TexturePack/TexturePackExtractor.cs @@ -86,8 +86,10 @@ namespace ClassicalSharp.TexturePack { void SetFontBitmap( Game game, Stream stream ) { game.FontBitmap = new Bitmap( stream ); - if( game.Drawer2D is GdiPlusDrawerMCFont ) - ((GdiPlusDrawerMCFont)game.Drawer2D).SetFontBitmap( game.FontBitmap ); + game.Drawer2D.SetFontBitmap( game.FontBitmap ); + + if( !game.UseArial) + game.Events.RaiseChatFontChanged( false ); } void UpdateTexture( ref int texId, Stream stream, bool setSkinType ) { diff --git a/Launcher2/LauncherWindow.cs b/Launcher2/LauncherWindow.cs index 7bb4d1198..81d78cfde 100644 --- a/Launcher2/LauncherWindow.cs +++ b/Launcher2/LauncherWindow.cs @@ -76,7 +76,7 @@ namespace Launcher2 { Window = new NativeWindow( 480, 480, Program.AppName, 0, GraphicsMode.Default, DisplayDevice.Default ); Window.Visible = true; - Drawer = new GdiPlusDrawerFont( null ); + Drawer = new GdiPlusDrawer2D( null ); Init(); platformDrawer.Init( Window.WindowInfo ); diff --git a/OpenTK/OpenTK.csproj b/OpenTK/OpenTK.csproj index f949e262d..ab81869bd 100644 --- a/OpenTK/OpenTK.csproj +++ b/OpenTK/OpenTK.csproj @@ -150,6 +150,12 @@ Always + + + {4A4110EE-21CA-4715-AF67-0C8B7CE0642F} + InteropPatcher + + diff --git a/OpenTK/SharpDX.Direct3D/Enumerations.cs b/OpenTK/SharpDX.Direct3D/Enumerations.cs index 90ee89a14..8d6bab2cb 100644 --- a/OpenTK/SharpDX.Direct3D/Enumerations.cs +++ b/OpenTK/SharpDX.Direct3D/Enumerations.cs @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -using System; +using System; namespace SharpDX.Direct3D9 {