Пример #1
0
 internal void DispatchObjectAdded(DisplayObject target)
 {
     if (ObjectAdded != null)
     {
         ObjectAdded.Invoke(target);
     }
 }
        /// <summary>
        /// Gets the currently selected objects.
        /// </summary>
        /// <param name="selectedObjs">The currently selected objects.</param>
        public void SetManySelected(IEnumerable <T> selectedObjs)
        {
            // Check if to clear instead
            if (selectedObjs == null || selectedObjs.IsEmpty())
            {
                Clear();
                return;
            }

            selectedObjs = selectedObjs.Distinct().ToImmutable();

            // Ignore if we already have this exact set as the current selection
            if (selectedObjs.ContainSameElements(_selectedObjs))
            {
                return;
            }

            // Set the new selected objects and update
            Clear();

            foreach (var obj in selectedObjs)
            {
                _selectedObjs.Add(obj);
                OnObjectAdded(obj);
                if (ObjectAdded != null)
                {
                    ObjectAdded.Raise(this, EventArgsHelper.Create(obj));
                }
            }

            UpdateSelection();
        }
        /// <summary>
        /// Gets the currently selected object.
        /// </summary>
        /// <param name="selected">The currently selected object.</param>
        public void SetSelected(T selected)
        {
            // Check if to clear instead
            if (selected == null)
            {
                Clear();
                return;
            }

            // Ignore if we already have this exact set as the current selection
            if (_selectedObjs.Count == 1 && _selectedObjs[0] == selected)
            {
                return;
            }

            // Set the new selected objects and update
            Clear();

            _selectedObjs.Add(selected);

            OnObjectAdded(selected);
            if (ObjectAdded != null)
            {
                ObjectAdded.Raise(this, EventArgsHelper.Create(selected));
            }

            UpdateSelection();
        }
        /// <summary>
        /// Sets the focused object.
        /// </summary>
        /// <param name="obj">The object to set as focused.</param>
        /// <param name="addIfMissing">If true, <paramref name="obj"/> will be added to the collection
        /// if it is not already in it.</param>
        /// <returns>True if the <paramref name="obj"/> was successfully set as the focused object; otherwise
        /// false.</returns>
        public bool SetFocused(T obj, bool addIfMissing = false)
        {
            if (obj == null)
            {
                return(false);
            }

            if (!_selectedObjs.Contains(obj))
            {
                if (!addIfMissing)
                {
                    return(false);
                }

                _selectedObjs.Add(obj);

                OnObjectAdded(obj);
                if (ObjectAdded != null)
                {
                    ObjectAdded.Raise(this, EventArgsHelper.Create(obj));
                }
            }

            Focused = obj;
            return(true);
        }
Пример #5
0
        /// <summary>
        /// Loads and adds an object to the simulation.
        /// </summary>
        /// <param name="object">Object to add to simulation.</param>
        public void AddObject(SimulationObject @object)
        {
            @object.OnLoad(Editor);

            if (@object is Wall)
            {
                objects.Add(@object);
            }
            else
            {
                objects.Insert(0, @object);
            }

            if (@object is ISelectable selectable && selectable.Selectable)
            {
                SelectObject(selectable);
            }

            if (@object is IPersistent)
            {
                ObjectAdded?.Invoke(this, new EventArgs());
            }

            // Cannon test
            if (@object is Cannon cannon)
            {
                cannon.Fired -= CannonFired;
                cannon.Fired += CannonFired;
            }
        }
Пример #6
0
        /// <summary>Invokes <see cref="ObjectAdded"/> and <see cref="CollectionChanged"/> events.</summary>
        /// <param name="item">Added item.</param>
        protected virtual void InvokeObjectAdded(TObject item)
        {
            Verify.Argument.IsNotNull(item, nameof(item));

            ObjectAdded?.Invoke(this, CreateEventArgs(item));
            CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(
                                          NotifyCollectionChangedAction.Add, item));
        }
Пример #7
0
        public void PlaceObject(string type, TilePos position, Dictionary <string, object> properties = null)
        {
            RemoveObject(position);

            _objects[position] = new PuzzleObject(type, position);

            if (properties != null)
            {
                properties.ToList().ForEach(x => SetProperty(position, x.Key, x.Value));
            }

            ObjectAdded.CallEvent(type, position);
        }
Пример #8
0
        private void CreateCustomObject()
        {
            var obj = new CustomModel();

            obj.Config.ID.Generate();
            obj.GenerateNewGeolayout();
            ButtonItem item;

            if (ImportNewModel(obj))
            {
                objBank.Models.Add(obj);
                item = AddItemToList(obj);
                item.RaiseClick();
                ObjectAdded?.Invoke(this, new EventArgs());
            }
        }
