Exemplo n.º 1
0
        /// <summary>Wraps the the method so it only executes if the player clickes on the specified tileposition and adds it to InputEvents.ButtonPressed.</summary>
        /// <returns>Returns the wrapped method.</returns>
        public static EventHandler <EventArgsInput> onClick(this ButtonClick t, TileLocationSelector tile, Action <Vector2> handler)
        {
            EventHandler <EventArgsInput> d = delegate(object sender, EventArgsInput e)
            {
                bool isButton = t.Equals(ButtonClick.UseToolButton) ? e.IsUseToolButton : e.IsActionButton;
                if (isButton && Game1.currentLocation is GameLocation location && tile.predicate(location, location.getTileAtMousePosition()))
                {
                    handler.Invoke(location.getTileAtMousePosition());
                }
            };

            InputEvents.ButtonPressed += d;
            return(d);
        }
Exemplo n.º 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));
        }