Initial implementation of being able to switch between arial and default.png (only works for FPSscreen right now)

This commit is contained in:
UnknownShadow200 2015-10-28 07:20:15 +11:00
parent 72db7f7245
commit 2493feb86f
22 changed files with 230 additions and 101 deletions

View File

@ -5,13 +5,14 @@ using ClassicalSharp.GraphicsAPI;
namespace ClassicalSharp { namespace ClassicalSharp {
public sealed class GdiPlusDrawerFont : GdiPlusDrawer2D { public sealed partial class GdiPlusDrawer2D {
StringFormat format; StringFormat format;
Bitmap measuringBmp; Bitmap measuringBmp;
Graphics measuringGraphics; Graphics measuringGraphics;
public GdiPlusDrawerFont( IGraphicsApi graphics ) : base( graphics ) { public GdiPlusDrawer2D( IGraphicsApi graphics ) {
this.graphics = graphics;
format = StringFormat.GenericTypographic; format = StringFormat.GenericTypographic;
format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
format.Trimming = StringTrimming.None; format.Trimming = StringTrimming.None;
@ -62,7 +63,7 @@ namespace ClassicalSharp {
format.Trimming = StringTrimming.None; format.Trimming = StringTrimming.None;
} }
public override Size MeasureSize( ref DrawTextArgs args ) { public override Size MeasureSize( ref DrawTextArgs args ) {
GetTextParts( args.Text ); GetTextParts( args.Text );
SizeF total = SizeF.Empty; SizeF total = SizeF.Empty;
for( int i = 0; i < parts.Count; i++ ) { for( int i = 0; i < parts.Count; i++ ) {
@ -77,8 +78,7 @@ namespace ClassicalSharp {
return Size.Ceiling( total ); return Size.Ceiling( total );
} }
public override void DisposeInstance() { void DisposeText() {
base.DisposeInstance();
measuringGraphics.Dispose(); measuringGraphics.Dispose();
measuringBmp.Dispose(); measuringBmp.Dispose();
} }

View File

@ -4,7 +4,7 @@ using ClassicalSharp.GraphicsAPI;
namespace ClassicalSharp { 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 // NOTE: This drawer is still a big work in progress and not close to done
// TODO: italic and bold // TODO: italic and bold
@ -13,10 +13,7 @@ namespace ClassicalSharp {
int boxSize; int boxSize;
const int italicSize = 8; const int italicSize = 8;
public GdiPlusDrawerMCFont( IGraphicsApi graphics ) : base( graphics ) { public override void SetFontBitmap( Bitmap bmp ) {
}
public void SetFontBitmap( Bitmap bmp ) {
fontBmp = bmp; fontBmp = bmp;
boxSize = fontBmp.Width / 16; boxSize = fontBmp.Width / 16;
fontPixels = new FastBitmap( fontBmp, true ); fontPixels = new FastBitmap( fontBmp, true );
@ -45,7 +42,7 @@ namespace ClassicalSharp {
widths[i] = 0; 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 ) if( !args.SkipPartsCheck )
GetTextParts( args.Text ); GetTextParts( args.Text );
@ -106,11 +103,7 @@ namespace ClassicalSharp {
} }
} }
public override void DrawClippedText( ref DrawTextArgs args, int x, int y, float maxWidth, float maxHeight ) { public override Size MeasureBitmappedSize( ref DrawTextArgs args ) {
throw new NotImplementedException( "Clipped text not implemented yet with minecraft font" );
}
public override Size MeasureSize( ref DrawTextArgs args ) {
GetTextParts( args.Text ); GetTextParts( args.Text );
float point = args.Font.Size; float point = args.Font.Size;
Size total = new Size( 0, PtToPx( point, boxSize ) ); Size total = new Size( 0, PtToPx( point, boxSize ) );
@ -149,8 +142,7 @@ namespace ClassicalSharp {
return (int)Math.Ceiling( (value / boxSize) * point / 72f * 96f ); return (int)Math.Ceiling( (value / boxSize) * point / 72f * 96f );
} }
public override void DisposeInstance() { void DisposeBitmappedText() {
base.DisposeInstance();
fontPixels.Dispose(); fontPixels.Dispose();
fontBmp.Dispose(); fontBmp.Dispose();
} }

View File

@ -3,19 +3,14 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Drawing.Text; using System.Drawing.Text;
using ClassicalSharp.GraphicsAPI;
namespace ClassicalSharp { namespace ClassicalSharp {
public abstract class GdiPlusDrawer2D : IDrawer2D { public sealed partial class GdiPlusDrawer2D : IDrawer2D {
Dictionary<int, SolidBrush> brushCache = new Dictionary<int, SolidBrush>( 16 ); Dictionary<int, SolidBrush> brushCache = new Dictionary<int, SolidBrush>( 16 );
Graphics g;
protected Graphics g; Bitmap curBmp;
protected Bitmap curBmp;
public GdiPlusDrawer2D( IGraphicsApi graphics ) {
this.graphics = graphics;
}
public override void SetBitmap( Bitmap bmp ) { public override void SetBitmap( Bitmap bmp ) {
if( g != null ) { if( g != null ) {
@ -87,17 +82,19 @@ namespace ClassicalSharp {
} }
public override void DisposeInstance() { public override void DisposeInstance() {
foreach( var pair in brushCache ) { foreach( var pair in brushCache )
pair.Value.Dispose(); pair.Value.Dispose();
}
DisposeText();
DisposeBitmappedText();
} }
protected SolidBrush GetOrCreateBrush( Color color ) { SolidBrush GetOrCreateBrush( Color color ) {
int key = color.ToArgb(); int key = color.ToArgb();
SolidBrush brush; SolidBrush brush;
if( brushCache.TryGetValue( key, out brush ) ) { if( brushCache.TryGetValue( key, out brush ) )
return brush; return brush;
}
brush = new SolidBrush( color ); brush = new SolidBrush( color );
brushCache[key] = brush; brushCache[key] = brush;
return brush; return brush;

View File

@ -16,14 +16,6 @@ namespace ClassicalSharp {
/// <summary> Sets the underlying bitmap that drawing operations will be performed on. </summary> /// <summary> Sets the underlying bitmap that drawing operations will be performed on. </summary>
public abstract void SetBitmap( Bitmap bmp ); public abstract void SetBitmap( Bitmap bmp );
/// <summary> Draws a string using the specified arguments and fonts at the
/// specified coordinates in the currently bound bitmap. </summary>
public abstract void DrawText( ref DrawTextArgs args, int x, int y );
/// <summary> Draws a string using the specified arguments and fonts at the
/// specified coordinates in the currently bound bitmap, clipping if necessary. </summary>
public abstract void DrawClippedText( ref DrawTextArgs args, int x, int y, float maxWidth, float maxHeight );
/// <summary> Draws a 2D flat rectangle of the specified dimensions at the /// <summary> Draws a 2D flat rectangle of the specified dimensions at the
/// specified coordinates in the currently bound bitmap. </summary> /// specified coordinates in the currently bound bitmap. </summary>
public abstract void DrawRect( FastColour colour, int x, int y, int width, int height ); public abstract void DrawRect( FastColour colour, int x, int y, int width, int height );
@ -55,30 +47,85 @@ namespace ClassicalSharp {
src = newBmp; src = newBmp;
} }
/// <summary> Draws a string using the specified arguments and font at the
/// specified coordinates in the currently bound bitmap. </summary>
public abstract void DrawText( ref DrawTextArgs args, int x, int y );
/// <summary> Draws a string using the specified arguments and fonts at the
/// specified coordinates in the currently bound bitmap, clipping if necessary. </summary>
public abstract void DrawClippedText( ref DrawTextArgs args, int x, int y, float maxWidth, float maxHeight );
/// <summary> Draws a string using the specified arguments and the current bitmapped font at the
/// specified coordinates in the currently bound bitmap. </summary>
public abstract void DrawBitmappedText( ref DrawTextArgs args, int x, int y );
/// <summary> 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. </summary>
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 );
}
/// <summary> Returns the size of a bitmap needed to contain the specified text with the given arguments. </summary> /// <summary> Returns the size of a bitmap needed to contain the specified text with the given arguments. </summary>
public abstract Size MeasureSize( ref DrawTextArgs args ); public abstract Size MeasureSize( ref DrawTextArgs args );
/// <summary> Disposes of all native resources used by this class. </summary> /// <summary> Returns the size of a bitmap needed to contain the specified text with the given arguments,
/// <remarks> You will no longer be able to perform measuring or drawing calls after this. </remarks> /// when drawn with the current bitmapped font. </summary>
public abstract void DisposeInstance(); public abstract Size MeasureBitmappedSize( ref DrawTextArgs args );
/// <summary> 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. </summary>
public Size MeasureChatSize( bool useFont, ref DrawTextArgs args ) {
return useFont ? MeasureSize( ref args ) :
MeasureBitmappedSize( ref args );
}
/// <summary> Sets the bitmap that contains the bitmapped font characters as an atlas. </summary>
public abstract void SetFontBitmap( Bitmap bmp );
/// <summary> Draws the specified string from the arguments into a new bitmap, /// <summary> Draws the specified string from the arguments into a new bitmap,
/// them creates a 2D texture with origin at the specified window coordinates. </summary> /// then creates a 2D texture with origin at the specified window coordinates. </summary>
public Texture MakeTextTexture( ref DrawTextArgs args, int windowX, int windowY ) { public Texture MakeTextTexture( ref DrawTextArgs args, int windowX, int windowY ) {
Size size = MeasureSize( ref args ); Size size = MeasureSize( ref args );
if( parts.Count == 0 ) if( parts.Count == 0 )
return new Texture( -1, windowX, windowY, 0, 0, 1, 1 ); return new Texture( -1, windowX, windowY, 0, 0, 1, 1 );
return MakeTextureImpl( size, ref args, windowX, windowY, false );
}
/// <summary> 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. </summary>
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 ) ) { using( Bitmap bmp = CreatePow2Bitmap( size ) ) {
SetBitmap( bmp ); SetBitmap( bmp );
args.SkipPartsCheck = true; args.SkipPartsCheck = true;
DrawText( ref args, 0, 0 ); if( !bitmapped )
DrawText( ref args, 0, 0 );
else
DrawBitmappedText( ref args, 0, 0 );
Dispose(); Dispose();
return Make2DTexture( bmp, size, windowX, windowY ); return Make2DTexture( bmp, size, windowX, windowY );
} }
} }
/// <summary> Disposes of all native resources used by this class. </summary>
/// <remarks> You will no longer be able to perform measuring or drawing calls after this. </remarks>
public abstract void DisposeInstance();
/// <summary> Creates a 2D texture with origin at the specified window coordinates. </summary> /// <summary> Creates a 2D texture with origin at the specified window coordinates. </summary>
public Texture Make2DTexture( Bitmap bmp, Size used, int windowX, int windowY ) { public Texture Make2DTexture( Bitmap bmp, Size used, int windowX, int windowY ) {
int texId = graphics.CreateTexture( bmp ); int texId = graphics.CreateTexture( bmp );

View File

@ -6,15 +6,13 @@ namespace ClassicalSharp {
public class FpsScreen : Screen { public class FpsScreen : Screen {
readonly Font font, posFont; Font font, posFont;
StringBuffer text; StringBuffer text;
public FpsScreen( Game game ) : base( game ) { public FpsScreen( Game game ) : base( game ) {
font = new Font( "Arial", 13 );
posFont = new Font( "Arial", 12, FontStyle.Italic );
text = new StringBuffer( 96 ); text = new StringBuffer( 96 );
} }
TextWidget fpsTextWidget, hackStatesWidget; TextWidget fpsTextWidget, hackStatesWidget;
Texture posTexture; Texture posTexture;
public override void Render( double delta ) { public override void Render( double delta ) {
@ -56,18 +54,22 @@ namespace ClassicalSharp {
} }
public override void Init() { 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.XOffset = 2;
fpsTextWidget.YOffset = 2; fpsTextWidget.YOffset = 2;
fpsTextWidget.Init(); fpsTextWidget.Init();
fpsTextWidget.SetText( "FPS: no data yet" ); fpsTextWidget.SetText( "FPS: no data yet" );
MakePosTextWidget(); MakePosTextWidget();
hackStatesWidget = new TextWidget( game, posFont ); hackStatesWidget = new ChatTextWidget( game, posFont );
hackStatesWidget.XOffset = 2; hackStatesWidget.XOffset = 2;
hackStatesWidget.YOffset = fpsTextWidget.Height + posHeight + 2; hackStatesWidget.YOffset = fpsTextWidget.Height + posHeight + 2;
hackStatesWidget.Init(); hackStatesWidget.Init();
UpdateHackState( true ); UpdateHackState( true );
} }
public override void Dispose() { public override void Dispose() {
@ -75,6 +77,12 @@ namespace ClassicalSharp {
posFont.Dispose(); posFont.Dispose();
fpsTextWidget.Dispose(); fpsTextWidget.Dispose();
graphicsApi.DeleteTexture( ref posTexture ); 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 ) { public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
@ -122,23 +130,23 @@ namespace ClassicalSharp {
DrawTextArgs args = new DrawTextArgs( "", posFont, true ); DrawTextArgs args = new DrawTextArgs( "", posFont, true );
for( int i = 0; i < possibleChars.Length; i++ ) { for( int i = 0; i < possibleChars.Length; i++ ) {
args.Text = new String( possibleChars[i], 1 ); 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 ) { using( IDrawer2D drawer = game.Drawer2D ) {
args.Text = "Feet pos: "; args.Text = "Feet pos: ";
Size size = game.Drawer2D.MeasureSize( ref args ); Size size = game.Drawer2D.MeasureChatSize( game.UseArial, ref args );
baseWidth = size.Width; baseWidth = size.Width;
size.Width += 16 * possibleChars.Length; size.Width += 16 * possibleChars.Length;
posHeight = size.Height; posHeight = size.Height;
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) { using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
drawer.SetBitmap( bmp ); 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++ ) { for( int i = 0; i < possibleChars.Length; i++ ) {
args.Text = new String( possibleChars[i], 1 ); 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; int y = fpsTextWidget.Height + 2;
@ -150,7 +158,6 @@ namespace ClassicalSharp {
} }
} }
void AddChar( int charIndex, ref int index ) { void AddChar( int charIndex, ref int index ) {
int width = widths[charIndex]; int width = widths[charIndex];
TextureRec xy = new TextureRec( curX, posTexture.Y1, width, posTexture.Height ); TextureRec xy = new TextureRec( curX, posTexture.Y1, width, posTexture.Height );

View File

@ -0,0 +1,46 @@
using System;
using System.Drawing;
namespace ClassicalSharp {
/// <summary> 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 </summary>
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;
}
}
}

View File

@ -40,7 +40,7 @@ namespace ClassicalSharp {
public MenuInputValidator Validator; public MenuInputValidator Validator;
double accumulator; double accumulator;
public override void Render( double delta ) { public override void Render( double delta ) {
chatInputTexture.Render( graphicsApi ); chatInputTexture.Render( graphicsApi );
if( (accumulator % 1) >= 0.5 ) if( (accumulator % 1) >= 0.5 )
chatCaretTexture.Render( graphicsApi ); chatCaretTexture.Render( graphicsApi );
@ -57,7 +57,7 @@ namespace ClassicalSharp {
chatInputText.Append( 0, value ); chatInputText.Append( 0, value );
DrawTextArgs args = new DrawTextArgs( value, font, false ); DrawTextArgs args = new DrawTextArgs( value, font, false );
Size textSize = game.Drawer2D.MeasureSize( ref args ); 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 ) ); Math.Max( textSize.Height, DesiredMaxHeight ) );
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) { using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
@ -69,10 +69,12 @@ namespace ClassicalSharp {
args.Text = Validator.Range; args.Text = Validator.Range;
args.SkipPartsCheck = false; args.SkipPartsCheck = false;
Size hintSize = drawer.MeasureSize( ref args ); Size hintSize = drawer.MeasureSize( ref args );
args.SkipPartsCheck = true; 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 ); chatInputTexture = drawer.Make2DTexture( bmp, size, 0, 0 );
} }
} }
@ -114,7 +116,7 @@ namespace ClassicalSharp {
public override bool HandlesKeyPress( char key ) { public override bool HandlesKeyPress( char key ) {
if( chatInputText.Length < 64 && !IsInvalidChar( key ) ) { if( chatInputText.Length < 64 && !IsInvalidChar( key ) ) {
if( !Validator.IsValidChar( key ) ) return true; if( !Validator.IsValidChar( key ) ) return true;
chatInputText.Append( chatInputText.Length, key ); chatInputText.Append( chatInputText.Length, key );
if( !Validator.IsValidString( chatInputText.GetString() ) ) { if( !Validator.IsValidString( chatInputText.GetString() ) ) {

View File

@ -1,10 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Drawing;
using System.Drawing;
namespace ClassicalSharp { namespace ClassicalSharp {
public sealed class TextWidget : Widget { public class TextWidget : Widget {
public TextWidget( Game game, Font font ) : base( game ) { public TextWidget( Game game, Font font ) : base( game ) {
this.font = font; this.font = font;
@ -21,10 +20,10 @@ namespace ClassicalSharp {
return widget; return widget;
} }
Texture texture; protected Texture texture;
public int XOffset = 0, YOffset = 0; public int XOffset = 0, YOffset = 0;
int defaultHeight; protected int defaultHeight;
readonly Font font; protected readonly Font font;
public override void Init() { public override void Init() {
DrawTextArgs args = new DrawTextArgs( "I", font, true ); DrawTextArgs args = new DrawTextArgs( "I", font, true );
@ -32,7 +31,7 @@ namespace ClassicalSharp {
Height = defaultHeight; Height = defaultHeight;
} }
public void SetText( string text ) { public virtual void SetText( string text ) {
graphicsApi.DeleteTexture( ref texture ); graphicsApi.DeleteTexture( ref texture );
if( String.IsNullOrEmpty( text ) ) { if( String.IsNullOrEmpty( text ) ) {
texture = new Texture(); texture = new Texture();
@ -48,9 +47,8 @@ namespace ClassicalSharp {
} }
public override void Render( double delta ) { public override void Render( double delta ) {
if( texture.IsValid ) { if( texture.IsValid )
texture.Render( graphicsApi ); texture.Render( graphicsApi );
}
} }
public override void Dispose() { public override void Dispose() {
@ -58,12 +56,9 @@ namespace ClassicalSharp {
} }
public override void MoveTo( int newX, int newY ) { public override void MoveTo( int newX, int newY ) {
int deltaX = newX - X; int diffX = newX - X, diffY = newY - Y;
int deltaY = newY - Y; texture.X1 += diffX; texture.Y1 += diffY;
texture.X1 += deltaX; X = newX; Y = newY;
texture.Y1 += deltaY;
X = newX;
Y = newY;
} }
} }
} }

View File

@ -2,6 +2,7 @@
namespace ClassicalSharp { namespace ClassicalSharp {
/// <summary> Stores various properties about the blocks in Minecraft Classic. </summary>
public partial class BlockInfo { public partial class BlockInfo {
internal int[] textures = new int[BlocksCount * TileSide.Sides]; internal int[] textures = new int[BlocksCount * TileSide.Sides];

View File

@ -2,6 +2,7 @@
namespace ClassicalSharp { namespace ClassicalSharp {
/// <summary> Stores various properties about the blocks in Minecraft Classic. </summary>
public partial class BlockInfo { public partial class BlockInfo {
bool[] hidden = new bool[BlocksCount * BlocksCount * TileSide.Sides]; bool[] hidden = new bool[BlocksCount * BlocksCount * TileSide.Sides];
@ -34,6 +35,8 @@ namespace ClassicalSharp {
hidden[( tile * BlocksCount + block ) * TileSide.Sides + tileSide] = value; hidden[( tile * BlocksCount + block ) * TileSide.Sides + tileSide] = value;
} }
/// <summary> 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. </summary>
public bool IsFaceHidden( byte tile, byte block, int tileSide ) { public bool IsFaceHidden( byte tile, byte block, int tileSide ) {
return hidden[( tile * BlocksCount + block ) * TileSide.Sides + tileSide]; return hidden[( tile * BlocksCount + block ) * TileSide.Sides + tileSide];
} }

View File

@ -32,10 +32,13 @@ namespace ClassicalSharp {
/// <summary> Gets whether the given block blocks sunlight. </summary> /// <summary> Gets whether the given block blocks sunlight. </summary>
public bool[] BlocksLight = new bool[BlocksCount]; public bool[] BlocksLight = new bool[BlocksCount];
/// <summary> Gets whether the given block should draw all it faces with a full white colour component. </summary>
public bool[] FullBright = new bool[BlocksCount]; public bool[] FullBright = new bool[BlocksCount];
public string[] Name = new string[BlocksCount]; public string[] Name = new string[BlocksCount];
/// <summary> 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. </summary>
public FastColour[] FogColour = new FastColour[BlocksCount]; public FastColour[] FogColour = new FastColour[BlocksCount];
public float[] FogDensity = new float[BlocksCount]; public float[] FogDensity = new float[BlocksCount];
@ -83,18 +86,18 @@ namespace ClassicalSharp {
SetBlockHeight( Block.Slab, 8/16f ); SetBlockHeight( Block.Slab, 8/16f );
SetBlockHeight( Block.CobblestoneSlab, 8/16f ); SetBlockHeight( Block.CobblestoneSlab, 8/16f );
SetBlockHeight( Block.Snow, 2/16f ); SetBlockHeight( Block.Snow, 2/16f );
MarkTranslucent( Block.StillWater ); MarkTranslucent( Block.Water ); MarkTranslucent( Block.StillWater ); MarkTranslucent( Block.Water );
MarkTranslucent( Block.Ice ); MarkTranslucent( Block.Ice );
MarkTransparent( Block.Glass, false ); MarkTransparent( Block.Leaves, false ); MarkTransparent( Block.Glass, false ); MarkTransparent( Block.Leaves, false );
MarkTransparent( Block.Slab, true ); MarkTransparent( Block.Snow, true ); MarkTransparent( Block.Slab, true ); MarkTransparent( Block.Snow, true );
MarkTransparent( Block.CobblestoneSlab, true ); MarkTransparent( Block.CobblestoneSlab, true );
MarkSprite( Block.Rose ); MarkSprite( Block.Sapling ); MarkSprite( Block.Rose ); MarkSprite( Block.Sapling );
MarkSprite( Block.Dandelion ); MarkSprite( Block.BrownMushroom ); MarkSprite( Block.Dandelion ); MarkSprite( Block.BrownMushroom );
MarkSprite( Block.RedMushroom ); MarkSprite( Block.Rope ); MarkSprite( Block.RedMushroom ); MarkSprite( Block.Rope );
MarkSprite( Block.Fire ); MarkSprite( Block.Fire );
SetIsLiquid( Block.StillWater ); SetIsLiquid( Block.Water ); 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.Lava, true ); SetFullBright( Block.StillLava, true );
SetFullBright( Block.Magma, true ); SetFullBright( Block.Fire, true ); SetFullBright( Block.Magma, true ); SetFullBright( Block.Fire, true );

View File

@ -75,8 +75,8 @@
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="2D\Drawing\GdiPlusDrawerFont.cs" /> <Compile Include="2D\Drawing\GdiPlusDrawer2D.Text.cs" />
<Compile Include="2D\Drawing\GdiPlusDrawerMCFont.cs" /> <Compile Include="2D\Drawing\GdiPlusDrawer2D.TextMC.cs" />
<Compile Include="2D\GuiElement.cs" /> <Compile Include="2D\GuiElement.cs" />
<Compile Include="2D\IsometricBlockDrawer.cs" /> <Compile Include="2D\IsometricBlockDrawer.cs" />
<Compile Include="2D\Drawing\DrawTextArgs.cs" /> <Compile Include="2D\Drawing\DrawTextArgs.cs" />
@ -103,14 +103,15 @@
<Compile Include="2D\Screens\Screen.cs" /> <Compile Include="2D\Screens\Screen.cs" />
<Compile Include="2D\Texture.cs" /> <Compile Include="2D\Texture.cs" />
<Compile Include="2D\Widgets\BlockHotbarWidget.cs" /> <Compile Include="2D\Widgets\BlockHotbarWidget.cs" />
<Compile Include="2D\Widgets\Chat\ChatTextWidget.cs" />
<Compile Include="2D\Widgets\Chat\TextGroupWidget.cs" />
<Compile Include="2D\Widgets\Chat\TextInputWidget.cs" />
<Compile Include="2D\Widgets\ExtPlayerListWidget.cs" /> <Compile Include="2D\Widgets\ExtPlayerListWidget.cs" />
<Compile Include="2D\Widgets\Menu\MenuInputValidator.cs" /> <Compile Include="2D\Widgets\Menu\MenuInputValidator.cs" />
<Compile Include="2D\Widgets\Menu\MenuInputWidget.cs" /> <Compile Include="2D\Widgets\Menu\MenuInputWidget.cs" />
<Compile Include="2D\Widgets\NormalPlayerListWidget.cs" /> <Compile Include="2D\Widgets\NormalPlayerListWidget.cs" />
<Compile Include="2D\Widgets\ButtonWidget.cs" /> <Compile Include="2D\Widgets\ButtonWidget.cs" />
<Compile Include="2D\Widgets\PlayerListWidget.cs" /> <Compile Include="2D\Widgets\PlayerListWidget.cs" />
<Compile Include="2D\Widgets\TextGroupWidget.cs" />
<Compile Include="2D\Widgets\TextInputWidget.cs" />
<Compile Include="2D\Widgets\TextWidget.cs" /> <Compile Include="2D\Widgets\TextWidget.cs" />
<Compile Include="2D\Widgets\Widget.cs" /> <Compile Include="2D\Widgets\Widget.cs" />
<Compile Include="Blocks\Block.cs" /> <Compile Include="Blocks\Block.cs" />
@ -230,6 +231,7 @@
<Folder Include="2D\Screens\Menu" /> <Folder Include="2D\Screens\Menu" />
<Folder Include="2D\Widgets" /> <Folder Include="2D\Widgets" />
<Folder Include="2D\Widgets\Menu" /> <Folder Include="2D\Widgets\Menu" />
<Folder Include="2D\Widgets\Chat" />
<Folder Include="Blocks" /> <Folder Include="Blocks" />
<Folder Include="Entities\Particles" /> <Folder Include="Entities\Particles" />
<Folder Include="GraphicsAPI" /> <Folder Include="GraphicsAPI" />

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Drawing; using System.Drawing;
using ClassicalSharp.Network; using ClassicalSharp.Network;
using OpenTK; using OpenTK;
namespace ClassicalSharp { namespace ClassicalSharp {

View File

@ -1,4 +1,4 @@
using System; using System;
namespace ClassicalSharp { namespace ClassicalSharp {
@ -66,6 +66,11 @@ namespace ClassicalSharp {
public event EventHandler<ChatEventArgs> ChatReceived; public event EventHandler<ChatEventArgs> ChatReceived;
internal void RaiseChatReceived( string text, CpeMessage type ) { chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); } internal void RaiseChatReceived( string text, CpeMessage type ) { chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); }
/// <summary> Raised when the user changes chat font to arial or back to bitmapped font,
/// also raised when the bitmapped font changes. </summary>
public event EventHandler<EventArgs> ChatFontChanged;
internal void RaiseChatFontChanged( bool arial ) { fontArgs.UseArial = arial; Raise( ChatFontChanged, fontArgs ); }
// Cache event instances so we don't create needless new objects. // Cache event instances so we don't create needless new objects.
@ -73,6 +78,7 @@ namespace ClassicalSharp {
MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs(); MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs();
EnvVarEventArgs envArgs = new EnvVarEventArgs(); EnvVarEventArgs envArgs = new EnvVarEventArgs();
ChatEventArgs chatArgs = new ChatEventArgs(); ChatEventArgs chatArgs = new ChatEventArgs();
ChatFontChangedEventArgs fontArgs = new ChatFontChangedEventArgs();
void Raise( EventHandler handler ) { void Raise( EventHandler handler ) {
if( handler != null ) { if( handler != null ) {
@ -94,21 +100,33 @@ namespace ClassicalSharp {
public sealed class ChatEventArgs : EventArgs { public sealed class ChatEventArgs : EventArgs {
/// <summary> Where this chat message should appear on the screen. </summary>
public CpeMessage Type; public CpeMessage Type;
/// <summary> Raw text of the message (including colour codes),
/// with code page 437 indices converted to their unicode representations. </summary>
public string Text; public string Text;
} }
public sealed class MapLoadingEventArgs : EventArgs { public sealed class MapLoadingEventArgs : EventArgs {
/// <summary> Percentage of the map that has been fully decompressed by the client. </summary>
public int Progress; public int Progress;
} }
public sealed class EnvVarEventArgs : EventArgs { public sealed class EnvVarEventArgs : EventArgs {
/// <summary> Map environment variable that was changed. </summary>
public EnvVar Var; public EnvVar Var;
} }
public sealed class ChatFontChangedEventArgs : EventArgs {
/// <summary> true if chat should be drawn using arial,
/// false if it should be drawn using the current bitmapped font. </summary>
public bool UseArial;
}
public enum EnvVar { public enum EnvVar {
SidesBlock, SidesBlock,
EdgeBlock, EdgeBlock,

View File

@ -74,6 +74,7 @@ namespace ClassicalSharp {
internal int CloudsTextureId, RainTextureId, SnowTextureId; internal int CloudsTextureId, RainTextureId, SnowTextureId;
internal bool screenshotRequested; internal bool screenshotRequested;
public Bitmap FontBitmap; public Bitmap FontBitmap;
public bool UseArial = false;
void LoadAtlas( Bitmap bmp ) { void LoadAtlas( Bitmap bmp ) {
TerrainAtlas1D.Dispose(); TerrainAtlas1D.Dispose();
@ -108,7 +109,7 @@ namespace ClassicalSharp {
ModelCache = new ModelCache( this ); ModelCache = new ModelCache( this );
ModelCache.InitCache(); ModelCache.InitCache();
AsyncDownloader = new AsyncDownloader( skinServer ); AsyncDownloader = new AsyncDownloader( skinServer );
Drawer2D = new GdiPlusDrawerFont( Graphics ); Drawer2D = new GdiPlusDrawer2D( Graphics );
TerrainAtlas1D = new TerrainAtlas1D( Graphics ); TerrainAtlas1D = new TerrainAtlas1D( Graphics );
TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D ); TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D );

View File

@ -268,6 +268,13 @@ namespace ClassicalSharp {
Key key = e.Key; Key key = e.Key;
if( SimulateMouse( key, true ) ) return; 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 )) ) { if( key == Key.F4 && (game.IsKeyDown( Key.AltLeft ) || game.IsKeyDown( Key.AltRight )) ) {
game.Exit(); game.Exit();
} else if( key == Keys[KeyBinding.Screenshot] ) { } else if( key == Keys[KeyBinding.Screenshot] ) {

View File

@ -86,8 +86,10 @@ namespace ClassicalSharp.TexturePack {
void SetFontBitmap( Game game, Stream stream ) { void SetFontBitmap( Game game, Stream stream ) {
game.FontBitmap = new Bitmap( stream ); game.FontBitmap = new Bitmap( stream );
if( game.Drawer2D is GdiPlusDrawerMCFont ) game.Drawer2D.SetFontBitmap( game.FontBitmap );
((GdiPlusDrawerMCFont)game.Drawer2D).SetFontBitmap( game.FontBitmap );
if( !game.UseArial)
game.Events.RaiseChatFontChanged( false );
} }
void UpdateTexture( ref int texId, Stream stream, bool setSkinType ) { void UpdateTexture( ref int texId, Stream stream, bool setSkinType ) {

View File

@ -76,7 +76,7 @@ namespace Launcher2 {
Window = new NativeWindow( 480, 480, Program.AppName, 0, Window = new NativeWindow( 480, 480, Program.AppName, 0,
GraphicsMode.Default, DisplayDevice.Default ); GraphicsMode.Default, DisplayDevice.Default );
Window.Visible = true; Window.Visible = true;
Drawer = new GdiPlusDrawerFont( null ); Drawer = new GdiPlusDrawer2D( null );
Init(); Init();
platformDrawer.Init( Window.WindowInfo ); platformDrawer.Init( Window.WindowInfo );

View File

@ -150,6 +150,12 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\InteropPatcher\InteropPatcher.csproj">
<Project>{4A4110EE-21CA-4715-AF67-0C8B7CE0642F}</Project>
<Name>InteropPatcher</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- This actually rewrites the calli and fixed code.--> <!-- This actually rewrites the calli and fixed code.-->
<Target Name="AfterBuild"> <Target Name="AfterBuild">

View File

@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
namespace SharpDX.Direct3D9 { namespace SharpDX.Direct3D9 {