Esempio n. 1
0
        public void Translate(Time delta)
        {
            if (GeneralDuration.Value == null)
            {
                return;
            }

            if (delta == Time.Zero)
            {
                return;
            }

            foreach (var item in items)
            {
                var newduration = item.Duration + delta;

                ItemMoved?.Invoke(item.Duration, newduration, item.Value);

                item.Duration = newduration;
            }

            elements_start.Translate(delta);
            elements_end.Translate(delta);

            FieldChanged?.Invoke(GeneralDuration.Value | (GeneralDuration.Value + delta));
            GeneralDuration.Value += delta;
        }
Esempio n. 2
0
        public void MoveTo(ContentItem item, ContentItem parent, int index)
        {
            if (item.Parent != parent || !parent.Children.Contains(item))
            {
                item.AddTo(parent);
                if (ItemMoved != null)
                {
                    ItemMoved.Invoke(this, new DestinationEventArgs(item, parent));
                }
            }
            else if (parent.Children.Contains(item) && parent.Children.Last() != item)
            {
                item.AddTo(null);
                item.AddTo(parent);
            }

            IList <ContentItem> siblings = parent.Children;

            Utility.MoveToIndex(siblings, item, index);
            using (var tx = persister.Repository.BeginTransaction())
            {
                persister.Repository.SaveOrUpdate(item);
                foreach (ContentItem updatedItem in Utility.UpdateSortOrder(siblings))
                {
                    persister.Repository.SaveOrUpdate(updatedItem);
                }
                tx.Commit();
            }
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public void MoveValid(Point current, Point target, List <T> itemsMovedOutput)
        {
            if (current == target)
            {
                return;
            }

            if (!_positionMapping.TryGetValue(current, out var item))
            {
                return;
            }

            if (_positionMapping.ContainsKey(target))
            {
                return;
            }

            itemsMovedOutput.Add(item);

            _positionMapping.Remove(current);
            _positionMapping[target] = item;
            _itemMapping[item]       = target;

            ItemMoved?.Invoke(this, new ItemMovedEventArgs <T>(item, current, target));
        }
Esempio n. 4
0
        public bool TryMoveUnique(Duration oldduration, Duration newduration)
        {
            var durateditem = items.FirstOrDefault(item => item.Duration == oldduration);

            if (durateditem == null)
            {
                return(false);
            }

            if (oldduration.Start != newduration.Start)
            {
                elements_start.Remove(durateditem, oldduration.Start);
                elements_start.Add(durateditem, newduration.Start);
            }

            if (oldduration.End != newduration.End)
            {
                elements_end.Remove(durateditem, oldduration.End);
                elements_end.Add(durateditem, newduration.End);
            }

            durateditem.Duration = newduration;

            ItemMoved?.Invoke(oldduration, newduration, durateditem.Value);

            return(true);
        }
Esempio n. 5
0
        protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs args)
        {
            switch (args.Action)
            {
            case NotifyCollectionChangedAction.Add:
                ItemAdded?.Invoke(this, args.NewStartingIndex, (T)args.NewItems[0]);
                OnCountChanged();
                break;

            case NotifyCollectionChangedAction.Remove:
                ItemRemoved?.Invoke(this, args.OldStartingIndex, (T)args.OldItems[0]);
                OnCountChanged();
                break;

            case NotifyCollectionChangedAction.Move:
                ItemMoved?.Invoke(this, args.OldStartingIndex, args.NewStartingIndex, (T)args.NewItems[0]);
                break;

            case NotifyCollectionChangedAction.Replace:
                ItemReplaced?.Invoke(this, args.OldStartingIndex, (T)args.OldItems[0], (T)args.NewItems[0]);
                break;

            case NotifyCollectionChangedAction.Reset:
                ItemsReset?.Invoke(this);
                OnCountChanged();
                break;
            }
            CollectionChanged?.Invoke(this, args);
        }