Пример #9
0
        /// <summary>
        /// Sets the terrain at the given objects location to the given object, overwriting any terrain already present there.
        /// </summary>
        /// <param name="terrain">Terrain to replace the current terrain with. <paramref name="terrain"/> must have its
        /// <see cref="IGameObject.IsStatic"/> flag set to true and its <see cref="IHasLayer.Layer"/> must be 0, or an exception will be thrown.</param>
        public void SetTerrain(IGameObject terrain)
        {
            if (terrain.Layer != 0)
            {
                throw new ArgumentException($"Terrain for Map must reside on layer 0.", nameof(terrain));
            }

            if (!terrain.IsStatic)
            {
                throw new ArgumentException($"Terrain for Map must be marked static via its {nameof(IGameObject.IsStatic)} flag.", nameof(terrain));
            }

            if (terrain.CurrentMap != null)
            {
                throw new ArgumentException($"Cannot add terrain to more than one {nameof(Map)}.", nameof(terrain));
            }

            if (!this.Contains(terrain.Position))
            {
                throw new ArgumentException($"Terrain added to map must be within the bounds of that map.");
            }

            if (!terrain.IsWalkable)
            {
                foreach (var obj in Entities.GetItems(terrain.Position))
                {
                    if (!obj.IsWalkable)
                    {
                        throw new Exception("Tried to place non-walkable terrain at a location that already has another non-walkable item.");
                    }
                }
            }

            var oldTerrain = _terrain[terrain.Position];

            if (oldTerrain != null)
            {
                oldTerrain.OnMapChanged(null);
                ObjectRemoved?.Invoke(this, new ItemEventArgs <IGameObject>(oldTerrain, oldTerrain.Position));
            }

            _terrain[terrain.Position] = terrain;

            terrain.OnMapChanged(this);
            ObjectAdded?.Invoke(this, new ItemEventArgs <IGameObject>(terrain, terrain.Position));
        }
        public void Insert <T>(T obj) where T : Sprite
        {
            if (obj == null)
            {
                return;
            }

            lock (Generator.Random)
            {
                obj.Serial = Generator.GenerateNumber();
            }

            lock (syncLock)
            {
                if (obj is Aisling)
                {
                    _aislings.Add(obj);
                }

                if (obj is Monster)
                {
                    _monsters.Add(obj);
                }

                if (obj is Mundane)
                {
                    _mundanes.Add(obj);
                }

                if (obj is Money)
                {
                    _money.Add(obj);
                }

                if (obj is Item)
                {
                    _items.Add(obj);
                }

                ObjectAdded?.Invoke(obj);
            }
        }
