/// Get a free tile for chest placement in a location. /// NOTE: This can return a value outside the map bounds. public static Point GetFreeTileInLocation(GameLocation location) { for (int h = 0; h <= location.map.Layers[0].LayerHeight; h++)//(int h = location.map.Layers[0].LayerHeight; h >= 0; h--) { for (int w = 0; w <= location.map.Layers[0].LayerWidth; w++) { // check if tile in width and height is placeable and not on wall if (location.isTileLocationTotallyClearAndPlaceable(w, h) && (!(location is DecoratableLocation) || !(location as DecoratableLocation).isTileOnWall(w, h))) { return(new Point(w, h)); } } } int y = 0; int x = 0; // move in y direction untill no other potential offmap objects are there while (location.isObjectAtTile(x, y)) { y++; } ModEntry.DebugLog("Warning, object might become placed out of bounds at tile x:" + x + ", y:" + y + " in location: " + location.Name, StardewModdingAPI.LogLevel.Warn); // return that position return(new Point(x, y)); }
/// Constructor starts tracking needed event for tracking fridge inventory menu. public Manager(ModEntry entry) { _entry = entry; _entry.Helper.Events.Display.MenuChanged += OnMenuChanged; _entry.Helper.Events.GameLoop.DayStarted += OnDayStarted; _entry.Helper.Events.GameLoop.DayEnding += OnDayEnding; ModEntry.DebugLog("Manager created"); }
/// Initiates custom menu with references and events. private void OnFridgeOpened(ItemGrabMenu menu) { // get multimutex from mini friges var farmHouse = Utilities.CurrentLocation as FarmHouse; var miniFridges = Utilities.GetAllMiniFridgesInLocation(farmHouse); _menu = menu; _fridges.Add(farmHouse.fridge); _fridges.AddRange(miniFridges); _entry.Helper.Events.Display.RenderingActiveMenu += DrawBeforeActiveMenu; _entry.Helper.Events.Input.ButtonPressed += RecieveButtonPressed; _entry.Helper.Events.Input.MouseWheelScrolled += RecieveMouseWheelScrolled; UpdateCustomComponents(); _customMenuInitiated = true; ModEntry.DebugLog("Fridge opened"); }
/// Releases custom menu, mutexes and unsubscribes events. private void OnFridgeClosed() { if (_customMenuInitiated) { _entry.Helper.Events.Display.RenderingActiveMenu -= DrawBeforeActiveMenu; _entry.Helper.Events.Input.ButtonPressed -= RecieveButtonPressed; _entry.Helper.Events.Input.MouseWheelScrolled -= RecieveMouseWheelScrolled; // release mutex if mini fridge selected if (_selectedTab > 0 && _selectedTab < _fridges.Count) { _fridges[_selectedTab].mutex.ReleaseLock(); } _menu = null; _fridges.Clear(); ClearCustomComponents(); _customMenuInitiated = false; } ModEntry.DebugLog("Fridge closed"); }
/// ************************************************************************************************************************************************** /// MARKED CHEST MANIPULATION /// Get a free tile for chest placement in our location. /// NOTE: This can return a value outside the map bound of the house. private Point GetFreeTileInLocation() { // for the whole width of the map for (int w = 0; w <= this.location.map.Layers[0].LayerWidth; w++) { // for the whole height of the map for (int h = 0; h <= this.location.map.Layers[0].LayerHeight; h++) { // check if tile in width and height is placeable and not on wall if (this.location.isTileLocationTotallyClearAndPlaceable(w, h) && !this.location.isTileOnWall(w, h)) { return(new Point(w, h)); } } } // NOTE: if we arrive here, the location is a mess!. We want to ensure the chests are safe so we give an out of reach option // we get a tile out of the map, this will be saved but cannot be accessed normally if the mod breaks but items can still be rescued // with an updated version or other cheat mods that accesses chests or enables movement out of the map. int y = 0; int x = 0; // move in y direction untill no other potential offmap objects are there while (this.location.isObjectAtTile(x, y)) { y++; } ModEntry.DebugLog( "A free tile could not be found in location, object might become placed out of bounds at tile x:" + x + ", y:" + y + " in location: " + location.Name, StardewModdingAPI.LogLevel.Warn); // return that position return(new Point(x, y)); }
/// Updates the menu reference of the fridge. private void OnFridgeUpdated(ItemGrabMenu menu) { _menu = menu; ModEntry.DebugLog("Fridge updated"); }