mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Initial implementation of being able to switch between arial and default.png (only works for FPSscreen right now)
This commit is contained in:
parent
72db7f7245
commit
2493feb86f
@ -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;
|
||||
@ -77,8 +78,7 @@ namespace ClassicalSharp {
|
||||
return Size.Ceiling( total );
|
||||
}
|
||||
|
||||
public override void DisposeInstance() {
|
||||
base.DisposeInstance();
|
||||
void DisposeText() {
|
||||
measuringGraphics.Dispose();
|
||||
measuringBmp.Dispose();
|
||||
}
|
@ -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();
|
||||
}
|
@ -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<int, SolidBrush> brushCache = new Dictionary<int, SolidBrush>( 16 );
|
||||
|
||||
protected Graphics g;
|
||||
protected Bitmap curBmp;
|
||||
public GdiPlusDrawer2D( IGraphicsApi graphics ) {
|
||||
this.graphics = graphics;
|
||||
}
|
||||
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;
|
||||
|
@ -16,14 +16,6 @@ namespace ClassicalSharp {
|
||||
/// <summary> Sets the underlying bitmap that drawing operations will be performed on. </summary>
|
||||
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
|
||||
/// specified coordinates in the currently bound bitmap. </summary>
|
||||
public abstract void DrawRect( FastColour colour, int x, int y, int width, int height );
|
||||
@ -55,30 +47,85 @@ namespace ClassicalSharp {
|
||||
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>
|
||||
public abstract Size MeasureSize( ref DrawTextArgs args );
|
||||
|
||||
/// <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> Returns the size of a bitmap needed to contain the specified text with the given arguments,
|
||||
/// when drawn with the current bitmapped font. </summary>
|
||||
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,
|
||||
/// 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 ) {
|
||||
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 );
|
||||
}
|
||||
|
||||
/// <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 ) ) {
|
||||
SetBitmap( bmp );
|
||||
args.SkipPartsCheck = true;
|
||||
|
||||
if( !bitmapped )
|
||||
DrawText( ref args, 0, 0 );
|
||||
else
|
||||
DrawBitmappedText( ref args, 0, 0 );
|
||||
Dispose();
|
||||
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>
|
||||
public Texture Make2DTexture( Bitmap bmp, Size used, int windowX, int windowY ) {
|
||||
int texId = graphics.CreateTexture( bmp );
|
||||
|
@ -6,12 +6,10 @@ 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 );
|
||||
}
|
||||
|
||||
@ -56,14 +54,18 @@ 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();
|
||||
@ -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 );
|
||||
|
46
ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs
Normal file
46
ClassicalSharp/2D/Widgets/Chat/ChatTextWidget.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -72,7 +72,9 @@ namespace ClassicalSharp {
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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,22 +47,18 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public override void Render( double delta ) {
|
||||
if( texture.IsValid ) {
|
||||
if( texture.IsValid )
|
||||
texture.Render( graphicsApi );
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
graphicsApi.DeleteTexture( ref texture );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
/// <summary> Stores various properties about the blocks in Minecraft Classic. </summary>
|
||||
public partial class BlockInfo {
|
||||
|
||||
internal int[] textures = new int[BlocksCount * TileSide.Sides];
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
/// <summary> Stores various properties about the blocks in Minecraft Classic. </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <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 ) {
|
||||
return hidden[( tile * BlocksCount + block ) * TileSide.Sides + tileSide];
|
||||
}
|
||||
|
@ -32,10 +32,13 @@ namespace ClassicalSharp {
|
||||
/// <summary> Gets whether the given block blocks sunlight. </summary>
|
||||
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 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 float[] FogDensity = new float[BlocksCount];
|
||||
|
@ -75,8 +75,8 @@
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="2D\Drawing\GdiPlusDrawerFont.cs" />
|
||||
<Compile Include="2D\Drawing\GdiPlusDrawerMCFont.cs" />
|
||||
<Compile Include="2D\Drawing\GdiPlusDrawer2D.Text.cs" />
|
||||
<Compile Include="2D\Drawing\GdiPlusDrawer2D.TextMC.cs" />
|
||||
<Compile Include="2D\GuiElement.cs" />
|
||||
<Compile Include="2D\IsometricBlockDrawer.cs" />
|
||||
<Compile Include="2D\Drawing\DrawTextArgs.cs" />
|
||||
@ -103,14 +103,15 @@
|
||||
<Compile Include="2D\Screens\Screen.cs" />
|
||||
<Compile Include="2D\Texture.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\Menu\MenuInputValidator.cs" />
|
||||
<Compile Include="2D\Widgets\Menu\MenuInputWidget.cs" />
|
||||
<Compile Include="2D\Widgets\NormalPlayerListWidget.cs" />
|
||||
<Compile Include="2D\Widgets\ButtonWidget.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\Widget.cs" />
|
||||
<Compile Include="Blocks\Block.cs" />
|
||||
@ -230,6 +231,7 @@
|
||||
<Folder Include="2D\Screens\Menu" />
|
||||
<Folder Include="2D\Widgets" />
|
||||
<Folder Include="2D\Widgets\Menu" />
|
||||
<Folder Include="2D\Widgets\Chat" />
|
||||
<Folder Include="Blocks" />
|
||||
<Folder Include="Entities\Particles" />
|
||||
<Folder Include="GraphicsAPI" />
|
||||
|
@ -66,6 +66,11 @@ namespace ClassicalSharp {
|
||||
public event EventHandler<ChatEventArgs> ChatReceived;
|
||||
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.
|
||||
@ -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 {
|
||||
|
||||
/// <summary> Where this chat message should appear on the screen. </summary>
|
||||
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 sealed class MapLoadingEventArgs : EventArgs {
|
||||
|
||||
/// <summary> Percentage of the map that has been fully decompressed by the client. </summary>
|
||||
public int Progress;
|
||||
}
|
||||
|
||||
public sealed class EnvVarEventArgs : EventArgs {
|
||||
|
||||
/// <summary> Map environment variable that was changed. </summary>
|
||||
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 {
|
||||
SidesBlock,
|
||||
EdgeBlock,
|
||||
|
@ -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 );
|
||||
|
@ -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] ) {
|
||||
|
@ -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 ) {
|
||||
|
@ -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 );
|
||||
|
||||
|
@ -150,6 +150,12 @@
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</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" />
|
||||
<!-- This actually rewrites the calli and fixed code.-->
|
||||
<Target Name="AfterBuild">
|
||||
|
Loading…
x
Reference in New Issue
Block a user