diff --git a/GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultAxeWorking.png b/GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultAxeWorking.png new file mode 100644 index 00000000..5ea2c373 Binary files /dev/null and b/GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultAxeWorking.png differ diff --git a/GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultHoeWorking.png b/GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultHoeWorking.png new file mode 100644 index 00000000..1922817b Binary files /dev/null and b/GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultHoeWorking.png differ diff --git a/GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultWateringCanWorking.png b/GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultWateringCanWorking.png new file mode 100644 index 00000000..724d4651 Binary files /dev/null and b/GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultWateringCanWorking.png differ diff --git a/GeneralMods/Revitalize/Framework/Hacks/ColorChanger.cs b/GeneralMods/Revitalize/Framework/Hacks/ColorChanger.cs index 508ae8a2..fe195c35 100644 --- a/GeneralMods/Revitalize/Framework/Hacks/ColorChanger.cs +++ b/GeneralMods/Revitalize/Framework/Hacks/ColorChanger.cs @@ -17,8 +17,15 @@ namespace Revitalize.Framework.Hacks public static class ColorChanger { - private static Texture2D mostRecentPicxaxeSwap; + private static bool AxeNeedsReset; + private static bool PickaxeNeedsReset; + private static bool WateringCanNeedsReset; + private static bool HoeNeedsReset; + /// + /// Swaps the colors for the pickaxe working animation. + /// + /// public static void SwapPickaxeTextures(Texture2D TargetTexture) { /* @@ -108,19 +115,354 @@ namespace Revitalize.Framework.Hacks //Reapply the texture. Game1.toolSpriteSheet.SetData(beforeData); - Stream stream = File.Create(Path.Combine(ModCore.ModHelper.DirectoryPath,"ToolTest.png")); - Game1.toolSpriteSheet.SaveAsPng(stream, width, height); - stream.Dispose(); + //Stream stream = File.Create(Path.Combine(ModCore.ModHelper.DirectoryPath,"ToolTest.png")); + //Game1.toolSpriteSheet.SaveAsPng(stream, width, height); + //stream.Dispose(); + PickaxeNeedsReset = true; } + /// + /// Swaps the colors for the hoe animation. + /// + /// + public static void SwapHoeTextures(Texture2D TargetTexture) + { + /* + if (mostRecentPicxaxeSwap != null) + { + if (TargetTexture == mostRecentPicxaxeSwap) return; + } + */ + int height = Game1.toolSpriteSheet.Height; + int width = Game1.toolSpriteSheet.Width; + + Color[] beforeData = new Color[Game1.toolSpriteSheet.Width * Game1.toolSpriteSheet.Height]; + Game1.toolSpriteSheet.GetData(beforeData); + Color[] afterData = new Color[TargetTexture.Width * TargetTexture.Height]; //Get a color data to replace + TargetTexture.GetData(afterData); //Get data from swap texture. + + ///Convert tool data to grid + Color[,] beforeGrid = new Color[height, width]; + for (int row = 0; row < height; row++) + { + for (int column = 0; column < width; column++) + { + // Assumes row major ordering of the array. + beforeGrid[row, column] = beforeData[row * width + column]; + } + } + //Convert target data to grid + int targetHeight = TargetTexture.Height; + int targetWidth = TargetTexture.Width; + Color[,] afterGrid = new Color[targetHeight, targetWidth]; + for (int row = 0; row < targetHeight; row++) + { + for (int column = 0; column < targetWidth; column++) + { + // Assumes row major ordering of the array. + afterGrid[row, column] = afterData[row * targetWidth + column]; + } + } + + + //Copy over data from the target texture into the before grid. + Rectangle stoneRegion = new Rectangle(0, 16, 80, 32); + Rectangle copperRegion = new Rectangle(); + Rectangle ironRegion = new Rectangle(224, 16, 80, 32); //Create the region we want to replace. + Rectangle goldRegion = new Rectangle(); + Rectangle irridumRegon = new Rectangle(); + + List rects = new List(); + //rects.Add(ironRegion); + rects.Add(stoneRegion); + foreach (Rectangle region in rects) + { + + for (int x = region.X; x < region.X + region.Width; x++) + { + for (int y = region.Y; y < region.Y + region.Height; y++) + { + //ModCore.log("value is: " + new Vector2(x, y)); + beforeGrid[y, x] = afterGrid[(int)(y - region.Y), x - region.X]; //Row, column order aka y,x order. + } + } + + + //Convert the tool grid back into a 1d color array + for (int row = 0; row < height; row++) + { + for (int column = 0; column < width; column++) + { + try + { + beforeData[row * width + column] = beforeGrid[row, column]; + } + catch (Exception err) + { + ModCore.log("Setting pixel color at: " + new Vector2(column, row)); + ModCore.log("That's position: " + (row * width + column).ToString()); + } + //ModCore.log("Setting pixel color at: " + new Vector2(column, row)); + //ModCore.log("That's position: " + (row * width + column).ToString()); + //beforeData[row * targetWidth + column] = beforeGrid[row,column]; + } + } + } + + + //beforeGrid.CopyTo(beforeData, 0); + //Reapply the texture. + Game1.toolSpriteSheet.SetData(beforeData); + HoeNeedsReset = true; + } + + /// + /// Swaps the colors for the axe working animation. + /// + /// + public static void SwapAxeTextures(Texture2D TargetTexture) + { + /* + if (mostRecentPicxaxeSwap != null) + { + if (TargetTexture == mostRecentPicxaxeSwap) return; + } + */ + int height = Game1.toolSpriteSheet.Height; + int width = Game1.toolSpriteSheet.Width; + + Color[] beforeData = new Color[Game1.toolSpriteSheet.Width * Game1.toolSpriteSheet.Height]; + Game1.toolSpriteSheet.GetData(beforeData); + Color[] afterData = new Color[TargetTexture.Width * TargetTexture.Height]; //Get a color data to replace + TargetTexture.GetData(afterData); //Get data from swap texture. + + ///Convert tool data to grid + Color[,] beforeGrid = new Color[height, width]; + for (int row = 0; row < height; row++) + { + for (int column = 0; column < width; column++) + { + // Assumes row major ordering of the array. + beforeGrid[row, column] = beforeData[row * width + column]; + } + } + //Convert target data to grid + int targetHeight = TargetTexture.Height; + int targetWidth = TargetTexture.Width; + Color[,] afterGrid = new Color[targetHeight, targetWidth]; + for (int row = 0; row < targetHeight; row++) + { + for (int column = 0; column < targetWidth; column++) + { + // Assumes row major ordering of the array. + afterGrid[row, column] = afterData[row * targetWidth + column]; + } + } + + + //Copy over data from the target texture into the before grid. + Rectangle stoneRegion = new Rectangle(0, 144, 80, 32); + Rectangle copperRegion = new Rectangle(); + Rectangle ironRegion = new Rectangle(224, 144, 80, 32); //Create the region we want to replace. + Rectangle goldRegion = new Rectangle(); + Rectangle irridumRegon = new Rectangle(); + + List rects = new List(); + //rects.Add(ironRegion); + rects.Add(stoneRegion); + foreach (Rectangle region in rects) + { + + for (int x = region.X; x < region.X + region.Width; x++) + { + for (int y = region.Y; y < region.Y + region.Height; y++) + { + //ModCore.log("value is: " + new Vector2(x, y)); + beforeGrid[y, x] = afterGrid[(int)(y - region.Y), x - region.X]; //Row, column order aka y,x order. + } + } + + + //Convert the tool grid back into a 1d color array + for (int row = 0; row < height; row++) + { + for (int column = 0; column < width; column++) + { + try + { + beforeData[row * width + column] = beforeGrid[row, column]; + } + catch (Exception err) + { + ModCore.log("Setting pixel color at: " + new Vector2(column, row)); + ModCore.log("That's position: " + (row * width + column).ToString()); + } + //ModCore.log("Setting pixel color at: " + new Vector2(column, row)); + //ModCore.log("That's position: " + (row * width + column).ToString()); + //beforeData[row * targetWidth + column] = beforeGrid[row,column]; + } + } + } + + + //beforeGrid.CopyTo(beforeData, 0); + //Reapply the texture. + Game1.toolSpriteSheet.SetData(beforeData); + AxeNeedsReset = true; + } + + /// + /// Swaps the colors for the watering can working animation. + /// + /// + public static void SwapWateringCanTextures(Texture2D TargetTexture) + { + /* + if (mostRecentPicxaxeSwap != null) + { + if (TargetTexture == mostRecentPicxaxeSwap) return; + } + */ + int height = Game1.toolSpriteSheet.Height; + int width = Game1.toolSpriteSheet.Width; + + Color[] beforeData = new Color[Game1.toolSpriteSheet.Width * Game1.toolSpriteSheet.Height]; + Game1.toolSpriteSheet.GetData(beforeData); + Color[] afterData = new Color[TargetTexture.Width * TargetTexture.Height]; //Get a color data to replace + TargetTexture.GetData(afterData); //Get data from swap texture. + + ///Convert tool data to grid + Color[,] beforeGrid = new Color[height, width]; + for (int row = 0; row < height; row++) + { + for (int column = 0; column < width; column++) + { + // Assumes row major ordering of the array. + beforeGrid[row, column] = beforeData[row * width + column]; + } + } + //Convert target data to grid + int targetHeight = TargetTexture.Height; + int targetWidth = TargetTexture.Width; + Color[,] afterGrid = new Color[targetHeight, targetWidth]; + for (int row = 0; row < targetHeight; row++) + { + for (int column = 0; column < targetWidth; column++) + { + // Assumes row major ordering of the array. + afterGrid[row, column] = afterData[row * targetWidth + column]; + } + } + + + //Copy over data from the target texture into the before grid. + Rectangle stoneRegion = new Rectangle(0, 208, 80, 32); + Rectangle copperRegion = new Rectangle(); + Rectangle ironRegion = new Rectangle(224, 208, 80, 32); //Create the region we want to replace. + Rectangle goldRegion = new Rectangle(); + Rectangle irridumRegon = new Rectangle(); + + List rects = new List(); + //rects.Add(ironRegion); + rects.Add(stoneRegion); + foreach (Rectangle region in rects) + { + + for (int x = region.X; x < region.X + region.Width; x++) + { + for (int y = region.Y; y < region.Y + region.Height; y++) + { + //ModCore.log("value is: " + new Vector2(x, y)); + beforeGrid[y, x] = afterGrid[(int)(y - region.Y), x - region.X]; //Row, column order aka y,x order. + } + } + + + //Convert the tool grid back into a 1d color array + for (int row = 0; row < height; row++) + { + for (int column = 0; column < width; column++) + { + try + { + beforeData[row * width + column] = beforeGrid[row, column]; + } + catch (Exception err) + { + ModCore.log("Setting pixel color at: " + new Vector2(column, row)); + ModCore.log("That's position: " + (row * width + column).ToString()); + } + //ModCore.log("Setting pixel color at: " + new Vector2(column, row)); + //ModCore.log("That's position: " + (row * width + column).ToString()); + //beforeData[row * targetWidth + column] = beforeGrid[row,column]; + } + } + } + + + //beforeGrid.CopyTo(beforeData, 0); + //Reapply the texture. + Game1.toolSpriteSheet.SetData(beforeData); + WateringCanNeedsReset = true; + } + + /// + /// Resets the colors for the pickaxe. + /// public static void ResetPickaxeTexture() { SwapPickaxeTextures(TextureManager.GetTexture(ModCore.Manifest, "Tools", "DefaultPickaxeWorking")); } + /// + /// Resets the colors for the hoe. + /// + public static void ResetHoeTexture() + { + SwapHoeTextures(TextureManager.GetTexture(ModCore.Manifest, "Tools", "DefaultHoeWorking")); + } + + /// + /// Resets the colors for the axe. + /// + public static void ResetAxeTexture() + { + SwapAxeTextures(TextureManager.GetTexture(ModCore.Manifest, "Tools", "DefaultAxeWorking")); + } + + /// + /// Resets the colors for the watering can. + /// + public static void ResetWateringCanTexture() + { + SwapAxeTextures(TextureManager.GetTexture(ModCore.Manifest, "Tools", "DefaultWateringCanWorking")); + } + + /// + /// Resets all of the custom color swaps for tools. + /// public static void ResetToolColorSwaps() { - ResetPickaxeTexture(); + if (PickaxeNeedsReset) + { + ResetPickaxeTexture(); + PickaxeNeedsReset = false; + } + if (HoeNeedsReset) + { + ResetHoeTexture(); + HoeNeedsReset = false; + } + if (AxeNeedsReset) + { + ResetAxeTexture(); + AxeNeedsReset = false; + } + if (WateringCanNeedsReset) + { + ResetWateringCanTexture(); + WateringCanNeedsReset = false; + } } } } diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs new file mode 100644 index 00000000..527ba22d --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs @@ -0,0 +1,305 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json; +using PyTK.CustomElementHandler; +using Revitalize.Framework.Objects.Interfaces; +using Revitalize.Framework.Utilities; +using StardewValley; +using StardewValley.Tools; +using StardustCore.UIUtilities; + +namespace Revitalize.Framework.Objects.Items.Tools +{ + public class AxeExtended: StardewValley.Tools.Axe, ISaveElement, IItemInfo + { + public BasicItemInformation info; + public Texture2DExtended workingTexture; + + /// + /// Used only for accessibility for casting. + /// + [JsonIgnore] + public BasicItemInformation Info + { + get + { + return this.info; + } + set + { + this.info = value; + } + } + + public Guid guid; + + public override string Name + { + + get + { + if (this.info != null) + { + return this.netName.Value.Split('>')[0]; + //return this.info.name; + } + if (this.netName == null) + { + return this.Name; + } + else + { + return this.netName.Value.Split('>')[0]; //Return the value before the name because that is the true value. + } + } + + set + { + if (this.netName == null) + { + return; + } + if (this.netName.Value == null) + { + return; + } + if (this.netName.Value.Split('>') is string[] split && split.Length > 1) + { + this.netName.Value = value + ">" + split[1]; //When setting the name if appended data is added on set the new value and add that appended data back. + } + else + { + this.netName.Value = value; //Otherwise just set the net name. + } + } + } + + public override string DisplayName + { + get + { + if (this.info != null) + { + return this.info.name; + } + return this.netName.Value.Split('>')[0]; + } + + set + { + if (this.netName == null) return; + if (this.netName.Value == null) return; + + if (this.netName.Value.Split('>') is string[] split && split.Length > 1) + this.netName.Value = value + ">" + split[1]; + else + this.netName.Value = value; + } + } + + public virtual string text + { + get + { + if (this.netName.Value.Split('>') is string[] split && split.Length > 1) + return split[1]; //This is custom data. If the net name has a much larger name split the value and return the result. + else + return ""; //Otherwise return nothing. + } + set + { + if (this.netName == null) return; + if (this.netName.Value == null) return; + { + this.netName.Value = this.netName.Value.Split('>')[0] + ">" + value; //When setting the custom dataappend it to the end of the name. + } + } + } + + [JsonIgnore] + public virtual string ItemInfo + { + get + { + return Revitalize.ModCore.Serializer.ToJSONString(this.info) + "<" + this.guid + "<" + Revitalize.ModCore.Serializer.ToJSONString(this.workingTexture); + } + set + { + if (string.IsNullOrEmpty(value)) return; + string[] data = value.Split('<'); + string infoString = data[0]; + string guidString = data[1]; + string WorkingTexture = data[2]; + + this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation)); + Guid oldGuid = this.guid; + this.guid = Guid.Parse(guidString); + this.workingTexture = Revitalize.ModCore.Serializer.DeserializeFromJSONString(WorkingTexture); + if (ModCore.CustomObjects.ContainsKey(this.guid)) + { + //ModCore.log("Update item with guid: " + this.guid); + ModCore.CustomItems[this.guid] = this; + } + else + { + //ModCore.log("Add in new guid: " + this.guid); + ModCore.CustomItems.Add(this.guid, this); + } + + } + } + + public AxeExtended() + { + + } + + public AxeExtended(BasicItemInformation ItemInfo, int UpgradeLevel, Texture2DExtended WorkingTexture) + { + this.info = ItemInfo; + this.upgradeLevel.Value = UpgradeLevel; + this.guid = Guid.NewGuid(); + this.workingTexture = WorkingTexture; + this.updateInfo(); + } + + + public override void draw(SpriteBatch b) + { + if (this.lastUser == null || this.lastUser.toolPower <= 0 || !this.lastUser.canReleaseTool) + return; + this.updateInfo(); + foreach (Vector2 vector2 in this.tilesAffected(this.lastUser.GetToolLocation(false) / 64f, this.lastUser.toolPower, this.lastUser)) + this.info.animationManager.draw(b, Game1.GlobalToLocal(new Vector2((float)((int)vector2.X * 64), (float)((int)vector2.Y * 64))), Color.White, 4f, SpriteEffects.None, 0.01f); + } + + public override void drawAttachments(SpriteBatch b, int x, int y) + { + this.updateInfo(); + //base.drawAttachments(b, x, y); + //this.info.animationManager.draw(b,) + + + } + + public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color color, bool drawShadow) + { + this.updateInfo(); + this.info.animationManager.draw(spriteBatch, location, color * transparency, 4f * scaleSize, SpriteEffects.None, layerDepth); + //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, color, drawShadow); + } + + public Dictionary getAdditionalSaveData() + { + Dictionary serializedInfo = new Dictionary(); + serializedInfo.Add("id", this.ItemInfo); + serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); + Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); + return serializedInfo; + } + + public override bool beginUsing(GameLocation location, int x, int y, Farmer who) + { + this.updateInfo(); + Revitalize.Framework.Hacks.ColorChanger.SwapAxeTextures(this.workingTexture.texture); + return base.beginUsing(location, x, y, who); + } + public override void endUsing(GameLocation location, Farmer who) + { + //Revitalize.Framework.Hacks.ColorChanger.ResetPickaxeTexture(); + base.endUsing(location, who); + } + + public override bool onRelease(GameLocation location, int x, int y, Farmer who) + { + //Revitalize.Framework.Hacks.ColorChanger.ResetPickaxeTexture(); + return base.onRelease(location, x, y, who); + } + + public override void actionWhenStopBeingHeld(Farmer who) + { + Revitalize.Framework.Hacks.ColorChanger.ResetAxeTexture(); + base.actionWhenStopBeingHeld(who); + } + + public override Color getCategoryColor() + { + return this.info.categoryColor; + } + + public override string getCategoryName() + { + return this.info.categoryName; + } + + public override string getDescription() + { + return this.info.name; + } + + public override Item getOne() + { + return new AxeExtended(this.info.Copy(), this.UpgradeLevel, this.workingTexture.Copy()); + } + + public object getReplacement() + { + return new StardewValley.Tools.Axe { UpgradeLevel = this.UpgradeLevel }; + } + + public void rebuild(Dictionary additionalSaveData, object replacement) + { + this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); + this.upgradeLevel.Value = (replacement as Axe).UpgradeLevel; + } + + + /// + /// Updates the info on the item. + /// + public virtual void updateInfo() + { + if (this.info == null || this.workingTexture == null) + { + this.ItemInfo = this.text; + return; + } + + if (this.requiresUpdate()) + { + this.text = this.ItemInfo; + this.info.cleanAfterUpdate(); + MultiplayerUtilities.RequestUpdateSync(this.guid); + } + } + + /// + /// Gets an update for this item. + /// + public virtual void getUpdate() + { + this.ItemInfo = this.text; + } + + /// + /// Checks to see if this item requires a sync update. + /// + /// + public virtual bool requiresUpdate() + { + if (this.info.requiresSyncUpdate()) + { + return true; + } + else + { + return false; + } + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/HoeExtended.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/HoeExtended.cs new file mode 100644 index 00000000..4f89a131 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/HoeExtended.cs @@ -0,0 +1,305 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json; +using PyTK.CustomElementHandler; +using Revitalize.Framework.Objects.Interfaces; +using Revitalize.Framework.Utilities; +using StardewValley; +using StardewValley.Tools; +using StardustCore.UIUtilities; + +namespace Revitalize.Framework.Objects.Items.Tools +{ + public class HoeExtended: StardewValley.Tools.Hoe, ISaveElement, IItemInfo + { + public BasicItemInformation info; + public Texture2DExtended workingTexture; + + /// + /// Used only for accessibility for casting. + /// + [JsonIgnore] + public BasicItemInformation Info + { + get + { + return this.info; + } + set + { + this.info = value; + } + } + + public Guid guid; + + public override string Name + { + + get + { + if (this.info != null) + { + return this.netName.Value.Split('>')[0]; + //return this.info.name; + } + if (this.netName == null) + { + return this.Name; + } + else + { + return this.netName.Value.Split('>')[0]; //Return the value before the name because that is the true value. + } + } + + set + { + if (this.netName == null) + { + return; + } + if (this.netName.Value == null) + { + return; + } + if (this.netName.Value.Split('>') is string[] split && split.Length > 1) + { + this.netName.Value = value + ">" + split[1]; //When setting the name if appended data is added on set the new value and add that appended data back. + } + else + { + this.netName.Value = value; //Otherwise just set the net name. + } + } + } + + public override string DisplayName + { + get + { + if (this.info != null) + { + return this.info.name; + } + return this.netName.Value.Split('>')[0]; + } + + set + { + if (this.netName == null) return; + if (this.netName.Value == null) return; + + if (this.netName.Value.Split('>') is string[] split && split.Length > 1) + this.netName.Value = value + ">" + split[1]; + else + this.netName.Value = value; + } + } + + public virtual string text + { + get + { + if (this.netName.Value.Split('>') is string[] split && split.Length > 1) + return split[1]; //This is custom data. If the net name has a much larger name split the value and return the result. + else + return ""; //Otherwise return nothing. + } + set + { + if (this.netName == null) return; + if (this.netName.Value == null) return; + { + this.netName.Value = this.netName.Value.Split('>')[0] + ">" + value; //When setting the custom dataappend it to the end of the name. + } + } + } + + [JsonIgnore] + public virtual string ItemInfo + { + get + { + return Revitalize.ModCore.Serializer.ToJSONString(this.info) + "<" + this.guid + "<" + Revitalize.ModCore.Serializer.ToJSONString(this.workingTexture); + } + set + { + if (string.IsNullOrEmpty(value)) return; + string[] data = value.Split('<'); + string infoString = data[0]; + string guidString = data[1]; + string WorkingTexture = data[2]; + + this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation)); + Guid oldGuid = this.guid; + this.guid = Guid.Parse(guidString); + this.workingTexture = Revitalize.ModCore.Serializer.DeserializeFromJSONString(WorkingTexture); + if (ModCore.CustomObjects.ContainsKey(this.guid)) + { + //ModCore.log("Update item with guid: " + this.guid); + ModCore.CustomItems[this.guid] = this; + } + else + { + //ModCore.log("Add in new guid: " + this.guid); + ModCore.CustomItems.Add(this.guid, this); + } + + } + } + + public HoeExtended() + { + + } + + public HoeExtended(BasicItemInformation ItemInfo, int UpgradeLevel, Texture2DExtended WorkingTexture) + { + this.info = ItemInfo; + this.upgradeLevel.Value = UpgradeLevel; + this.guid = Guid.NewGuid(); + this.workingTexture = WorkingTexture; + this.updateInfo(); + } + + + public override void draw(SpriteBatch b) + { + if (this.lastUser == null || this.lastUser.toolPower <= 0 || !this.lastUser.canReleaseTool) + return; + this.updateInfo(); + foreach (Vector2 vector2 in this.tilesAffected(this.lastUser.GetToolLocation(false) / 64f, this.lastUser.toolPower, this.lastUser)) + this.info.animationManager.draw(b, Game1.GlobalToLocal(new Vector2((float)((int)vector2.X * 64), (float)((int)vector2.Y * 64))), Color.White, 4f, SpriteEffects.None, 0.01f); + } + + public override void drawAttachments(SpriteBatch b, int x, int y) + { + this.updateInfo(); + //base.drawAttachments(b, x, y); + //this.info.animationManager.draw(b,) + + + } + + public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color color, bool drawShadow) + { + this.updateInfo(); + this.info.animationManager.draw(spriteBatch, location, color * transparency, 4f * scaleSize, SpriteEffects.None, layerDepth); + //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, color, drawShadow); + } + + public Dictionary getAdditionalSaveData() + { + Dictionary serializedInfo = new Dictionary(); + serializedInfo.Add("id", this.ItemInfo); + serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); + Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); + return serializedInfo; + } + + public override bool beginUsing(GameLocation location, int x, int y, Farmer who) + { + this.updateInfo(); + Revitalize.Framework.Hacks.ColorChanger.SwapHoeTextures(this.workingTexture.texture); + return base.beginUsing(location, x, y, who); + } + public override void endUsing(GameLocation location, Farmer who) + { + //Revitalize.Framework.Hacks.ColorChanger.ResetPickaxeTexture(); + base.endUsing(location, who); + } + + public override bool onRelease(GameLocation location, int x, int y, Farmer who) + { + //Revitalize.Framework.Hacks.ColorChanger.ResetPickaxeTexture(); + return base.onRelease(location, x, y, who); + } + + public override void actionWhenStopBeingHeld(Farmer who) + { + Revitalize.Framework.Hacks.ColorChanger.ResetHoeTexture(); + base.actionWhenStopBeingHeld(who); + } + + public override Color getCategoryColor() + { + return this.info.categoryColor; + } + + public override string getCategoryName() + { + return this.info.categoryName; + } + + public override string getDescription() + { + return this.info.name; + } + + public override Item getOne() + { + return new HoeExtended(this.info.Copy(), this.UpgradeLevel, this.workingTexture.Copy()); + } + + public object getReplacement() + { + return new StardewValley.Tools.Hoe { UpgradeLevel = this.UpgradeLevel }; + } + + public void rebuild(Dictionary additionalSaveData, object replacement) + { + this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); + this.upgradeLevel.Value = (replacement as Hoe).UpgradeLevel; + } + + + /// + /// Updates the info on the item. + /// + public virtual void updateInfo() + { + if (this.info == null || this.workingTexture == null) + { + this.ItemInfo = this.text; + return; + } + + if (this.requiresUpdate()) + { + this.text = this.ItemInfo; + this.info.cleanAfterUpdate(); + MultiplayerUtilities.RequestUpdateSync(this.guid); + } + } + + /// + /// Gets an update for this item. + /// + public virtual void getUpdate() + { + this.ItemInfo = this.text; + } + + /// + /// Checks to see if this item requires a sync update. + /// + /// + public virtual bool requiresUpdate() + { + if (this.info.requiresSyncUpdate()) + { + return true; + } + else + { + return false; + } + } + } +} diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/PickaxeExtended.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/PickaxeExtended.cs index 27e5da44..43526d82 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/PickaxeExtended.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/PickaxeExtended.cs @@ -268,7 +268,6 @@ namespace Revitalize.Framework.Objects.Items.Tools if (this.info == null || this.workingTexture==null) { this.ItemInfo = this.text; - ModCore.log("Updated item info!"); return; } diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/WateringCanExtended.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/WateringCanExtended.cs new file mode 100644 index 00000000..08189630 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/WateringCanExtended.cs @@ -0,0 +1,306 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json; +using PyTK.CustomElementHandler; +using Revitalize.Framework.Objects.Interfaces; +using Revitalize.Framework.Utilities; +using StardewValley; +using StardewValley.Tools; +using StardustCore.UIUtilities; + +namespace Revitalize.Framework.Objects.Items.Tools +{ + public class WateringCanExtended:StardewValley.Tools.WateringCan, ISaveElement, IItemInfo + { + public BasicItemInformation info; + public Texture2DExtended workingTexture; + + /// + /// Used only for accessibility for casting. + /// + [JsonIgnore] + public BasicItemInformation Info + { + get + { + return this.info; + } + set + { + this.info = value; + } + } + + public Guid guid; + + public override string Name + { + + get + { + if (this.info != null) + { + return this.netName.Value.Split('>')[0]; + //return this.info.name; + } + if (this.netName == null) + { + return this.Name; + } + else + { + return this.netName.Value.Split('>')[0]; //Return the value before the name because that is the true value. + } + } + + set + { + if (this.netName == null) + { + return; + } + if (this.netName.Value == null) + { + return; + } + if (this.netName.Value.Split('>') is string[] split && split.Length > 1) + { + this.netName.Value = value + ">" + split[1]; //When setting the name if appended data is added on set the new value and add that appended data back. + } + else + { + this.netName.Value = value; //Otherwise just set the net name. + } + } + } + + public override string DisplayName + { + get + { + if (this.info != null) + { + return this.info.name; + } + return this.netName.Value.Split('>')[0]; + } + + set + { + if (this.netName == null) return; + if (this.netName.Value == null) return; + + if (this.netName.Value.Split('>') is string[] split && split.Length > 1) + this.netName.Value = value + ">" + split[1]; + else + this.netName.Value = value; + } + } + + public virtual string text + { + get + { + if (this.netName.Value.Split('>') is string[] split && split.Length > 1) + return split[1]; //This is custom data. If the net name has a much larger name split the value and return the result. + else + return ""; //Otherwise return nothing. + } + set + { + if (this.netName == null) return; + if (this.netName.Value == null) return; + { + this.netName.Value = this.netName.Value.Split('>')[0] + ">" + value; //When setting the custom dataappend it to the end of the name. + } + } + } + + [JsonIgnore] + public virtual string ItemInfo + { + get + { + return Revitalize.ModCore.Serializer.ToJSONString(this.info) + "<" + this.guid + "<" + Revitalize.ModCore.Serializer.ToJSONString(this.workingTexture); + } + set + { + if (string.IsNullOrEmpty(value)) return; + string[] data = value.Split('<'); + string infoString = data[0]; + string guidString = data[1]; + string WorkingTexture = data[2]; + + this.info = (BasicItemInformation)Revitalize.ModCore.Serializer.DeserializeFromJSONString(infoString, typeof(BasicItemInformation)); + Guid oldGuid = this.guid; + this.guid = Guid.Parse(guidString); + this.workingTexture = Revitalize.ModCore.Serializer.DeserializeFromJSONString(WorkingTexture); + if (ModCore.CustomObjects.ContainsKey(this.guid)) + { + //ModCore.log("Update item with guid: " + this.guid); + ModCore.CustomItems[this.guid] = this; + } + else + { + //ModCore.log("Add in new guid: " + this.guid); + ModCore.CustomItems.Add(this.guid, this); + } + + } + } + + public WateringCanExtended() + { + + } + + public WateringCanExtended(BasicItemInformation ItemInfo, int UpgradeLevel, Texture2DExtended WorkingTexture,int WaterCapacity) + { + this.info = ItemInfo; + this.upgradeLevel.Value = UpgradeLevel; + this.guid = Guid.NewGuid(); + this.workingTexture = WorkingTexture; + this.waterCanMax = WaterCapacity; + this.updateInfo(); + } + + + public override void draw(SpriteBatch b) + { + if (this.lastUser == null || this.lastUser.toolPower <= 0 || !this.lastUser.canReleaseTool) + return; + this.updateInfo(); + foreach (Vector2 vector2 in this.tilesAffected(this.lastUser.GetToolLocation(false) / 64f, this.lastUser.toolPower, this.lastUser)) + this.info.animationManager.draw(b, Game1.GlobalToLocal(new Vector2((float)((int)vector2.X * 64), (float)((int)vector2.Y * 64))), Color.White, 4f, SpriteEffects.None, 0.01f); + } + + public override void drawAttachments(SpriteBatch b, int x, int y) + { + this.updateInfo(); + //base.drawAttachments(b, x, y); + //this.info.animationManager.draw(b,) + + + } + + public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color color, bool drawShadow) + { + this.updateInfo(); + this.info.animationManager.draw(spriteBatch, location, color * transparency, 4f * scaleSize, SpriteEffects.None, layerDepth); + //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, color, drawShadow); + } + + public Dictionary getAdditionalSaveData() + { + Dictionary serializedInfo = new Dictionary(); + serializedInfo.Add("id", this.ItemInfo); + serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); + Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); + return serializedInfo; + } + + public override bool beginUsing(GameLocation location, int x, int y, Farmer who) + { + this.updateInfo(); + Revitalize.Framework.Hacks.ColorChanger.SwapWateringCanTextures(this.workingTexture.texture); + return base.beginUsing(location, x, y, who); + } + public override void endUsing(GameLocation location, Farmer who) + { + //Revitalize.Framework.Hacks.ColorChanger.ResetPickaxeTexture(); + base.endUsing(location, who); + } + + public override bool onRelease(GameLocation location, int x, int y, Farmer who) + { + //Revitalize.Framework.Hacks.ColorChanger.ResetPickaxeTexture(); + return base.onRelease(location, x, y, who); + } + + public override void actionWhenStopBeingHeld(Farmer who) + { + Revitalize.Framework.Hacks.ColorChanger.ResetWateringCanTexture(); + base.actionWhenStopBeingHeld(who); + } + + public override Color getCategoryColor() + { + return this.info.categoryColor; + } + + public override string getCategoryName() + { + return this.info.categoryName; + } + + public override string getDescription() + { + return this.info.name; + } + + public override Item getOne() + { + return new WateringCanExtended(this.info.Copy(), this.UpgradeLevel, this.workingTexture.Copy(),this.waterCanMax); + } + + public object getReplacement() + { + return new StardewValley.Tools.WateringCan { UpgradeLevel = this.UpgradeLevel, waterCanMax=this.waterCanMax }; + } + + public void rebuild(Dictionary additionalSaveData, object replacement) + { + this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); + this.upgradeLevel.Value = (replacement as WateringCan).UpgradeLevel; + } + + + /// + /// Updates the info on the item. + /// + public virtual void updateInfo() + { + if (this.info == null || this.workingTexture == null) + { + this.ItemInfo = this.text; + return; + } + + if (this.requiresUpdate()) + { + this.text = this.ItemInfo; + this.info.cleanAfterUpdate(); + MultiplayerUtilities.RequestUpdateSync(this.guid); + } + } + + /// + /// Gets an update for this item. + /// + public virtual void getUpdate() + { + this.ItemInfo = this.text; + } + + /// + /// Checks to see if this item requires a sync update. + /// + /// + public virtual bool requiresUpdate() + { + if (this.info.requiresSyncUpdate()) + { + return true; + } + else + { + return false; + } + } + } +}