mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Press F8 (temp debug) to switch between default.png and arial for chat.
This commit is contained in:
parent
2493feb86f
commit
57d4a937c8
@ -47,6 +47,9 @@ namespace ClassicalSharp {
|
|||||||
src = newBmp;
|
src = newBmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Whether chat text should be drawn and measuring using the currently bitmapped font,
|
||||||
|
/// false uses the font supplied as the DrawTextArgs argument supplied to the function. </summary>
|
||||||
|
public bool UseBitmappedChat = false;
|
||||||
|
|
||||||
/// <summary> Draws a string using the specified arguments and font at the
|
/// <summary> Draws a string using the specified arguments and font at the
|
||||||
/// specified coordinates in the currently bound bitmap. </summary>
|
/// specified coordinates in the currently bound bitmap. </summary>
|
||||||
@ -63,8 +66,8 @@ namespace ClassicalSharp {
|
|||||||
/// <summary> Draws a string using the specified arguments, using the specified font or
|
/// <summary> Draws a string using the specified arguments, using the specified font or
|
||||||
/// the current bitmapped font depending on the 'useFont' argument, at the
|
/// the current bitmapped font depending on the 'useFont' argument, at the
|
||||||
/// specified coordinates in the currently bound bitmap. </summary>
|
/// specified coordinates in the currently bound bitmap. </summary>
|
||||||
public void DrawChatText( bool useFont, ref DrawTextArgs args, int windowX, int windowY ) {
|
public void DrawChatText( ref DrawTextArgs args, int windowX, int windowY ) {
|
||||||
if( useFont )
|
if( !UseBitmappedChat )
|
||||||
DrawText( ref args, windowX, windowY );
|
DrawText( ref args, windowX, windowY );
|
||||||
else
|
else
|
||||||
DrawBitmappedText( ref args, windowX, windowY );
|
DrawBitmappedText( ref args, windowX, windowY );
|
||||||
@ -79,8 +82,8 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
/// <summary> Returns the size of a bitmap needed to contain the specified text with the given arguments,
|
/// <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>
|
/// 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 ) {
|
public Size MeasureChatSize( ref DrawTextArgs args ) {
|
||||||
return useFont ? MeasureSize( ref args ) :
|
return !UseBitmappedChat ? MeasureSize( ref args ) :
|
||||||
MeasureBitmappedSize( ref args );
|
MeasureBitmappedSize( ref args );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +121,7 @@ namespace ClassicalSharp {
|
|||||||
game.chatInInputBuffer = null;
|
game.chatInInputBuffer = null;
|
||||||
}
|
}
|
||||||
game.Events.ChatReceived += ChatReceived;
|
game.Events.ChatReceived += ChatReceived;
|
||||||
|
game.Events.ChatFontChanged += ChatFontChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatReceived( object sender, ChatEventArgs e ) {
|
void ChatReceived( object sender, ChatEventArgs e ) {
|
||||||
@ -159,6 +160,12 @@ namespace ClassicalSharp {
|
|||||||
bottomRight.Dispose();
|
bottomRight.Dispose();
|
||||||
graphicsApi.DeleteTexture( ref announcementTex );
|
graphicsApi.DeleteTexture( ref announcementTex );
|
||||||
game.Events.ChatReceived -= ChatReceived;
|
game.Events.ChatReceived -= ChatReceived;
|
||||||
|
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 ) {
|
||||||
|
@ -62,7 +62,9 @@ namespace ClassicalSharp {
|
|||||||
fpsTextWidget.XOffset = 2;
|
fpsTextWidget.XOffset = 2;
|
||||||
fpsTextWidget.YOffset = 2;
|
fpsTextWidget.YOffset = 2;
|
||||||
fpsTextWidget.Init();
|
fpsTextWidget.Init();
|
||||||
fpsTextWidget.SetText( "FPS: no data yet" );
|
string fpsText = text.Length > 0 ? text.GetString() :
|
||||||
|
"FPS: no data yet";
|
||||||
|
fpsTextWidget.SetText( fpsText );
|
||||||
MakePosTextWidget();
|
MakePosTextWidget();
|
||||||
|
|
||||||
hackStatesWidget = new ChatTextWidget( game, posFont );
|
hackStatesWidget = new ChatTextWidget( game, posFont );
|
||||||
@ -130,23 +132,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.MeasureChatSize( game.UseArial, ref args ).Width;
|
widths[i] = game.Drawer2D.MeasureChatSize( 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.MeasureChatSize( game.UseArial, ref args );
|
Size size = game.Drawer2D.MeasureChatSize( 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.DrawChatText( game.UseArial, ref args, 0, 0 );
|
drawer.DrawChatText( 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.DrawChatText( game.UseArial, ref args, baseWidth + 16 * i, 0 );
|
drawer.DrawChatText( ref args, baseWidth + 16 * i, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
int y = fpsTextWidget.Height + 2;
|
int y = fpsTextWidget.Height + 2;
|
||||||
|
@ -21,7 +21,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
DrawTextArgs args = new DrawTextArgs( "I", font, true );
|
DrawTextArgs args = new DrawTextArgs( "I", font, true );
|
||||||
defaultHeight = game.Drawer2D.MeasureChatSize( game.UseArial, ref args ).Height;
|
defaultHeight = game.Drawer2D.MeasureChatSize( ref args ).Height;
|
||||||
Height = defaultHeight;
|
Height = defaultHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ namespace ClassicalSharp {
|
|||||||
Height = defaultHeight;
|
Height = defaultHeight;
|
||||||
} else {
|
} else {
|
||||||
DrawTextArgs args = new DrawTextArgs( text, font, true );
|
DrawTextArgs args = new DrawTextArgs( text, font, true );
|
||||||
if( game.UseArial )
|
texture = game.Drawer2D.UseBitmappedChat ?
|
||||||
texture = game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
|
game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ) :
|
||||||
else
|
game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
|
||||||
texture = game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 );
|
|
||||||
X = texture.X1 = CalcOffset( game.Width, texture.Width, XOffset, HorizontalAnchor );
|
X = texture.X1 = CalcOffset( game.Width, texture.Width, XOffset, HorizontalAnchor );
|
||||||
Y = texture.Y1 = CalcOffset( game.Height, texture.Height, YOffset, VerticalAnchor );
|
Y = texture.Y1 = CalcOffset( game.Height, texture.Height, YOffset, VerticalAnchor );
|
||||||
Height = texture.Height;
|
Height = texture.Height;
|
||||||
|
@ -19,11 +19,10 @@ namespace ClassicalSharp {
|
|||||||
public override void Init() {
|
public override void Init() {
|
||||||
Textures = new Texture[ElementsCount];
|
Textures = new Texture[ElementsCount];
|
||||||
DrawTextArgs args = new DrawTextArgs( "I", font, true );
|
DrawTextArgs args = new DrawTextArgs( "I", font, true );
|
||||||
defaultHeight = game.Drawer2D.MeasureSize( ref args ).Height;
|
defaultHeight = game.Drawer2D.MeasureChatSize( ref args ).Height;
|
||||||
|
|
||||||
for( int i = 0; i < Textures.Length; i++ ) {
|
for( int i = 0; i < Textures.Length; i++ )
|
||||||
Textures[i].Height = defaultHeight;
|
Textures[i].Height = defaultHeight;
|
||||||
}
|
|
||||||
UpdateDimensions();
|
UpdateDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,8 +30,11 @@ namespace ClassicalSharp {
|
|||||||
graphicsApi.DeleteTexture( ref Textures[index] );
|
graphicsApi.DeleteTexture( ref Textures[index] );
|
||||||
DrawTextArgs args = new DrawTextArgs( text, font, true );
|
DrawTextArgs args = new DrawTextArgs( text, font, true );
|
||||||
|
|
||||||
if( !String.IsNullOrEmpty( text ) ) {
|
if( !String.IsNullOrEmpty( text ) ) {
|
||||||
Texture tex = game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
|
Texture tex = game.Drawer2D.UseBitmappedChat ?
|
||||||
|
game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ) :
|
||||||
|
game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
|
||||||
|
|
||||||
tex.X1 = CalcOffset( game.Width, tex.Width, XOffset, HorizontalAnchor );
|
tex.X1 = CalcOffset( game.Width, tex.Width, XOffset, HorizontalAnchor );
|
||||||
tex.Y1 = CalcY( index, tex.Height );
|
tex.Y1 = CalcY( index, tex.Height );
|
||||||
Textures[index] = tex;
|
Textures[index] = tex;
|
||||||
@ -109,20 +111,17 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
for( int i = 0; i < Textures.Length; i++ ) {
|
for( int i = 0; i < Textures.Length; i++ )
|
||||||
graphicsApi.DeleteTexture( ref Textures[i] );
|
graphicsApi.DeleteTexture( ref Textures[i] );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
for( int i = 0; i < Textures.Length; i++ ) {
|
for( int i = 0; i < Textures.Length; i++ ) {
|
||||||
Textures[i].X1 += deltaX;
|
Textures[i].X1 += diffX;
|
||||||
Textures[i].Y1 += deltaY;
|
Textures[i].Y1 += diffY;
|
||||||
}
|
}
|
||||||
X = newX;
|
X = newX; Y = newY;
|
||||||
Y = newY;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -68,8 +68,8 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
/// <summary> Raised when the user changes chat font to arial or back to bitmapped font,
|
/// <summary> Raised when the user changes chat font to arial or back to bitmapped font,
|
||||||
/// also raised when the bitmapped font changes. </summary>
|
/// also raised when the bitmapped font changes. </summary>
|
||||||
public event EventHandler<EventArgs> ChatFontChanged;
|
public event EventHandler ChatFontChanged;
|
||||||
internal void RaiseChatFontChanged( bool arial ) { fontArgs.UseArial = arial; Raise( ChatFontChanged, fontArgs ); }
|
internal void RaiseChatFontChanged() { Raise( ChatFontChanged ); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -78,7 +78,6 @@ 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 ) {
|
||||||
@ -120,13 +119,6 @@ namespace ClassicalSharp {
|
|||||||
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,
|
||||||
|
@ -74,7 +74,6 @@ 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();
|
||||||
|
@ -271,8 +271,8 @@ namespace ClassicalSharp {
|
|||||||
// TODO: this is a temp debug statement
|
// TODO: this is a temp debug statement
|
||||||
// NOTE: this is a temp debug statement
|
// NOTE: this is a temp debug statement
|
||||||
if( key == Key.F8 ) {
|
if( key == Key.F8 ) {
|
||||||
game.UseArial = !game.UseArial;
|
game.Drawer2D.UseBitmappedChat = !game.Drawer2D.UseBitmappedChat;
|
||||||
game.Events.RaiseChatFontChanged( game.UseArial );
|
game.Events.RaiseChatFontChanged();
|
||||||
return;
|
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 )) ) {
|
||||||
|
@ -88,8 +88,8 @@ namespace ClassicalSharp.TexturePack {
|
|||||||
game.FontBitmap = new Bitmap( stream );
|
game.FontBitmap = new Bitmap( stream );
|
||||||
game.Drawer2D.SetFontBitmap( game.FontBitmap );
|
game.Drawer2D.SetFontBitmap( game.FontBitmap );
|
||||||
|
|
||||||
if( !game.UseArial)
|
if( game.Drawer2D.UseBitmappedChat )
|
||||||
game.Events.RaiseChatFontChanged( false );
|
game.Events.RaiseChatFontChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateTexture( ref int texId, Stream stream, bool setSkinType ) {
|
void UpdateTexture( ref int texId, Stream stream, bool setSkinType ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user