From ebf4a6aa5fbed4b62afd9e84b6db84b613a605a6 Mon Sep 17 00:00:00 2001 From: GinYuH <72181395+GinYuH@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:40:03 -0800 Subject: [PATCH] finished border system --- Tiles/Furniture/CalamityCanvasBorder.png | Bin 435 -> 415 bytes Tiles/Furniture/CalamityCanvasCorner.png | Bin 0 -> 159 bytes Tiles/Furniture/CalamityCanvasTile.cs | 100 +++++++++++++++++++---- 3 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 Tiles/Furniture/CalamityCanvasCorner.png diff --git a/Tiles/Furniture/CalamityCanvasBorder.png b/Tiles/Furniture/CalamityCanvasBorder.png index d5afe617d01382cd410e91dab4f3e6335a429b23..ba0d27387e14e0e7d4d51ec904096f00293adb8c 100644 GIT binary patch delta 354 zcmdnYJfC@jI9CD(GXn#|-mR=g6BQLKr2~9IT)DV-CpI<}C#R`NN{8Dyca)YT2Zg#B znE};(c~klsNO6_~`33)n0)}A!3ZaR0;`IzaJY5_^BHZ83Jk7YUDA?wwmc3S~LDiM#a|)hLF_xLk{DYrU1& zQlHJAs95^t!=n%3PFfp3dUNf2VcUAeb$=7Ypgs5bpZ_q^vibQ}KtFzm!N16TuOEu> z9oj8-?qhC9MUm~2OUJxle5mZ^UhHnUZ-N%z^E&Dk%59^ zQdK4y8%8oV0002WcOdBi000VfQchF<|NsC0|NsC00J6+1&j0`b32;bRa{vGi!vFvd z!vV){sAK>D0SHM%K~z{r?U>;T!ypWV8_i<&{x7^9S{aND)?Of`y&pv@eyC9+x12$L zBBj(?it1yhR69W=23V_zSzU#%S@}b~NAD|AYZMTbc2Ip#Q9#w!o(I($!g5_;DIB0` z6p%ILIG`ChD0E={HRJ%@~!cCHff@Ixznla)9^yaQxpb0PpwVF$E;4 zw=|j`m_5q*fvn5n%I`xI7=|Pa)EFQPQ<%=*ZD+JWqxvDVVNherbfAc@>eew#=gmgm nOyypOezk)!opv%XwU*@tc#5zg0e97C00000NkvXXu0mjfW{ITb diff --git a/Tiles/Furniture/CalamityCanvasCorner.png b/Tiles/Furniture/CalamityCanvasCorner.png new file mode 100644 index 0000000000000000000000000000000000000000..cb1dc47a9e56b34039f5bdb2e18da4316842f95c GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^93afX3?$7I7w-U4jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCim11AIbUxwv>O)wGI})57hXlY>H)j{S`TN^ur=L>4nJ@ErzW#^d=bQh border; + public static Asset corner; - public override void Load() => border = ModContent.Request("CalamityMod/Tiles/Furniture/CalamityCanvasBorder"); + public override void Load() + { + border = ModContent.Request("CalamityMod/Tiles/Furniture/CalamityCanvasBorder"); + corner = ModContent.Request("CalamityMod/Tiles/Furniture/CalamityCanvasCorner"); + } public override void SetStaticDefaults() { @@ -105,48 +110,115 @@ namespace CalamityMod.Tiles.Furniture public static void DrawBorders(SpriteBatch spriteBatch, Vector2 pos, Point cords) { Texture2D texture = border.Value; + Texture2D cornerTex = corner.Value; ushort canvasID = (ushort)ModContent.TileType(); int commonDim = 8; + int finalCord = 72; + int size = 80; Color light = Lighting.GetColor(cords.X, cords.Y); + // Check for nearby Canvas paintings + // If they are cleanly lined up with this Canvas painting, don't draw borders between them bool drawTop = true; bool drawLeft = true; bool drawRight = true; bool drawBottom = true; + // Corners + bool drawTopLeft = false; + bool drawTopRight = false; + bool drawBottomLeft = false; + bool drawBottomRight = false; + // The bottom right tile of the canvas painting Point bottomRight = new Point(cords.X + 4, cords.Y + 4); + // Adjacent tiles that may or may not have other canvas paintings Tile left = CalamityUtils.ParanoidTileRetrieval(cords.X - 1, cords.Y); Tile top = CalamityUtils.ParanoidTileRetrieval(cords.X, cords.Y - 1); - if (top.HasTile && top.TileType == canvasID) + Tile right = CalamityUtils.ParanoidTileRetrieval(bottomRight.X + 1, bottomRight.Y); + Tile bottom = CalamityUtils.ParanoidTileRetrieval(bottomRight.X, bottomRight.Y + 1); + + // Check if adjacent tiles are canvas paintings that are lined up with this one + bool validTop = ValidCanvasFrame(top, 0, size, canvasID); + bool validRight = ValidCanvasFrame(right, 0, size, canvasID); + bool validLeft = ValidCanvasFrame(left, finalCord, 0, canvasID); + bool validBottom = ValidCanvasFrame(bottom, finalCord, 0, canvasID); + + if (validTop) { drawTop = false; } - if (left.HasTile && left.TileType == canvasID) - { - drawLeft = false; - } - Tile right = CalamityUtils.ParanoidTileRetrieval(bottomRight.X + 1, bottomRight.Y); - Tile bottom = CalamityUtils.ParanoidTileRetrieval(bottomRight.X, bottomRight.Y + 1); - if (bottom.HasTile && bottom.TileType == canvasID) + if (validBottom) { drawBottom = false; } - if (right.HasTile && right.TileType == canvasID) + if (validRight) { drawRight = false; + // Check for junction corners + Tile topright = CalamityUtils.ParanoidTileRetrieval(bottomRight.X + 1, cords.Y - 1); + Tile bottomright = CalamityUtils.ParanoidTileRetrieval(bottomRight.X + 1, bottomRight.Y + 1); + if (!drawTop && !ValidCanvasFrame(topright, 0, size, canvasID)) + { + drawTopRight = true; + } + if (!drawBottom && !ValidCanvasFrame(bottomright, 0, 0, canvasID)) + { + drawBottomRight = true; + } + } + if (validLeft) + { + drawLeft = false; + // Check for junction corners + Tile topleft = CalamityUtils.ParanoidTileRetrieval(cords.X - 1, cords.Y - 1); + Tile bottomleft = CalamityUtils.ParanoidTileRetrieval(cords.X - 1, bottomRight.Y + 1); + if (!drawTop && !ValidCanvasFrame(topleft, finalCord, size, canvasID)) + { + drawTopLeft = true; + } + if (!drawBottom && !ValidCanvasFrame(bottomleft, finalCord, 0, canvasID)) + { + drawBottomLeft = true; + } } + // Draw the sides if (drawBottom) - spriteBatch.Draw(texture, pos + Vector2.UnitY * 72, new Rectangle(0, texture.Height - commonDim, texture.Width, commonDim), light, 0, new Vector2(0, 0), 1, 0, 0); + spriteBatch.Draw(texture, pos + Vector2.UnitY * finalCord, new Rectangle(0, texture.Height - commonDim, texture.Width, commonDim), light, 0, new Vector2(0, 0), 1, 0, 0); if (drawTop) spriteBatch.Draw(texture, pos, new Rectangle(0, 0, texture.Width, commonDim), light, 0, new Vector2(0, 0), 1, 0, 0); - if (drawRight) - spriteBatch.Draw(texture, pos + Vector2.UnitX * 72, new Rectangle(texture.Width - commonDim, 0, commonDim, texture.Height), light, 0, new Vector2(0, 0), 1, 0, 0); + spriteBatch.Draw(texture, pos + Vector2.UnitX * finalCord, new Rectangle(texture.Width - commonDim, commonDim, commonDim, texture.Height - (2 * commonDim)), light, 0, new Vector2(0, 0), 1, 0, 0); if (drawLeft) - spriteBatch.Draw(texture, pos, new Rectangle(0, 0, commonDim, texture.Height), light, 0, new Vector2(0, 0), 1, 0, 0); + spriteBatch.Draw(texture, pos, new Rectangle(0, commonDim, commonDim, texture.Height - (2 * commonDim)), light, 0, new Vector2(0, 0), 1, 0, 0); + // Draw the corners + // All corner drawing is done with a single corner sprite that is rotated and flipped about depending on the situation + if (drawTop && drawLeft) + spriteBatch.Draw(cornerTex, pos, null, light, 0, new Vector2(0, 0), 1, 0, 0); + if (drawTop && drawRight) + spriteBatch.Draw(cornerTex, pos + Vector2.UnitX * finalCord, null, light, 0, new Vector2(0, 0), 1, SpriteEffects.FlipHorizontally, 0); + if (drawBottom && drawLeft) + spriteBatch.Draw(cornerTex, pos + Vector2.UnitY * finalCord, null, light, 0, new Vector2(0, 0), 1, SpriteEffects.FlipVertically, 0); + if (drawBottom && drawRight) + spriteBatch.Draw(cornerTex, pos + Vector2.One * size, null, light, MathHelper.Pi, new Vector2(0, 0), 1, 0, 0); + + // Draw junction corners + if (drawTopLeft) + spriteBatch.Draw(cornerTex, pos + corner.Size(), null, light, MathHelper.Pi, new Vector2(0, 0), 1, 0, 0); + if (drawTopRight) + spriteBatch.Draw(cornerTex, pos + Vector2.UnitX * finalCord, null, light, 0, new Vector2(0, 0), 1, SpriteEffects.FlipVertically, 0); + if (drawBottomLeft) + spriteBatch.Draw(cornerTex, pos + Vector2.UnitY * finalCord, null, light, 0, new Vector2(0, 0), 1, SpriteEffects.FlipHorizontally, 0); + if (drawBottomRight) + spriteBatch.Draw(cornerTex, pos - corner.Size() + Vector2.One * size, null, light, 0, new Vector2(0, 0), 1, 0, 0); + } + + // Check if the tile is a canvas tile that has the correct tile frames + public static bool ValidCanvasFrame(Tile t, int frameX, int frameY, ushort canvasID) + { + return t.HasTile && t.TileType == canvasID && t.TileFrameX == frameX && t.TileFrameY == frameY; } } }