public override bool doAction(Vector2 tileLocation, Farmer who) { if ((int)daysOfConstructionLeft <= 0 && tileLocation.X >= (float)(int)tileX && tileLocation.X <= (float)((int)tileX + 1) && tileLocation.Y == (float)(int)tileY) { if (!Game1.didPlayerJustRightClick(ignoreNonMouseHeldInput: true)) { return(false); } ItemGrabMenu itemGrabMenu = new ItemGrabMenu(null, reverseGrab: true, showReceivingMenu: false, Utility.highlightShippableObjects, shipItem, "", null, snapToBottom: true, canBeExitedWithKey: true, playRightClickSound: false, allowRightClick: true, showOrganizeButton: false, 0, null, -1, this); itemGrabMenu.initializeUpperRightCloseButton(); itemGrabMenu.setBackgroundTransparency(b: false); itemGrabMenu.setDestroyItemOnClick(b: true); itemGrabMenu.initializeShippingBin(); Game1.activeClickableMenu = itemGrabMenu; if (who.IsLocalPlayer) { Game1.playSound("shwip"); } if (Game1.player.FacingDirection == 1) { Game1.player.Halt(); } Game1.player.showCarrying(); return(true); } return(base.doAction(tileLocation, who)); }
internal void HandleClick(ButtonPressedEventArgs e) { ItemGrabMenu menu = null; var oldUiMode = Game1.uiMode; Game1.uiMode = true; var cursorPos = e.Cursor.GetScaledScreenPixels(); Game1.uiMode = oldUiMode; if (modEntry.GetValidButtonSmashMenu() is ItemGrabMenu) { menu = modEntry.GetValidButtonSmashMenu() as ItemGrabMenu; } if (menu == null) { return; } if (buttonColor.containsPoint((int)cursorPos.X, (int)cursorPos.Y)) { Game1.playSound("clubhit"); DoSmash(menu, ModEntry.SmashType.Color); } if (buttonQuality.containsPoint((int)cursorPos.X, (int)cursorPos.Y)) { Game1.playSound("clubhit"); DoSmash(menu, ModEntry.SmashType.Quality); } }
/// <summary>The method invoked when the active menu changes.</summary> /// <param name="previousMenu">The previous menu (if any)</param> /// <param name="newMenu">The new menu (if any).</param> private void ReceiveMenuChanged(IClickableMenu previousMenu, IClickableMenu newMenu) { // remove overlay if (previousMenu is ItemGrabMenu) { this.ManageChestOverlay?.Dispose(); this.ManageChestOverlay = null; } // add overlay if (newMenu is ItemGrabMenu) { // get open chest ItemGrabMenu chestMenu = (ItemGrabMenu)newMenu; ManagedChest chest = ChestFactory.GetChestFromMenu(chestMenu); if (chest == null) { return; } // add overlay ManagedChest[] chests = ChestFactory.GetChestsForDisplay(selectedChest: chest.Chest).ToArray(); this.ManageChestOverlay = new ManageChestOverlay(chestMenu, chest, chests, this.Config); this.ManageChestOverlay.OnChestSelected += selected => { this.SelectedChest = selected.Chest; Game1.activeClickableMenu = selected.OpenMenu(); }; } }
internal void HandleClick(ButtonPressedEventArgs e) { ItemGrabMenu menu = null; var oldUiMode = Game1.uiMode; Game1.uiMode = true; var cursorPos = e.Cursor.GetScaledScreenPixels(); Game1.uiMode = oldUiMode; if (modEntry.GetValidButtonSmashMenu() is ItemGrabMenu) { menu = modEntry.GetValidButtonSmashMenu() as ItemGrabMenu; } if (menu == null) { return; } var buttonClicked = buttonHandler.GetButtonClicked((int)cursorPos.X, (int)cursorPos.Y); if (buttonClicked == ModEntry.SmashType.None) { return; } Game1.playSound("clubhit"); DoSmash(menu, buttonClicked); }
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"); } } }
//PhthaloBlue: these blocks of codes below are from Chest Pooling mod by mralbobo //repo link here: https://github.com/mralbobo/stardew-chest-pooling, they are useful so I use them static Chest getOpenChest() { if (Game1.activeClickableMenu == null) { return(null); } ItemGrabMenu itemGrabMenu = Game1.activeClickableMenu as ItemGrabMenu; if (itemGrabMenu != null) { if (itemGrabMenu.behaviorOnItemGrab != null && itemGrabMenu.behaviorOnItemGrab.Target is Chest) { return(itemGrabMenu.behaviorOnItemGrab.Target as Chest); } } else { if (Game1.activeClickableMenu.GetType().Name == "ACAMenu") { dynamic thing = (dynamic)Game1.activeClickableMenu; if (thing != null && thing.chestItems != null) { Chest aChest = new Chest(true); aChest.items = thing.chestItems; return(aChest); } } } return(null); }
private static void CookingMenu_DrawActualInventory_Postfix(ItemGrabMenu __instance, SpriteBatch b) { if (!Config.EnableMod) { return; } if (currentCookables == null) { UpdateCurrentCookables(); } int xStart = Game1.activeClickableMenu.xPositionOnScreen + IClickableMenu.spaceToClearSideBorder + IClickableMenu.borderWidth; int yStart = Game1.activeClickableMenu.yPositionOnScreen + IClickableMenu.borderWidth + IClickableMenu.spaceToClearTopBorder + Config.YOffset; string whichFridge = fridgeIndex >= 0 ? string.Format(SHelper.Translation.Get("fridge-x"), fridgeIndex + 1) : SHelper.Translation.Get("player"); Utility.drawTextWithShadow(Game1.spriteBatch, whichFridge, Game1.smallFont, new Vector2(xStart + 88, yStart - 20), Color.Black, 1f, -1f, -1, -1, 1f, 3); AccessTools.Method(typeof(IClickableMenu), "drawHorizontalPartition").Invoke(Game1.activeClickableMenu, new object[] { Game1.spriteBatch, yStart, false, -1, -1, -1 }); Utility.drawTextWithShadow(Game1.spriteBatch, SHelper.Translation.Get("ingredients") + (Config.ShowProductInfo && currentCookables.Count > 0 ? " " + string.Format(currentCookables.Count == 1 ? SHelper.Translation.Get("will-cook-1") : SHelper.Translation.Get("will-cook-x"), currentCookables.Count) : ""), Game1.smallFont, new Vector2(xStart, yStart + 46), Color.Black, 1f, -1f, -1, -1, 1f, 3); ingredientMenu.draw(Game1.spriteBatch); cookButton.draw(Game1.spriteBatch); fridgeLeftButton.draw(Game1.spriteBatch); fridgeRightButton.draw(Game1.spriteBatch); if (Config.ShowCookTooltip && cookButton.containsPoint(Game1.getMouseX(), Game1.getMouseY())) { DrawCookButtonTooltip(); } }
public static void TryCloseItemGrabMenu(ItemGrabMenu menu) { if (!menu.areAllItemsTaken() || menu.heldItem != null) { return; } if (menu.shippingBin || ShippingEstimationInfoBox.IsCaShippingBinMenu(menu)) { //It's a shipping bin. return; } if (menu.context is Event && GetEssential(menu)) { // You should not emergency close in events (it may stop the dialogue). return; } switch (menu.source) { case ItemGrabMenu.source_chest: case ItemGrabMenu.source_none when menu.context == null: return; // It's a chest. } menu.exitThisMenu(); }
/// <summary> /// Postfix method. Occurs after the original method of Farm.checkAction is executed. /// /// Reimplements operations pertaining to user clicking on the starting shipping bin, /// allowing for the shipping bin to be relocated. /// </summary> /// <param name="__instance">The instance of the Farm class</param> /// <param name="__result">The results from the original checkAction method.</param> /// <param name="tileLocation">From original method. The tile location that was clicked.</param> /// <param name="viewport">From original method. The user's viewport.</param> /// <param name="who">From original method. The farmer (player) who clicked</param> public static void Postfix(Farm __instance, ref bool __result, Location tileLocation, Rectangle viewport, Farmer who) { if (currentFarm != __instance) { currentFarm = __instance; } int binX = (customManager.Canon) ? 71 : customManager.ShippingBinPoints.X; int binY = (customManager.Canon) ? 13 : customManager.ShippingBinPoints.Y; if (tileLocation.X >= binX && tileLocation.X <= binX + 1 && tileLocation.Y >= binY && tileLocation.Y <= binY + 1) { ItemGrabMenu itemGrabMenu = new ItemGrabMenu(null, true, false, new InventoryMenu.highlightThisItem(Utility.highlightShippableObjects), new ItemGrabMenu.behaviorOnItemSelect(shipItem), "", null, true, true, false, true, false, 0, null, -1, null); itemGrabMenu.initializeUpperRightCloseButton(); itemGrabMenu.setBackgroundTransparency(false); itemGrabMenu.setDestroyItemOnClick(true); itemGrabMenu.initializeShippingBin(); Game1.activeClickableMenu = itemGrabMenu; __instance.playSound("shwip"); if (Game1.player.FacingDirection == 1) { Game1.player.Halt(); } Game1.player.showCarrying(); __result = true; } return; }
public static void Postfix(Farm __instance, ref bool __result, Location tileLocation, Rectangle viewport, Farmer who) { if (__instance is FarmExtension) { return; } int binX = (Memory.isCustomFarmLoaded) ? Memory.loadedFarm.shippingBin.pointOfInteraction.x : 71; int binY = (Memory.isCustomFarmLoaded) ? Memory.loadedFarm.shippingBin.pointOfInteraction.y : 13; if (tileLocation.X >= binX && tileLocation.X <= binX + 1 && tileLocation.Y >= binY && tileLocation.Y <= binY + 1) { currentFarm = __instance; ItemGrabMenu itemGrabMenu = new ItemGrabMenu(null, true, false, new InventoryMenu.highlightThisItem(Utility.highlightShippableObjects), new ItemGrabMenu.behaviorOnItemSelect(shipItem), "", null, true, true, false, true, false, 0, null, -1, null); itemGrabMenu.initializeUpperRightCloseButton(); itemGrabMenu.setBackgroundTransparency(false); itemGrabMenu.setDestroyItemOnClick(true); itemGrabMenu.initializeShippingBin(); Game1.activeClickableMenu = itemGrabMenu; __instance.playSound("shwip"); if (Game1.player.FacingDirection == 1) { Game1.player.Halt(); } Game1.player.showCarrying(); __result = true; } }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="menu">The underlying chest menu.</param> /// <param name="chest">The selected chest.</param> /// <param name="chests">The available chests.</param> /// <param name="config">The mod configuration.</param> public ManageChestOverlay(ItemGrabMenu menu, ManagedChest chest, ManagedChest[] chests, ModConfig config) : base(keepAlive: () => Game1.activeClickableMenu is ItemGrabMenu) { // menu this.Menu = menu; #if SDV_1_2 this.MenuInventoryMenu = ((ItemGrabMenu)Game1.activeClickableMenu).ItemsToGrabMenu; #else this.MenuInventoryMenu = (InventoryMenu)typeof(ItemGrabMenu).GetField("ItemsToGrabMenu", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(menu); if (this.MenuInventoryMenu == null) { throw new InvalidOperationException("The menu doesn't seem to have a player inventory."); } #endif this.DefaultChestHighlighter = menu.inventory.highlightMethod; this.DefaultInventoryHighlighter = this.MenuInventoryMenu.highlightMethod; // chests & config this.Chest = chest; this.Chests = chests; this.Groups = chests.Select(p => p.GetGroup()).Distinct().OrderBy(p => p).ToArray(); this.Config = config; // components this.ReinitialiseComponents(); }
public virtual void OnCollectReward(Item item, Farmer farmer) { if (!(Game1.activeClickableMenu is ItemGrabMenu) || (Game1.activeClickableMenu as ItemGrabMenu).context != this) { return; } ItemGrabMenu grab_menu = Game1.activeClickableMenu as ItemGrabMenu; if (Game1.player.addItemToInventoryBool(grab_menu.heldItem)) { uncollectedRewards.Remove(item); grab_menu.ItemsToGrabMenu.actualInventory = new List <Item>(uncollectedRewards); grab_menu.heldItem = null; if ((int)item.parentSheetIndex != 73) { Game1.playSound("coin"); } } else { Game1.playSound("cancel"); Game1.showRedMessage(Game1.content.LoadString("Strings\\StringsFromCSFiles:Crop.cs.588")); grab_menu.ItemsToGrabMenu.actualInventory = new List <Item>(uncollectedRewards); grab_menu.heldItem = null; } }
/********* ** Public methods *********/ /// <summary>Construct an instance.</summary> /// <param name="menu">The underlying chest menu.</param> /// <param name="chest">The selected chest.</param> /// <param name="chests">The available chests.</param> /// <param name="config">The mod configuration.</param> /// <param name="keys">The configured key bindings.</param> /// <param name="events">The SMAPI events available for mods.</param> /// <param name="input">An API for checking and changing input state.</param> /// <param name="translations">Provides translations stored in the mod's folder.</param> /// <param name="showAutomateOptions">Whether to show Automate options.</param> public ChestOverlay(ItemGrabMenu menu, ManagedChest chest, ManagedChest[] chests, ModConfig config, ModConfigKeys keys, IModEvents events, IInputHelper input, ITranslationHelper translations, bool showAutomateOptions) : base(menu, chest, chests, config, keys, events, input, translations, showAutomateOptions, keepAlive: () => Game1.activeClickableMenu is ItemGrabMenu, topOffset: -Game1.pixelZoom * 9) { this.Menu = menu; this.MenuInventoryMenu = menu.ItemsToGrabMenu; this.DefaultChestHighlighter = menu.inventory.highlightMethod; this.DefaultInventoryHighlighter = this.MenuInventoryMenu.highlightMethod; }
public override bool checkForAction(Farmer who, bool justCheckingForActivity = false) { if (justCheckingForActivity) { return(true); } if ((bool)giftbox) { Game1.player.Halt(); Game1.player.freezePause = 1000; who.currentLocation.playSound("Ship"); dumpContents(who.currentLocation); } else if ((bool)playerChest) { mutex.RequestLock(delegate { frameCounter.Value = 5; Game1.playSound(fridge ? "doorCreak" : "openChest"); Game1.player.Halt(); Game1.player.freezePause = 1000; }); } else if (!playerChest) { if (currentLidFrame == 501 && (int)frameCounter <= -1) { frameCounter.Value = 5; who.currentLocation.playSound("openChest"); } else if (currentLidFrame == 503 && items.Count > 0) { Item item = items[0]; items[0] = null; items.RemoveAt(0); if (Game1.mine != null) { Game1.mine.chestConsumed(); } who.addItemByMenuIfNecessaryElseHoldUp(item); ItemGrabMenu grab_menu; if ((grab_menu = (Game1.activeClickableMenu as ItemGrabMenu)) != null) { ItemGrabMenu itemGrabMenu = grab_menu; itemGrabMenu.behaviorBeforeCleanup = (Action <IClickableMenu>)Delegate.Combine(itemGrabMenu.behaviorBeforeCleanup, (Action <IClickableMenu>) delegate { grab_menu.DropRemainingItems(); }); } } } if (items.Count == 0 && (int)coins == 0 && !playerChest) { who.currentLocation.removeObject(tileLocation, showDestroyedObject: false); who.currentLocation.playSound("woodWhack"); } return(true); }
private static void GameLoop_UpdateTicking(object sender, UpdateTickingEventArgs e) { if (Context.IsWorldReady) { PreviousInventoryCursorSlotItem = Game1.player.CursorSlotItem; // Geode menu if (Game1.activeClickableMenu is GeodeMenu GM) { PreviousGeodeMenuCursorSlotItem = GM.heldItem; } else { PreviousGeodeMenuCursorSlotItem = null; } // Fishing Treasure menu if (IsFishingTreasureChestMenu(Game1.activeClickableMenu, out Item FishingChestHeldItem)) { PreviousFishingChestCursorSlotItem = FishingChestHeldItem; } else { PreviousFishingChestCursorSlotItem = null; } try { // Chest menu if (ItemBagsMod.UserConfig.AllowAutofillInsideChest && IsChestMenu(Game1.activeClickableMenu, out Item ChestHeldItem)) { ItemGrabMenu IGM = Game1.activeClickableMenu as ItemGrabMenu; Chest Chest = IGM.context as Chest; // Compare previous chest items to current chest items to see if any items were just added to chest List <Item> CurrentChestMenuContents = Chest.items.Where(x => x != null).ToList(); if (PreviousChestMenuContents != null) { List <Item> AddedItems = CurrentChestMenuContents.Where(x => !PreviousChestMenuContents.Contains(x)).ToList(); if (AddedItems.Any()) { OnItemsAddedToChest(IGM, Chest, AddedItems); } } PreviousChestMenuContents = CurrentChestMenuContents; } } catch (Exception ex) { PreviousChestMenuContents = null; ItemBagsMod.ModInstance.Monitor.Log(string.Format("Error while attempting to autofill bags inside of the active chest: {0}\n\n{1}", ex.Message, ex.ToString()), LogLevel.Error); } } }
/// Sets the selected tab and updates the inventory menu. private void SetSelectedTab(int tab) { if (tab >= 0 && tab < _fridges.Count && tab != _selectedTab) { if (tab == 0) { // release mutex if mini fridge selected if (_selectedTab > 0 && _selectedTab < _fridges.Count) { _fridges[_selectedTab].mutex.ReleaseLock(); } _selectedTab = tab; if (tab > 0) { _menu = Utilities.GetNewItemGrabMenuFromChest(_fridges[tab], true); } else { _menu = Utilities.GetNewItemGrabMenuFromChest(_fridges[tab], false); } Game1.activeClickableMenu = _menu; Game1.playSound("smallSelect"); } else { // request mini fridge to be opened _fridges[tab].mutex.RequestLock(() => { // release mutex if mini fridge selected if (_selectedTab > 0 && _selectedTab < _fridges.Count) { _fridges[_selectedTab].mutex.ReleaseLock(); } _selectedTab = tab; if (tab > 0) { _menu = Utilities.GetNewItemGrabMenuFromChest(_fridges[tab], true); } else { _menu = Utilities.GetNewItemGrabMenuFromChest(_fridges[tab], false); } Game1.activeClickableMenu = _menu; Game1.playSound("smallSelect"); }, () => { Game1.playSound("cancel"); }); } } }
public static void LootAllAcceptableItems(ItemGrabMenu menu, bool skipCheck = false) { if (!skipCheck) { if (menu.shippingBin || ShippingEstimationInfoBox.IsCaShippingBinMenu(menu)) { Logger.Log("Don't do anything with shipping bin"); return; } if (menu.reverseGrab) { Logger.Log("You can't get item from this menu."); return; } if (menu.source == ItemGrabMenu.source_chest) { Logger.Log("Don't do anything with chest player placed"); return; } if (menu.showReceivingMenu && menu.source == ItemGrabMenu.source_none) { Logger.Log("showReceivingMenu true but is not gift or fishing chest."); return; } } for (int i = menu.ItemsToGrabMenu.actualInventory.Count - 1; i >= 0; i--) { if (i >= menu.ItemsToGrabMenu.actualInventory.Count) { continue; } Item item = menu.ItemsToGrabMenu.actualInventory[i]; int oldStack = item.Stack; int remain = Util.AddItemIntoInventory(item); int taken = oldStack - remain; if (taken > 0) { Logger.Log($"You looted {item.DisplayName}{(taken == 1 ? "" : " x" + taken)}."); } if (remain == 0) { menu.ItemsToGrabMenu.actualInventory.Remove(item); continue; } menu.ItemsToGrabMenu.actualInventory[i].Stack = remain; } }
/// <summary>Open a menu to transfer items between the player's inventory and this chest.</summary> /// <remarks>Derived from <see cref="StardewValley.Objects.Chest.updateWhenCurrentLocation"/>.</remarks> public IClickableMenu OpenMenu() { switch (this.Mode) { case ShippingBinMode.Normal: return(new ItemGrabMenu( inventory: this.Inventory, reverseGrab: false, showReceivingMenu: true, highlightFunction: this.CanAcceptItem, behaviorOnItemSelectFunction: this.GrabItemFromInventory, message: null, behaviorOnItemGrab: this.GrabItemFromContainer, canBeExitedWithKey: true, showOrganizeButton: true, context: this.Farm )); case ShippingBinMode.MobileStore: { var menu = new ItemGrabMenu( inventory: this.Inventory, reverseGrab: false, showReceivingMenu: true, highlightFunction: this.CanAcceptItem, behaviorOnItemSelectFunction: null, message: null, behaviorOnItemGrab: this.GrabItemFromContainer, canBeExitedWithKey: true, showOrganizeButton: true, context: this.Farm ); menu.initializeShippingBin(); return(menu); } case ShippingBinMode.MobileTake: return(new ItemGrabMenu( inventory: this.Inventory, reverseGrab: false, showReceivingMenu: true, highlightFunction: this.CanAcceptItem, behaviorOnItemSelectFunction: null, message: null, behaviorOnItemGrab: this.GrabItemFromContainer, canBeExitedWithKey: true, showOrganizeButton: true, context: this.Farm )); default: throw new NotSupportedException($"Unknown shipping bin mode '{this.Mode}'."); } }
private void CreateMenu(ItemGrabMenu itemGrabMenu) { var chest = itemGrabMenu.behaviorOnItemGrab?.Target as Chest; if (chest != null) { WidgetHost = new WidgetHost(); var overlay = new ChestOverlay(itemGrabMenu, chest, Config, ChestDataManager, ChestFiller, ItemDataManager, WidgetHost.TooltipManager); WidgetHost.RootWidget.AddChild(overlay); } }
private void CreateMenu(ItemGrabMenu itemGrabMenu) { if (!(itemGrabMenu.behaviorOnItemGrab?.Target is Chest chest)) { return; } WidgetHost = new WidgetHost(); var overlay = new ChestOverlay(this, chest, itemGrabMenu, WidgetHost.TooltipManager); WidgetHost.RootWidget.AddChild(overlay); }
private void CreateMenu(ItemGrabMenu itemGrabMenu) { if (!(itemGrabMenu.context is Chest chest)) { return; } WidgetHost = new WidgetHost(Events, ModEntry.Helper.Input); var overlay = new ChestOverlay(this, chest, itemGrabMenu, WidgetHost.TooltipManager); WidgetHost.RootWidget.AddChild(overlay); }
public ChestOverlay(CategorizeChestsModule module, Chest chest, ItemGrabMenu menu, ITooltipManager tooltipManager) { Module = module; Chest = chest; ItemGrabMenu = menu; _inventoryMenu = menu.ItemsToGrabMenu; TooltipManager = tooltipManager; _defaultChestHighlighter = ItemGrabMenu.inventory.highlightMethod; _defaultInventoryHighlighter = _inventoryMenu.highlightMethod; AddButtons(); }
private ItemGrabMenu ShippingBin() { ItemGrabMenu itemGrabMenu = new ItemGrabMenu(null, true, false, Utility.highlightShippableObjects, Game1.getFarm().shipItem, "", snapToBottom: true, canBeExitedWithKey: true, playRightClickSound: false, context: this); itemGrabMenu.initializeUpperRightCloseButton(); itemGrabMenu.setBackgroundTransparency(false); itemGrabMenu.setDestroyItemOnClick(true); itemGrabMenu.initializeShippingBin(); return(itemGrabMenu); }
/// <summary> /// Determine whether the menu should be closed or not on an error /// </summary> /// <param name="menu">the inventory to check</param> /// <param name="msg">Added to the error message</param> private void HandleItemGrabMenuError(ItemGrabMenu menu, string msg) { log.Info($"There was an error getting all menu items - {msg}"); if (config.pauseTreasureOnError) { log.Trace("Pausing collection until resolved."); } else { log.Info("Option pauseTreasureOnError is false, continuing with loss of treasure"); menu.exitThisMenu(true); } }
internal void PopulateIds(ItemGrabMenu menu) { if (menu.fillStacksButton != null) { buttonQuality.leftNeighborID = menu.fillStacksButton.myID; menu.fillStacksButton.rightNeighborID = 102907; } if (menu.colorPickerToggleButton != null) { menu.colorPickerToggleButton.rightNeighborID = 102906; buttonColor.leftNeighborID = menu.colorPickerToggleButton.myID; } }
/// <summary> /// Invokes the onAddItem delegate action of type (ItemGrabMenu.behaviorOnItemSelect) for an item that's been added to inventory. /// </summary> /// <param name="grabMenu">ItemGrabMenu instance where the method call originated</param> /// <param name="who">Farmer (Game1.player) who is using the menu</param> public static void OnAddItemCheck_Hook(ItemGrabMenu grabMenu, Farmer who) { try { if (grabMenu.inventory.onAddItem != null) { grabMenu.inventory.onAddItem(grabMenu.heldItem, who); Monitor.Log($"Ran patch for bug in game code: {nameof(OnAddItemCheck_Hook)}", LogLevel.Trace); } } catch (Exception ex) { Monitor.Log($"Failed in {nameof(OnAddItemCheck_Hook)}:\n{ex}", LogLevel.Error); } }
private static void OnItemsAddedToChest(ItemGrabMenu ChestMenu, Chest Chest, IList <Item> NewItemStacks) { if (ItemBagsMod.UserConfig.AllowAutofillInsideChest) { // Autofill the added items to any bags inside of the chest List <ItemBag> AutofillableBags = GetAutofillableBags(Chest.items, out HashSet <ItemBag> NestedBags); if (AutofillableBags.Any()) { foreach (Item NewItem in NewItemStacks) { TryAutofill(Chest.items, AutofillableBags, NestedBags, NewItem, out int AutofilledQuantity); } } } }
private static void ItemGrabMenu_Postfix(ItemGrabMenu __instance, InventoryMenu.highlightThisItem highlightFunction, object context) { if (!(context is Chest) || (context as Chest)?.ParentSheetIndex == null || !customChestTypesDict.ContainsKey((context as Chest).ParentSheetIndex)) { return; } CustomChestType cct = customChestTypesDict[(context as Chest).ParentSheetIndex]; SMonitor.Log($"Creating inventory menu for chest {cct.name}, rows: {cct.rows}, cap: {cct.capacity}, "); int containerWidth = 64 * (cct.capacity / cct.rows); __instance.ItemsToGrabMenu = new InventoryMenu(Game1.uiViewport.Width / 2 - containerWidth / 2, __instance.yPositionOnScreen + 64, false, __instance.ItemsToGrabMenu.actualInventory, highlightFunction, cct.capacity, cct.rows, 0, 0, true); __instance.ItemsToGrabMenu.populateClickableComponentList(); }
private static void ShipmentBin(string tileActionString, Vector2 position) { MethodInfo method = typeof(Farm).GetMethod("shipItem"); ItemGrabMenu itemGrabMenu = new ItemGrabMenu((List <Item>)null, true, false, new InventoryMenu.highlightThisItem(Utility.highlightShippableObjects), (ItemGrabMenu.behaviorOnItemSelect)Delegate.CreateDelegate(typeof(ItemGrabMenu.behaviorOnItemSelect), (object)Game1.getFarm(), method), "", (ItemGrabMenu.behaviorOnItemSelect)null, true, true, false, true, false, 0, (Item)null, -1, (object)null); itemGrabMenu.initializeUpperRightCloseButton(); int num1 = 0; itemGrabMenu.setBackgroundTransparency((uint)num1 > 0U); int num2 = 1; itemGrabMenu.setDestroyItemOnClick((uint)num2 > 0U); itemGrabMenu.initializeShippingBin(); Game1.activeClickableMenu = (IClickableMenu)itemGrabMenu; }
/// <summary>Get the player chest from the specified menu (if any).</summary> /// <param name="menu">The menu to check.</param> public static ManagedChest GetChestFromMenu(ItemGrabMenu menu) { // from menu target Chest target = menu.behaviorOnItemGrab?.Target as Chest; ManagedChest chest = target != null ? ChestFactory.GetChests().FirstOrDefault(p => p.Chest == target) : null; if (chest != null) { return(chest); } // fallback to open chest return(ChestFactory.GetChests().FirstOrDefault(p => p.Chest.currentLidFrame == 135)); }