mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 12:35:52 -04:00
Fix text input being slightly expanded when using default.png, block in hand now doesn't draw in third person, uses sunlight/shadowlight and has a left click animation.
This commit is contained in:
parent
25fe4e68ac
commit
4c219b8a46
@ -65,6 +65,9 @@ namespace ClassicalSharp {
|
||||
|
||||
public override Size MeasureSize( ref DrawTextArgs args ) {
|
||||
GetTextParts( args.Text );
|
||||
if( parts.Count == 0 )
|
||||
return Size.Empty;
|
||||
|
||||
SizeF total = SizeF.Empty;
|
||||
for( int i = 0; i < parts.Count; i++ ) {
|
||||
SizeF size = measuringGraphics.MeasureString( parts[i].Text, args.Font, Int32.MaxValue, format );
|
||||
@ -72,7 +75,7 @@ namespace ClassicalSharp {
|
||||
total.Width += size.Width;
|
||||
}
|
||||
|
||||
if( args.UseShadow && parts.Count > 0 ) {
|
||||
if( args.UseShadow ) {
|
||||
total.Width += Offset; total.Height += Offset;
|
||||
}
|
||||
return Size.Ceiling( total );
|
||||
|
@ -127,6 +127,8 @@ namespace ClassicalSharp {
|
||||
|
||||
public override Size MeasureBitmappedSize( ref DrawTextArgs args ) {
|
||||
GetTextParts( args.Text );
|
||||
if( parts.Count == 0 )
|
||||
return Size.Empty;
|
||||
float point = args.Font.Size;
|
||||
Size total = new Size( 0, PtToPx( point, boxSize ) );
|
||||
|
||||
@ -139,7 +141,7 @@ namespace ClassicalSharp {
|
||||
|
||||
if( args.Font.Style == FontStyle.Italic )
|
||||
total.Width += Utils.CeilDiv( total.Height, italicSize );
|
||||
if( args.UseShadow && parts.Count > 0 ) {
|
||||
if( args.UseShadow ) {
|
||||
int offset = ShadowOffset( args.Font.Size );
|
||||
total.Width += offset; total.Height += offset;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ namespace ClassicalSharp {
|
||||
|
||||
int inputOldHeight = -1;
|
||||
void UpdateChatYOffset( bool force ) {
|
||||
int height = textInput.RealHeight;
|
||||
int height = textInput.RealHeight;
|
||||
if( force || height != inputOldHeight ) {
|
||||
normalChat.YOffset = height + blockSize + 15;
|
||||
int y = game.Height - normalChat.Height - normalChat.YOffset;
|
||||
|
@ -92,6 +92,7 @@ namespace ClassicalSharp {
|
||||
game.ParticleManager.BreakBlockEffect( pos, block );
|
||||
game.UpdateBlock( pos.X, pos.Y, pos.Z, 0 );
|
||||
game.Network.SendSetBlock( pos.X, pos.Y, pos.Z, false, (byte)inv.HeldBlock );
|
||||
game.BlockHandRenderer.SetAnimation( true );
|
||||
}
|
||||
} else if( right ) {
|
||||
Vector3I pos = game.SelectedPos.TranslatedPos;
|
||||
@ -102,6 +103,7 @@ namespace ClassicalSharp {
|
||||
&& CheckIsFree( game.SelectedPos, block ) ) {
|
||||
game.UpdateBlock( pos.X, pos.Y, pos.Z, block );
|
||||
game.Network.SendSetBlock( pos.X, pos.Y, pos.Z, true, block );
|
||||
game.BlockHandRenderer.SetAnimation( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,9 @@ namespace ClassicalSharp.Model {
|
||||
// TODO: using 'is' is ugly, but means we can avoid creating
|
||||
// a string every single time held block changes.
|
||||
if( p is FakePlayer ) {
|
||||
col = FastColour.Scale( FastColour.White, 0.8f );
|
||||
Vector3I eyePos = Vector3I.Floor( game.LocalPlayer.EyePosition );
|
||||
FastColour baseCol = game.Map.IsLit( eyePos ) ? game.Map.Sunlight : game.Map.Shadowlight;
|
||||
col = FastColour.Scale( baseCol, 0.8f );
|
||||
block = ((FakePlayer)p).Block;
|
||||
} else {
|
||||
block = Byte.Parse( p.ModelName );
|
||||
|
@ -9,6 +9,7 @@ namespace ClassicalSharp.Renderers {
|
||||
Game game;
|
||||
BlockModel block;
|
||||
FakePlayer fakePlayer;
|
||||
bool playAnimation, leftAnimation;
|
||||
|
||||
public BlockHandRenderer( Game window ) {
|
||||
this.game = window;
|
||||
@ -20,11 +21,18 @@ namespace ClassicalSharp.Renderers {
|
||||
SetupMatrices();
|
||||
}
|
||||
|
||||
double animTime;
|
||||
public void Render( double delta ) {
|
||||
if( game.Camera.IsThirdPerson )
|
||||
return;
|
||||
game.Graphics.Texturing = true;
|
||||
game.Graphics.DepthTest = false;
|
||||
game.Graphics.AlphaTest = true;
|
||||
|
||||
fakePlayer.Position = Vector3.Zero;
|
||||
if( playAnimation )
|
||||
DoAnimation( delta );
|
||||
|
||||
byte type = (byte)game.Inventory.HeldBlock;
|
||||
if( game.BlockInfo.IsSprite[type] )
|
||||
game.Graphics.LoadMatrix( ref spriteMat );
|
||||
@ -39,9 +47,25 @@ namespace ClassicalSharp.Renderers {
|
||||
game.Graphics.AlphaTest = false;
|
||||
}
|
||||
|
||||
const double animPeriod = 0.25;
|
||||
const double animSpeed = Math.PI / 0.25;
|
||||
void DoAnimation( double delta ) {
|
||||
if( !leftAnimation ) {
|
||||
fakePlayer.Position.Y = -(float)Math.Sin( animTime * animSpeed );
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
animTime += delta;
|
||||
if( animTime > animPeriod ) {
|
||||
animTime = 0;
|
||||
playAnimation = false;
|
||||
fakePlayer.Position = Vector3.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
Matrix4 normalMat, spriteMat;
|
||||
void SetupMatrices() {
|
||||
void SetupMatrices() {
|
||||
Matrix4 m = Matrix4.Identity;
|
||||
m = m * Matrix4.Scale( 0.6f );
|
||||
m = m * Matrix4.RotateY( 45 * Utils.Deg2Rad );
|
||||
@ -52,8 +76,18 @@ namespace ClassicalSharp.Renderers {
|
||||
|
||||
public void Dispose() {
|
||||
}
|
||||
|
||||
/// <summary> Sets the current animation state of the held block.<br/>
|
||||
/// true = left mouse pressed, false = right mouse pressed. </summary>
|
||||
public void SetAnimation( bool left ) {
|
||||
playAnimation = true;
|
||||
animTime = 0;
|
||||
leftAnimation = left;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Skeleton implementation of a player entity so we can reuse
|
||||
/// block model rendering code. </summary>
|
||||
internal class FakePlayer : Player {
|
||||
|
||||
public FakePlayer( Game game ) : base( game ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user