Skip to content

Commit

Permalink
Added Vanilla Paint support to the SuperPaintingTool
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirtle committed Jun 22, 2020
1 parent 64e4bc5 commit 6f1855c
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Items/Accessories/CreativeWrench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
69 changes: 56 additions & 13 deletions Items/SuperPaintingTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ class SuperPaintingTool : ModItem
//TODO: ENSURE MULTIPLAYER COMPATIBILITY (66% done)
//TODO: ADD VANILLA PAINT COMPATIBILITY
public List<int> paints;
bool foundModdedPaint;
public override void SetDefaults()
{
paints = new List<int>();
for (int i = 0; i < 27; i++) //Basic && Deep colors type
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;
Expand Down Expand Up @@ -105,10 +107,10 @@ public override void HoldItem(Player player)
public override bool CanUseItem(Player player)
{
BuilderPlayer modPlayer = player.GetModPlayer<BuilderPlayer>();
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<InfinitePaintBucket>())
{
foundModdedPaint = true;
break;
Expand All @@ -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:
Expand All @@ -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<Item> paintInInventory = new List<Item>();
//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()
Expand Down
101 changes: 101 additions & 0 deletions UI/BasePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions Utilities/FurnitureFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
}

0 comments on commit 6f1855c

Please sign in to comment.