diff --git a/ExtendedFridge/ExtendedFridge.cs b/ExtendedFridge/ExtendedFridge.cs new file mode 100644 index 0000000..3f383c4 --- /dev/null +++ b/ExtendedFridge/ExtendedFridge.cs @@ -0,0 +1,192 @@ +using System; +using System.Collections.Generic; +using System.IO; +using StardewModdingAPI; +using StardewModdingAPI.Events; +using StardewValley; +using StardewValley.Locations; +using StardewValley.Menus; +using xTile.Dimensions; +using SObject = StardewValley.Object; + +namespace ExtendedFridge +{ + public class ExtendedFridgeMod : Mod + { + private static FridgeChest _fridge; + private static FridgeModConfig _config; + internal static ISemanticVersion Version; + //private static bool _isInFridgeMenu; + private static readonly int FRIDGE_TILE_ID = 173; + private PlayerData _pData; + private string _cfgPath; + //Create instance so we can get monitor. + public static ExtendedFridgeMod Instance; + + public override void Entry(IModHelper helper) + { + _config = Helper.ReadConfig(); + Version = ModManifest.Version; + //Set instance + Instance = this; + + MenuEvents.MenuChanged += Event_MenuChanged; + + SaveEvents.AfterLoad += SaveEvents_AfterLoad; + SaveEvents.BeforeSave += SaveEvents_BeforeSave; + PlayerEvents.Warped += PlayerEvents_Warped; + ControlEvents.KeyReleased += Event_KeyReleased; + Monitor.Log("ExtendedFridge Entry"); + } + + public void CheckForAction(bool isBack = false) + { + //int a = 5; + } + + public void SaveEvents_AfterLoad(object sender, EventArgs e) + { + //Set Up Player Data + _cfgPath = Path.Combine("data", $"{Constants.SaveFolderName}.json"); + _pData = Helper.ReadJsonFile(_cfgPath) ?? new PlayerData(); + Helper.WriteJsonFile(_cfgPath, _pData); + FarmHouse h = (FarmHouse)Game1.currentLocation; + + //Lets try to load up the items now. + if (_pData.PItems == null || _pData.PItems.Count < 1 || (h != null && h.upgradeLevel == 0)) + return; + + if (h == null) + return; + if (h.fridge.Value.items.Count > 0) + h.fridge.Value.items.Clear(); + //Passed the count, now we move on to adding them + foreach (int[] i in _pData.PItems) + { + h.fridge.Value.items.Add(new SObject(i[0], i[1], false, -1, i[2])); + } + } + + private void SaveEvents_BeforeSave(object sender, EventArgs e) + { + FarmHouse h = (FarmHouse)Game1.currentLocation; + if (h == null || h.upgradeLevel == 0) + return; + //this.pData.pItems = _fridge.items; + _pData.PItems?.Clear(); + if(_pData.PItems == null) + _pData.PItems = new List(); + foreach (Item i in _fridge.Items) + { + if (i is SObject obj) + { + + _pData.PItems.Add(new[]{i.ParentSheetIndex, i.Stack, obj.Quality}); + } + } + Helper.WriteJsonFile(_cfgPath, _pData); + } + + private void Event_KeyReleased(object send, EventArgsKeyPressed e) + { + if (e.KeyPressed.ToString().Equals(_config.fridgeNextPageKey) && Game1.activeClickableMenu is FridgeGrabMenu) + { + _fridge.MovePageToNext(); + } + + if (e.KeyPressed.ToString().Equals(_config.fridgePrevPageKey) && Game1.activeClickableMenu is FridgeGrabMenu) + { + _fridge.MovePageToPrevious(); + } + } + + private void PlayerEvents_Warped(object send, EventArgsPlayerWarped e) + { + + } + + private void Event_MenuChanged(object send, EventArgsClickableMenuChanged e) + { + //Log.Debug("M007_ExtendedFridge Event_MenuChanged HIT", new object[0]); + /* + if (Game1.currentLocation is FarmHouse) + { + this.Monitor.Log(String.Format("M007_ExtendedFridge lastGrabTileX:{0} lastGrabTileY:{1}", (int)Game1.player.lastGrabTile.X, (int)Game1.player.lastGrabTile.Y)); + }*/ + + if (ClickedOnFridge()) + { + + //_isInFridgeMenu = true; + if (e.NewMenu is ItemGrabMenu) + { + if (_fridge == null || _fridge.Items.Count == 0) + { + _fridge = new FridgeChest(_config.autoSwitchPageOnGrab); + FarmHouse h = (FarmHouse)Game1.currentLocation; + _fridge.Items.AddRange(h.fridge.Value.items); + } + _fridge.ShowCurrentPage(); + // this.Monitor.Log("M007_ExtendedFridge Fridge HOOKED"); + } + + } + if (e.NewMenu is CraftingPage && Game1.currentLocation is FarmHouse fh) + { + if (_fridge != null) + { + fh.fridge.Value.items.Clear(); + fh.fridge.Value.items.AddRange(_fridge.Items); + _fridge.Items.Clear(); + } + + } + + + } + + public void GrabItemFromChest(Item item, Farmer who) + { + _fridge.GrabItemFromChest(item, who); + } + + public void GrabItemFromInventory(Item item, Farmer who) + { + _fridge.GrabItemFromInventory(item, who); + } + + private bool ClickedOnFridge() + { + if (Game1.currentLocation is FarmHouse ptrFarmhouse) + { + Location tileLocation = new Location((int)Game1.player.lastGrabTile.X, (int)Game1.player.lastGrabTile.Y); + + if (ptrFarmhouse.map.GetLayer("Buildings").Tiles[tileLocation] != null) + { + int currTileIdx = ptrFarmhouse.map.GetLayer("Buildings").Tiles[tileLocation].TileIndex; + + return currTileIdx == FRIDGE_TILE_ID; + } + } + + return false; + } + + + public static List Organize() + { + var outItem = _fridge?.Items; + return outItem; + } + + public static string ShowMessage() + { + //return + string outPut = ""; + if (_fridge != null) + outPut = + $"Extended Fridge {Version} Current Page: 0 | {_fridge.Items.Count} items in fridge."; + return outPut; + } + } +} \ No newline at end of file diff --git a/ExtendedFridge/ExtendedFridge.csproj b/ExtendedFridge/ExtendedFridge.csproj index 98ff555..cb0ec6c 100644 --- a/ExtendedFridge/ExtendedFridge.csproj +++ b/ExtendedFridge/ExtendedFridge.csproj @@ -14,6 +14,8 @@ SAK SAK ExtendedFridge + + bin\Debug @@ -41,6 +43,7 @@ + false false @@ -49,7 +52,7 @@ false false - + false false @@ -62,12 +65,15 @@ + + + - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/ExtendedFridge/FridgeChest.cs b/ExtendedFridge/FridgeChest.cs index ba8a670..db6607e 100644 --- a/ExtendedFridge/FridgeChest.cs +++ b/ExtendedFridge/FridgeChest.cs @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using System.Linq; using StardewValley; using StardewValley.Menus; @@ -8,37 +6,37 @@ namespace ExtendedFridge { internal class FridgeChest { - public readonly int MAX_CAPACITY = ITEMS_PER_PAGE * MAX_ITEM_PAGE; - public const int ITEMS_PER_PAGE = 36; - public const int MAX_ITEM_PAGE = 6; - public int currentpage = 0; - public Item lastAddedItem; - private bool _autoSwitchPageOnGrab = false; + public readonly int MaxCapacity = ItemsPerPage * MaxItemPage; + public const int ItemsPerPage = 36; + public const int MaxItemPage = 6; + public int Currentpage; + public Item LastAddedItem; + private readonly bool _autoSwitchPageOnGrab; - public List items = new List(); + public List Items = new List(); public FridgeChest(bool bSwitchPage) { _autoSwitchPageOnGrab = bSwitchPage; } - + #region "Old" //public void DisplayCurrentPage() //{ // List newItems = GetCurrentPageItems(); // Game1.activeClickableMenu = (IClickableMenu)new ItemGrabMenu(newItems, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), new ItemGrabMenu.behaviorOnItemSelect(this.grabItemFromInventory), GetPageString(), new ItemGrabMenu.behaviorOnItemSelect(this.grabItemFromChest), false, true, true, true, true, 1); //} - +#endregion public bool PageHasItems(int pagenumber) { - return ( items.Count >= (pagenumber * 36) ); + return ( Items.Count >= (pagenumber * 36) ); } public void MovePageToNext() { - if ( (this.currentpage + 1) > (MAX_ITEM_PAGE- 1 ) || !PageHasItems(currentpage +1 ) ) { return; } + if ( (Currentpage + 1) > (MaxItemPage- 1 ) || !PageHasItems(Currentpage +1 ) ) { return; } - currentpage += 1; + Currentpage += 1; ShowCurrentPage(); } @@ -46,25 +44,22 @@ public void ShowCurrentPage() { List newItems = GetCurrentPageItems(); - bool bShowNextPage = false; - bool bShowPrevPage = false; - - int nextpage = currentpage + 1; - int prevpage = currentpage - 1; + int nextpage = Currentpage + 1; + int prevpage = Currentpage - 1; - bShowPrevPage = ( (prevpage >= 0) && PageHasItems(prevpage) ); - bShowNextPage = ( ( nextpage <= (MAX_ITEM_PAGE - 1) ) && PageHasItems(nextpage) ); + var bShowPrevPage = ( (prevpage >= 0) && PageHasItems(prevpage) ); + var bShowNextPage = ( ( nextpage <= (MaxItemPage - 1) ) && PageHasItems(nextpage) ); //Game1.activeClickableMenu = (IClickableMenu)new FridgeGrabMenu(newItems, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), new FridgeGrabMenu.behaviorOnItemSelect(this.grabItemFromInventory), GetPageString(), new FridgeGrabMenu.behaviorOnItemSelect(this.grabItemFromChest), false, true, true, true, true, 1, new FridgeGrabMenu.behaviorOnPageCtlClick(this.MovePageToNext), new FridgeGrabMenu.behaviorOnPageCtlClick(this.MovePageToPrevious), bShowPrevPage, bShowNextPage, new FridgeGrabMenu.behaviorOnOrganizeItems(this.OrganizeItems)); - Game1.activeClickableMenu = (IClickableMenu)new FridgeGrabMenu(newItems, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), new FridgeGrabMenu.behaviorOnItemSelect(this.grabItemFromInventory), GetPageString(), new FridgeGrabMenu.behaviorOnItemSelect(this.grabItemFromChest), false, true, true, true, true, 1, null, -1, null, new FridgeGrabMenu.behaviorOnPageCtlClick(this.MovePageToNext), new FridgeGrabMenu.behaviorOnPageCtlClick(this.MovePageToPrevious), bShowPrevPage, bShowNextPage, new FridgeGrabMenu.behaviorOnOrganizeItems(this.OrganizeItems)); + Game1.activeClickableMenu = new FridgeGrabMenu(newItems, false, true, InventoryMenu.highlightAllItems, GrabItemFromInventory, GetPageString(), GrabItemFromChest, false, true, true, true, true, 1, null, -1, null, MovePageToNext, MovePageToPrevious, bShowPrevPage, bShowNextPage, OrganizeItems); } public void MovePageToPrevious() { - if (this.currentpage <= 0) { return; } - if (!PageHasItems(currentpage - 1)) { return; } + if (Currentpage <= 0) { return; } + if (!PageHasItems(Currentpage - 1)) { return; } - currentpage -= 1; + Currentpage -= 1; ShowCurrentPage(); } @@ -72,26 +67,23 @@ private int GetPageForIndex(int itemindex) { if (itemindex % 36 == 0) { - return ((int)itemindex / 36) - 1; - } - else - { - return (int)itemindex / 36; + return (itemindex / 36) - 1; } + return itemindex / 36; } private List GetCurrentPageItems() { List curPageItems = new List(); - int low_limit = currentpage * 36; - int high_limit = low_limit + 35; + int lowLimit = Currentpage * 36; + int highLimit = lowLimit + 35; - for (int i = low_limit; i <= high_limit; i++) + for (int i = lowLimit; i <= highLimit; i++) { - if (i < items.Count) + if (i < Items.Count) { - curPageItems.Add(items[i]); + curPageItems.Add(Items[i]); } else { @@ -103,100 +95,89 @@ private List GetCurrentPageItems() } //behaviorOnItemGrab - public void grabItemFromChest(Item item, StardewValley.Farmer who) + public void GrabItemFromChest(Item item, Farmer who) { if (!who.couldInventoryAcceptThisItem(item)) return; - this.items.Remove(item); - this.clearNulls(); + Items.Remove(item); + ClearNulls(); - StardewValley.Locations.FarmHouse h = (StardewValley.Locations.FarmHouse)Game1.currentLocation; - h.fridge.items = items; - - //TODO: implement page change + //1TODO: implement page change //List newItems = GetCurrentPageItems(); - this.ShowCurrentPage(); + ShowCurrentPage(); } //behaviorOnItemSelectFunction - public void grabItemFromInventory(Item item, StardewValley.Farmer who) + public void GrabItemFromInventory(Item item, Farmer who) { if (item.Stack == 0) item.Stack = 1; - Item obj = this.addItem(item); + Item obj = AddItem(item); if (obj == null) who.removeItemFromInventory(item); else who.addItemToInventory(obj); - this.clearNulls(); + ClearNulls(); - //TODO: implement page change + //1TODO: implement page change //List newItems = GetCurrentPageItems(); - this.ShowCurrentPage(); + ShowCurrentPage(); } - public Item addItem(Item item) + public Item AddItem(Item item) { - lastAddedItem = null; + LastAddedItem = null; - for (int index = 0; index < this.items.Count(); ++index) + for (int index = 0; index < Items.Count; ++index) { - if (this.items[index] != null && this.items[index].canStackWith(item)) + if (Items[index] != null && Items[index].canStackWith(item)) { - item.Stack = this.items[index].addToStack(item.Stack); - if (item.Stack <= 0) { return (Item)null; } + item.Stack = Items[index].addToStack(item.Stack); + if (item.Stack <= 0) { return null; } - if (_autoSwitchPageOnGrab) { currentpage = GetPageForIndex(index); } + if (_autoSwitchPageOnGrab) { Currentpage = GetPageForIndex(index); } } } - if (this.items.Count() >= MAX_CAPACITY) { return item; } + if (Items.Count >= MaxCapacity) { return item; } - this.items.Add(item); - if (_autoSwitchPageOnGrab) { currentpage = GetPageForIndex(this.items.Count); } + Items.Add(item); + if (_autoSwitchPageOnGrab) { Currentpage = GetPageForIndex(Items.Count); } - lastAddedItem = item; + LastAddedItem = item; - StardewValley.Locations.FarmHouse h = (StardewValley.Locations.FarmHouse)Game1.currentLocation; - h.fridge.items = items; - - return (Item)null; + return null; } - public void clearNulls() + public void ClearNulls() { - for (int index = this.items.Count() - 1; index >= 0; --index) + for (int index = Items.Count - 1; index >= 0; --index) { - if (this.items[index] == null) + if (Items[index] == null) { - this.items.RemoveAt(index); + Items.RemoveAt(index); //if (_autoSwitchPageOnGrab) { currentpage = GetPageForIndex(index); } } } - - StardewValley.Locations.FarmHouse h = (StardewValley.Locations.FarmHouse)Game1.currentLocation; - h.fridge.items = items; } private string GetPageString() { - return String.Format("Extended Fridge {0} | Current Page: {1} | {2} items in fridge", M007_ExtendedFridge_Mod.Version, (currentpage + 1), this.items.Count); + return + $"Extended Fridge {ExtendedFridgeMod.Version} | Current Page: {(Currentpage + 1)} | {Items.Count} items in fridge"; } //organize items behaviour public void OrganizeItems() { - items.Sort(); - items.Reverse(); - - StardewValley.Locations.FarmHouse h = (StardewValley.Locations.FarmHouse)Game1.currentLocation; - h.fridge.items = items; + Items.Sort(); + Items.Reverse(); - currentpage = 0; + Currentpage = 0; ShowCurrentPage(); } } diff --git a/ExtendedFridge/FridgeGrabMenu.cs b/ExtendedFridge/FridgeGrabMenu.cs index 42f2bf9..3271189 100644 --- a/ExtendedFridge/FridgeGrabMenu.cs +++ b/ExtendedFridge/FridgeGrabMenu.cs @@ -1,12 +1,15 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; +using StardewModdingAPI; using StardewValley; using StardewValley.Buildings; using StardewValley.Menus; using StardewValley.Objects; +using Object = StardewValley.Object; //using xTile.Dimensions; @@ -15,102 +18,100 @@ namespace ExtendedFridge { internal class FridgeGrabMenu : MenuWithInventory { - public const int region_itemsToGrabMenuModifier = 53910; + public const int RegionItemsToGrabMenuModifier = 53910; - public const int region_organizeButton = 106; + public const int RegionOrganizeButton = 106; - public const int region_colorPickToggle = 27346; + public const int RegionColorPickToggle = 27346; - public const int region_specialButton = 12485; + public const int RegionSpecialButton = 12485; - public const int region_lastShippedHolder = 12598; + public const int RegionLastShippedHolder = 12598; - public const int source_none = 0; + public const int SourceNone = 0; - public const int source_chest = 1; + public const int SourceChest = 1; - public const int source_gift = 2; + public const int SourceGift = 2; - public const int source_fishingChest = 3; + public const int SourceFishingChest = 3; - public const int specialButton_junimotoggle = 1; + public const int SpecialButtonJunimotoggle = 1; public InventoryMenu ItemsToGrabMenu; - private TemporaryAnimatedSprite poof; + private TemporaryAnimatedSprite _poof; - public bool reverseGrab; + public bool ReverseGrab; - public bool showReceivingMenu = true; + public bool ShowReceivingMenu = true; - public bool drawBG = true; + public bool DrawBg = true; - public bool destroyItemOnClick; + public bool DestroyItemOnClick; - public bool canExitOnKey; + public bool CanExitOnKey; - public bool playRightClickSound; + public bool PlayRightClickSound; - public bool allowRightClick; + public bool AllowRightClick; - public bool shippingBin; + public bool ShippingBin; - private string message; + private readonly string _message; //M07: Comment these when copy-pasting code //private ItemGrabMenu.behaviorOnItemSelect behaviorFunction; //public ItemGrabMenu.behaviorOnItemSelect behaviorOnItemGrab; //M07: And use these instead - public FridgeGrabMenu.behaviorOnItemSelect behaviorFunction; - public FridgeGrabMenu.behaviorOnItemSelect behaviorOnItemGrab; + public BehaviorOnItemSelect BehaviorFunction; + public BehaviorOnItemSelect BehaviorOnItemGrab; //END_M07 - private Item hoverItem; + private Item _sourceItem; - private Item sourceItem; + public ClickableTextureComponent OrganizeButton; - public ClickableTextureComponent organizeButton; + public ClickableTextureComponent ColorPickerToggleButton; - public ClickableTextureComponent colorPickerToggleButton; + public ClickableTextureComponent SpecialButton; - public ClickableTextureComponent specialButton; + public ClickableTextureComponent LastShippedHolder; - public ClickableTextureComponent lastShippedHolder; + public List DiscreteColorPickerCc; - public List discreteColorPickerCC; + public int Source; - public int source; + public int WhichSpecialButton; - public int whichSpecialButton; + public object SpecialObject; - public object specialObject; + private readonly bool _snappedtoBottom; - private bool snappedtoBottom; - - public DiscreteColorPicker chestColorPicker; + public DiscreteColorPicker ChestColorPicker; #region -- Events -- - public delegate void behaviorOnItemSelect(Item item, StardewValley.Farmer who); + public delegate void BehaviorOnItemSelect(Item item, Farmer who); #endregion #region -- Needed for Extended Fridge -- - private ClickableTextureComponent previousPageButton; - private ClickableTextureComponent nextPageButton; + private readonly ClickableTextureComponent _previousPageButton; + private readonly ClickableTextureComponent _nextPageButton; - private bool showPrevButton; - private bool showNextButton; + private readonly bool _showPrevButton; + private readonly bool _showNextButton; - public FridgeGrabMenu.behaviorOnPageCtlClick behaviorOnClickNextButton; - public FridgeGrabMenu.behaviorOnPageCtlClick behaviorOnClickPreviousButton; - public FridgeGrabMenu.behaviorOnOrganizeItems behaviorOnClickOrganize; + public BehaviorOnPageCtlClick BehaviorOnClickNextButton; + public BehaviorOnPageCtlClick BehaviorOnClickPreviousButton; + public BehaviorOnOrganizeItems BehaviorOnClickOrganize; - public delegate void behaviorOnPageCtlClick(); - public delegate void behaviorOnOrganizeItems(); + public delegate void BehaviorOnPageCtlClick(); + public delegate void BehaviorOnOrganizeItems(); #endregion //WAS: @@ -123,26 +124,24 @@ internal class FridgeGrabMenu : MenuWithInventory //IS: //DONE - public FridgeGrabMenu(List inventory) : base(null, true, true, 0, 0) + public FridgeGrabMenu(List inventory) : base(null, true, true) { - this.ItemsToGrabMenu = new InventoryMenu(this.xPositionOnScreen + Game1.tileSize / 2, this.yPositionOnScreen, false, inventory, null, -1, 3, 0, 0, true); - this.trashCan.myID = 106; - this.ItemsToGrabMenu.populateClickableComponentList(); - for (int i = 0; i < this.ItemsToGrabMenu.inventory.Count; i++) + ItemsToGrabMenu = new InventoryMenu(xPositionOnScreen + Game1.tileSize / 2, yPositionOnScreen, false, inventory); + trashCan.myID = 106; + ItemsToGrabMenu.populateClickableComponentList(); + foreach (ClickableComponent t in ItemsToGrabMenu.inventory) { - if (this.ItemsToGrabMenu.inventory[i] != null) - { - ClickableComponent item = this.ItemsToGrabMenu.inventory[i]; - item.myID = item.myID + 53910; - ClickableComponent clickableComponent = this.ItemsToGrabMenu.inventory[i]; - clickableComponent.upNeighborID = clickableComponent.upNeighborID + 53910; - ClickableComponent item1 = this.ItemsToGrabMenu.inventory[i]; - item1.rightNeighborID = item1.rightNeighborID + 53910; - this.ItemsToGrabMenu.inventory[i].downNeighborID = -7777; - ClickableComponent clickableComponent1 = this.ItemsToGrabMenu.inventory[i]; - clickableComponent1.leftNeighborID = clickableComponent1.leftNeighborID + 53910; - this.ItemsToGrabMenu.inventory[i].fullyImmutable = true; - } + if (t == null) continue; + ClickableComponent item = t; + item.myID = item.myID + 53910; + ClickableComponent clickableComponent = t; + clickableComponent.upNeighborID = clickableComponent.upNeighborID + 53910; + ClickableComponent item1 = t; + item1.rightNeighborID = item1.rightNeighborID + 53910; + t.downNeighborID = -7777; + ClickableComponent clickableComponent1 = t; + clickableComponent1.leftNeighborID = clickableComponent1.leftNeighborID + 53910; + t.fullyImmutable = true; } if (Game1.options.SnappyMenus) { @@ -150,10 +149,10 @@ public FridgeGrabMenu(List inventory) : base(null, true, true, 0, 0) { if (this.inventory != null && this.inventory.inventory != null && this.inventory.inventory.Count >= 12) { - this.inventory.inventory[j].upNeighborID = (this.shippingBin ? 12598 : -7777); + this.inventory.inventory[j].upNeighborID = (ShippingBin ? 12598 : -7777); } } - if (!this.shippingBin) + if (!ShippingBin) { for (int k = 0; k < 36; k++) { @@ -164,16 +163,16 @@ public FridgeGrabMenu(List inventory) : base(null, true, true, 0, 0) } } } - if (this.trashCan != null) + if (trashCan != null) { - this.trashCan.leftNeighborID = 11; + trashCan.leftNeighborID = 11; } - if (this.okButton != null) + if (okButton != null) { - this.okButton.leftNeighborID = 11; + okButton.leftNeighborID = 11; } - base.populateClickableComponentList(); - this.snapToDefaultClickableComponent(); + populateClickableComponentList(); + snapToDefaultClickableComponent(); } this.inventory.showGrayedOutSlots = true; } @@ -229,129 +228,126 @@ public FridgeGrabMenu(List inventory) : base(null, true, true, 0, 0) //2. ItemGrabMenu.behaviorOnItemSelectFunction to FridgeGrabMenu.behaviorOnItemSelectFunction behaviorOnItemGrab //3. Add FridgeGrabMenu.behaviorOnPageCtlClick behaviorOnClickNextButton = null, FridgeGrabMenu.behaviorOnPageCtlClick behaviorOnClickPreviousButton = null, bool bShowPrevButton = false, bool bShowNextButton = false, FridgeGrabMenu.behaviorOnOrganizeItems behaviorOnClickOrganize = null at the end //DONE - public FridgeGrabMenu(List inventory, bool reverseGrab, bool showReceivingMenu, InventoryMenu.highlightThisItem highlightFunction, FridgeGrabMenu.behaviorOnItemSelect behaviorOnItemSelectFunction, string message, FridgeGrabMenu.behaviorOnItemSelect behaviorOnItemGrab = null, bool snapToBottom = false, bool canBeExitedWithKey = false, bool playRightClickSound = true, bool allowRightClick = true, bool showOrganizeButton = false, int source = 0, Item sourceItem = null, int whichSpecialButton = -1, object specialObject = null, FridgeGrabMenu.behaviorOnPageCtlClick behaviorOnClickNextButton = null, FridgeGrabMenu.behaviorOnPageCtlClick behaviorOnClickPreviousButton = null, bool bShowPrevButton = false, bool bShowNextButton = false, FridgeGrabMenu.behaviorOnOrganizeItems behaviorOnClickOrganize = null) : base(highlightFunction, true, true, 0, 0) + public FridgeGrabMenu(IList inventory, bool reverseGrab, bool showReceivingMenu, InventoryMenu.highlightThisItem highlightFunction, BehaviorOnItemSelect behaviorOnItemSelectFunction, string message, BehaviorOnItemSelect behaviorOnItemGrab = null, bool snapToBottom = false, bool canBeExitedWithKey = false, bool playRightClickSound = true, bool allowRightClick = true, bool showOrganizeButton = false, int source = 0, Item sourceItem = null, int whichSpecialButton = -1, object specialObject = null, BehaviorOnPageCtlClick behaviorOnClickNextButton = null, BehaviorOnPageCtlClick behaviorOnClickPreviousButton = null, bool bShowPrevButton = false, bool bShowNextButton = false, BehaviorOnOrganizeItems behaviorOnClickOrganize = null) : base(highlightFunction, true, true) { - int num; - int num1; - this.source = source; - this.message = message; - this.reverseGrab = reverseGrab; - this.showReceivingMenu = showReceivingMenu; - this.playRightClickSound = playRightClickSound; - this.allowRightClick = allowRightClick; + Source = source; + _message = message; + ReverseGrab = reverseGrab; + ShowReceivingMenu = showReceivingMenu; + PlayRightClickSound = playRightClickSound; + AllowRightClick = allowRightClick; this.inventory.showGrayedOutSlots = true; - this.sourceItem = sourceItem; + _sourceItem = sourceItem; //M07 - this.behaviorOnClickPreviousButton = behaviorOnClickPreviousButton; - this.behaviorOnClickNextButton = behaviorOnClickNextButton; - this.behaviorOnClickOrganize = behaviorOnClickOrganize; + BehaviorOnClickPreviousButton = behaviorOnClickPreviousButton; + BehaviorOnClickNextButton = behaviorOnClickNextButton; + BehaviorOnClickOrganize = behaviorOnClickOrganize; //END_M07 - if (source == 1 && sourceItem != null && sourceItem is Chest) + if (source == 1 && sourceItem is Chest) { - this.chestColorPicker = new DiscreteColorPicker(this.xPositionOnScreen, this.yPositionOnScreen - Game1.tileSize - IClickableMenu.borderWidth * 2, 0, new Chest(true)) + ChestColorPicker = new DiscreteColorPicker(xPositionOnScreen, yPositionOnScreen - Game1.tileSize - borderWidth * 2, 0, new Chest(true)) { - colorSelection = this.chestColorPicker.getSelectionFromColor((sourceItem as Chest).playerChoiceColor) + colorSelection = ChestColorPicker.getSelectionFromColor((sourceItem as Chest).playerChoiceColor.Value) }; - (this.chestColorPicker.itemToDrawColored as Chest).playerChoiceColor = this.chestColorPicker.getColorFromSelection(this.chestColorPicker.colorSelection); - ClickableTextureComponent clickableTextureComponent = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + this.width, this.yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 5, 16 * Game1.pixelZoom, 16 * Game1.pixelZoom), Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(119, 469, 16, 16), (float)Game1.pixelZoom, false) + (ChestColorPicker.itemToDrawColored as Chest).playerChoiceColor.Value = ChestColorPicker.getColorFromSelection(ChestColorPicker.colorSelection); + ClickableTextureComponent clickableTextureComponent = new ClickableTextureComponent(new Rectangle(xPositionOnScreen + width, yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 5, 16 * Game1.pixelZoom, 16 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(119, 469, 16, 16), Game1.pixelZoom) { hoverText = Game1.content.LoadString("Strings\\UI:Toggle_ColorPicker", new object[0]), myID = 27346, downNeighborID = (showOrganizeButton ? 106 : 5948), leftNeighborID = 11 }; - this.colorPickerToggleButton = clickableTextureComponent; + ColorPickerToggleButton = clickableTextureComponent; } - this.whichSpecialButton = whichSpecialButton; - this.specialObject = specialObject; + WhichSpecialButton = whichSpecialButton; + SpecialObject = specialObject; if (whichSpecialButton == 1) { - this.specialButton = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + this.width, this.yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 5, 16 * Game1.pixelZoom, 16 * Game1.pixelZoom), Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(108, 491, 16, 16), (float)Game1.pixelZoom, false) + SpecialButton = new ClickableTextureComponent(new Rectangle(xPositionOnScreen + width, yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 5, 16 * Game1.pixelZoom, 16 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(108, 491, 16, 16), Game1.pixelZoom) { myID = 12485, downNeighborID = (showOrganizeButton ? 106 : 5948) }; - if (specialObject != null && specialObject is JunimoHut) + if (specialObject is JunimoHut) { - this.specialButton.sourceRect.X = ((specialObject as JunimoHut).noHarvest ? 124 : 108); + SpecialButton.sourceRect.X = ((specialObject as JunimoHut).noHarvest.Value ? 124 : 108); } } if (snapToBottom) { - base.movePosition(0, Game1.viewport.Height - (this.yPositionOnScreen + this.height - IClickableMenu.spaceToClearTopBorder)); - this.snappedtoBottom = true; + movePosition(0, Game1.viewport.Height - (yPositionOnScreen + height - spaceToClearTopBorder)); + _snappedtoBottom = true; } //new InventoryMenu(this.xPositionOnScreen + Game1.tileSize / 2, this.yPositionOnScreen, false, inventory, highlightFunction) - this.ItemsToGrabMenu = new InventoryMenu(this.xPositionOnScreen + Game1.tileSize / 2, this.yPositionOnScreen, false, inventory, highlightFunction, -1, 3, 0, 0, true); + ItemsToGrabMenu = new InventoryMenu(xPositionOnScreen + Game1.tileSize / 2, yPositionOnScreen, false, inventory, highlightFunction); if (Game1.options.SnappyMenus) { - this.ItemsToGrabMenu.populateClickableComponentList(); - for (int i = 0; i < this.ItemsToGrabMenu.inventory.Count; i++) + ItemsToGrabMenu.populateClickableComponentList(); + foreach (ClickableComponent t in ItemsToGrabMenu.inventory) { - if (this.ItemsToGrabMenu.inventory[i] != null) - { - ClickableComponent item = this.ItemsToGrabMenu.inventory[i]; - item.myID = item.myID + 53910; - ClickableComponent clickableComponent = this.ItemsToGrabMenu.inventory[i]; - clickableComponent.upNeighborID = clickableComponent.upNeighborID + 53910; - ClickableComponent item1 = this.ItemsToGrabMenu.inventory[i]; - item1.rightNeighborID = item1.rightNeighborID + 53910; - this.ItemsToGrabMenu.inventory[i].downNeighborID = -7777; - ClickableComponent clickableComponent1 = this.ItemsToGrabMenu.inventory[i]; - clickableComponent1.leftNeighborID = clickableComponent1.leftNeighborID + 53910; - this.ItemsToGrabMenu.inventory[i].fullyImmutable = true; - } + if (t == null) continue; + ClickableComponent item = t; + item.myID = item.myID + 53910; + ClickableComponent clickableComponent = t; + clickableComponent.upNeighborID = clickableComponent.upNeighborID + 53910; + ClickableComponent item1 = t; + item1.rightNeighborID = item1.rightNeighborID + 53910; + t.downNeighborID = -7777; + ClickableComponent clickableComponent1 = t; + clickableComponent1.leftNeighborID = clickableComponent1.leftNeighborID + 53910; + t.fullyImmutable = true; } } - this.behaviorFunction = behaviorOnItemSelectFunction; - this.behaviorOnItemGrab = behaviorOnItemGrab; - this.canExitOnKey = canBeExitedWithKey; + BehaviorFunction = behaviorOnItemSelectFunction; + BehaviorOnItemGrab = behaviorOnItemGrab; + CanExitOnKey = canBeExitedWithKey; //M07 - this.previousPageButton = new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen + this.width + Game1.tileSize, (this.yPositionOnScreen + this.height / 3 - Game1.tileSize) + 2, Game1.tileSize, Game1.tileSize), "", "Previous Page", Game1.mouseCursors, new Rectangle(352, 494, 12, 12), (float)Game1.pixelZoom); - this.nextPageButton = new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen + this.width + 2 * Game1.tileSize, (this.yPositionOnScreen + this.height / 3 - Game1.tileSize) + 2, Game1.tileSize, Game1.tileSize), "", "Next Page", Game1.mouseCursors, new Rectangle(365, 494, 12, 12), (float)Game1.pixelZoom); + _previousPageButton = new ClickableTextureComponent("", new Rectangle(xPositionOnScreen + width + Game1.tileSize, (yPositionOnScreen + height / 3 - Game1.tileSize) + 2, Game1.tileSize, Game1.tileSize), "", "Previous Page", Game1.mouseCursors, new Rectangle(352, 494, 12, 12), Game1.pixelZoom); + _nextPageButton = new ClickableTextureComponent("", new Rectangle(xPositionOnScreen + width + 2 * Game1.tileSize, (yPositionOnScreen + height / 3 - Game1.tileSize) + 2, Game1.tileSize, Game1.tileSize), "", "Next Page", Game1.mouseCursors, new Rectangle(365, 494, 12, 12), Game1.pixelZoom); - this.showPrevButton = bShowPrevButton; - this.showNextButton = bShowNextButton; + _showPrevButton = bShowPrevButton; + _showNextButton = bShowNextButton; //END_M07 if (showOrganizeButton) { - ClickableTextureComponent clickableTextureComponent1 = new ClickableTextureComponent("", new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + this.width, this.yPositionOnScreen + this.height / 3 - Game1.tileSize, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:ItemGrab_Organize", new object[0]), Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(162, 440, 16, 16), (float)Game1.pixelZoom, false) + ClickableTextureComponent clickableTextureComponent1 = new ClickableTextureComponent("", new Rectangle(xPositionOnScreen + width, yPositionOnScreen + height / 3 - Game1.tileSize, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:ItemGrab_Organize", new object[0]), Game1.mouseCursors, new Rectangle(162, 440, 16, 16), Game1.pixelZoom) { myID = 106 }; - if (this.colorPickerToggleButton != null) + int num1; + if (ColorPickerToggleButton != null) { num1 = 27346; } else { - num1 = (this.specialButton != null ? 12485 : -500); + num1 = (SpecialButton != null ? 12485 : -500); } clickableTextureComponent1.upNeighborID = num1; clickableTextureComponent1.downNeighborID = 5948; - this.organizeButton = clickableTextureComponent1; + OrganizeButton = clickableTextureComponent1; } - if ((Game1.isAnyGamePadButtonBeingPressed() || !Game1.lastCursorMotionWasMouse) && this.ItemsToGrabMenu.actualInventory.Count > 0 && Game1.activeClickableMenu == null) + if ((Game1.isAnyGamePadButtonBeingPressed() || !Game1.lastCursorMotionWasMouse) && ItemsToGrabMenu.actualInventory.Count > 0 && Game1.activeClickableMenu == null) { Game1.setMousePosition(this.inventory.inventory[0].bounds.Center); } if (Game1.options.snappyMenus && Game1.options.gamepadControls) { - if (this.chestColorPicker != null) + if (ChestColorPicker != null) { - this.discreteColorPickerCC = new List(); - for (int j = 0; j < this.chestColorPicker.totalColors; j++) + DiscreteColorPickerCc = new List(); + for (int j = 0; j < ChestColorPicker.totalColors; j++) { - this.discreteColorPickerCC.Add(new ClickableComponent(new Microsoft.Xna.Framework.Rectangle(this.chestColorPicker.xPositionOnScreen + IClickableMenu.borderWidth / 2 + j * 9 * Game1.pixelZoom, this.chestColorPicker.yPositionOnScreen + IClickableMenu.borderWidth / 2, 9 * Game1.pixelZoom, 7 * Game1.pixelZoom), "") + DiscreteColorPickerCc.Add(new ClickableComponent(new Rectangle(ChestColorPicker.xPositionOnScreen + borderWidth / 2 + j * 9 * Game1.pixelZoom, ChestColorPicker.yPositionOnScreen + borderWidth / 2, 9 * Game1.pixelZoom, 7 * Game1.pixelZoom), "") { myID = j + 4343, - rightNeighborID = (j < this.chestColorPicker.totalColors - 1 ? j + 4343 + 1 : -1), + rightNeighborID = (j < ChestColorPicker.totalColors - 1 ? j + 4343 + 1 : -1), leftNeighborID = (j > 0 ? j + 4343 - 1 : -1), - downNeighborID = (this.ItemsToGrabMenu == null || this.ItemsToGrabMenu.inventory.Count <= 0 ? 0 : 53910) + downNeighborID = (ItemsToGrabMenu == null || ItemsToGrabMenu.inventory.Count <= 0 ? 0 : 53910) }); } } @@ -360,13 +356,14 @@ public FridgeGrabMenu(List inventory, bool reverseGrab, bool showReceiving if (this.inventory != null && this.inventory.inventory != null && this.inventory.inventory.Count >= 12) { ClickableComponent item2 = this.inventory.inventory[k]; - if (this.shippingBin) + int num; + if (ShippingBin) { num = 12598; } - else if (this.discreteColorPickerCC == null || this.ItemsToGrabMenu == null || this.ItemsToGrabMenu.inventory.Count > k) + else if (DiscreteColorPickerCc == null || ItemsToGrabMenu == null || ItemsToGrabMenu.inventory.Count > k) { - num = (this.ItemsToGrabMenu.inventory.Count > k ? 53910 + k : 53910); + num = (ItemsToGrabMenu.inventory.Count > k ? 53910 + k : 53910); } else { @@ -374,12 +371,12 @@ public FridgeGrabMenu(List inventory, bool reverseGrab, bool showReceiving } item2.upNeighborID = num; } - if (this.discreteColorPickerCC != null && this.ItemsToGrabMenu != null && this.ItemsToGrabMenu.inventory.Count > k) + if (DiscreteColorPickerCc != null && ItemsToGrabMenu != null && ItemsToGrabMenu.inventory.Count > k) { - this.ItemsToGrabMenu.inventory[k].upNeighborID = 4343; + ItemsToGrabMenu.inventory[k].upNeighborID = 4343; } } - if (!this.shippingBin) + if (!ShippingBin) { for (int l = 0; l < 36; l++) { @@ -390,28 +387,28 @@ public FridgeGrabMenu(List inventory, bool reverseGrab, bool showReceiving } } } - if (this.trashCan != null && this.inventory.inventory.Count >= 12 && this.inventory.inventory[11] != null) + if (trashCan != null && this.inventory.inventory.Count >= 12 && this.inventory.inventory[11] != null) { this.inventory.inventory[11].rightNeighborID = 5948; } - if (this.trashCan != null) + if (trashCan != null) { - this.trashCan.leftNeighborID = 11; + trashCan.leftNeighborID = 11; } - if (this.okButton != null) + if (okButton != null) { - this.okButton.leftNeighborID = 11; + okButton.leftNeighborID = 11; } - base.populateClickableComponentList(); - this.snapToDefaultClickableComponent(); + populateClickableComponentList(); + snapToDefaultClickableComponent(); } } //NOMOD - public void initializeShippingBin() + public void InitializeShippingBin() { - this.shippingBin = true; - this.lastShippedHolder = new ClickableTextureComponent("", new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + this.width / 2 - 12 * Game1.pixelZoom, this.yPositionOnScreen + this.height / 2 - 20 * Game1.pixelZoom - Game1.tileSize, 24 * Game1.pixelZoom, 24 * Game1.pixelZoom), "", Game1.content.LoadString("Strings\\UI:ShippingBin_LastItem", new object[0]), Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(293, 360, 24, 24), (float)Game1.pixelZoom, false) + ShippingBin = true; + LastShippedHolder = new ClickableTextureComponent("", new Rectangle(xPositionOnScreen + width / 2 - 12 * Game1.pixelZoom, yPositionOnScreen + height / 2 - 20 * Game1.pixelZoom - Game1.tileSize, 24 * Game1.pixelZoom, 24 * Game1.pixelZoom), "", Game1.content.LoadString("Strings\\UI:ShippingBin_LastItem", new object[0]), Game1.mouseCursors, new Rectangle(293, 360, 24, 24), Game1.pixelZoom) { myID = 12598, region = 12598 @@ -420,32 +417,32 @@ public void initializeShippingBin() { for (int i = 0; i < 12; i++) { - if (this.inventory != null && this.inventory.inventory != null && this.inventory.inventory.Count >= 12) + if (inventory != null && inventory.inventory != null && inventory.inventory.Count >= 12) { - this.inventory.inventory[i].upNeighborID = -7777; + inventory.inventory[i].upNeighborID = -7777; if (i == 11) { - this.inventory.inventory[i].rightNeighborID = 5948; + inventory.inventory[i].rightNeighborID = 5948; } } } - base.populateClickableComponentList(); - this.snapToDefaultClickableComponent(); + populateClickableComponentList(); + snapToDefaultClickableComponent(); } } //NOMOD - public void setBackgroundTransparency(bool b) + public void SetBackgroundTransparency(bool b) { - this.drawBG = b; + DrawBg = b; } //NOMOD - public void setDestroyItemOnClick(bool b) + public void SetDestroyItemOnClick(bool b) { - this.destroyItemOnClick = b; + DestroyItemOnClick = b; } - + #region "Old Code" //WAS: //public override void receiveRightClick(int x, int y, bool playSound = true) //{ @@ -500,46 +497,46 @@ public void setDestroyItemOnClick(bool b) // this.heldItem = (Item)null; // } //} - + #endregion //IS //DONE public override void receiveRightClick(int x, int y, bool playSound = true) { - if (!this.allowRightClick) + if (!AllowRightClick) { return; } - base.receiveRightClick(x, y, (!playSound ? false : this.playRightClickSound)); - if (this.heldItem == null && this.showReceivingMenu) + base.receiveRightClick(x, y, (playSound && PlayRightClickSound)); + if (heldItem == null && ShowReceivingMenu) { - this.heldItem = this.ItemsToGrabMenu.rightClick(x, y, this.heldItem, false); - if (this.heldItem != null && this.behaviorOnItemGrab != null) + heldItem = ItemsToGrabMenu.rightClick(x, y, heldItem, false); + if (heldItem != null && BehaviorOnItemGrab != null && Game1.activeClickableMenu is ItemGrabMenu itm) { - this.behaviorOnItemGrab(this.heldItem, Game1.player); - if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is ItemGrabMenu) + BehaviorOnItemGrab(heldItem, Game1.player); + if (Game1.activeClickableMenu != null) { - (Game1.activeClickableMenu as ItemGrabMenu).setSourceItem(this.sourceItem); + itm.setSourceItem(_sourceItem); } if (Game1.options.SnappyMenus) { - (Game1.activeClickableMenu as ItemGrabMenu).currentlySnappedComponent = this.currentlySnappedComponent; - (Game1.activeClickableMenu as ItemGrabMenu).snapCursorToCurrentSnappedComponent(); + itm.currentlySnappedComponent = currentlySnappedComponent; + itm.snapCursorToCurrentSnappedComponent(); } } - if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).parentSheetIndex == 326) + if (heldItem is Object && (heldItem as Object).ParentSheetIndex == 326) { - this.heldItem = null; + heldItem = null; Game1.player.canUnderstandDwarves = true; - this.poof = new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); + //this.poof = new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); Game1.playSound("fireball"); return; } - if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).isRecipe) + if (heldItem is Object && (heldItem as Object).IsRecipe) { - string str = this.heldItem.Name.Substring(0, this.heldItem.Name.IndexOf("Recipe") - 1); + string str = heldItem.Name.Substring(0, heldItem.Name.IndexOf("Recipe", StringComparison.Ordinal) - 1); try { - if ((this.heldItem as StardewValley.Object).category != -7) + if ((heldItem as Object).Category != -7) { Game1.player.craftingRecipes.Add(str, 0); } @@ -547,57 +544,53 @@ public override void receiveRightClick(int x, int y, bool playSound = true) { Game1.player.cookingRecipes.Add(str, 0); } - this.poof = new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); + //this.poof = new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); Game1.playSound("newRecipe"); } catch (Exception exception) { + ExtendedFridgeMod.Instance.Monitor.Log($"Error: {exception}", LogLevel.Trace); } - this.heldItem = null; + heldItem = null; return; } - if (Game1.player.addItemToInventoryBool(this.heldItem, false)) + if (Game1.player.addItemToInventoryBool(heldItem)) { - this.heldItem = null; + heldItem = null; Game1.playSound("coin"); - return; } } - else if (this.reverseGrab || this.behaviorFunction != null) + else if (ReverseGrab || BehaviorFunction != null) { - this.behaviorFunction(this.heldItem, Game1.player); + BehaviorFunction(heldItem, Game1.player); if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is ItemGrabMenu) { - (Game1.activeClickableMenu as ItemGrabMenu).setSourceItem(this.sourceItem); + ((ItemGrabMenu) Game1.activeClickableMenu).setSourceItem(_sourceItem); } - if (this.destroyItemOnClick) + if (DestroyItemOnClick) { - this.heldItem = null; - return; + heldItem = null; } } } //DONE - public override void gameWindowSizeChanged(Microsoft.Xna.Framework.Rectangle oldBounds, Microsoft.Xna.Framework.Rectangle newBounds) + public override void gameWindowSizeChanged(Rectangle oldBounds, Rectangle newBounds) { - if (this.snappedtoBottom) - { - base.movePosition((newBounds.Width - oldBounds.Width) / 2, Game1.viewport.Height - (this.yPositionOnScreen + this.height - IClickableMenu.spaceToClearTopBorder)); - } - if (this.ItemsToGrabMenu != null) + if (_snappedtoBottom) { - this.ItemsToGrabMenu.gameWindowSizeChanged(oldBounds, newBounds); + movePosition((newBounds.Width - oldBounds.Width) / 2, Game1.viewport.Height - (yPositionOnScreen + height - spaceToClearTopBorder)); } - if (this.organizeButton != null) + ItemsToGrabMenu?.gameWindowSizeChanged(oldBounds, newBounds); + if (OrganizeButton != null) { - this.organizeButton = new ClickableTextureComponent("", new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + this.width, this.yPositionOnScreen + this.height / 3 - Game1.tileSize, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:ItemGrab_Organize", new object[0]), Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(162, 440, 16, 16), (float)Game1.pixelZoom, false); + OrganizeButton = new ClickableTextureComponent("", new Rectangle(xPositionOnScreen + width, yPositionOnScreen + height / 3 - Game1.tileSize, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:ItemGrab_Organize", new object[0]), Game1.mouseCursors, new Rectangle(162, 440, 16, 16), Game1.pixelZoom); } - if (this.source == 1 && this.sourceItem != null && this.sourceItem is Chest) + if (Source == 1 && _sourceItem is Chest) { - this.chestColorPicker = new DiscreteColorPicker(this.xPositionOnScreen, this.yPositionOnScreen - Game1.tileSize - IClickableMenu.borderWidth * 2, 0, null) + ChestColorPicker = new DiscreteColorPicker(xPositionOnScreen, yPositionOnScreen - Game1.tileSize - borderWidth * 2) { - colorSelection = this.chestColorPicker.getSelectionFromColor((this.sourceItem as Chest).playerChoiceColor) + colorSelection = ChestColorPicker.getSelectionFromColor(((Chest) _sourceItem).playerChoiceColor.Value) }; } } @@ -605,10 +598,10 @@ public override void gameWindowSizeChanged(Microsoft.Xna.Framework.Rectangle old //DONE public override void receiveLeftClick(int x, int y, bool playSound = true) { - base.receiveLeftClick(x, y, (this.destroyItemOnClick ? false : true)); - if (this.shippingBin && this.lastShippedHolder.containsPoint(x, y)) + base.receiveLeftClick(x, y, (!DestroyItemOnClick)); + if (ShippingBin && LastShippedHolder.containsPoint(x, y)) { - if (Game1.getFarm().lastItemShipped != null && Game1.player.addItemToInventoryBool(Game1.getFarm().lastItemShipped, false)) + if (Game1.getFarm().lastItemShipped != null && Game1.player.addItemToInventoryBool(Game1.getFarm().lastItemShipped)) { Game1.playSound("coin"); Game1.getFarm().shippingBin.Remove(Game1.getFarm().lastItemShipped); @@ -621,71 +614,72 @@ public override void receiveLeftClick(int x, int y, bool playSound = true) } return; } - if (this.chestColorPicker != null) + if (ChestColorPicker != null) { - this.chestColorPicker.receiveLeftClick(x, y, true); - if (this.sourceItem != null && this.sourceItem is Chest) + ChestColorPicker.receiveLeftClick(x, y); + if (_sourceItem is Chest item) { - (this.sourceItem as Chest).playerChoiceColor = this.chestColorPicker.getColorFromSelection(this.chestColorPicker.colorSelection); + item.playerChoiceColor.Value = ChestColorPicker.getColorFromSelection(ChestColorPicker.colorSelection); } } - if (this.colorPickerToggleButton != null && this.colorPickerToggleButton.containsPoint(x, y)) + if (ColorPickerToggleButton != null && ColorPickerToggleButton.containsPoint(x, y)) { Game1.player.showChestColorPicker = !Game1.player.showChestColorPicker; - this.chestColorPicker.visible = Game1.player.showChestColorPicker; + if (ChestColorPicker != null) ChestColorPicker.visible = Game1.player.showChestColorPicker; try { Game1.playSound("drumkit6"); } catch (Exception exception) { + ExtendedFridgeMod.Instance.Monitor.Log($"Error: {exception}", LogLevel.Trace); } } - if (this.whichSpecialButton != -1 && this.specialButton != null && this.specialButton.containsPoint(x, y)) + if (WhichSpecialButton != -1 && SpecialButton != null && SpecialButton.containsPoint(x, y)) { Game1.playSound("drumkit6"); - if (this.whichSpecialButton == 1 && this.specialObject != null && this.specialObject is JunimoHut) + if (WhichSpecialButton == 1 && SpecialObject is JunimoHut) { - (this.specialObject as JunimoHut).noHarvest = !(this.specialObject as JunimoHut).noHarvest; - this.specialButton.sourceRect.X = ((this.specialObject as JunimoHut).noHarvest ? 124 : 108); + (SpecialObject as JunimoHut).noHarvest.Value = !((JunimoHut) SpecialObject).noHarvest.Value; + SpecialButton.sourceRect.X = (((JunimoHut) SpecialObject).noHarvest.Value ? 124 : 108); } } - if (this.heldItem == null && this.showReceivingMenu) + if (heldItem == null && ShowReceivingMenu) { - this.heldItem = this.ItemsToGrabMenu.leftClick(x, y, this.heldItem, false); - if (this.heldItem != null && this.behaviorOnItemGrab != null) + heldItem = ItemsToGrabMenu.leftClick(x, y, heldItem, false); + if (heldItem != null && BehaviorOnItemGrab != null) { - this.behaviorOnItemGrab(this.heldItem, Game1.player); + BehaviorOnItemGrab(heldItem, Game1.player); if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is ItemGrabMenu) { - (Game1.activeClickableMenu as ItemGrabMenu).setSourceItem(this.sourceItem); + ((ItemGrabMenu) Game1.activeClickableMenu).setSourceItem(_sourceItem); if (Game1.options.SnappyMenus) { - (Game1.activeClickableMenu as ItemGrabMenu).currentlySnappedComponent = this.currentlySnappedComponent; - (Game1.activeClickableMenu as ItemGrabMenu).snapCursorToCurrentSnappedComponent(); + ((ItemGrabMenu) Game1.activeClickableMenu).currentlySnappedComponent = currentlySnappedComponent; + ((ItemGrabMenu) Game1.activeClickableMenu).snapCursorToCurrentSnappedComponent(); } } } - if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).parentSheetIndex == 326) + if (heldItem is Object && (heldItem as Object).ParentSheetIndex == 326) { - this.heldItem = null; + heldItem = null; Game1.player.canUnderstandDwarves = true; - this.poof = new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); + //this.poof = new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); Game1.playSound("fireball"); } - else if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).parentSheetIndex == 102) + else if (heldItem is Object && (heldItem as Object).ParentSheetIndex == 102) { - this.heldItem = null; + heldItem = null; Game1.player.foundArtifact(102, 1); - this.poof = new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); + //this.poof = new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); Game1.playSound("fireball"); } - else if (this.heldItem is StardewValley.Object && (this.heldItem as StardewValley.Object).isRecipe) + else if (heldItem is Object && (heldItem as Object).IsRecipe) { - string str = this.heldItem.Name.Substring(0, this.heldItem.Name.IndexOf("Recipe") - 1); + string str = heldItem.Name.Substring(0, heldItem.Name.IndexOf("Recipe", StringComparison.Ordinal) - 1); try { - if ((this.heldItem as StardewValley.Object).category != -7) + if ((heldItem as Object).Category != -7) { Game1.player.craftingRecipes.Add(str, 0); } @@ -693,90 +687,82 @@ public override void receiveLeftClick(int x, int y, bool playSound = true) { Game1.player.cookingRecipes.Add(str, 0); } - this.poof = new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); + //this.poof = new TemporaryAnimatedSprite(Game1.animations, new Microsoft.Xna.Framework.Rectangle(0, 320, 64, 64), 50f, 8, 0, new Vector2((float)(x - x % Game1.tileSize + Game1.tileSize / 4), (float)(y - y % Game1.tileSize + Game1.tileSize / 4)), false, false); Game1.playSound("newRecipe"); } catch (Exception exception1) { + ExtendedFridgeMod.Instance.Monitor.Log($"Error: {exception1}", LogLevel.Trace); } - this.heldItem = null; + heldItem = null; } - else if (Game1.player.addItemToInventoryBool(this.heldItem, false)) + else if (Game1.player.addItemToInventoryBool(heldItem)) { - this.heldItem = null; + heldItem = null; Game1.playSound("coin"); } } - else if ((this.reverseGrab || this.behaviorFunction != null) && this.isWithinBounds(x, y)) + else if ((ReverseGrab || BehaviorFunction != null) && isWithinBounds(x, y)) { - this.behaviorFunction(this.heldItem, Game1.player); + BehaviorFunction(heldItem, Game1.player); if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is ItemGrabMenu) { - (Game1.activeClickableMenu as ItemGrabMenu).setSourceItem(this.sourceItem); + ((ItemGrabMenu) Game1.activeClickableMenu).setSourceItem(_sourceItem); if (Game1.options.SnappyMenus) { - (Game1.activeClickableMenu as ItemGrabMenu).currentlySnappedComponent = this.currentlySnappedComponent; - (Game1.activeClickableMenu as ItemGrabMenu).snapCursorToCurrentSnappedComponent(); + ((ItemGrabMenu) Game1.activeClickableMenu).currentlySnappedComponent = currentlySnappedComponent; + ((ItemGrabMenu) Game1.activeClickableMenu).snapCursorToCurrentSnappedComponent(); } } - if (this.destroyItemOnClick) + if (DestroyItemOnClick) { - this.heldItem = null; + heldItem = null; return; } } - if (this.organizeButton != null && this.organizeButton.containsPoint(x, y)) + if (OrganizeButton != null && OrganizeButton.containsPoint(x, y)) { - ItemGrabMenu.organizeItemsInList(this.ItemsToGrabMenu.actualInventory); - Game1.activeClickableMenu = new FridgeGrabMenu(this.ItemsToGrabMenu.actualInventory, false, true, new InventoryMenu.highlightThisItem(InventoryMenu.highlightAllItems), this.behaviorFunction, null, this.behaviorOnItemGrab, false, true, true, true, true, this.source, this.sourceItem, -1, null); + ItemGrabMenu.organizeItemsInList(ExtendedFridgeMod.Organize()); + //ItemGrabMenu.organizeItemsInList(this.ItemsToGrabMenu.actualInventory); + Game1.activeClickableMenu = new FridgeGrabMenu(ItemsToGrabMenu.actualInventory, false, true, InventoryMenu.highlightAllItems, BehaviorFunction, null, BehaviorOnItemGrab, false, true, true, true, true, Source, _sourceItem); Game1.playSound("Ship"); return; } - if (this.previousPageButton != null && this.previousPageButton.containsPoint(x, y) && this.behaviorOnClickPreviousButton != null) + if (_previousPageButton != null && _previousPageButton.containsPoint(x, y) && BehaviorOnClickPreviousButton != null) { - this.behaviorOnClickPreviousButton(); + BehaviorOnClickPreviousButton(); Game1.playSound("Ship"); return; } - if (this.nextPageButton != null && this.nextPageButton.containsPoint(x, y) && this.behaviorOnClickNextButton != null) + if (_nextPageButton != null && _nextPageButton.containsPoint(x, y) && BehaviorOnClickNextButton != null) { - this.behaviorOnClickNextButton(); + BehaviorOnClickNextButton(); Game1.playSound("Ship"); return; } - if (this.heldItem != null && !this.isWithinBounds(x, y) && this.heldItem.canBeTrashed()) + if (heldItem != null && !isWithinBounds(x, y) && heldItem.canBeTrashed()) { Game1.playSound("throwDownITem"); - Game1.createItemDebris(this.heldItem, Game1.player.getStandingPosition(), Game1.player.FacingDirection, null); - if (this.inventory.onAddItem != null) - { - this.inventory.onAddItem(this.heldItem, Game1.player); - } - this.heldItem = null; + Game1.createItemDebris(heldItem, Game1.player.getStandingPosition(), Game1.player.FacingDirection); + inventory.onAddItem?.Invoke(heldItem, Game1.player); + heldItem = null; } } //NOMOD - public static void organizeItemsInList(List items) + public static void OrganizeItemsInList(IList items) { - items.Sort(); - items.Reverse(); + items.ToList().Sort(); + items.ToList().Reverse(); } //NOMOD - public bool areAllItemsTaken() + public bool AreAllItemsTaken() { - for (int i = 0; i < this.ItemsToGrabMenu.actualInventory.Count; i++) - { - if (this.ItemsToGrabMenu.actualInventory[i] != null) - { - return false; - } - } - return true; + return ItemsToGrabMenu.actualInventory.All(t => t == null); } //DONE @@ -784,28 +770,28 @@ public override void receiveKeyPress(Keys key) { if (Game1.options.snappyMenus && Game1.options.gamepadControls) { - base.applyMovementKey(key); + applyMovementKey(key); } - if ((this.canExitOnKey || this.areAllItemsTaken()) && Game1.options.doesInputListContain(Game1.options.menuButton, key) && this.readyToClose()) + if ((CanExitOnKey || AreAllItemsTaken()) && Game1.options.doesInputListContain(Game1.options.menuButton, key) && readyToClose()) { - base.exitThisMenu(true); + exitThisMenu(); if (Game1.currentLocation.currentEvent != null) { Event currentCommand = Game1.currentLocation.currentEvent; currentCommand.CurrentCommand = currentCommand.CurrentCommand + 1; } } - else if (Game1.options.doesInputListContain(Game1.options.menuButton, key) && this.heldItem != null) + else if (Game1.options.doesInputListContain(Game1.options.menuButton, key) && heldItem != null) { - Game1.setMousePosition(this.trashCan.bounds.Center); + Game1.setMousePosition(trashCan.bounds.Center); } - if (key == Keys.Delete && this.heldItem != null && this.heldItem.canBeTrashed()) + if (key == Keys.Delete && heldItem != null && heldItem.canBeTrashed()) { - if (this.heldItem is StardewValley.Object && Game1.player.specialItems.Contains((this.heldItem as StardewValley.Object).parentSheetIndex)) + if (heldItem is Object && Game1.player.specialItems.Contains(((Object) heldItem).ParentSheetIndex)) { - Game1.player.specialItems.Remove((this.heldItem as StardewValley.Object).parentSheetIndex); + Game1.player.specialItems.Remove(((Object) heldItem).ParentSheetIndex); } - this.heldItem = null; + heldItem = null; Game1.playSound("trashcan"); } } @@ -814,158 +800,149 @@ public override void receiveKeyPress(Keys key) public override void update(GameTime time) { base.update(time); - if (this.poof != null && this.poof.update(time)) - { - this.poof = null; - } - if (this.chestColorPicker != null) + if (_poof != null && _poof.update(time)) { - this.chestColorPicker.update(time); + _poof = null; } + ChestColorPicker?.update(time); } //DONE public override void performHoverAction(int x, int y) { - if (this.colorPickerToggleButton != null) + if (ColorPickerToggleButton != null) { - this.colorPickerToggleButton.tryHover(x, y, 0.25f); - if (this.colorPickerToggleButton.containsPoint(x, y)) + ColorPickerToggleButton.tryHover(x, y, 0.25f); + if (ColorPickerToggleButton.containsPoint(x, y)) { - this.hoverText = this.colorPickerToggleButton.hoverText; + hoverText = ColorPickerToggleButton.hoverText; return; } } - if (this.specialButton != null) - { - this.specialButton.tryHover(x, y, 0.25f); - } - if (!this.ItemsToGrabMenu.isWithinBounds(x, y) || !this.showReceivingMenu) + SpecialButton?.tryHover(x, y, 0.25f); + if (!ItemsToGrabMenu.isWithinBounds(x, y) || !ShowReceivingMenu) { base.performHoverAction(x, y); } else { - this.hoveredItem = this.ItemsToGrabMenu.hover(x, y, this.heldItem); + hoveredItem = ItemsToGrabMenu.hover(x, y, heldItem); } - if (this.organizeButton != null) + if (OrganizeButton != null) { - this.hoverText = null; - this.organizeButton.tryHover(x, y, 0.1f); - if (this.organizeButton.containsPoint(x, y)) + hoverText = null; + OrganizeButton.tryHover(x, y); + if (OrganizeButton.containsPoint(x, y)) { - this.hoverText = this.organizeButton.hoverText; + hoverText = OrganizeButton.hoverText; } } //M07: Needed to make previous/next page button usable - if (this.previousPageButton.containsPoint(x, y) && this.showPrevButton) + if (_previousPageButton.containsPoint(x, y) && _showPrevButton) { - this.hoverText = this.previousPageButton.hoverText; + hoverText = _previousPageButton.hoverText; } - if (this.nextPageButton.containsPoint(x, y) && this.showNextButton) + if (_nextPageButton.containsPoint(x, y) && _showNextButton) { - this.hoverText = this.nextPageButton.hoverText; + hoverText = _nextPageButton.hoverText; } //END_M07 - if (this.shippingBin) + if (ShippingBin) { - this.hoverText = null; - if (this.lastShippedHolder.containsPoint(x, y) && Game1.getFarm().lastItemShipped != null) + hoverText = null; + if (LastShippedHolder.containsPoint(x, y) && Game1.getFarm().lastItemShipped != null) { - this.hoverText = this.lastShippedHolder.hoverText; + hoverText = LastShippedHolder.hoverText; } } - if (this.chestColorPicker != null) - { - this.chestColorPicker.performHoverAction(x, y); - } + ChestColorPicker?.performHoverAction(x, y); } //DONE - protected override void customSnapBehavior(int direction, int oldRegion, int oldID) + protected override void customSnapBehavior(int direction, int oldRegion, int oldId) { if (direction != 2) { if (direction == 0) { - if (this.shippingBin && Game1.getFarm().lastItemShipped != null && oldID < 12) + if (ShippingBin && Game1.getFarm().lastItemShipped != null && oldId < 12) { - this.currentlySnappedComponent = base.getComponentWithID(12598); - this.currentlySnappedComponent.downNeighborID = oldID; - this.snapCursorToCurrentSnappedComponent(); + currentlySnappedComponent = getComponentWithID(12598); + currentlySnappedComponent.downNeighborID = oldId; + snapCursorToCurrentSnappedComponent(); return; } - if (oldID < 53910 && oldID >= 12) + if (oldId < 53910 && oldId >= 12) { - this.currentlySnappedComponent = base.getComponentWithID(oldID - 12); + currentlySnappedComponent = getComponentWithID(oldId - 12); return; } - int num = oldID + 24; - for (int i = 0; i < 3 && this.ItemsToGrabMenu.inventory.Count <= num; i++) + int num = oldId + 24; + for (int i = 0; i < 3 && ItemsToGrabMenu.inventory.Count <= num; i++) { num = num - 12; } if (num >= 0) { - this.currentlySnappedComponent = base.getComponentWithID(num + 53910); + currentlySnappedComponent = getComponentWithID(num + 53910); } - else if (this.ItemsToGrabMenu.inventory.Count > 0) + else if (ItemsToGrabMenu.inventory.Count > 0) { - this.currentlySnappedComponent = base.getComponentWithID(53910 + this.ItemsToGrabMenu.inventory.Count - 1); + currentlySnappedComponent = getComponentWithID(53910 + ItemsToGrabMenu.inventory.Count - 1); } - else if (this.discreteColorPickerCC != null) + else if (DiscreteColorPickerCc != null) { - this.currentlySnappedComponent = base.getComponentWithID(4343); + currentlySnappedComponent = getComponentWithID(4343); } - this.snapCursorToCurrentSnappedComponent(); + snapCursorToCurrentSnappedComponent(); } return; } for (int j = 0; j < 12; j++) { - if (this.inventory != null && this.inventory.inventory != null && this.inventory.inventory.Count >= 12 && this.shippingBin) + if (inventory != null && inventory.inventory != null && inventory.inventory.Count >= 12 && ShippingBin) { - this.inventory.inventory[j].upNeighborID = (this.shippingBin ? 12598 : Math.Min(j, this.ItemsToGrabMenu.inventory.Count - 1) + 53910); + inventory.inventory[j].upNeighborID = (ShippingBin ? 12598 : Math.Min(j, ItemsToGrabMenu.inventory.Count - 1) + 53910); } } - if (!this.shippingBin && oldID >= 53910) + if (!ShippingBin && oldId >= 53910) { - int num1 = oldID - 53910; - if (num1 + 12 <= this.ItemsToGrabMenu.inventory.Count - 1) + int num1 = oldId - 53910; + if (num1 + 12 <= ItemsToGrabMenu.inventory.Count - 1) { - this.currentlySnappedComponent = base.getComponentWithID(num1 + 12 + 53910); - this.snapCursorToCurrentSnappedComponent(); + currentlySnappedComponent = getComponentWithID(num1 + 12 + 53910); + snapCursorToCurrentSnappedComponent(); return; } } - this.currentlySnappedComponent = base.getComponentWithID((oldRegion == 12598 ? 0 : (oldID - 53910) % 12)); - this.snapCursorToCurrentSnappedComponent(); + currentlySnappedComponent = getComponentWithID((oldRegion == 12598 ? 0 : (oldId - 53910) % 12)); + snapCursorToCurrentSnappedComponent(); } - //TODO + //TODOx public override void draw(SpriteBatch b) { - if (this.drawBG) + if (DrawBg) { b.Draw(Game1.fadeToBlackRect, new Rectangle(0, 0, Game1.viewport.Width, Game1.viewport.Height), Color.Black * 0.5f); } - this.draw(b, false, false); + draw(b, false, false); - if (this.showReceivingMenu) + if (ShowReceivingMenu) { - b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 16 * Game1.pixelZoom), (float)(this.yPositionOnScreen + this.height / 2 + Game1.tileSize + Game1.pixelZoom * 4)), new Rectangle?(new Rectangle(16, 368, 12, 16)), Color.White, 4.712389f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); - b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 16 * Game1.pixelZoom), (float)(this.yPositionOnScreen + this.height / 2 + Game1.tileSize - Game1.pixelZoom * 4)), new Rectangle?(new Rectangle(21, 368, 11, 16)), Color.White, 4.712389f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); - b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 10 * Game1.pixelZoom), (float)(this.yPositionOnScreen + this.height / 2 + Game1.tileSize - Game1.pixelZoom * 11)), new Rectangle?(new Rectangle(4, 372, 8, 11)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); - if (this.source != 0) + b.Draw(Game1.mouseCursors, new Vector2(xPositionOnScreen - 16 * Game1.pixelZoom, yPositionOnScreen + height / 2 + Game1.tileSize + Game1.pixelZoom * 4), new Rectangle(16, 368, 12, 16), Color.White, 4.712389f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2(xPositionOnScreen - 16 * Game1.pixelZoom, yPositionOnScreen + height / 2 + Game1.tileSize - Game1.pixelZoom * 4), new Rectangle(21, 368, 11, 16), Color.White, 4.712389f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2(xPositionOnScreen - 10 * Game1.pixelZoom, yPositionOnScreen + height / 2 + Game1.tileSize - Game1.pixelZoom * 11), new Rectangle(4, 372, 8, 11), Color.White, 0.0f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 1f); + if (Source != 0) { - b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 18 * Game1.pixelZoom), (float)(this.yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 4)), new Rectangle?(new Rectangle(16, 368, 12, 16)), Color.White, 4.712389f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); - b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 18 * Game1.pixelZoom), (float)(this.yPositionOnScreen + Game1.tileSize - Game1.pixelZoom * 4)), new Rectangle?(new Rectangle(21, 368, 11, 16)), Color.White, 4.712389f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); - Rectangle rectangle = new Rectangle((int)sbyte.MaxValue, 412, 10, 11); - switch (this.source) + b.Draw(Game1.mouseCursors, new Vector2(xPositionOnScreen - 18 * Game1.pixelZoom, yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 4), new Rectangle(16, 368, 12, 16), Color.White, 4.712389f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2(xPositionOnScreen - 18 * Game1.pixelZoom, yPositionOnScreen + Game1.tileSize - Game1.pixelZoom * 4), new Rectangle(21, 368, 11, 16), Color.White, 4.712389f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 1f); + Rectangle rectangle = new Rectangle(sbyte.MaxValue, 412, 10, 11); + switch (Source) { case 2: rectangle.X += 20; @@ -974,97 +951,89 @@ public override void draw(SpriteBatch b) rectangle.X += 10; break; } - b.Draw(Game1.mouseCursors, new Vector2((float)(this.xPositionOnScreen - 13 * Game1.pixelZoom), (float)(this.yPositionOnScreen + Game1.tileSize - Game1.pixelZoom * 11)), new Rectangle?(rectangle), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2(xPositionOnScreen - 13 * Game1.pixelZoom, yPositionOnScreen + Game1.tileSize - Game1.pixelZoom * 11), rectangle, Color.White, 0.0f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 1f); } - Game1.drawDialogueBox(this.ItemsToGrabMenu.xPositionOnScreen - IClickableMenu.borderWidth - IClickableMenu.spaceToClearSideBorder, this.ItemsToGrabMenu.yPositionOnScreen - IClickableMenu.borderWidth - IClickableMenu.spaceToClearTopBorder, this.ItemsToGrabMenu.width + IClickableMenu.borderWidth * 2 + IClickableMenu.spaceToClearSideBorder * 2, this.ItemsToGrabMenu.height + IClickableMenu.spaceToClearTopBorder + IClickableMenu.borderWidth * 2, false, true, message, false); - this.ItemsToGrabMenu.draw(b); + Game1.drawDialogueBox(ItemsToGrabMenu.xPositionOnScreen - borderWidth - spaceToClearSideBorder, ItemsToGrabMenu.yPositionOnScreen - borderWidth - spaceToClearTopBorder, ItemsToGrabMenu.width + borderWidth * 2 + spaceToClearSideBorder * 2, ItemsToGrabMenu.height + spaceToClearTopBorder + borderWidth * 2, false, true, _message); + ItemsToGrabMenu.draw(b); } - else if (this.message != null) + else if (_message != null) { - Game1.drawDialogueBox(Game1.viewport.Width / 2, this.ItemsToGrabMenu.yPositionOnScreen + this.ItemsToGrabMenu.height / 2, false, false, this.message); + Game1.drawDialogueBox(Game1.viewport.Width / 2, ItemsToGrabMenu.yPositionOnScreen + ItemsToGrabMenu.height / 2, false, false, _message); } - if (this.poof != null) - { - this.poof.draw(b, true, 0, 0); - } + _poof?.draw(b, true); - if (this.shippingBin && Game1.getFarm().lastItemShipped != null) + if (ShippingBin && Game1.getFarm().lastItemShipped != null) { - this.lastShippedHolder.draw(b); - Game1.getFarm().lastItemShipped.drawInMenu(b, new Vector2((float)(this.lastShippedHolder.bounds.X + Game1.pixelZoom * 4), (float)(this.lastShippedHolder.bounds.Y + Game1.pixelZoom * 4)), 1f); - b.Draw(Game1.mouseCursors, new Vector2((float)(this.lastShippedHolder.bounds.X + Game1.pixelZoom * -2), (float)(this.lastShippedHolder.bounds.Bottom - Game1.pixelZoom * 25)), new Rectangle?(new Rectangle(325, 448, 5, 14)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); - b.Draw(Game1.mouseCursors, new Vector2((float)(this.lastShippedHolder.bounds.X + Game1.pixelZoom * 21), (float)(this.lastShippedHolder.bounds.Bottom - Game1.pixelZoom * 25)), new Rectangle?(new Rectangle(325, 448, 5, 14)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); - b.Draw(Game1.mouseCursors, new Vector2((float)(this.lastShippedHolder.bounds.X + Game1.pixelZoom * -2), (float)(this.lastShippedHolder.bounds.Bottom - Game1.pixelZoom * 11)), new Rectangle?(new Rectangle(325, 452, 5, 13)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); - b.Draw(Game1.mouseCursors, new Vector2((float)(this.lastShippedHolder.bounds.X + Game1.pixelZoom * 21), (float)(this.lastShippedHolder.bounds.Bottom - Game1.pixelZoom * 11)), new Rectangle?(new Rectangle(325, 452, 5, 13)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, 1f); + LastShippedHolder.draw(b); + Game1.getFarm().lastItemShipped.drawInMenu(b, new Vector2(LastShippedHolder.bounds.X + Game1.pixelZoom * 4, LastShippedHolder.bounds.Y + Game1.pixelZoom * 4), 1f); + b.Draw(Game1.mouseCursors, new Vector2(LastShippedHolder.bounds.X + Game1.pixelZoom * -2, LastShippedHolder.bounds.Bottom - Game1.pixelZoom * 25), new Rectangle(325, 448, 5, 14), Color.White, 0.0f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2(LastShippedHolder.bounds.X + Game1.pixelZoom * 21, LastShippedHolder.bounds.Bottom - Game1.pixelZoom * 25), new Rectangle(325, 448, 5, 14), Color.White, 0.0f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2(LastShippedHolder.bounds.X + Game1.pixelZoom * -2, LastShippedHolder.bounds.Bottom - Game1.pixelZoom * 11), new Rectangle(325, 452, 5, 13), Color.White, 0.0f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 1f); + b.Draw(Game1.mouseCursors, new Vector2(LastShippedHolder.bounds.X + Game1.pixelZoom * 21, LastShippedHolder.bounds.Bottom - Game1.pixelZoom * 11), new Rectangle(325, 452, 5, 13), Color.White, 0.0f, Vector2.Zero, Game1.pixelZoom, SpriteEffects.None, 1f); } - if (this.organizeButton != null) - { - this.organizeButton.draw(b); - } + OrganizeButton?.draw(b); + + if (_showPrevButton) { _previousPageButton.draw(b); } + if (_showNextButton) { _nextPageButton.draw(b); } - if (this.showPrevButton) { this.previousPageButton.draw(b); } - if (this.showNextButton) { this.nextPageButton.draw(b); } - - if (this.hoverText != null && (this.hoveredItem == null || this.hoveredItem == null || this.ItemsToGrabMenu == null)) - IClickableMenu.drawHoverText(b, this.hoverText, Game1.smallFont, 0, 0, -1, (string)null, -1, (string[])null, (Item)null, 0, -1, -1, -1, -1, 1f, (CraftingRecipe)null); - if (this.hoveredItem != null) - IClickableMenu.drawToolTip(b, this.hoveredItem.getDescription(), this.hoveredItem.Name, this.hoveredItem, this.heldItem != null, -1, 0, -1, -1, (CraftingRecipe)null, -1); - else if (this.hoveredItem != null && this.ItemsToGrabMenu != null) - IClickableMenu.drawToolTip(b, this.ItemsToGrabMenu.descriptionText, this.ItemsToGrabMenu.descriptionTitle, this.hoveredItem, this.heldItem != null, -1, 0, -1, -1, (CraftingRecipe)null, -1); - if (this.heldItem != null) - this.heldItem.drawInMenu(b, new Vector2((float)(Game1.getOldMouseX() + 8), (float)(Game1.getOldMouseY() + 8)), 1f); + if (hoverText != null && (hoveredItem == null || ItemsToGrabMenu == null)) + drawHoverText(b, hoverText, Game1.smallFont); + if (hoveredItem != null) + drawToolTip(b, hoveredItem.getDescription(), hoveredItem.Name, hoveredItem, heldItem != null); + else if (hoveredItem != null && ItemsToGrabMenu != null) + drawToolTip(b, ItemsToGrabMenu.descriptionText, ItemsToGrabMenu.descriptionTitle, hoveredItem, heldItem != null); + heldItem?.drawInMenu(b, new Vector2(Game1.getOldMouseX() + 8, Game1.getOldMouseY() + 8), 1f); Game1.mouseCursorTransparency = 1f; //IClickableMenu.drawTextureBox(b, Game1.menuTexture, new Rectangle(0, 256, 60, 60), 200, 20, 880, 76,new Color(125f,125f,125f) , 1f, true); - this.drawBorderLabel(b, message, Game1.smallFont, this.xPositionOnScreen, 0); + drawBorderLabel(b, ExtendedFridgeMod.ShowMessage()/*message*/, Game1.smallFont, xPositionOnScreen, 0); - this.drawMouse(b); + drawMouse(b); } //NOMOD - public void setSourceItem(Item item) + public void SetSourceItem(Item item) { - this.sourceItem = item; - this.chestColorPicker = null; - this.colorPickerToggleButton = null; - if (this.source == 1 && this.sourceItem != null && this.sourceItem is Chest) + _sourceItem = item; + ChestColorPicker = null; + ColorPickerToggleButton = null; + if (Source == 1 && _sourceItem is Chest) { - this.chestColorPicker = new DiscreteColorPicker(this.xPositionOnScreen, this.yPositionOnScreen - Game1.tileSize - IClickableMenu.borderWidth * 2, 0, new Chest(true)) + if (ChestColorPicker != null) { - colorSelection = this.chestColorPicker.getSelectionFromColor((this.sourceItem as Chest).playerChoiceColor) - }; - (this.chestColorPicker.itemToDrawColored as Chest).playerChoiceColor = this.chestColorPicker.getColorFromSelection(this.chestColorPicker.colorSelection); - ClickableTextureComponent clickableTextureComponent = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(this.xPositionOnScreen + this.width, this.yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 5, 16 * Game1.pixelZoom, 16 * Game1.pixelZoom), Game1.mouseCursors, new Microsoft.Xna.Framework.Rectangle(119, 469, 16, 16), (float)Game1.pixelZoom, false) + ChestColorPicker = new DiscreteColorPicker(xPositionOnScreen, + yPositionOnScreen - Game1.tileSize - borderWidth * 2, 0, new Chest(true)) + { + colorSelection = + ChestColorPicker.getSelectionFromColor(((Chest) _sourceItem).playerChoiceColor.Value) + }; + ((Chest) ChestColorPicker.itemToDrawColored).playerChoiceColor.Value = + ChestColorPicker.getColorFromSelection(ChestColorPicker.colorSelection); + } + var clickableTextureComponent = new ClickableTextureComponent(new Rectangle(xPositionOnScreen + width, yPositionOnScreen + Game1.tileSize + Game1.pixelZoom * 5, 16 * Game1.pixelZoom, 16 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(119, 469, 16, 16), Game1.pixelZoom) { hoverText = Game1.content.LoadString("Strings\\UI:Toggle_ColorPicker", new object[0]) }; - this.colorPickerToggleButton = clickableTextureComponent; + ColorPickerToggleButton = clickableTextureComponent; } } //NOMOD - public override void snapToDefaultClickableComponent() + public sealed override void snapToDefaultClickableComponent() { - if (!this.shippingBin) - { - this.currentlySnappedComponent = base.getComponentWithID((this.ItemsToGrabMenu.inventory.Count > 0 ? 53910 : 0)); - } - else - { - this.currentlySnappedComponent = base.getComponentWithID(0); - } - this.snapCursorToCurrentSnappedComponent(); + currentlySnappedComponent = !ShippingBin ? getComponentWithID((ItemsToGrabMenu.inventory.Count > 0 ? 53910 : 0)) : getComponentWithID(0); + snapCursorToCurrentSnappedComponent(); } //NOMOD public override void receiveGamePadButton(Buttons b) { base.receiveGamePadButton(b); - if (b == Buttons.Back && this.organizeButton != null) + if (b == Buttons.Back && OrganizeButton != null) { - FridgeGrabMenu.organizeItemsInList(Game1.player.items); + OrganizeItemsInList(Game1.player.Items); Game1.playSound("Ship"); } } diff --git a/ExtendedFridge/M007_ExtendedFridge.cs b/ExtendedFridge/M007_ExtendedFridge.cs deleted file mode 100644 index 60a00d8..0000000 --- a/ExtendedFridge/M007_ExtendedFridge.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using StardewModdingAPI; -using StardewModdingAPI.Events; -using StardewValley; -using StardewValley.Locations; -using StardewValley.Menus; - -namespace ExtendedFridge -{ - public class M007_ExtendedFridge_Mod : Mod - { - private static FridgeChest _fridge; - private static FridgeModConfig config; - internal static ISemanticVersion Version; - private static bool IsInFridgeMenu = false; - private static readonly int FRIDGE_TILE_ID = 173; - - public override void Entry(IModHelper helper) - { - var modPath = Helper.DirectoryPath; - config = Helper.ReadConfig(); - Version = this.ModManifest.Version; - - MenuEvents.MenuChanged += Event_MenuChanged; - - //LocationEvents.CurrentLocationChanged += Event_LocationChanged; - StardewModdingAPI.Events.ControlEvents.KeyReleased += Event_KeyReleased; - this.Monitor.Log("ExtendedFridge Entry"); - } - - public void CheckForAction(bool isBack = false) - { - int a = 5; - } - - private void Event_KeyReleased(object send, EventArgsKeyPressed e) - { - if (e.KeyPressed.ToString().Equals(config.fridgeNextPageKey) && Game1.activeClickableMenu is FridgeGrabMenu) - { - _fridge.MovePageToNext(); - } - - if (e.KeyPressed.ToString().Equals(config.fridgePrevPageKey) && Game1.activeClickableMenu is FridgeGrabMenu) - { - _fridge.MovePageToPrevious(); - } - } - - private void Event_LocationChanged(object send, EventArgsCurrentLocationChanged e) - { - var priorlocation = e.PriorLocation; - if (e.NewLocation is FarmHouse) - { - FarmHouse ptrFH = (FarmHouse)Game1.currentLocation; - } - } - - private void Event_MenuChanged(object send, EventArgsClickableMenuChanged e) - { - Microsoft.Xna.Framework.Vector2 lastGrabbedTile = Game1.player.lastGrabTile; - //Log.Debug("M007_ExtendedFridge Event_MenuChanged HIT", new object[0]); - - if (Game1.currentLocation is FarmHouse) - { - this.Monitor.Log(String.Format("M007_ExtendedFridge lastGrabTileX:{0} lastGrabTileY:{1}", (int)Game1.player.lastGrabTile.X, (int)Game1.player.lastGrabTile.Y)); - } - - if (ClickedOnFridge()) - { - - IsInFridgeMenu = true; - if (e.NewMenu is ItemGrabMenu) - { - ItemGrabMenu ptrMenu = (ItemGrabMenu)e.NewMenu; - - if (_fridge == null) - { - _fridge = new FridgeChest(config.autoSwitchPageOnGrab); - StardewValley.Locations.FarmHouse h = (StardewValley.Locations.FarmHouse)Game1.currentLocation; - _fridge.items.AddRange(h.fridge.items); - } - _fridge.ShowCurrentPage(); - this.Monitor.Log("M007_ExtendedFridge Fridge HOOKED"); - } - - } - } - - void runConfig() - { - var myconfig = Helper.ReadConfig(); - } - - public void grabItemFromChest(Item item, StardewValley.Farmer who) - { - _fridge.grabItemFromChest(item, who); - } - - public void grabItemFromInventory(Item item, StardewValley.Farmer who) - { - _fridge.grabItemFromInventory(item, who); - } - - private bool ClickedOnFridge() - { - if (Game1.currentLocation is FarmHouse) - { - FarmHouse ptrFarmhouse = (FarmHouse)Game1.currentLocation; - xTile.Dimensions.Location tileLocation = new xTile.Dimensions.Location((int)Game1.player.lastGrabTile.X, (int)Game1.player.lastGrabTile.Y); - - if (ptrFarmhouse.map.GetLayer("Buildings").Tiles[tileLocation] != null) - { - int currTileIdx = ptrFarmhouse.map.GetLayer("Buildings").Tiles[tileLocation].TileIndex; - - return currTileIdx == FRIDGE_TILE_ID; - } - } - - return false; - } - } -} \ No newline at end of file diff --git a/ExtendedFridge/PlayerData.cs b/ExtendedFridge/PlayerData.cs new file mode 100644 index 0000000..3def8a4 --- /dev/null +++ b/ExtendedFridge/PlayerData.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using SObject = StardewValley.Object; + +namespace ExtendedFridge +{ + public class PlayerData + { + public IList PItems { get; set; } = new List(); + //public Tuple pItems { get; set; } + } +} diff --git a/ExtendedFridge/manifest.json b/ExtendedFridge/manifest.json index 6d7b56e..077b344 100644 --- a/ExtendedFridge/manifest.json +++ b/ExtendedFridge/manifest.json @@ -4,8 +4,8 @@ "Version": { "MajorVersion": 1, "MinorVersion": 1, - "PatchVersion": 0, - "Build": null + "PatchVersion": 1, + "Build": "-unofficial.4.mizzion" }, "Description": "Lets you add more items to the fridge.", "UniqueID": "Crystalmir.ExtendedFridge", diff --git a/ExtendedFridge/packages.config b/ExtendedFridge/packages.config index 010d980..d798813 100644 --- a/ExtendedFridge/packages.config +++ b/ExtendedFridge/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file