mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 19:15:14 -04:00
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:
parent
d012d7dd0a
commit
35fa930ece
@ -395,7 +395,7 @@ namespace ClassicalSharp.Gui {
|
||||
|
||||
if( Utils.IsUrlPrefix( url, 0 ) ) {
|
||||
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,
|
||||
"Be careful - urls from strangers may link to websites that",
|
||||
" may have viruses, or things you may not want to open/see."
|
||||
|
@ -7,7 +7,7 @@ namespace ClassicalSharp.Gui {
|
||||
|
||||
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> renderFrame, params string[] body ) : base( game ) {
|
||||
this.Metadata = metadata;
|
||||
@ -17,13 +17,14 @@ namespace ClassicalSharp.Gui {
|
||||
this.title = title;
|
||||
this.body = body;
|
||||
this.confirmNo = confirmNo;
|
||||
this.showAlways = showAlways;
|
||||
}
|
||||
|
||||
internal Screen lastScreen;
|
||||
internal bool wasCursorVisible;
|
||||
string title, lastTitle;
|
||||
string[] body, lastBody;
|
||||
bool confirmNo, confirmMode;
|
||||
bool confirmNo, confirmMode, showAlways;
|
||||
|
||||
public override void Init() {
|
||||
titleFont = new Font( game.FontName, 16, FontStyle.Bold );
|
||||
@ -51,7 +52,7 @@ namespace ClassicalSharp.Gui {
|
||||
labels[i].Dispose();
|
||||
}
|
||||
this.title = title;
|
||||
this.body = body;
|
||||
this.body = body;
|
||||
|
||||
labels = new TextWidget[body.Length + 1];
|
||||
labels[0] = TextWidget.Create( game, 0, -120, title,
|
||||
@ -100,16 +101,17 @@ namespace ClassicalSharp.Gui {
|
||||
}
|
||||
|
||||
void InitStandardButtons() {
|
||||
widgets = new ButtonWidget[] {
|
||||
ButtonWidget.Create( game, -110, 30, 160, 35, "Yes", Anchor.Centre,
|
||||
Anchor.Centre, titleFont, OnYesClick ),
|
||||
ButtonWidget.Create( game, 110, 30, 160, 35, "No", Anchor.Centre,
|
||||
Anchor.Centre, titleFont, OnNoClick ),
|
||||
ButtonWidget.Create( game, -110, 80, 160, 35, "Always yes", Anchor.Centre,
|
||||
Anchor.Centre, titleFont, OnYesAlwaysClick ),
|
||||
ButtonWidget.Create( game, 110, 80, 160, 35, "Always no", Anchor.Centre,
|
||||
Anchor.Centre, titleFont, OnNoAlwaysClick ),
|
||||
};
|
||||
widgets = new ButtonWidget[showAlways ? 4 : 2];
|
||||
widgets[0] = ButtonWidget.Create( game, -110, 30, 160, 35, "Yes", Anchor.Centre,
|
||||
Anchor.Centre, titleFont, OnYesClick );
|
||||
widgets[1] = ButtonWidget.Create( game, 110, 30, 160, 35, "No", Anchor.Centre,
|
||||
Anchor.Centre, titleFont, OnNoClick );
|
||||
if( !showAlways ) return;
|
||||
|
||||
widgets[2] = ButtonWidget.Create( game, -110, 80, 160, 35, "Always yes", Anchor.Centre,
|
||||
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;
|
||||
|
@ -137,7 +137,7 @@ namespace ClassicalSharp.Gui {
|
||||
for( int i = 0; i < Textures.Length; i++ ) {
|
||||
Texture tex = Textures[i];
|
||||
if( tex.IsValid && tex.Bounds.Contains( mouseX, mouseY ) )
|
||||
return GetUrl( i, mouseX ) ?? lines[i];
|
||||
return GetUrl( i, mouseX ) ?? lines[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -48,25 +48,12 @@ namespace ClassicalSharp.Entities {
|
||||
Vector3 max = new Vector3( x, y, z ) + info.MaxBB[block];
|
||||
|
||||
BoundingBox blockBB = new BoundingBox( min, max );
|
||||
if( !blockBB.Intersects( bounds ) ) continue;
|
||||
if( !blockBB.Intersects( bounds ) ) continue;
|
||||
if( condition( block ) ) return true;
|
||||
}
|
||||
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
|
||||
/// bounding box of this entity are rope. </summary>
|
||||
public bool TouchesAnyRope() {
|
||||
@ -75,24 +62,56 @@ namespace ClassicalSharp.Entities {
|
||||
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
|
||||
/// bounding box of this entity are water or still water. </summary>
|
||||
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 );
|
||||
AdjustLiquidTestBounds( ref bounds );
|
||||
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 );
|
||||
return TouchesAnyLiquid( bounds, (byte)Block.Water, (byte)Block.StillWater );
|
||||
}
|
||||
}
|
||||
}
|
@ -53,7 +53,7 @@ namespace ClassicalSharp {
|
||||
public bool ServerSupportsFullCP437;
|
||||
|
||||
|
||||
#region Texture pack / terrain.png
|
||||
#region Texture pack / terrain.png
|
||||
|
||||
protected Game game;
|
||||
|
||||
@ -76,7 +76,7 @@ namespace ClassicalSharp {
|
||||
if( !game.AcceptedUrls.HasUrl( url ) && !game.DeniedUrls.HasUrl( url ) ) {
|
||||
game.AsyncDownloader.RetrieveContentLength( url, true, "CL_" + url );
|
||||
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,
|
||||
"Texture pack url:", url,
|
||||
"Download size: Determining..." ) );
|
||||
@ -127,14 +127,14 @@ namespace ClassicalSharp {
|
||||
game.World.TextureUrl = item.Url;
|
||||
} else if( Is304Status( item.WebEx ) ) {
|
||||
Bitmap bmp = TextureCache.GetBitmapFromCache( item.Url );
|
||||
if( bmp != null ) game.World.TextureUrl = item.Url;
|
||||
|
||||
if( bmp == null ) // Should never happen, but handle anyways.
|
||||
ExtractDefault();
|
||||
else if( item.Url != game.World.TextureUrl )
|
||||
game.ChangeTerrainAtlas( bmp );
|
||||
game.ChangeTerrainAtlas( bmp );
|
||||
|
||||
if( bmp != null ) game.World.TextureUrl = item.Url;
|
||||
} else {
|
||||
ExtractDefault();
|
||||
ExtractDefault();
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,14 +146,14 @@ namespace ClassicalSharp {
|
||||
game.World.TextureUrl = item.Url;
|
||||
} else if( Is304Status( item.WebEx ) ) {
|
||||
byte[] data = TextureCache.GetDataFromCache( item.Url );
|
||||
if( data != null ) game.World.TextureUrl = item.Url;
|
||||
|
||||
if( data == null ) { // Should never happen, but handle anyways.
|
||||
ExtractDefault();
|
||||
} else if( item.Url != game.World.TextureUrl ) {
|
||||
TexturePackExtractor extractor = new TexturePackExtractor();
|
||||
extractor.Extract( data, game );
|
||||
}
|
||||
}
|
||||
|
||||
if( data != null ) game.World.TextureUrl = item.Url;
|
||||
} else {
|
||||
ExtractDefault();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user