Esempio n. 6
0
        private HashSet <Coord> _positionCache;        // Cached hash-set used for returning all positions in the LayeredSpatialMap

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="comparer">
        /// Equality comparer to use for comparison and hashing of type T. Be especially mindful of the
        /// efficiency of its GetHashCode function, as it will determine the efficiency of
        /// many AdvancedLayeredSpatialMap functions.
        /// </param>
        /// <param name="numberOfLayers">Number of layers to include.</param>
        /// <param name="startingLayer">Index to use for the first layer.</param>
        /// <param name="layersSupportingMultipleItems">
        /// A layer mask indicating which layers should support multiple items residing at the same
        /// location on that layer. Defaults to no layers.
        /// </param>
        public AdvancedLayeredSpatialMap(IEqualityComparer <T> comparer, int numberOfLayers, int startingLayer = 0, uint layersSupportingMultipleItems = 0)
        {
            if (numberOfLayers > 32 - startingLayer)
            {
                throw new ArgumentOutOfRangeException(nameof(numberOfLayers), $"More than {32 - startingLayer} layers is not supported by {nameof(AdvancedLayeredSpatialMap<T>)} starting at layer {startingLayer}");
            }

            _layers        = new ISpatialMap <T> [numberOfLayers];
            StartingLayer  = startingLayer;
            _positionCache = new HashSet <Coord>();

            LayerMasker          = new LayerMasker(numberOfLayers + startingLayer);
            _internalLayerMasker = new LayerMasker(numberOfLayers);

            for (int i = 0; i < _layers.Length; i++)
            {
                if (LayerMasker.HasLayer(layersSupportingMultipleItems, i + StartingLayer))
                {
                    _layers[i] = new AdvancedMultiSpatialMap <T>(comparer);
                }
                else
                {
                    _layers[i] = new AdvancedSpatialMap <T>(comparer);
                }
            }

            foreach (var layer in _layers)
            {
                layer.ItemAdded   += (_, e) => ItemAdded?.Invoke(this, e);
                layer.ItemRemoved += (_, e) => ItemRemoved?.Invoke(this, e);
                layer.ItemMoved   += (_, e) => ItemMoved?.Invoke(this, e);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Moves the item at the specified source location to the target location.  Throws ArgumentException if one or
        /// more items cannot be moved, eg.
        /// if no item exists at the current position or the new position is already filled by some other item.
        /// </summary>
        /// <param name="current">Location to move items from.</param>
        /// <param name="target">Location to move items to.</param>
        public void MoveAll(Point current, Point target)
        {
            if (current == target)
            {
                throw new ArgumentException(
                          $"Tried to move all items from {current} in {GetType().Name}, but the current and target positions were the same.",
                          nameof(target));
            }

            if (!_positionMapping.TryGetValue(current, out var item))
            {
                throw new ArgumentException(
                          $"Tried to move item from {current} in {GetType().Name}, but there was nothing at the that position.",
                          nameof(current));
            }

            if (_positionMapping.ContainsKey(target))
            {
                throw new ArgumentException(
                          $"Tried to move item at a location in {GetType().Name}, but the target position already contains an item.",
                          nameof(target));
            }

            _positionMapping.Remove(current);
            _positionMapping[target] = item;
            _itemMapping[item]       = target;

            ItemMoved?.Invoke(this, new ItemMovedEventArgs <T>(item, current, target));
        }
Esempio n. 8
0
        /// <summary>
        /// Moves the item specified to the position specified. Throws ArgumentException if the item
        /// does not exist in the spatial map or if the position is already filled by some other item.
        /// </summary>
        /// <param name="item">Item to move.</param>
        /// <param name="target">Location to move item to.</param>
        public void Move(T item, Point target)
        {
            Point oldPos;

            try
            {
                oldPos = _itemMapping[item];
            }
            catch (KeyNotFoundException)
            {
                throw new ArgumentException(
                          $"Tried to move item in {GetType().Name}, but the item does not exist.",
                          nameof(item));
            }

            try
            {
                _positionMapping.Add(target, item);
            }
            catch (ArgumentException)
            {
                throw new ArgumentException(
                          $"Tried to move item in {GetType().Name}, but the target position already contains an item.",
                          nameof(target));
            }

            _positionMapping.Remove(oldPos);
            _itemMapping[item] = target;
            ItemMoved?.Invoke(this, new ItemMovedEventArgs <T>(item, oldPos, target));
        }
Esempio n. 9
0
        public void Move(int oldindex, int newindex)
        {
            T item;

            lock (locker) {
                item             = intern[oldindex];
                status[oldindex] = false;

                while (newindex >= intern.Count)
                {
                    intern.Add(default(T));
                }

                if (status[newindex] == true)
                {
                    var olditem = intern[newindex];

                    ItemRemoved?.Invoke(olditem);
                    ItemWithdrawn?.Invoke(olditem, newindex);
                }
                else
                {
                    status[newindex] = true;
                }

                intern[newindex] = item;
            }

            ItemMoved?.Invoke(item, oldindex, newindex);
        }
Esempio n. 10
0
        public void MoveTo(ContentItem item, ContentItem parent)
        {
            if (item.Parent == parent)
            {
                // move it last
                item.AddTo(null);
                item.AddTo(parent);
            }
            else if (item.Parent == null || !parent.Children.Contains(item))
            {
                item.AddTo(parent);
                if (ItemMoved != null)
                {
                    ItemMoved.Invoke(this, new DestinationEventArgs(item, parent));
                }
            }

            using (var tx = persister.Repository.BeginTransaction())
            {
                foreach (ContentItem updatedItem in Utility.UpdateSortOrder(parent.Children))
                {
                    persister.Repository.SaveOrUpdate(updatedItem);
                }
                tx.Commit();
            }
        }
Esempio n. 11
0
        public void Move(IDuratedItem <T> item, Duration newduration)
        {
            var durateditem =
                item as DuratedItem <T> ??
                items.FirstOrDefault(_ => _.Duration == item.Duration && _.Value.Equals(item.Value));

            var oldduration =
                item.Duration;

            if (oldduration == newduration)
            {
                return;
            }

            if (oldduration.Start != newduration.Start)
            {
                elements_start.Remove(durateditem, oldduration.Start);
                elements_start.Add(durateditem, newduration.Start);
            }

            if (oldduration.End != newduration.End)
            {
                elements_end.Remove(durateditem, oldduration.End);
                elements_end.Add(durateditem, newduration.End);
            }

            durateditem.Duration = newduration;

            ItemMoved?.Invoke(oldduration, newduration, item.Value);
        }
Esempio n. 12
0
        /// <inheritdoc />
        public bool TryMove(T item, Point target)
        {
            if (!_itemMapping.TryGetValue(item, out Point oldPos))
            {
                return(false);
            }

            if (oldPos == target)
            {
                return(false);
            }

            // Key guaranteed to exist due to state invariant of spatial map (oldPos existed in the other map)
            var oldPosList = _positionMapping[oldPos];

            // We'll get the target list now as well, since we can do some special case shortcutting if the target doesn't
            // exist and the source has only one element.  C# doesn't offer a nice Get-Or-Insert type function, so this
            // will have to do.  This at least keeps it to two lookups max.
            if (!_positionMapping.TryGetValue(target, out var targetList))
            {
                // If the existing list has only the item we're moving, and the target doesn't exist, we'll just
                // switch the list over to avoid any removing and interacting with the pool.  This also handles a special case
                // where no list exists in the pool, but the one for the old position is about to be freed.  This ensures
                // that, in this case, the list will simply be hot-swapped over instead of a new one allocated then the
                // old one added to the pool after.
                if (oldPosList.Count == 1)
                {
                    _positionMapping[target] = oldPosList;
                    _positionMapping.Remove(oldPos);
                    _itemMapping[item] = target;
                    ItemMoved?.Invoke(this, new ItemMovedEventArgs <T>(item, oldPos, target));
                    return(true);
                }

                // Otherwise, we'll have to get a new list.
                _positionMapping[target] = targetList = _itemListPool.Rent();
            }

            // Add item to target list
            targetList.Add(item);

            // Remove the old one, and if it was the last item, return the list to the pool.  It could be the last
            // item if and only if the target list already existed (so the above code does not return)
            oldPosList.Remove(item);
            if (oldPosList.Count == 0)
            {
                _itemListPool.Return(oldPosList, false);
                _positionMapping.Remove(oldPos);
            }

            // Switch position of item in spatial map, and fire moved event.
            _itemMapping[item] = target;
            ItemMoved?.Invoke(this, new ItemMovedEventArgs <T>(item, oldPos, target));

            return(true);
        }
Esempio n. 13
0
        private void UiTreeView_ItemMoved(ITreeItem itemView, ITreeFolder oldParentView, ITreeFolder newParentView, int index)
        {
            //Data에 적용하기
            UiItem     item              = ((UiItemView)itemView).Data;
            UiItem     newParentItem     = ((UiItemView)newParentView).Data;
            UiItemView oldParentItemView = (oldParentView as UiItemView);

            if (oldParentItemView != null)
            {
                oldParentItemView.Data.RemoveChildItem(item);
            }
            newParentItem.InsertChildItem(index, item);

            ItemMoved?.Invoke(item, newParentItem, oldParentItemView.Data);
        }
Esempio n. 14
0
        private OperationResponse ItemOperationMove(MmoItem item, Move operation, SendParameters sendParameters, MmoActor actor) {
            // should always be OK
            MethodReturnValue result = this.CheckAccess(item, actor);

            if (result) {
                // save previous for event
                float[] oldPosition = item.transform.position.ToArray();
                float[] oldRotation = item.transform.rotation.ToArray();

                // move
                item.transform.SetRotation(operation.Rotation);
                item.Move(operation.Position);

                float speed = 0f;
                var ship = item.GetComponent<PlayerShip>();
                var movalble = item.GetComponent<MovableObject>();
                if(ship) {
                    speed = movalble.speed;
                }

                // send event
                var eventInstance = new ItemMoved {
                    ItemId = item.Id,
                    ItemType = item.Type,
                    OldPosition = oldPosition,
                    Position = operation.Position,
                    Rotation = operation.Rotation,
                    OldRotation = oldRotation,
                    Speed = speed
                };

                var eventData = new EventData((byte)EventCode.ItemMoved, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                //I ADDED toMOVE AT POSITION
                //item.ReceiveEvent(eventData, sendParameters);

                // no response sent
                operation.OnComplete();
                return null;
            }

            return operation.GetOperationResponse(result);
        }
Esempio n. 15
0
        /// <inheritdoc />
        public bool TryMove(T item, Point target)
        {
            if (!_itemMapping.TryGetValue(item, out Point oldPos))
            {
                return(false);
            }

            if (!_positionMapping.TryAdd(target, item))
            {
                return(false);
            }

            _positionMapping.Remove(oldPos);
            _itemMapping[item] = target;
            ItemMoved?.Invoke(this, new ItemMovedEventArgs <T>(item, oldPos, target));

            return(true);
        }
Esempio n. 16
0
        public void PublishMove(float[] fromPos, float[] fromRot, float[] toPos, float[] toRot, float speed)
        {
            if (nebulaObject)
            {
                var eventInstance = new ItemMoved {
                    ItemId      = nebulaObject.Id,
                    ItemType    = nebulaObject.Type,
                    OldPosition = fromPos,
                    Position    = toPos,
                    OldRotation = fromRot,
                    Rotation    = toRot,
                    Speed       = speed
                };

                var            eventData      = new EventData((byte)EventCode.ItemMoved, eventInstance);
                SendParameters sendParameters = new SendParameters {
                    ChannelId = Settings.ItemEventChannel, Unreliable = true
                };
                var message = new ItemEventMessage(nebulaObject as Item, eventData, sendParameters);
                (nebulaObject as Item).EventChannel.Publish(message);
            }
        }
        private void ClientRpcMoveItem(NetworkConnection conn, int instanceID, int fromCollectionIndex, int toCollectionIndex, int fromSlot, int toSlot)
        {
            NetworkIdentity identity       = NetworkIdentityManager.Instance.Get(instanceID);
            InventoryItem   item           = identity.GetComponent <InventoryItem>();
            ItemCollection  fromCollection = GetCollectionFromIndex(fromCollectionIndex);
            ItemCollection  toCollection   = GetCollectionFromIndex(toCollectionIndex);

            bool contains = toCollection.Contains(item);

            if (fromCollection == toCollection || !toCollection.IsReferenceCollection)
            {
                fromCollection[fromSlot] = null;
            }

            toCollection[toSlot] = item;

            if (!contains)
            {
                ItemAdded?.Invoke(toCollection, item, toSlot);
            }
            else
            {
                ItemMoved?.Invoke(fromCollection, toCollection, fromSlot, toSlot, item);
            }

            if (toCollection == fromCollection)
            {
                toCollection.RepaintUI();
                return;
            }

            if (fromCollection[fromSlot] == null)
            {
                ItemRemoved?.Invoke(fromCollection, item, fromSlot);
            }

            toCollection.RepaintUI();
            fromCollection.RepaintUI();
        }
Esempio n. 18
0
        /// <inheritdoc/>
        public bool TryMoveAll(Point current, Point target)
        {
            if (current == target)
            {
                return(false);
            }

            if (!_positionMapping.TryGetValue(current, out var item))
            {
                return(false);
            }

            if (_positionMapping.ContainsKey(target))
            {
                return(false);
            }

            _positionMapping.Remove(current);
            _positionMapping[target] = item;
            _itemMapping[item]       = target;

            ItemMoved?.Invoke(this, new ItemMovedEventArgs <T>(item, current, target));
            return(true);
        }
Esempio n. 19
0
 protected virtual void OnItemMoved(TradeItem item, bool modified, int difference)
 {
     ItemMoved?.Invoke(this, item, modified, difference);
 }
Esempio n. 20
0
 protected virtual void OnItemMoved(int oldIndex, int newIndex, T item)
 {
     ItemMoved?.Invoke(oldIndex, newIndex, item);
 }
Esempio n. 21
0
 protected virtual void OnItemMoved(int oldIndex, int newIndex)
 {
     ItemMoved?.Invoke(this, oldIndex, newIndex);
 }
Esempio n. 22
0
        public void MoveTo(ContentItem item, NodePosition position, ContentItem relativeTo)
        {
            if (relativeTo == null)
            {
                throw new ArgumentNullException("item");
            }
            if (relativeTo == null)
            {
                throw new ArgumentNullException("relativeTo");
            }
            if (relativeTo.Parent == null)
            {
                throw new ArgumentException("The supplied item '" + relativeTo + "' has no parent to add to.", "relativeTo");
            }

            using (var tx = persister.Repository.BeginTransaction())
            {
                if (item.Parent == null ||
                    item.Parent != relativeTo.Parent ||
                    !item.Parent.Children.Contains(item))
                {
                    item.AddTo(relativeTo.Parent);
                    if (ItemMoved != null)
                    {
                        ItemMoved.Invoke(this, new DestinationEventArgs(item, relativeTo.Parent));
                    }
                    //foreach (ContentItem updatedItem in item.UpdateAncestralTrailRecursive(relativeTo.Parent))
                    //{
                    //	persister.Repository.SaveOrUpdate(updatedItem);
                    //}
                }

                IList <ContentItem> siblings = item.Parent.Children;

                int itemIndex       = siblings.IndexOf(item);
                int relativeToIndex = siblings.IndexOf(relativeTo);

                if (itemIndex < 0)
                {
                    if (position == NodePosition.Before)
                    {
                        siblings.Insert(relativeToIndex, item);
                    }
                    else
                    {
                        siblings.Insert(relativeToIndex + 1, item);
                    }
                }
                else if (itemIndex < relativeToIndex && position == NodePosition.Before)
                {
                    MoveTo(item, relativeToIndex - 1);
                }
                else if (itemIndex > relativeToIndex && position == NodePosition.After)
                {
                    MoveTo(item, relativeToIndex + 1);
                }
                else
                {
                    MoveTo(item, relativeToIndex);
                }

                tx.Commit();
            }
        }