From 36e7b5e6ef0199a258842c32442848dfe8c99d47 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Fri, 6 Sep 2019 15:18:12 -0700 Subject: [PATCH] Added in axes, watering cans, and hoes and default color swaps. Now to make content. --- .../Items/Tools/DefaultAxeWorking.png | Bin 0 -> 993 bytes .../Items/Tools/DefaultHoeWorking.png | Bin 0 -> 1141 bytes .../Items/Tools/DefaultWateringCanWorking.png | Bin 0 -> 1222 bytes .../Framework/Hacks/ColorChanger.cs | 352 +++++++++++++++++- .../Objects/Items/Tools/AxeExtended.cs | 305 +++++++++++++++ .../Objects/Items/Tools/HoeExtended.cs | 305 +++++++++++++++ .../Objects/Items/Tools/PickaxeExtended.cs | 1 - .../Items/Tools/WateringCanExtended.cs | 306 +++++++++++++++ 8 files changed, 1263 insertions(+), 6 deletions(-) create mode 100644 GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultAxeWorking.png create mode 100644 GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultHoeWorking.png create mode 100644 GeneralMods/Revitalize/Content/Graphics/Items/Tools/DefaultWateringCanWorking.png create mode 100644 GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs create mode 100644 GeneralMods/Revitalize/Framework/Objects/Items/Tools/HoeExtended.cs create mode 100644 GeneralMods/Revitalize/Framework/Objects/Items/Tools/WateringCanExtended.cs 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 0000000000000000000000000000000000000000..5ea2c373e13bf2164a9075b97a8d38025e2bb514 GIT binary patch literal 993 zcmV<710MW|P)Px&n@L1LRA_Fnrq_fD1*%6*IO zp5A-^`~Ua<|NGxTN=iyfN=iyfN=iyf%KwSYT3u|`>f&9m<9+6Xs192@+oVPeC)9wO zwYs>wQN=Kf>s-%!MVtuyFzgSvH(;w!@SooWmW}|h2WS8#(-HtiPUq*B4Q-yXOQt1O z%_7-s7C?l_o9KZh(-PHM#ec8XD*ocHgOX_pOGkWJyves4A7SZ;l4%Jer}OnUUn$L# zWZhC0K%r1z)hvdlvB(?<$X!sz(h<^&;!-j#@#Ohqme=bX|9OkOgBvWb*Lm{%F?Tnr zzCv*^a{631KQx4A#nKU^rm#v*`U>n0Qa9x*fw+nz_7_?fg$T_4J zt(wIvNkL(AOf{ffbidzEBs8BHv9h$l;i=lV*RS^YsrLdSr{nepNJFSbf{LeJMj9-e z&2r>)Li>dp@W|=VeEJZ8<@I{vh5YvWzsh5z(SpC=DdW0s0a zul8VrsU8s|Zof%rLz{f@CIH9%CNSBXr-pDoGXhW!!OdD-csc9>p{2lO+K#OSbLipe z8J_o8!u{a|LGQYZ^gg#YKpWbg;6*Eu7k=@%XP)C`c%O-21*Fq;SN9oztt@8FTsndv$unZ<*W z+=L`?^q*S@%Un3?JV_1UeY`lo@I7%Jgc{HjdN%U{l7{bf8DP5nX#M{K%wm;4HsWjV P00000NkvXXu0mjf7PRVK literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..1922817b8f090464179fba35ac565ae3ff161c8c GIT binary patch literal 1141 zcmV-*1d98KP)Px(FG)l}RA_JrD!lEny$iKoDd7R>ZRLFv= zs%m~Zoeou1l`^3}C0{xX#ezT=*H%!iR&Dmp7tf%#yYwb^y;u01LnD0|4Ft zSa@XbM+gDOakzIki<!Ec?q)r`iit-E0U^Y+Z@zd2gor3f z5*0-e9LG7u$K~ZE2qBOpiCRT;2?!YC>Fus7i9aYz`pxY^$bwEyWct5)G>V9ZXNTvt zmeNdlg|1aRC%UdN0x(WMCcx2o6FLOw?QY=0 zoZP?t9{F4vN9WPUu=HTvfTQzXWG^O!K+`lc{MogpX`y3ZE5{(B2u;&augUoK-5&q| zb?kfaYdi=cuE?|rXw7Xx7WDq@_x%M7UNYRelfu+Q2F-3S_E_uuVa%83=yYk;CYZ8a zF&cl`F>U?)>g$DU{O+qC@T4>b060|-0jzj#f@cU@$>-9*aab<{X9E5YKpnu>rQk$7 ztoecKgGbq}m=PdvS8O8s@$#UW(%W4+Tb=;`oSa?ZyN8BEjYb3V!J*5MLIng6$%BFt zFvBkq2NBhS^>!E2xb~o<^B#ZQ$HIJLBLygqDQVZ0ke~ovADKk z_KCy4Z=%=AtOU|D&8#B_Lnb+3SF)C3#Flq^O-FG;I3K%DZ zm_R(wW9DZGzyG=l;QF;JYB^ygjt4rc2y0v1VxAGU{-Jqbzbv5qn&DxhC_)rfSHF5q zj`dy|X9I77unqiTn3L)4E;LQEc^SKA_PE9PhcGpf!Q;u%fyd`_>Cg=f6fmDlPx(fJsC_RA_Be7RVw*JArEyTR27{UAwpOaKZRVo!oL#o>Nl#q?xUSE|6 zy_`&%Nu2Y@qUShH;`b2&*IQQj({H~<8kEarbh}-;ohYSSD@~MMGhBa?IQy%e^|Of~ z@#;+uv>gD$6@PPkLoXu}Wm0jvplZ19bzmCFS)&A`l>Pa~Us5~X+}_A!NDu^Qtuz4u z*PkRxuNhh^O$0&kpz)mZusB_aJs&q_x7P=6y~XP4>J;ZZoGs0O`e-y70Dy~&i%hly zz-(y-H-lTauB)Dv=jY&h@wQ69Zm*B}-L?PmL#$zSVNtakhwpU&0E|JK{l78z=NeK< z^*#yHsD-9!f-x3ZfbNJmKf1vAUPq;!J^|H*Mfe{-pwVb#5|MKrT9yT1Xnzm{W1~2d z!ct1?AMXJerY=D#Oq=2~h9N#oAK&ZX5>Bj*UZav=jN#quk#gXA@29A4>0|05CPZ{1mu&}|+Z(uSJ1W~~ zXF)dT#8zP%SkHe-t1M6y(n+M=)-ocCslMEYBL(ONfQwJGl9etLSSue4MGUmwhh;HCq7B+ zAMauRkKa{YO+)WjPkD+Ux(4niVst|28Gy+5)W2RvIOpN$K99H=+^Q%$+S$d?&Msz4 zGm-vulz_ScLI}973)3{=x~^J0oU`*x8&cD#h5N^Q5JKR)Z@-5S0{h2%iT}vZn6#JE z>+fg;>7pe?^QefIZAXbm&x_LqSe6CLvSOQMT|`392C_jXmcpN}zrb}}6sHT3-?Vf| z<7j7BrJ8egp1P3S385S*&KH!3dL%ux5JmgDpC}TYCa>P)I5{{4olqXa_d3e=BpYJ0 zNCVN9;AU{EI+*1AniOqWzSoamIuC7svf9L3Z&fW!I-cqN>lCL8i8dq}^jPPgisu}k k(l+gEn>PMa+K{91FAy@ym?$$?VE_OC07*qoM6N<$f|9sJ(EtDd literal 0 HcmV?d00001 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; + } + } + } +}