コード例 #1
0
        private void LocationEvents_ObjectsChanged(object sender, EventArgsLocationObjectsChanged e)
        {
            if (e.Added.Any())
            {
                foreach (KeyValuePair <Vector2, StardewValley.Object> pair in e.Added)
                {
                    //Monitor.Log($"  Object Added: {pair.Value.Name} {pair.Value.ParentSheetIndex}, {e.Location.Name}-{pair.Key.X},{pair.Key.Y}", LogLevel.Trace);

                    //Handle creating new instances
                    if (pair.Value.parentSheetIndex == AutoGrabber.ParentIndex)
                    {
                        var g = new AutoGrabber(e.Location, pair.Value, pair.Key);
                        if (!AutoGrabbers.ContainsKey(g.Id))
                        {
                            Monitor.Log($"  - Adding Instance {g.Id}");
                            AutoGrabbers.Add(g.Id, g);
                        }
                    }
                }

                foreach (var grabber in AutoGrabbers.Where(g => (bool)g.Value.FeatureType <Forage>().Value).ToArray())
                {
                    if (grabber.Value.Location.Name == e.Location.Name)
                    {
                        (grabber.Value.FeatureType <Forage>() as Forage).ActionItemAddedRemoved(sender, e);
                    }
                }
            }
            if (e.Removed.Any())
            {
                foreach (KeyValuePair <Vector2, StardewValley.Object> pair in e.Removed)
                {
                    //Monitor.Log($"  Object Removed: {pair.Value.Name}, ID: {pair.Value.ParentSheetIndex}, Location: {e.Location.Name}-{pair.Key.X},{pair.Key.Y}", LogLevel.Trace);

                    //Handle removing instances
                    if (pair.Value.ParentSheetIndex == AutoGrabber.ParentIndex)
                    {
                        var grabber = AutoGrabbers.Values.Where(g => g.Location.Equals(e.Location) && g.Tile.Equals(pair.Key)).FirstOrDefault();
                        if (grabber != null)
                        {
                            Monitor.Log($"  Cleaning instance {grabber.Id}");
                            AutoGrabbers.Remove(grabber.Id);
                        }
                    }
                }
            }
        }
コード例 #2
0
 private void GetTileUnderCursor(object sender, EventArgs e)
 {
     if (Game1.currentLocation != null)
     {
         if (Game1.currentLocation.Objects == null || !AutoGrabbers.TryGetValue(AutoGrabber.MakeId(Game1.currentLocation, Game1.currentCursorTile), out _currentGrabber))
         {
             _currentGrabber = null;
             foreach (var g in AutoGrabbers.Values)
             {
                 g.IsMouseOver = false;
             }
         }
         else
         {
             _currentGrabber.IsMouseOver = true;
         }
     }
 }
コード例 #3
0
ファイル: ModEntry.cs プロジェクト: savaatti/smapi-mod-dump
 /// <summary>Raised after the game state is updated (≈60 times per second).</summary>
 /// <param name="sender">The event sender.</param>
 /// <param name="e">The event data.</param>
 private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
 {
     // get tile under cursor
     if (e.IsMultipleOf(4) && Game1.currentLocation != null)
     {
         if (Game1.currentLocation.Objects == null || !AutoGrabbers.TryGetValue(AutoGrabber.MakeId(Game1.currentLocation, Game1.currentCursorTile), out _currentGrabber))
         {
             _currentGrabber = null;
             foreach (var g in AutoGrabbers.Values)
             {
                 g.IsMouseOver = false;
             }
         }
         else
         {
             _currentGrabber.IsMouseOver = true;
         }
     }
 }
コード例 #4
0
 private void ReturnToTitle(object sender, EventArgs e)
 {
     _currentGrabber = null;
     AutoGrabbers.Clear();
 }
