Пример #1
0
        /// <summary>Wraps the the method so it only executes if the player clicks on the specified tileposition and adds it to <see cref="IInputEvents.ButtonPressed"/>.</summary>
        /// <returns>Returns the wrapped method.</returns>
        public static EventHandler <ButtonPressedEventArgs> onClick(this ButtonClick t, TileLocationSelector tile, Action <Vector2> handler)
        {
            EventHandler <ButtonPressedEventArgs> d = delegate(object sender, ButtonPressedEventArgs e)
            {
                bool isButton = t.Equals(ButtonClick.UseToolButton) ? e.Button.IsUseToolButton() : e.Button.IsActionButton();
                if (isButton && Game1.currentLocation is GameLocation location && tile.predicate(location, location.getTileAtMousePosition()))
                {
                    handler.Invoke(location.getTileAtMousePosition());
                }
            };

            PyEvents.Events.Input.ButtonPressed += d;
            return(d);
        }
Пример #2
0
        public static Dictionary <GameLocation, NotifyCollectionChangedEventHandler> whenRemovedFromLocation(this TileLocationSelector t, Action <GameLocation, List <Vector2> > action)
        {
            List <GameLocation> gls = new List <GameLocation>();

            if (t.location == null)
            {
                gls = PyUtils.getAllLocationsAndBuidlings();
            }
            else
            {
                gls.Add(t.location);
            }

            Action <GameLocation, NotifyCollectionChangedEventArgs> a = delegate(GameLocation location, NotifyCollectionChangedEventArgs e)
            {
                List <Vector2> keys = new List <Vector2>();

                if (e.Action == NotifyCollectionChangedAction.Remove)
                {
                    foreach (Vector2 key in e.OldItems)
                    {
                        if (t.predicate(location, key))
                        {
                            keys.Add(key);
                        }
                    }
                }

                action.Invoke(location, keys);
            };

            Dictionary <GameLocation, NotifyCollectionChangedEventHandler> d = new Dictionary <GameLocation, NotifyCollectionChangedEventHandler>();

            foreach (GameLocation gl in gls)
            {
                d.AddOrReplace(gl, (o, e) => a(gl, e));
            }

            return(d.useAll(p => p.Key.terrainFeatures.CollectionChanged += p.Value));
        }