From 599944d943e4c85e7e6bf8b4762d6fde8d3c56db Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 17 Jan 2016 16:40:14 +1100 Subject: [PATCH] Fix isometric blocks/block models sampling from wrong vertical location and fix order of rendering of elements in the hotbar. (Thanks 123DontMessWitMe) --- ClassicalSharp/2D/IsometricBlockDrawer.cs | 32 +++++++++---------- .../2D/Widgets/BlockHotbarWidget.cs | 10 ++---- ClassicalSharp/2D/Widgets/ButtonWidget.cs | 2 ++ ClassicalSharp/Model/BlockModel.cs | 30 ++++++++--------- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/ClassicalSharp/2D/IsometricBlockDrawer.cs b/ClassicalSharp/2D/IsometricBlockDrawer.cs index 2d7fb43c9..4b3fedf20 100644 --- a/ClassicalSharp/2D/IsometricBlockDrawer.cs +++ b/ClassicalSharp/2D/IsometricBlockDrawer.cs @@ -76,7 +76,7 @@ namespace ClassicalSharp { FlushIfNotSame(); FastColour col = colNormal; - float vOrigin = rec.V1; + float vOrigin = (texLoc % atlas.elementsPerAtlas1D) * atlas.invElementSize; rec.U1 = minBB.X; rec.U2 = maxBB.X; rec.V1 = vOrigin + minBB.Z * atlas.invElementSize; rec.V2 = vOrigin + maxBB.Z * atlas.invElementSize * 15.99f/16f; @@ -97,18 +97,18 @@ namespace ClassicalSharp { FlushIfNotSame(); FastColour col = fullBright ? colNormal : colZSide; - float vOrigin = rec.V1; + float vOrigin = (texLoc % atlas.elementsPerAtlas1D) * atlas.invElementSize; rec.U1 = minBB.X; rec.U2 = maxBB.X; - rec.V1 = vOrigin + minBB.Y * atlas.invElementSize; - rec.V2 = vOrigin + maxBB.Y * atlas.invElementSize * 15.99f/16f; + rec.V1 = vOrigin + (1 - minBB.Y) * atlas.invElementSize; + rec.V2 = vOrigin + (1 - maxBB.Y) * atlas.invElementSize * 15.99f/16f; - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + Make( minBB.X ), pos.Y + Make( minBB.Y ), - pos.Z + z, rec.U2, rec.V2, col ); cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + Make( minBB.X ), pos.Y + Make( maxBB.Y ), + pos.Z + z, rec.U2, rec.V2, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + Make( minBB.X ), pos.Y + Make( minBB.Y ), pos.Z + z, rec.U2, rec.V1, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + Make( maxBB.X ), pos.Y + Make( maxBB.Y ), - pos.Z + z, rec.U1, rec.V1, col ); cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + Make( maxBB.X ), pos.Y + Make( minBB.Y ), + pos.Z + z, rec.U1, rec.V1, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + Make( maxBB.X ), pos.Y + Make( maxBB.Y ), pos.Z + z, rec.U1, rec.V2, col ); } @@ -118,18 +118,18 @@ namespace ClassicalSharp { FlushIfNotSame(); FastColour col = fullBright ? colNormal : colXSide; - float vOrigin = rec.V1; + float vOrigin = (texLoc % atlas.elementsPerAtlas1D) * atlas.invElementSize; rec.U1 = minBB.Z; rec.U2 = maxBB.Z; - rec.V1 = vOrigin + minBB.Y * atlas.invElementSize; - rec.V2 = vOrigin + maxBB.Y * atlas.invElementSize * 15.99f/16f; + rec.V1 = vOrigin + (1 - minBB.Y) * atlas.invElementSize; + rec.V2 = vOrigin + (1 - maxBB.Y) * atlas.invElementSize * 15.99f/16f; - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + Make( minBB.Y ), + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + Make( maxBB.Y ), pos.Z + Make( minBB.Z ), rec.U2, rec.V2, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + Make( maxBB.Y ), - pos.Z + Make( minBB.Z ), rec.U2, rec.V1, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + Make( maxBB.Y ), - pos.Z + Make( maxBB.Z ), rec.U1, rec.V1, col ); cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + Make( minBB.Y ), + pos.Z + Make( minBB.Z ), rec.U2, rec.V1, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + Make( minBB.Y ), + pos.Z + Make( maxBB.Z ), rec.U1, rec.V1, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + Make( maxBB.Y ), pos.Z + Make( maxBB.Z ), rec.U1, rec.V2, col ); } diff --git a/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs b/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs index 2bbc13b3b..cb0b2c888 100644 --- a/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs +++ b/ClassicalSharp/2D/Widgets/BlockHotbarWidget.cs @@ -45,10 +45,9 @@ namespace ClassicalSharp { int x = (int)(X + barXOffset + (elemSize + borderSize) * i + elemSize / 2); int y = (int)(game.Height - barHeight / 2); - float scale = (elemSize * 14/16f) / 2f; + float scale = (elemSize * 13.5f/16f) / 2f; IsometricBlockDrawer.Draw( game, block, scale, x, y ); } - RenderSelected(); graphicsApi.Texturing = false; } @@ -56,16 +55,13 @@ namespace ClassicalSharp { int texId = game.UseClassicGui ? game.GuiClassicTexId : game.GuiTexId; backTex.ID = texId; backTex.Render( graphicsApi ); - } - - void RenderSelected() { - int texId = game.UseClassicGui ? game.GuiClassicTexId : game.GuiTexId; + int i = game.Inventory.HeldBlockIndex; int x = (int)(X + barXOffset + (elemSize + borderSize) * i + elemSize / 2); selTex.ID = texId; selTex.X1 = (int)(x - selBlockSize / 2); - selTex.Render( graphicsApi ); + graphicsApi.Draw2DTexture( ref selTex ); } public override void Dispose() { } diff --git a/ClassicalSharp/2D/Widgets/ButtonWidget.cs b/ClassicalSharp/2D/Widgets/ButtonWidget.cs index 3bcf7a1c2..725b6e1a9 100644 --- a/ClassicalSharp/2D/Widgets/ButtonWidget.cs +++ b/ClassicalSharp/2D/Widgets/ButtonWidget.cs @@ -31,6 +31,8 @@ namespace ClassicalSharp { int defaultHeight; readonly Font font; + public string[] Description; + public override void Init() { DrawTextArgs args = new DrawTextArgs( "I", font, true ); defaultHeight = game.Drawer2D.MeasureSize( ref args ).Height; diff --git a/ClassicalSharp/Model/BlockModel.cs b/ClassicalSharp/Model/BlockModel.cs index 72dfdca73..613910cf0 100644 --- a/ClassicalSharp/Model/BlockModel.cs +++ b/ClassicalSharp/Model/BlockModel.cs @@ -106,7 +106,7 @@ namespace ClassicalSharp.Model { FlushIfNotSame( texIndex ); FastColour col = bright ? FastColour.White : FastColour.Scale( this.col, shade ); - float vOrigin = rec.V1; + float vOrigin = (texId % atlas.elementsPerAtlas1D) * atlas.invElementSize; rec.U1 = minBB.X; rec.U2 = maxBB.X; rec.V1 = vOrigin + minBB.Z * atlas.invElementSize; rec.V2 = vOrigin + maxBB.Z * atlas.invElementSize * 15.99f/16f; @@ -123,16 +123,16 @@ namespace ClassicalSharp.Model { FlushIfNotSame( texIndex ); FastColour col = bright ? FastColour.White : FastColour.Scale( this.col, shade ); - float vOrigin = rec.V1; + float vOrigin = (texId % atlas.elementsPerAtlas1D) * atlas.invElementSize; rec.U1 = minBB.X; rec.U2 = maxBB.X; - rec.V1 = vOrigin + minBB.Y * atlas.invElementSize; - rec.V2 = vOrigin + maxBB.Y * atlas.invElementSize * 15.99f/16f; + rec.V1 = vOrigin + (1 - minBB.Y) * atlas.invElementSize; + rec.V2 = vOrigin + (1 - maxBB.Y) * atlas.invElementSize * 15.99f/16f; if( swapU ) rec.SwapU(); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( minBB.X - 0.5f, 0, z, rec.U1, rec.V2, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( minBB.X - 0.5f, height, z, rec.U1, rec.V1, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( maxBB.X - 0.5f, height, z, rec.U2, rec.V1, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( maxBB.X - 0.5f, 0, z, rec.U2, rec.V2, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( minBB.X - 0.5f, 0, z, rec.U1, rec.V1, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( minBB.X - 0.5f, height, z, rec.U1, rec.V2, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( maxBB.X - 0.5f, height, z, rec.U2, rec.V2, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( maxBB.X - 0.5f, 0, z, rec.U2, rec.V1, col ); } void XQuad( float x, int side, bool swapU, float shade ) { @@ -141,16 +141,16 @@ namespace ClassicalSharp.Model { FlushIfNotSame( texIndex ); FastColour col = bright ? FastColour.White : FastColour.Scale( this.col, shade ); - float vOrigin = rec.V1; + float vOrigin = (texId % atlas.elementsPerAtlas1D) * atlas.invElementSize; rec.U1 = minBB.Z; rec.U2 = maxBB.Z; - rec.V1 = vOrigin + minBB.Y * atlas.invElementSize; - rec.V2 = vOrigin + maxBB.Y * atlas.invElementSize * 15.99f/16f; + rec.V1 = vOrigin + (1 - minBB.Y) * atlas.invElementSize; + rec.V2 = vOrigin + (1 - maxBB.Y) * atlas.invElementSize * 15.99f/16f; if( swapU ) rec.SwapU(); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( x, 0, minBB.Z - 0.5f, rec.U1, rec.V2, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( x, height, minBB.Z - 0.5f, rec.U1, rec.V1, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( x, height, maxBB.Z - 0.5f, rec.U2, rec.V1, col ); - cache.vertices[index++] = new VertexPos3fTex2fCol4b( x, 0, maxBB.Z - 0.5f, rec.U2, rec.V2, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( x, 0, minBB.Z - 0.5f, rec.U1, rec.V1, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( x, height, minBB.Z - 0.5f, rec.U1, rec.V2, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( x, height, maxBB.Z - 0.5f, rec.U2, rec.V2, col ); + cache.vertices[index++] = new VertexPos3fTex2fCol4b( x, 0, maxBB.Z - 0.5f, rec.U2, rec.V1, col ); } void SpriteZQuad( int side, bool firstPart ) {