示例#1
0
 /// <summary>Get all player chests in the order they should be displayed.</summary>
 /// <param name="selectedChest">The chest to show even if it's ignored.</param>
 /// <param name="excludeIgnored">Whether to exclude chests marked as hidden.</param>
 public static IEnumerable <ManagedChest> GetChestsForDisplay(Chest selectedChest = null, bool excludeIgnored = true)
 {
     return(ChestFactory.GetChests()
            .Where(chest => !excludeIgnored || !chest.IsIgnored || chest.Chest == selectedChest)
            .OrderBy(p => p.Order ?? int.MaxValue)
            .ThenBy(p => p.Name));
 }
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
        public override void Entry(IModHelper helper)
        {
            // initialise
            this.Config       = helper.ReadConfig <RawModConfig>().GetParsed();
            this.ChestFactory = new ChestFactory(helper.Translation);

            // hook UI
            GraphicsEvents.OnPostRenderHudEvent += (sender, e) => this.ReceiveHudRendered();
            MenuEvents.MenuChanged += (sender, e) => this.ReceiveMenuChanged(e.PriorMenu, e.NewMenu);
            MenuEvents.MenuClosed  += (sender, e) => this.ReceiveMenuClosed(e.PriorMenu);

            // hook input
            if (this.Config.Keyboard.HasAny())
            {
                ControlEvents.KeyPressed += (sender, e) => this.ReceiveKeyPress(e.KeyPressed, this.Config.Keyboard);
            }
            if (this.Config.Controller.HasAny())
            {
                ControlEvents.ControllerButtonPressed  += (sender, e) => this.ReceiveKeyPress(e.ButtonPressed, this.Config.Controller);
                ControlEvents.ControllerTriggerPressed += (sender, e) => this.ReceiveKeyPress(e.ButtonPressed, this.Config.Controller);
            }

            // hook game events
            SaveEvents.AfterLoad += this.ReceiveAfterLoad;
        }
        /// <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();
                };
            }
        }
        /// <summary>The method invoked when the interface has finished rendering.</summary>
        private void ReceiveHudRendered()
        {
            // render update warning
            if (this.Config.CheckForUpdates && !this.HasSeenUpdateWarning && this.NewRelease != null)
            {
                try
                {
                    this.HasSeenUpdateWarning = true;
                    CommonHelper.ShowInfoMessage($"You can update Chests Anywhere from {this.CurrentVersion} to {this.NewRelease}.");
                }
                catch (Exception ex)
                {
                    this.HandleError(ex, "showing the new version available");
                }
            }

            // show chest label
            if (this.Config.ShowHoverTooltips)
            {
                ManagedChest cursorChest = ChestFactory.GetChestFromTile(Game1.currentCursorTile);
                if (cursorChest != null)
                {
                    Vector2 tooltipPosition = new Vector2(Game1.getMouseX(), Game1.getMouseY()) + new Vector2(Game1.tileSize / 2f);
                    CommonHelper.DrawHoverBox(Game1.spriteBatch, cursorChest.Name, tooltipPosition, Game1.viewport.Width - tooltipPosition.X - Game1.tileSize / 2f);
                }
            }
        }
示例#5
0
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
        public override void Entry(IModHelper helper)
        {
            // initialise
            this.Config       = helper.ReadConfig <RawModConfig>().GetParsed();
            this.ChestFactory = new ChestFactory(helper.Translation);

            // hook UI
            GraphicsEvents.OnPostRenderHudEvent += (sender, e) => this.ReceiveHudRendered();
            MenuEvents.MenuChanged += (sender, e) => this.ReceiveMenuChanged(e.PriorMenu, e.NewMenu);
            MenuEvents.MenuClosed  += (sender, e) => this.ReceiveMenuClosed(e.PriorMenu);

            // hook input
            if (this.Config.Keyboard.HasAny())
            {
                ControlEvents.KeyPressed += (sender, e) => this.ReceiveKeyPress(e.KeyPressed, this.Config.Keyboard);
            }
            if (this.Config.Controller.HasAny())
            {
                ControlEvents.ControllerButtonPressed  += (sender, e) => this.ReceiveKeyPress(e.ButtonPressed, this.Config.Controller);
                ControlEvents.ControllerTriggerPressed += (sender, e) => this.ReceiveKeyPress(e.ButtonPressed, this.Config.Controller);
            }

            // hook game events
            SaveEvents.AfterLoad += this.ReceiveAfterLoad;

            // validate translations
            if (!helper.Translation.GetTranslations().Any())
            {
                this.Monitor.Log("The translation files in this mod's i18n folder seem to be missing. The mod will still work, but you'll see 'missing translation' messages. Try reinstalling the mod to fix this.", LogLevel.Warn);
            }
        }