コード例 #5
0
        public MenuContainer(AutoGrabber[] grabbers, int indexGrabberSettings, ModConfig config) : base(Game1.viewport.Width / 2 - (600 + IClickableMenu.borderWidth * 2) / 2, Game1.viewport.Height / 2 - (600 + IClickableMenu.borderWidth * 2) / 2, 800 + IClickableMenu.borderWidth * 2, 600 + IClickableMenu.borderWidth * 2)
        {
            this.Config          = config;
            this.Title           = new ClickableComponent(new Rectangle(this.xPositionOnScreen + this.width / 2, this.yPositionOnScreen, Game1.tileSize * 4, Game1.tileSize), "Auto-Grabber Mod");
            this.upArrow         = new ClickableTextureComponent(new Rectangle(base.xPositionOnScreen + width + 16, base.yPositionOnScreen + 64, 44, 48), Game1.mouseCursors, new Rectangle(421, 459, 11, 12), 4f, false);
            this.downArrow       = new ClickableTextureComponent(new Rectangle(base.xPositionOnScreen + width + 16, base.yPositionOnScreen + height - 64, 44, 48), Game1.mouseCursors, new Rectangle(421, 472, 11, 12), 4f, false);
            this.scrollBar       = new ClickableTextureComponent(new Rectangle(this.upArrow.bounds.X + 12, this.upArrow.bounds.Y + this.upArrow.bounds.Height + 4, 24, 40), Game1.mouseCursors, new Rectangle(435, 463, 6, 10), 4f, false);
            this.scrollBarRunner = new Rectangle(this.scrollBar.bounds.X, this.upArrow.bounds.Y + this.upArrow.bounds.Height + 4, this.scrollBar.bounds.Width, height - 128 - this.upArrow.bounds.Height - 8);
            for (int i = 0; i < 7; i++)
            {
                this.optionSlots.Add(new ClickableComponent(new Rectangle(base.xPositionOnScreen + 16, base.yPositionOnScreen + 80 + 4 + i * ((height - 128) / 7), width - 32, (height - 128) / 7 + 4), string.Concat(i)));
            }
            var dropDownItems = new List <string>();

            foreach (AutoGrabber grabber in grabbers)
            {
                dropDownItems.Add($"{grabber.InstanceName}");
            }
            dropDownItems.Add("Global Options");
            this.options.Add(new DropDown("", dropDownItems, value =>
            {
                if (value != indexGrabberSettings)
                {
                    Game1.activeClickableMenu = new MenuContainer(grabbers, value, config);
                }
            }, indexGrabberSettings, x: 40, y: 40));

            if (grabbers.Length < (indexGrabberSettings + 1))
            {
                Utilities.Monitor.Log($"  Viewing settings for: Global");
                this.options.Add(new OptionsCheckbox("Show All Range Grids", Config.ShowAllRangeGrids, value =>
                {
                    Config.ShowAllRangeGrids = value;
                }));

                this.options.Add(new OptionsCheckbox("Show Range Grid When Mouse Over", Config.ShowRangeGridMouseOver, value =>
                {
                    Config.ShowRangeGridMouseOver = value;
                }));

                this.options.Add(new OptionsSlider("Max Range", Config.MaxRange, 1, 100, value =>
                {
                    if (value == 0)
                    {
                        value = 1;
                    }
                    Config.MaxRange = value;
                    foreach (var g in grabbers.Where(g => g.Range > value).ToArray())
                    {
                        g.Range = value;
                        g.Update();
                    }
                }));

                this.options.Add(new OptionsCheckbox("Allow Auto Harvesting", Config.AllowAutoHarvest, value =>
                {
                    Config.AllowAutoHarvest = value;
                    if (!value)
                    {
                        Utilities.Monitor.Log("Value is false for harvesting setting false to all");
                        foreach (var g in grabbers.Where(g => (bool)g.FeatureType <Harvest>().Value).ToArray())
                        {
                            g.FeatureType <Harvest>().Value = value;
                            g.Update();
                        }
                    }
                }));
                this.options.Add(new OptionsCheckbox("Allow Auto Hoe Tiles", Config.AllowAutoHoe, value =>
                {
                    Config.AllowAutoHoe = value;
                    if (!value)
                    {
                        foreach (var g in grabbers.Where(g => (bool)g.FeatureType <HoeTiles>().Value).ToArray())
                        {
                            g.FeatureType <HoeTiles>().Value = value;
                            g.Update();
                        }
                    }
                }));
                this.options.Add(new OptionsCheckbox("Allow Auto Fertilize Soil", Config.AllowAutoFertilize, value =>
                {
                    Config.AllowAutoFertilize = value;
                    if (!value)
                    {
                        foreach (var g in grabbers.Where(g => (bool)g.FeatureType <Fertilize>().Value).ToArray())
                        {
                            g.FeatureType <Fertilize>().Value = value;
                            g.Update();
                        }
                    }
                }));
                this.options.Add(new OptionsCheckbox("Allow Auto Seeding", Config.AllowAutoSeed, value =>
                {
                    Config.AllowAutoSeed = value;
                    if (!value)
                    {
                        foreach (var g in grabbers.Where(g => (bool)g.FeatureType <PlantSeeds>().Value).ToArray())
                        {
                            g.FeatureType <PlantSeeds>().Value = value;
                            g.Update();
                        }
                    }
                }));
                this.options.Add(new OptionsCheckbox("Allow Auto Watering", Config.AllowAutoWater, value =>
                {
                    Config.AllowAutoWater = value;
                    if (!value)
                    {
                        foreach (var g in grabbers.Where(g => (bool)g.FeatureType <WaterFields>().Value).ToArray())
                        {
                            g.FeatureType <WaterFields>().Value = value;
                            g.Update();
                        }
                    }
                }));
                this.options.Add(new OptionsCheckbox("Allow Auto Forage", Config.AllowAutoForage, value =>
                {
                    Config.AllowAutoForage = value;
                    if (!value)
                    {
                        foreach (var g in grabbers.Where(g => (bool)g.FeatureType <Forage>().Value).ToArray())
                        {
                            g.FeatureType <Forage>().Value = value;
                            g.Update();
                        }
                    }
                }));
                this.options.Add(new OptionsCheckbox("Allow Auto Dig Artifacts", Config.AllowAutoDig, value =>
                {
                    Config.AllowAutoDig = value;
                    if (!value)
                    {
                        foreach (var g in grabbers.Where(g => (bool)g.FeatureType <DigArtifacts>().Value).ToArray())
                        {
                            g.FeatureType <DigArtifacts>().Value = value;
                            g.Update();
                        }
                    }
                }));
                this.options.Add(new OptionsCheckbox("Allow Auto Pet", Config.AllowAutoPet, value =>
                {
                    Config.AllowAutoPet = value;
                    if (!value)
                    {
                        foreach (var g in grabbers.Where(g => (bool)g.FeatureType <PetAnimals>().Value).ToArray())
                        {
                            g.FeatureType <PetAnimals>().Value = value;
                            g.Update();
                        }
                    }
                }));
            }
            else
            {
                AutoGrabber selectedGrabber = grabbers[indexGrabberSettings];
                //Utilities.Monitor.Log($"  Viewing settings for: {selectedGrabber.InstanceName}");

                //Range options
                var grid = new OptionsCheckbox("Show Grid", selectedGrabber.ShowRange, value =>
                {
                    selectedGrabber.ShowRange = value;
                    selectedGrabber.Update();
                });
                grid.greyedOut = selectedGrabber.RangeEntireMap;

                this.options.Add(new OptionsCheckbox("Use Entire Map", selectedGrabber.RangeEntireMap, value =>
                {
                    selectedGrabber.RangeEntireMap = value;
                    selectedGrabber.Update();
                    grid.greyedOut = selectedGrabber.RangeEntireMap;
                }));
                this.options.Add(new OptionsSlider("Range", selectedGrabber.Range, 1, config.MaxRange, value =>
                {
                    if (value == 0)
                    {
                        value = 1;
                    }
                    selectedGrabber.Range = value;
                    selectedGrabber.Update();
                }, () => selectedGrabber.RangeEntireMap));

                this.options.Add(grid);

                foreach (var feature in selectedGrabber.FeaturesConfig)
                {
                    if (feature.IsAllowed)
                    {
                        this.options.AddRange(feature.InterfaceElement());
                    }
                }

                this.options.Add(new OptionsCheckbox("Gain Experience", selectedGrabber.GainExperience, value =>
                {
                    selectedGrabber.GainExperience = value;
                    selectedGrabber.Update();
                }));
            }
        }