From 6f1855c2d67ed79fb51a9aa32a0aaf767d76990f Mon Sep 17 00:00:00 2001 From: Kirtle Date: Mon, 22 Jun 2020 04:26:07 +0100 Subject: [PATCH] Added Vanilla Paint support to the SuperPaintingTool --- Items/Accessories/CreativeWrench.cs | 4 +- Items/SuperPaintingTool.cs | 69 +++++++++++++++---- UI/BasePanel.cs | 101 ++++++++++++++++++++++++++++ Utilities/FurnitureFinder.cs | 15 +++++ 4 files changed, 174 insertions(+), 15 deletions(-) diff --git a/Items/Accessories/CreativeWrench.cs b/Items/Accessories/CreativeWrench.cs index d9e67de..bd16c83 100644 --- a/Items/Accessories/CreativeWrench.cs +++ b/Items/Accessories/CreativeWrench.cs @@ -46,8 +46,8 @@ public override void UpdateAccessory(Player player, bool hideVisual) Player.tileRangeX = 65; Player.tileRangeY = 55; + //TODO: Make a static bool in Utilities that evaluates if it is possible to open a UI to improve readability //Thanks direwolf420 for the monstrosity checks - //Right click timer if (Main.mouseRight && player.talkNPC == -1 && !Main.HoveringOverAnNPC && !player.showItemIcon && !Main.editSign && !Main.editChest && !Main.blockInput && !player.dead && !Main.gamePaused && Main.hasFocus && !player.CCed @@ -104,7 +104,7 @@ public override bool CanPlace(int i, int j, int type) if (modPlayer.creativeWheelSelectedIndex.Contains((int)CreativeWheelItem.PlacementAnywhere) && !tile.active()) { Item selectedItem = Main.LocalPlayer.inventory[Main.LocalPlayer.selectedItem]; - WorldGen.PlaceTile(Player.tileTargetX, Player.tileTargetY, selectedItem.createTile); + WorldGen.PlaceTile(Player.tileTargetX, Player.tileTargetY, selectedItem.createTile, false, false, -1, selectedItem.placeStyle); if (Main.netMode == NetmodeID.MultiplayerClient) NetMessage.SendTileSquare(-1, Player.tileTargetX, Player.tileTargetY, 1); diff --git a/Items/SuperPaintingTool.cs b/Items/SuperPaintingTool.cs index df190e4..2cc3de4 100644 --- a/Items/SuperPaintingTool.cs +++ b/Items/SuperPaintingTool.cs @@ -12,6 +12,7 @@ class SuperPaintingTool : ModItem //TODO: ENSURE MULTIPLAYER COMPATIBILITY (66% done) //TODO: ADD VANILLA PAINT COMPATIBILITY public List paints; + bool foundModdedPaint; public override void SetDefaults() { paints = new List(); @@ -19,6 +20,7 @@ public override void SetDefaults() paints.Add(1073 + i); for (int i = 0; i < 3; i++) paints.Add(1966 + i); //Extra Color Effects type + foundModdedPaint = false; item.height = 44; item.width = 44; @@ -105,10 +107,10 @@ public override void HoldItem(Player player) public override bool CanUseItem(Player player) { BuilderPlayer modPlayer = player.GetModPlayer(); - bool foundModdedPaint = false; + foundModdedPaint = false; for (int i = 0; i < player.inventory.Length; i++) { - if (player.inventory[i].type == mod.ItemType("InfinitePaintBucket")) + if (player.inventory[i].type == ItemType()) { foundModdedPaint = true; break; @@ -120,25 +122,32 @@ public override bool CanUseItem(Player player) Tile pointedTile = Main.tile[posX, posY]; //TODO: Fix below //If user tries to use the tool without opening the UI first it won't work since paintingPanel is null and I can't check if mouse is hovering - if (foundModdedPaint && BasePanel.paintingPanel != null && !BasePanel.paintingPanel.IsMouseHovering) + if (BasePanel.paintingPanel != null && !BasePanel.paintingPanel.IsMouseHovering) { bool anyOperationDone = false; + byte selectedColor = (byte)(modPlayer.paintingColorSelectedIndex + 1); //selectedindex + 1 because paint bytes don't start at 0 switch (modPlayer.paintingToolSelected) { case 0: - if (pointedTile.color() != (modPlayer.paintingColorSelectedIndex + 1) && modPlayer.paintingColorSelectedIndex != 30) + if (pointedTile.color() != selectedColor && selectedColor != 31) { - pointedTile.color((byte)(modPlayer.paintingColorSelectedIndex + 1)); - anyOperationDone = true; + if (CheckIfPaintIsInInventoryAndUseIt(selectedColor)) + { + pointedTile.color(selectedColor); + anyOperationDone = true; + } } break; case 1: - if (pointedTile.wallColor() != (modPlayer.paintingColorSelectedIndex + 1) && modPlayer.paintingColorSelectedIndex != 30) + if (pointedTile.wallColor() != selectedColor && selectedColor != 31) { - pointedTile.wallColor((byte)(modPlayer.paintingColorSelectedIndex + 1)); - anyOperationDone = true; + if (CheckIfPaintIsInInventoryAndUseIt(selectedColor)) + { + pointedTile.wallColor(selectedColor); + anyOperationDone = true; + } } break; case 2: @@ -155,15 +164,49 @@ public override bool CanUseItem(Player player) break; } - if (anyOperationDone) + if (anyOperationDone && Main.netMode == NetmodeID.MultiplayerClient) + NetMessage.SendTileSquare(-1, posX, posY, 1); //syncs painting tiles and walls, not the scraper + } + return false; + } + + private bool CheckIfPaintIsInInventoryAndUseIt(byte paintColor) + { + if (!foundModdedPaint) + { + List paintInInventory = new List(); + //Grabs all paint in the inventory to check if player is trying to use it + foreach (Item item in Main.LocalPlayer.inventory) { - if (Main.netMode == NetmodeID.MultiplayerClient) + if (paints.Contains(item.type)) + paintInInventory.Add(item); + } + + foreach (Item item in paintInInventory) + { + //Check if selected color byte (converted to int item.type) is present in the paintInInventory + if (PaintByteToItemType(paintColor) == item.type) { - NetMessage.SendTileSquare(-1, posX, posY, 1); //syncs painting tiles and walls, not the scraper + item.stack--; + return true; } } + + //No result found and InifnitePaintBucket isn't in the inventory + return false; + } + else //InfinitePaintBucket is in the inventory + return true; + + int PaintByteToItemType(byte color) + { + if (color <= 27) + return color + 1072; + else if (color >= 28 && color <= 30) + return color + 1938; + + return 31; } - return false; } public override void AddRecipes() diff --git a/UI/BasePanel.cs b/UI/BasePanel.cs index e6719e2..4ba0d22 100644 --- a/UI/BasePanel.cs +++ b/UI/BasePanel.cs @@ -20,6 +20,13 @@ public class BasePanel : UIState public static bool creativeWheelUIOpen; public static bool isPaintingUIVisible; public static bool paintingUIOpen; + + + //Temporary, this is stupid + static UIText hoverText0; + static UIText hoverText1; + static UIText hoverText2; + static UIText hoverText3; public override void OnInitialize() { buttonTexture = BuilderEssentials.BuildingModeOff; @@ -94,6 +101,100 @@ public override void Update(GameTime gameTime) paintingPanel.Remove(); isPaintingUIVisible = false; } + + + //Maybe make a whole class for the CreativeWheelElements so that I have access to the Update method? + //TODO: CLEAN THIS CODE AND MAKE IT PROPERLY + if (CreativeWheelRework.CreativeWheelReworkPanel != null) + { + if (CreativeWheelRework.CreativeWheelElements[0].IsMouseHovering) + { + //ItemPicker + if (hoverText0 == null) + { + hoverText0 = new UIText("Middle Click to grab a block to your inventory", 1, false); + hoverText0.VAlign = 0f; + hoverText0.HAlign = 0f; + hoverText0.Left.Set(Main.mouseX + 22, 0); + hoverText0.Top.Set(Main.mouseY + 22, 0); + Append(hoverText0); + } + } + else + { + if (hoverText0 != null) + { + hoverText0.Remove(); + hoverText0 = null; + } + } + + if (CreativeWheelRework.CreativeWheelElements[1].IsMouseHovering) + { + //Infinite Placement + if (hoverText1 == null) + { + hoverText1 = new UIText("Allows infinite placements of any block/wall", 1, false); + hoverText1.VAlign = 0f; + hoverText1.HAlign = 0f; + hoverText1.Left.Set(Main.mouseX + 22, 0); + hoverText1.Top.Set(Main.mouseY + 22, 0); + Append(hoverText1); + } + } + else + { + if (hoverText1 != null) + { + hoverText1.Remove(); + hoverText1 = null; + } + } + + if (CreativeWheelRework.CreativeWheelElements[2].IsMouseHovering) + { + //Infinite Placement + if (hoverText2 == null) + { + hoverText2 = new UIText("Select a slope and Left Mouse Click with an empty hand", 1, false); + hoverText2.VAlign = 0f; + hoverText2.HAlign = 0f; + hoverText2.Left.Set(Main.mouseX + 22, 0); + hoverText2.Top.Set(Main.mouseY + 22, 0); + Append(hoverText2); + } + } + else + { + if (hoverText2 != null) + { + hoverText2.Remove(); + hoverText2 = null; + } + } + + if (CreativeWheelRework.CreativeWheelElements[3].IsMouseHovering) + { + //Infinite Placement + if (hoverText3 == null) + { + hoverText3 = new UIText("Allows block placements in the middle of the air", 1, false); + hoverText3.VAlign = 0f; + hoverText3.HAlign = 0f; + hoverText3.Left.Set(Main.mouseX + 22, 0); + hoverText3.Top.Set(Main.mouseY + 22, 0); + Append(hoverText3); + } + } + else + { + if (hoverText3 != null) + { + hoverText3.Remove(); + hoverText3 = null; + } + } + } } public void ChangeAccessories_OnClick(UIMouseEvent evt, UIElement listeningElement) diff --git a/Utilities/FurnitureFinder.cs b/Utilities/FurnitureFinder.cs index 1e757ca..3af0ba2 100644 --- a/Utilities/FurnitureFinder.cs +++ b/Utilities/FurnitureFinder.cs @@ -1153,6 +1153,21 @@ public static void FindFurniture(Tile tile, ref Item item) break; } } + if (tile.type == 89) //Sofas + { + switch (tile.frameX / 54) + { + case 0: + item.SetDefaults(ItemID.Bench); + break; + case 1: + item.SetDefaults(ItemID.Sofa); + break; + case 2: + item.SetDefaults(ItemID.EbonwoodSofa); + break; + } + } } } }