Fix texture pack/terrain.png not changing anymore when loaded from texcache, also 'always yes/no' should not be shown in the 'sure you want to visit url' dialog.

This commit is contained in:
UnknownShadow200 2016-04-03 15:17:57 +10:00
parent d012d7dd0a
commit 35fa930ece
5 changed files with 73 additions and 52 deletions

View File

@ -395,7 +395,7 @@ namespace ClassicalSharp.Gui {
if( Utils.IsUrlPrefix( url, 0 ) ) { if( Utils.IsUrlPrefix( url, 0 ) ) {
game.ShowWarning( new WarningScreen( game.ShowWarning( new WarningScreen(
game, url, false, "Are you sure you want to go to this url?", game, url, false, false, "Are you sure you want to go to this url?",
OpenUrl, AppendUrl, null, url, OpenUrl, AppendUrl, null, url,
"Be careful - urls from strangers may link to websites that", "Be careful - urls from strangers may link to websites that",
" may have viruses, or things you may not want to open/see." " may have viruses, or things you may not want to open/see."

View File

@ -7,7 +7,7 @@ namespace ClassicalSharp.Gui {
public sealed class WarningScreen : MenuScreen { public sealed class WarningScreen : MenuScreen {
public WarningScreen( Game game, object metadata, bool confirmNo, string title, public WarningScreen( Game game, object metadata, bool showAlways, bool confirmNo, string title,
Action<WarningScreen> yesClick, Action<WarningScreen> noClick, Action<WarningScreen> yesClick, Action<WarningScreen> noClick,
Action<WarningScreen> renderFrame, params string[] body ) : base( game ) { Action<WarningScreen> renderFrame, params string[] body ) : base( game ) {
this.Metadata = metadata; this.Metadata = metadata;
@ -17,13 +17,14 @@ namespace ClassicalSharp.Gui {
this.title = title; this.title = title;
this.body = body; this.body = body;
this.confirmNo = confirmNo; this.confirmNo = confirmNo;
this.showAlways = showAlways;
} }
internal Screen lastScreen; internal Screen lastScreen;
internal bool wasCursorVisible; internal bool wasCursorVisible;
string title, lastTitle; string title, lastTitle;
string[] body, lastBody; string[] body, lastBody;
bool confirmNo, confirmMode; bool confirmNo, confirmMode, showAlways;
public override void Init() { public override void Init() {
titleFont = new Font( game.FontName, 16, FontStyle.Bold ); titleFont = new Font( game.FontName, 16, FontStyle.Bold );
@ -51,7 +52,7 @@ namespace ClassicalSharp.Gui {
labels[i].Dispose(); labels[i].Dispose();
} }
this.title = title; this.title = title;
this.body = body; this.body = body;
labels = new TextWidget[body.Length + 1]; labels = new TextWidget[body.Length + 1];
labels[0] = TextWidget.Create( game, 0, -120, title, labels[0] = TextWidget.Create( game, 0, -120, title,
@ -100,16 +101,17 @@ namespace ClassicalSharp.Gui {
} }
void InitStandardButtons() { void InitStandardButtons() {
widgets = new ButtonWidget[] { widgets = new ButtonWidget[showAlways ? 4 : 2];
ButtonWidget.Create( game, -110, 30, 160, 35, "Yes", Anchor.Centre, widgets[0] = ButtonWidget.Create( game, -110, 30, 160, 35, "Yes", Anchor.Centre,
Anchor.Centre, titleFont, OnYesClick ), Anchor.Centre, titleFont, OnYesClick );
ButtonWidget.Create( game, 110, 30, 160, 35, "No", Anchor.Centre, widgets[1] = ButtonWidget.Create( game, 110, 30, 160, 35, "No", Anchor.Centre,
Anchor.Centre, titleFont, OnNoClick ), Anchor.Centre, titleFont, OnNoClick );
ButtonWidget.Create( game, -110, 80, 160, 35, "Always yes", Anchor.Centre, if( !showAlways ) return;
Anchor.Centre, titleFont, OnYesAlwaysClick ),
ButtonWidget.Create( game, 110, 80, 160, 35, "Always no", Anchor.Centre, widgets[2] = ButtonWidget.Create( game, -110, 80, 160, 35, "Always yes", Anchor.Centre,
Anchor.Centre, titleFont, OnNoAlwaysClick ), Anchor.Centre, titleFont, OnYesAlwaysClick );
}; widgets[3] = ButtonWidget.Create( game, 110, 80, 160, 35, "Always no", Anchor.Centre,
Anchor.Centre, titleFont, OnNoAlwaysClick );
} }
Action<WarningScreen> yesClick, noClick, renderFrame; Action<WarningScreen> yesClick, noClick, renderFrame;

View File

@ -137,7 +137,7 @@ namespace ClassicalSharp.Gui {
for( int i = 0; i < Textures.Length; i++ ) { for( int i = 0; i < Textures.Length; i++ ) {
Texture tex = Textures[i]; Texture tex = Textures[i];
if( tex.IsValid && tex.Bounds.Contains( mouseX, mouseY ) ) if( tex.IsValid && tex.Bounds.Contains( mouseX, mouseY ) )
return GetUrl( i, mouseX ) ?? lines[i]; return GetUrl( i, mouseX ) ?? lines[i];
} }
return null; return null;
} }

View File

@ -48,25 +48,12 @@ namespace ClassicalSharp.Entities {
Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block]; Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block];
BoundingBox blockBB = new BoundingBox( min, max ); BoundingBox blockBB = new BoundingBox( min, max );
if( !blockBB.Intersects( bounds ) ) continue; if( !blockBB.Intersects( bounds ) ) continue;
if( condition( block ) ) return true; if( condition( block ) ) return true;
} }
return false; return false;
} }
/// <summary> Constant offset used to avoid floating point roundoff errors. </summary>
public const float Adjustment = 0.001f;
static readonly Vector3 liqExpand = new Vector3( 0.25f/16f, 0/16f, 0.25f/16f );
/// <summary> Determines whether any of the blocks that intersect the
/// bounding box of this entity are lava or still lava. </summary>
public bool TouchesAnyLava() {
BoundingBox bounds = CollisionBounds.Expand( liqExpand );
AdjustLiquidTestBounds( ref bounds );
return TouchesAny( bounds,
b => b == (byte)Block.Lava || b == (byte)Block.StillLava );
}
/// <summary> Determines whether any of the blocks that intersect the /// <summary> Determines whether any of the blocks that intersect the
/// bounding box of this entity are rope. </summary> /// bounding box of this entity are rope. </summary>
public bool TouchesAnyRope() { public bool TouchesAnyRope() {
@ -75,24 +62,56 @@ namespace ClassicalSharp.Entities {
return TouchesAny( bounds, b => b == (byte)Block.Rope ); return TouchesAny( bounds, b => b == (byte)Block.Rope );
} }
/// <summary> Constant offset used to avoid floating point roundoff errors. </summary>
public const float Adjustment = 0.001f;
static readonly Vector3 liqExpand = new Vector3( 0.25f/16f, 0/16f, 0.25f/16f );
// If liquid block above, leave height same
// otherwise reduce water BB height by 0.5 blocks
bool TouchesAnyLiquid( BoundingBox bounds, byte block1, byte block2 ) {
Vector3I bbMin = Vector3I.Floor( bounds.Min );
Vector3I bbMax = Vector3I.Floor( bounds.Max );
int height = game.World.Height;
// Order loops so that we minimise cache misses
for( int y = bbMin.Y; y <= bbMax.Y; y++ )
for( int z = bbMin.Z; z <= bbMax.Z; z++ )
for( int x = bbMin.X; x <= bbMax.X; x++ )
{
if( !game.World.IsValidPos( x, y, z ) ) continue;
byte block = game.World.GetBlock( x, y, z );
byte below = (y - 1) < 0 ? (byte)0 : game.World.GetBlock( x, y - 1, z );
byte above = (y + 1) >= height ? (byte)0 : game.World.GetBlock( x, y + 1, z );
// TODO: use recording to find right constants when I have more time
Vector3 min = new Vector3( x, y, z ) + info.MinBB[block];
Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block];
//if( game.BlockInfo.Collide[below] != CollideType.SwimThrough )
// min.Y += 4/16f;
//if( game.BlockInfo.Collide[above] != CollideType.SwimThrough )
// max.Y -= 4/16f;
BoundingBox blockBB = new BoundingBox( min, max );
if( !blockBB.Intersects( bounds ) ) continue;
if( block == block1 || block == block2 ) return true;
}
return false;
}
/// <summary> Determines whether any of the blocks that intersect the
/// bounding box of this entity are lava or still lava. </summary>
public bool TouchesAnyLava() {
BoundingBox bounds = CollisionBounds.Expand( liqExpand );
return TouchesAnyLiquid( bounds, (byte)Block.Lava, (byte)Block.StillLava );
}
/// <summary> Determines whether any of the blocks that intersect the /// <summary> Determines whether any of the blocks that intersect the
/// bounding box of this entity are water or still water. </summary> /// bounding box of this entity are water or still water. </summary>
public bool TouchesAnyWater() { public bool TouchesAnyWater() {
// TODO: proper way to check seems to be:
// If liquid block above, leave height same
// otherwise reduce water BB height by 0.5 blocks
BoundingBox bounds = CollisionBounds.Expand( liqExpand ); BoundingBox bounds = CollisionBounds.Expand( liqExpand );
AdjustLiquidTestBounds( ref bounds ); return TouchesAnyLiquid( bounds, (byte)Block.Water, (byte)Block.StillWater );
return TouchesAny( bounds,
b => b == (byte)Block.Water || b == (byte)Block.StillWater );
}
void AdjustLiquidTestBounds( ref BoundingBox bounds ) {
// Even though we collide with lava 3 blocks above our feet, vanilla client thinks
// that we do not.. so we have to maintain compatibility here.
float height = bounds.Max.Y - bounds.Min.Y;
const float pHeight = (28.5f - 4f)/16f;
bounds.Max.Y = bounds.Min.Y + Math.Min( height, pHeight );
} }
} }
} }

View File

@ -53,7 +53,7 @@ namespace ClassicalSharp {
public bool ServerSupportsFullCP437; public bool ServerSupportsFullCP437;
#region Texture pack / terrain.png #region Texture pack / terrain.png
protected Game game; protected Game game;
@ -76,7 +76,7 @@ namespace ClassicalSharp {
if( !game.AcceptedUrls.HasUrl( url ) && !game.DeniedUrls.HasUrl( url ) ) { if( !game.AcceptedUrls.HasUrl( url ) && !game.DeniedUrls.HasUrl( url ) ) {
game.AsyncDownloader.RetrieveContentLength( url, true, "CL_" + url ); game.AsyncDownloader.RetrieveContentLength( url, true, "CL_" + url );
game.ShowWarning( new WarningScreen( game.ShowWarning( new WarningScreen(
game, "CL_" + url, true, "Do you want to download the server's texture pack?", game, "CL_" + url, true, true, "Do you want to download the server's texture pack?",
DownloadTexturePack, null, WarningScreenTick, DownloadTexturePack, null, WarningScreenTick,
"Texture pack url:", url, "Texture pack url:", url,
"Download size: Determining..." ) ); "Download size: Determining..." ) );
@ -127,14 +127,14 @@ namespace ClassicalSharp {
game.World.TextureUrl = item.Url; game.World.TextureUrl = item.Url;
} else if( Is304Status( item.WebEx ) ) { } else if( Is304Status( item.WebEx ) ) {
Bitmap bmp = TextureCache.GetBitmapFromCache( item.Url ); Bitmap bmp = TextureCache.GetBitmapFromCache( item.Url );
if( bmp != null ) game.World.TextureUrl = item.Url;
if( bmp == null ) // Should never happen, but handle anyways. if( bmp == null ) // Should never happen, but handle anyways.
ExtractDefault(); ExtractDefault();
else if( item.Url != game.World.TextureUrl ) else if( item.Url != game.World.TextureUrl )
game.ChangeTerrainAtlas( bmp ); game.ChangeTerrainAtlas( bmp );
if( bmp != null ) game.World.TextureUrl = item.Url;
} else { } else {
ExtractDefault(); ExtractDefault();
} }
} }
@ -146,14 +146,14 @@ namespace ClassicalSharp {
game.World.TextureUrl = item.Url; game.World.TextureUrl = item.Url;
} else if( Is304Status( item.WebEx ) ) { } else if( Is304Status( item.WebEx ) ) {
byte[] data = TextureCache.GetDataFromCache( item.Url ); byte[] data = TextureCache.GetDataFromCache( item.Url );
if( data != null ) game.World.TextureUrl = item.Url;
if( data == null ) { // Should never happen, but handle anyways. if( data == null ) { // Should never happen, but handle anyways.
ExtractDefault(); ExtractDefault();
} else if( item.Url != game.World.TextureUrl ) { } else if( item.Url != game.World.TextureUrl ) {
TexturePackExtractor extractor = new TexturePackExtractor(); TexturePackExtractor extractor = new TexturePackExtractor();
extractor.Extract( data, game ); extractor.Extract( data, game );
} }
if( data != null ) game.World.TextureUrl = item.Url;
} else { } else {
ExtractDefault(); ExtractDefault();
} }