Пример #11
0
        public static void ChangeMade(int id, Operation operation)
        {
            switch (operation)
            {
            case Operation.ADD:
                ObjectAdded?.Invoke(id);
                break;

            case Operation.REMOVE:
                ObjectDeleted?.Invoke(id);
                break;

            case Operation.VALUE_CHANGE:
                ValueChanged?.Invoke(id);
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Adds a new object to the collection of selected objects.
        /// </summary>
        /// <param name="obj">The object to add.</param>
        public void Add(T obj)
        {
            if (obj == null)
            {
                return;
            }

            if (_selectedObjs.Contains(obj))
            {
                return;
            }

            _selectedObjs.Add(obj);

            OnObjectAdded(obj);
            if (ObjectAdded != null)
            {
                ObjectAdded.Raise(this, EventArgsHelper.Create(obj));
            }

            UpdateSelection();
        }
Пример #13
0
        public static T CreateNew()
        {
            //Edge case where we have not initialized the factory with a prefab.
            if (prefab == null)
            {
                Debug.LogError("Factory must be instantiated before use. No prefab set.");
            }

            if (managers.Count == 0)
            {
                Debug.LogError($"Factory for {typeof(T).ToString()} must be instantiated before use. No managers added.");
            }

            T script;

            if (cachedObjects.Count > 0)
            {
                script = cachedObjects.Dequeue();
                script.gameObject.SetActive(true);
                script.Reset();
            }
            else
            {
                var newObj = GameObject.Instantiate(prefab);
                script            = FindScript(newObj);
                script.Destroyed += Script_Destroyed;
            }

            foreach (var manager in managers)
            {
                manager.Add(script);
            }

            ObjectAdded?.Invoke(script);
            return(script);
        }
Пример #14
0
        public bool Add(ISimpleGameObject obj)
        {
            if (!AddToPrimaryRegionAndTiles(obj))
            {
                return(false);
            }

            // Keeps track of objects that exist in the map
            obj.InWorld = true;

            RegisterObjectEventListeners(obj);

            // Add appropriate objects to the minimap
            IMiniMapRegionObject miniMapRegionObject = obj as IMiniMapRegionObject;

            if (miniMapRegionObject != null)
            {
                MiniMapRegions.Add(miniMapRegionObject);
            }

            // Post to channel
            ushort regionId = regionLocator.GetRegionIndex(obj);

            channel.Post("/WORLD/" + regionId, () =>
            {
                var packet = new Packet(Command.ObjectAdd);
                packet.AddUInt16(regionId);
                PacketHelper.AddToPacket(obj, packet);
                return(packet);
            });

            // Raise event
            ObjectAdded.Raise(this, new ObjectEvent(obj));

            return(true);
        }
Пример #15
0
        /// <summary>
        /// Constructor.  Constructs map with the given terrain layer, determining width/height based on the width/height of that terrain layer.
        /// </summary>
        /// <remarks>
        /// Because of the way polymorphism works for custom classes in C#, the <paramref name="terrainLayer"/> parameter MUST be of type
        /// <see cref="ISettableMapView{IGameObject}"/>, rather than <see cref="ISettableMapView{T}"/> where T is a type that derives from or implements
        /// <see cref="IGameObject"/>.  If you need to use a map view storing type T rather than IGameObject, use the
        /// <see cref="CreateMap{T}(ISettableMapView{T}, int, Distance, uint, uint, uint)"/> function to create the map.
        /// </remarks>
        /// <param name="terrainLayer">The <see cref="ISettableMapView{IGameObject}"/> that represents the terrain layer for this map.  After the
        /// map has been created, you should use the <see cref="SetTerrain(IGameObject)"/> function to modify the values in this map view, rather
        /// than setting the values via the map view itself -- if you re-assign the value at a location via the map view, the
        /// <see cref="ObjectAdded"/>/<see cref="ObjectRemoved"/> events are NOT guaranteed to be called, and many invariants of map may not be properly
        /// enforced.</param>
        /// <param name="numberOfEntityLayers">Number of non-terrain layers for the map.</param>
        /// <param name="distanceMeasurement"><see cref="Distance"/> measurement to use for pathing/measuring distance on the map.</param>
        /// <param name="layersBlockingWalkability">Layer mask containing those layers that should be allowed to have items that block walkability.
        /// Defaults to all layers.</param>
        /// <param name="layersBlockingTransparency">Layer mask containing those layers that should be allowed to have items that block FOV.
        /// Defaults to all layers.</param>
        /// <param name="entityLayersSupportingMultipleItems">Layer mask containing those layers that should be allowed to have multiple objects at the same
        /// location on the same layer.  Defaults to no layers.</param>
        public Map(ISettableMapView <IGameObject> terrainLayer, int numberOfEntityLayers, Distance distanceMeasurement, uint layersBlockingWalkability = uint.MaxValue,
                   uint layersBlockingTransparency = uint.MaxValue, uint entityLayersSupportingMultipleItems = 0)
        {
            _terrain = terrainLayer;
            Explored = new ArrayMap <bool>(_terrain.Width, _terrain.Height);

            _entities = new LayeredSpatialMap <IGameObject>(numberOfEntityLayers, 1, entityLayersSupportingMultipleItems);

            LayersBlockingWalkability  = layersBlockingWalkability;
            LayersBlockingTransparency = layersBlockingTransparency;

            _entities.ItemAdded   += (s, e) => ObjectAdded?.Invoke(this, e);
            _entities.ItemRemoved += (s, e) => ObjectRemoved?.Invoke(this, e);
            _entities.ItemMoved   += (s, e) => ObjectMoved?.Invoke(this, e);

            if (layersBlockingTransparency == 1)             // Only terrain so we optimize
            {
                TransparencyView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, c => _terrain[c] == null || _terrain[c].IsTransparent);
            }
            else
            {
                TransparencyView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, FullIsTransparent);
            }

            if (layersBlockingWalkability == 1)             // Similar, only terrain blocks, so optimize
            {
                WalkabilityView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, c => _terrain[c] == null || _terrain[c].IsWalkable);
            }
            else
            {
                WalkabilityView = new LambdaMapView <bool>(_terrain.Width, _terrain.Height, FullIsWalkable);
            }

            _fov  = new FOV(TransparencyView);
            AStar = new AStar(WalkabilityView, distanceMeasurement);
        }
Пример #16
0
 public void OnObjectAdded(Album a)
 {
     ObjectAdded?.Invoke(this, new ObjectAddedEventArgs <Album>(a));
 }
Пример #17
0
 public static void AddObject(GameObject gameObject)
 {
     sceneObjects.Add(gameObject);
     SceneObjectListChanged?.Invoke(gameObject, new EventArgs());
     ObjectAdded?.Invoke(gameObject, new EventArgs());
 }