示例#6
0
        /*********
        ** Public methods
        *********/
        /// <summary>Get all player chests.</summary>
        public static IEnumerable <ManagedChest> GetChests()
        {
            foreach (GameLocation location in Game1.locations)
            {
                // chests in location
                {
                    int namelessCount = 0;
                    foreach (KeyValuePair <Vector2, Object> pair in location.Objects)
                    {
                        Vector2 tile  = pair.Key;
                        Chest   chest = pair.Value as Chest;
                        if (chest != null && chest.playerChest)
                        {
                            yield return(new ManagedChest(chest, ChestFactory.GetLocationName(location), tile, $"Chest #{++namelessCount}"));
                        }
                    }
                }

                // chests in constructed buildings
                if (location is BuildableGameLocation)
                {
                    foreach (Building building in (location as BuildableGameLocation).buildings)
                    {
                        int namelessCount = 0;
                        if (building.indoors == null)
                        {
                            continue;
                        }
                        foreach (KeyValuePair <Vector2, Object> pair in building.indoors.Objects)
                        {
                            Vector2 tile  = pair.Key;
                            Chest   chest = pair.Value as Chest;
                            if (chest != null && chest.playerChest)
                            {
                                yield return(new ManagedChest(chest, ChestFactory.GetLocationName(building), tile, $"Chest #{++namelessCount}"));
                            }
                        }
                    }
                }

                // farmhouse containers
                if (location is FarmHouse && Game1.player.HouseUpgradeLevel > 0)
                {
                    Chest fridge = (location as FarmHouse).fridge;
                    if (fridge != null)
                    {
                        yield return(new ManagedChest(fridge, location.Name, Vector2.Zero, "Fridge"));
                    }
                }
            }
        }
示例#7
0
        /// <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));
        }
        /// <summary>Open the menu UI.</summary>
        private void OpenMenu()
        {
            // get chests
            ManagedChest[] chests        = ChestFactory.GetChestsForDisplay().ToArray();
            ManagedChest   selectedChest = chests.FirstOrDefault(p => p.Chest == this.SelectedChest) ?? chests.FirstOrDefault();

            // render menu
            if (selectedChest != null)
            {
                Game1.activeClickableMenu = selectedChest.OpenMenu();
            }
            else
            {
                CommonHelper.ShowInfoMessage("You don't have any chests yet. :)", duration: 1000);
            }
        }
示例#9
0
        /// <summary>Get the player chest on the specified tile (if any).</summary>
        /// <param name="tile">The tile to check.</param>
        public static ManagedChest GetChestFromTile(Vector2 tile)
        {
            // get chest
            Chest chest;

            {
                Object obj;
                Game1.currentLocation.Objects.TryGetValue(tile, out obj);
                chest = obj as Chest;
            }

            // return if valid
            if (chest != null && chest.playerChest)
            {
                return(new ManagedChest(chest, ChestFactory.GetLocationName(Game1.currentLocation), tile));
            }
            return(null);
        }
示例#10
0
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
        public override void Entry(IModHelper helper)
        {
            // initialise
            this.Config       = helper.ReadConfig <ModConfig>();
            this.Data         = helper.Data.ReadJsonFile <ModData>("data.json") ?? new ModData();
            this.ChestFactory = new ChestFactory(helper.Translation, helper.Data, this.Config.EnableShippingBin);

            // hook events
            helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded;
            helper.Events.Display.RenderedHud += this.OnRenderedHud;
            helper.Events.Display.MenuChanged += this.OnMenuChanged;
            helper.Events.Input.ButtonPressed += this.OnButtonPressed;

            // validate translations
            if (!helper.Translation.GetTranslations().Any())
            {
                this.Monitor.Log("The translation files in this mod's i18n folder seem to be missing. The mod will still work, but you'll see 'missing translation' messages. Try reinstalling the mod to fix this.", LogLevel.Warn);
            }
        }
示例#11
0
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
        public override void Entry(IModHelper helper)
        {
            // initialize
            I18n.Init(helper.Translation);
            this.Config       = helper.ReadConfig <ModConfig>();
            this.Keys         = this.Config.Controls.ParseControls(helper.Input, this.Monitor);
            this.Data         = helper.Data.ReadJsonFile <ModData>("assets/data.json") ?? new ModData();
            this.ChestFactory = new ChestFactory(helper.Multiplayer, helper.Reflection, this.Config.EnableShippingBin);

            // hook events
            helper.Events.GameLoop.SaveLoaded       += this.OnSaveLoaded;
            helper.Events.World.LocationListChanged += this.OnLocationListChanged;
            helper.Events.GameLoop.UpdateTicked     += this.OnUpdateTicked;
            helper.Events.GameLoop.UpdateTicking    += this.OnUpdateTicking;
            helper.Events.Display.RenderedHud       += this.OnRenderedHud;
            helper.Events.Input.ButtonPressed       += this.OnButtonPressed;

            // validate translations
            if (!helper.Translation.GetTranslations().Any())
            {
                this.Monitor.Log("The translation files in this mod's i18n folder seem to be missing. The mod will still work, but you'll see 'missing translation' messages. Try reinstalling the mod to fix this.", LogLevel.Warn);
            }
        }
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
        public override void Entry(IModHelper helper)
        {
            // initialise
            this.Config       = helper.ReadConfig <ModConfig>();
            this.ChestFactory = new ChestFactory(helper.Translation, helper.Reflection);

            // hook UI
            GraphicsEvents.OnPostRenderHudEvent += this.GraphicsEvents_OnPostRenderHudEvent;
            MenuEvents.MenuChanged += this.MenuEvents_MenuChanged;
            MenuEvents.MenuClosed  += this.MenuEvents_MenuClosed;

            // hook input
            InputEvents.ButtonPressed += this.InputEvents_ButtonPressed;

            // hook game events
            SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;

            // validate translations
            if (!helper.Translation.GetTranslations().Any())
            {
                this.Monitor.Log("The translation files in this mod's i18n folder seem to be missing. The mod will still work, but you'll see 'missing translation' messages. Try reinstalling the mod to fix this.", LogLevel.Warn);
            }
        }