private static void OnMenuChanged(object sender, EventArgsClickableMenuChanged args) { if (IsSaveGameMenu(args.NewMenu)) { BeforeSaving?.Invoke(); } }
public void onMenuChange(object sender, EventArgsClickableMenuChanged e) { try { // Save TeleChests before saving to prevent crash if (e.NewMenu is SaveGameMenu) { handleOpenSaveGameMenu(); } else if (e.NewMenu is GameMenu) { CraftingPage craftingPage = null; List <IClickableMenu> pages = ((List <IClickableMenu>) typeof(GameMenu).GetField("pages", BindingFlags.Instance | BindingFlags.NonPublic).GetValue((GameMenu)e.NewMenu)); foreach (IClickableMenu menu in pages) { if (menu is CraftingPage) { craftingPage = (CraftingPage)menu; } } if (craftingPage == null) { return; } handleOpenCraftingPage(craftingPage); } } catch (Exception ex) { Console.WriteLine(ex); } }
private void menuChanged(object sender, EventArgsClickableMenuChanged args) { var menu = args.NewMenu as ShopMenu; if (menu == null || menu.portraitPerson == null) { return; } if (menu.portraitPerson.name == "Pierre") { Log.trace("Adding crops to shop"); var forSale = Helper.Reflection.GetPrivateValue <List <Item> >(menu, "forSale"); var itemPriceAndStock = Helper.Reflection.GetPrivateValue <Dictionary <Item, int[]> >(menu, "itemPriceAndStock"); var precondMeth = Helper.Reflection.GetPrivateMethod(Game1.currentLocation, "checkEventPrecondition"); foreach (var crop in CropData.crops) { if (!crop.Value.Seasons.Contains(Game1.currentSeason)) { continue; } if (crop.Value.SeedPurchaseRequirements.Count > 0 && precondMeth.Invoke <int>(new object[] { crop.Value.GetSeedPurchaseRequirementString() }) == -1) { continue; } Item item = new StardewValley.Object(Vector2.Zero, crop.Value.GetSeedId(), int.MaxValue); forSale.Add(item); itemPriceAndStock.Add(item, new int[] { crop.Value.SeedPurchasePrice, int.MaxValue }); } } }
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"); } } }
private void OnMenuChanged(object s, EventArgsClickableMenuChanged e) { if (e.NewMenu?.GetType().FullName != "CJBItemSpawner.ItemMenu") { return; } Log.Trace("Overriding CJB Item Spawner menu items..."); CurrentMenu = e.NewMenu; var itemListField = _itemListField ?? (_itemListField = CurrentMenu.GetType().GetInstanceField("itemList")); var itemList = CurrentMenu.GetFieldValue <List <Item> >(itemListField); for (var i = 0; i < itemList.Count; ++i) { var item = itemList[i] as Object; if (item == null) { continue; } itemList[i] = Wrapper.Instance.Wrap(item); } var loadInventoryMethod = _loadInventoryMethod ?? (_loadInventoryMethod = CurrentMenu.GetType().GetInstanceMethod("loadInventory")); loadInventoryMethod.Invoke(CurrentMenu, null); Log.Trace("Overrided CJB Item Spawner menu items."); }
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (Game1.player.hat is SpeedsterMask && SpeedsterMask.hyperdrive) { int index = (Game1.player.hat as SpeedsterMask).index; SpeedsterMask.hyperdrive = false; SpeedsterMask.takeOffCostume(); SpeedsterMask.putOnCostume(index); } if (Game1.activeClickableMenu is ShopMenu) { ShopMenu shop = (ShopMenu)Game1.activeClickableMenu; Dictionary <Item, int[]> items = Helper.Reflection.GetField <Dictionary <Item, int[]> >(shop, "itemPriceAndStock").GetValue(); List <Item> selling = Helper.Reflection.GetField <List <Item> >(shop, "forSale").GetValue(); if (items.Keys.FirstOrDefault <Item>() is Hat) { Dictionary <Item, int> newItemsToSell = new Dictionary <Item, int>(); newItemsToSell.Add(new SpeedsterMask(0), 10000); newItemsToSell.Add(new SpeedsterMask(1), 20000); foreach (Item item in newItemsToSell.Keys) { items.Add(item, new int[] { newItemsToSell[item], int.MaxValue }); selling.Add(item); } } } }
/* GameEvents_OnUpdateTick * Triggers every time the menu changes. * Handles the setup of the SBobberBar, used to detect if the player is fishing. */ private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (e.NewMenu is BobberBar bobberBarMenu) { this.Bobber = SBobberBar.ConstructFromBaseClass(bobberBarMenu); } // Player just caught a fish, but inventory is full if (e.NewMenu is ItemGrabMenu itemGrabMenu && e.PriorMenu is DialogueBox && FishItem.itemToAdd != null) { Item itemToChange = null; foreach (Item item in itemGrabMenu.ItemsToGrabMenu.actualInventory) { // Item is a fish if (item.Category == -4) { itemToChange = item; } } if (itemToChange != null) { itemGrabMenu.ItemsToGrabMenu.actualInventory.Remove(itemToChange); itemGrabMenu.ItemsToGrabMenu.actualInventory.Add(FishItem.itemToAdd); } } }
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (Game1.activeClickableMenu is ShopMenu) { ShopMenu shop = (ShopMenu)Game1.activeClickableMenu; Dictionary <Item, int[]> items = Helper.Reflection.GetPrivateValue <Dictionary <Item, int[]> >(shop, "itemPriceAndStock"); List <Item> selling = Helper.Reflection.GetPrivateValue <List <Item> >(shop, "forSale"); int currency = Helper.Reflection.GetPrivateValue <int>(shop, "currency"); bool isCatalogue = (currency == 0 && selling[0] is Furniture); if ((shop.portraitPerson != null && shop.portraitPerson.name == "Robin") || isCatalogue) { Dictionary <Item, int> newItemsToSell = new Dictionary <Item, int>(); foreach (CustomFurniture f in furniture.Values) { newItemsToSell.Add(f, isCatalogue ? 0 : f.price); } foreach (Item item in newItemsToSell.Keys) { items.Add(item, new int[] { newItemsToSell[item], int.MaxValue }); selling.Add(item); } } } }
/// <summary>Callback for the menu changed event; switches the currently handler to the one for the new menu type.</summary> private void OnMenuChanged(object sender, EventArgsClickableMenuChanged e) { this.Monitor.DebugLog($"Menu changed from {e?.PriorMenu} to {e?.NewMenu}"); // Resize event; ignore if (e.PriorMenu?.GetType() == e.NewMenu?.GetType() && this.WasResizeEvent) { this.WasResizeEvent = false; return; } this.WasResizeEvent = false; // Reset var newMenuType = e.NewMenu.GetType(); if (this.MenuHandlers.ContainsKey(newMenuType)) { // Close the current one of it's valid and not the same as the current one if (this.CurrentMenuHandler != null && this.CurrentMenuHandler != this.MenuHandlers[newMenuType]) { this.CurrentMenuHandler.Close(); } this.CurrentMenuHandler = this.MenuHandlers[newMenuType]; this.CurrentMenuHandler.Open(e.NewMenu); SubscribeEvents(); } }
private void menuChanged(object sender, EventArgsClickableMenuChanged args) { if (args.NewMenu == null) { return; } if (args.NewMenu is GameMenu gameMenu) { var pages = (List <IClickableMenu>)Helper.Reflection.GetField <List <IClickableMenu> >(gameMenu, "pages").GetValue(); var oldInv = pages[GameMenu.inventoryTab]; if (oldInv.GetType() == typeof(InventoryPage)) { pages[GameMenu.inventoryTab] = new NewInventoryPage(oldInv.xPositionOnScreen, oldInv.yPositionOnScreen, oldInv.width, oldInv.height); } } else if (args.NewMenu is MenuWithInventory menuWithInv) { menuWithInv.inventory.capacity = 48; menuWithInv.inventory.rows = 4; menuWithInv.height += 64; } else if (args.NewMenu is ShopMenu shop) { shop.inventory = new InventoryMenu(shop.inventory.xPositionOnScreen, shop.inventory.yPositionOnScreen, false, (List <Item>)null, new InventoryMenu.highlightThisItem(shop.highlightItemToSell), 48, 4, 0, 0, true); } else if (args.NewMenu is DialogueBox) { GameEvents.UpdateTick += watchSelectedResponse; } }
public void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { System.Console.Write($"Type of new menu is {e.NewMenu.GetType().ToString()}"); if (e.NewMenu is CraftingPage page && !(e.NewMenu is ListenerCraftingPage)) { ListenerCraftingPage replacement = new ListenerCraftingPage(page, this.replacer); Game1.activeClickableMenu = replacement; } if (e.NewMenu is GameMenu) { IReflectedField <List <IClickableMenu> > pages = this.Helper.Reflection.GetField <List <IClickableMenu> >(e.NewMenu, "pages"); var menuPages = pages.GetValue(); for (int i = 0; i < menuPages.Count; i++) { if (menuPages[i] is CraftingPage craftingPage) { menuPages[i] = new ListenerCraftingPage(craftingPage, this.replacer); break; } } pages.SetValue(menuPages); } }
/********* ** Private methods *********/ private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (e.NewMenu is BobberBar menu) { this.Bobber = SBobberBar.ConstructFromBaseClass(menu); } }
/// <summary>The method invoked when the active menu changes.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { // remove overlay if (e.PriorMenu is ItemGrabMenu) { this.ManageChestOverlay?.Dispose(); this.ManageChestOverlay = null; } // add overlay if (e.NewMenu is ItemGrabMenu chestMenu) { // get open chest ManagedChest chest = this.ChestFactory.GetChestFromMenu(chestMenu); if (chest == null) { return; } // reopen shipping box in standard chest UI if (chest.Container is ShippingBinContainer && !chestMenu.showReceivingMenu) { Game1.activeClickableMenu = chest.OpenMenu(); } // add overlay ManagedChest[] chests = this.ChestFactory.GetChestsForDisplay(selected: chest.Container).ToArray(); this.ManageChestOverlay = new ManageChestOverlay(chestMenu, chest, chests, this.Config, this.Helper.Translation); this.ManageChestOverlay.OnChestSelected += selected => { this.SelectedInventory = selected.Container.Inventory; Game1.activeClickableMenu = selected.OpenMenu(); }; } }
/// <summary>The event called after a new menu is opened.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { // add blueprint to carpenter menu if (Context.IsWorldReady && !this.HasAnyGarages) { // default menu if (e.NewMenu is CarpenterMenu) { this.Helper.Reflection .GetPrivateValue <List <BluePrint> >(e.NewMenu, "blueprints") .Add(this.GetBlueprint()); } // modded menus else if (this.IsPelicanFiberLoaded && e.NewMenu.GetType().FullName == this.PelicanFiberMenuFullName) { this.Helper.Reflection .GetPrivateValue <List <BluePrint> >(e.NewMenu, "Blueprints") .Add(this.GetBlueprint()); } else if (this.IsFarmExpansionLoaded && e.NewMenu.GetType().FullName == this.FarmExpansionMenuFullName) { this.Helper.Reflection .GetPrivateMethod(e.NewMenu, "AddFarmBluePrint") .Invoke(this.GetBlueprint()); } } }
/********* ** Private methods *********/ /**** ** Event handlers ****/ /// <summary>The method called when the player returns to the title screen.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (e.NewMenu is TitleMenu) { GameEvents.UpdateTick += this.GameEvents_UpdateTick; } }
/// <summary>The event called after a new menu is opened.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (!this.IsEnabled) { return; } // add blueprint to carpenter menu if (Context.IsWorldReady && !this.HasAnyGarages) { // default menu if (e.NewMenu is CarpenterMenu) { this.Helper.Reflection .GetField <List <BluePrint> >(e.NewMenu, "blueprints") .GetValue() .Add(this.GetBlueprint()); } // modded menus else if (this.IsPelicanFiberLoaded && e.NewMenu.GetType().FullName == this.PelicanFiberMenuFullName) { this.Helper.Reflection .GetField <List <BluePrint> >(e.NewMenu, "Blueprints") .GetValue() .Add(this.GetBlueprint()); } } }
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(); } } }
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (Game1.activeClickableMenu is DialogueBox && (!(Game1.activeClickableMenu is PortraitureDialogueBoxNew))) { DialogueBox oldBox = (DialogueBox)Game1.activeClickableMenu; NPC speaker = Game1.currentSpeaker; if (oldBox.isPortraitBox() == true && speaker != null && speaker.Portrait != null) { Dialogue dialogue = speaker.CurrentDialogue.Peek(); bool isLewis = (speaker != Game1.getCharacterFromName("Lewis")); int count = 0; if (isLewis && Game1.isFestival()) { try { count = dialogue.getResponseOptions().Count; } catch { } } if (count == 0 || !isLewis || Game1.isFestival() == false) { Game1.activeClickableMenu = new PortraitureDialogueBoxNew(dialogue); } } } }
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (Game1.activeClickableMenu is ShopMenu) { ShopMenu shop = (ShopMenu)Game1.activeClickableMenu; Dictionary <Item, int[]> items = Helper.Reflection.GetField <Dictionary <Item, int[]> >(shop, "itemPriceAndStock").GetValue(); List <Item> selling = Helper.Reflection.GetField <List <Item> >(shop, "forSale").GetValue(); int currency = Helper.Reflection.GetField <int>(shop, "currency").GetValue(); bool isCatalogue = (currency == 0 && selling.Count > 0 && selling[0] is Furniture); if (isCatalogue || (shop.portraitPerson != null && shop.portraitPerson is NPC shopk && shopk.name == "Robin")) { Dictionary <Item, int> newItemsToSell = new Dictionary <Item, int>(); foreach (ItemFrameData f in ItemFrameMod.itemFrameDatum) { Item item = (Item) new ItemFrame(f, new Vector2(0, 0), ItemFrameMod.instance.Monitor); if (f.displayItems.Count != 0) { item.DisplayName = $"ItemFrame{item.DisplayName}"; } items.Add(item, new int[] { isCatalogue ? 0 : f.price, int.MaxValue }); selling.Add(item); } } } }
private void menuChanged(object sender, EventArgsClickableMenuChanged args) { var menu = args.NewMenu as ShopMenu; if (menu == null || menu.portraitPerson == null) { return; } //if (menu.portraitPerson.name == "Pierre") { Log.trace($"Adding objects to {menu.portraitPerson.name}'s shop"); var forSale = Helper.Reflection.GetPrivateValue <List <Item> >(menu, "forSale"); var itemPriceAndStock = Helper.Reflection.GetPrivateValue <Dictionary <Item, int[]> >(menu, "itemPriceAndStock"); var precondMeth = Helper.Reflection.GetPrivateMethod(Game1.currentLocation, "checkEventPrecondition"); foreach (var obj in objects) { if (obj.Recipe != null && obj.Recipe.CanPurchase) { if (obj.Recipe.PurchaseFrom != menu.portraitPerson.name) { continue; } if (Game1.player.craftingRecipes.ContainsKey(obj.Name) || Game1.player.cookingRecipes.ContainsKey(obj.Name)) { continue; } if (obj.Recipe.PurchaseRequirements != null && obj.Recipe.PurchaseRequirements.Count > 0 && precondMeth.Invoke <int>(new object[] { obj.Recipe.GetPurchaseRequirementString() }) == -1) { continue; } var recipeObj = new StardewValley.Object(obj.id, 1, true, obj.Recipe.PurchasePrice, 0); forSale.Add(recipeObj); itemPriceAndStock.Add(recipeObj, new int[] { obj.Recipe.PurchasePrice, 1 }); Log.trace($"\tAdding recipe for {obj.Name}"); } if (!obj.CanPurchase) { continue; } if (obj.PurchaseFrom != menu.portraitPerson.name) { continue; } if (obj.PurchaseRequirements != null && obj.PurchaseRequirements.Count > 0 && precondMeth.Invoke <int>(new object[] { obj.GetPurchaseRequirementString() }) == -1) { continue; } Item item = new StardewValley.Object(Vector2.Zero, obj.id, int.MaxValue); forSale.Add(item); itemPriceAndStock.Add(item, new int[] { obj.PurchasePrice, int.MaxValue }); Log.trace($"\tAdding {obj.Name}"); } } }
private void OnMenuChanged(object sender, EventArgsClickableMenuChanged e) { if (e.NewMenu is TitleMenu) { UnsubscribeEvents(); SaveData(); } }
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (Game1.activeClickableMenu is GameMenu) { GameMenu menu = Game1.activeClickableMenu as GameMenu; xPositionOnScreen = menu.xPositionOnScreen + menu.width - 200; } }
/********* ** Private methods *********/ /**** ** Event handlers ****/ /// <summary>The method called when the player returns to the title screen.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (e.NewMenu is TitleMenu) { this.CurrentStage = Stage.SkipIntro; GameEvents.UpdateTick += this.GameEvents_UpdateTick; } }
internal static void OnMenuChanged(object sender, EventArgsClickableMenuChanged e) { if (!_IsCookingMenu(e.NewMenu)) { return; } _AddFreezerItemsToFridge(); }
private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (e.NewMenu is TitleMenu) { UnsubscribeEvents(); MemoryCache.Default.Dispose(); } }
private void drainMenu_Open(object sender, EventArgsClickableMenuChanged args) { if (!modEnabled) { return; } isMenuOpen = true; }
/// <summary> /// When a menu changes, check if its the invite code menu. If so, add the copy to clipboard option. /// </summary> private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (e.NewMenu is ConfirmationDialog confDialog && this.Helper.Reflection .GetField <string>(confDialog, "message").GetValue().StartsWith(GetFirstPartOfInviteMessage())) { this.AddCopyToClipboardOption(confDialog); } }
/// <summary> /// Replace the menu /// </summary> /// <param name="argEvents"></param> public void LoadMenu(EventArgsClickableMenuChanged argEvents) { FridgeList = new FridgeVirtualList(this); if (!_cookingSkillLoaded || ModEntry.Instance.CookinSkillApi == null) { Game1.activeClickableMenu = new RemoteFridgeCraftingPage(argEvents.NewMenu, this); } }
// In-game events private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (_refreshReport && e.PriorMenu is SettingsMenu && e.NewMenu is ReportMenu) { OpenReport(true); } _refreshReport = false; }
private void menuChanged(object sender, EventArgsClickableMenuChanged args) { if (args.NewMenu is BobberBar bobber && hasRingEquipped(Ring_Fishing_LargeBar) > 0) { var field = Helper.Reflection.GetField <int>(bobber, "bobberBarHeight"); field.SetValue((int)(field.GetValue() * 1.50)); } }