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); }
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); }
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; }
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(); } }
/// <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)); }
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); }
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); }
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); } }
/// <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)); }
/// <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)); }
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(); } }
/// <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); }
/// <summary> /// Moves whatever is at position current, if anything, to postion target. If something was /// moved, returns what was moved. If nothing was moved, eg. either there was nothing at /// position current or already something at position target, returns nothing. /// </summary> /// <remarks> /// Since this implementation of ISpatialMap guarantees that only one item may be at any /// given location at a time, the returned values will either be none, or a single value. /// </remarks> /// <param name="current">The position of the item to move.</param> /// <param name="target">The position to move the item to.</param> /// <returns> /// The item moved as a 1-element IEnumerable if something was moved, or nothing if no item /// was moved. /// </returns> public IEnumerable <T> Move(Coord current, Coord target) { if (positionMapping.ContainsKey(current) && !positionMapping.ContainsKey(target)) { var movingTuple = positionMapping[current]; positionMapping.Remove(current); movingTuple.Position = target; positionMapping.Add(target, movingTuple); yield return(movingTuple.Item); ItemMoved?.Invoke(this, new ItemMovedEventArgs <T>(movingTuple.Item, current, target)); } }
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); }
/// <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); }
/// <summary> /// Constructor. /// </summary> /// <param name="itemComparer"> /// 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="customListPoolCreator"> /// A function used to determine the list pool implementation used for the spatial maps which support multiple /// items in a location (if any). The function takes the layer it is creating the pool for as a parameter. /// If no custom creator is specified, a ListPool is used. /// </param> /// <param name="pointComparer"> /// Equality comparer to use for comparison and hashing of points, as object are added to/removed from/moved /// around the spatial map. Be especially mindful of the efficiency of its GetHashCode function, as it will /// determine the efficiency of many AdvancedLayeredSpatialMap functions. Defaults to the default equality /// comparer for Point, which uses a fairly efficient generalized hashing algorithm. /// </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> itemComparer, int numberOfLayers, Func <int, IListPool <T> >?customListPoolCreator = null, IEqualityComparer <Point>?pointComparer = null, 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}"); } customListPoolCreator ??= _ => new ListPool <T>(50, 16); pointComparer ??= EqualityComparer <Point> .Default; _layers = new ISpatialMap <T> [numberOfLayers]; StartingLayer = startingLayer; _positionCache = new HashSet <Point>(pointComparer); LayerMasker = new LayerMasker(numberOfLayers + startingLayer); _internalLayerMasker = new LayerMasker(numberOfLayers); // Create layers based on mask parameters for (int i = 0; i < _layers.Length; i++) { var layerNum = i + startingLayer; if (LayerMasker.HasLayer(layersSupportingMultipleItems, layerNum)) { _layers[i] = new AdvancedMultiSpatialMap <T>(itemComparer, customListPoolCreator(layerNum), pointComparer); } else { _layers[i] = new AdvancedSpatialMap <T>(itemComparer, pointComparer); } } 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); } }
/// <summary> /// Move the item specified to the position specified. Returns true if successful. If the /// item does not exist in the SpatialMap, or the position is already filled by something, /// does nothing and returns false. Otherwise, returns true. /// </summary> /// <param name="item">The item to move.</param> /// <param name="target">The position to move it to.</param> /// <returns>True if the item was moved, false if not.</returns> public bool Move(T item, Coord target) { if (!itemMapping.ContainsKey(item.ID)) { return(false); } if (positionMapping.ContainsKey(target)) { return(false); } var movingTuple = itemMapping[item.ID]; Coord oldPos = movingTuple.Position; positionMapping.Remove(movingTuple.Position); movingTuple.Position = target; positionMapping.Add(target, movingTuple); ItemMoved?.Invoke(this, new ItemMovedEventArgs <T>(item, oldPos, target)); return(true); }
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(); }
/// <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); }
void InitializeSmartEvent() { _selected = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "selected", GenListItemEventArgs.CreateFromSmartEvent); _unselected = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "unselected", GenListItemEventArgs.CreateFromSmartEvent); _activated = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "activated", GenListItemEventArgs.CreateFromSmartEvent); _pressed = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "pressed", GenListItemEventArgs.CreateFromSmartEvent); _released = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "released", GenListItemEventArgs.CreateFromSmartEvent); _doubleClicked = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "clicked,double", GenListItemEventArgs.CreateFromSmartEvent); _expanded = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "expanded", GenListItemEventArgs.CreateFromSmartEvent); _realized = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "realized", GenListItemEventArgs.CreateFromSmartEvent); _unrealized = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "unrealized", GenListItemEventArgs.CreateFromSmartEvent); _longpressed = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "longpressed", GenListItemEventArgs.CreateFromSmartEvent); _moved = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "moved", GenListItemEventArgs.CreateFromSmartEvent); _movedAfter = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "moved,after", GenListItemEventArgs.CreateFromSmartEvent); _movedBefore = new SmartEvent <GenListItemEventArgs>(this, this.RealHandle, "moved,before", GenListItemEventArgs.CreateFromSmartEvent); _scrollAnimationStarted = new SmartEvent(this, this.RealHandle, "scroll,anim,start"); _scrollAnimationStopped = new SmartEvent(this, this.RealHandle, "scroll,anim,stop"); _changed = new SmartEvent(this, this.RealHandle, "changed"); _selected.On += (s, e) => { if (e.Item != null) { ItemSelected?.Invoke(this, e); } }; _unselected.On += (s, e) => { if (e.Item != null) { ItemUnselected?.Invoke(this, e); } }; _activated.On += (s, e) => { if (e.Item != null) { ItemActivated?.Invoke(this, e); } }; _pressed.On += (s, e) => { if (e.Item != null) { ItemPressed?.Invoke(this, e); } }; _released.On += (s, e) => { if (e.Item != null) { ItemReleased?.Invoke(this, e); } }; _doubleClicked.On += (s, e) => { if (e.Item != null) { ItemDoubleClicked?.Invoke(this, e); } }; _expanded.On += (s, e) => { if (e.Item != null) { ItemExpanded?.Invoke(this, e); } }; _realized.On += (s, e) => { if (e.Item != null) { ItemRealized?.Invoke(this, e); } }; _unrealized.On += (s, e) => { if (e.Item != null) { ItemUnrealized?.Invoke(this, e); } }; _longpressed.On += (s, e) => { if (e.Item != null) { ItemLongPressed?.Invoke(this, e); } }; _moved.On += (s, e) => { if (e.Item != null) { ItemMoved?.Invoke(this, e); } }; _movedAfter.On += (s, e) => { if (e.Item != null) { ItemMovedAfter?.Invoke(this, e); } }; _movedBefore.On += (s, e) => { if (e.Item != null) { ItemMovedBefore?.Invoke(this, e); } }; }
public void NotifyItemMoved(BasePlayerItem item, CharacterInventoryPositionEnum lastPosition) { OnItemMoved(item, lastPosition); ItemMoved?.Invoke(this, item, lastPosition); }
protected virtual void OnItemMoved(TradeItem item, bool modified, int difference) { ItemMoved?.Invoke(this, item, modified, difference); }
protected virtual void OnItemMoved(int oldIndex, int newIndex, T item) { ItemMoved?.Invoke(oldIndex, newIndex, item); }
private void BoxedCollectionItemMovedHandler(int oldIndex, int newIndex, TBoxed value) { ItemMoved?.Invoke(oldIndex, newIndex, value); }
protected virtual void OnItemMoved(int oldIndex, int newIndex) { ItemMoved?.Invoke(this, oldIndex, newIndex); }
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(); } }
private bool MoveSelectedItems(SelectedListItemSet selectedItemSet, NodeTarget target) { if (target == null) { return(false); } ITreeFolder[] selectedFolders = selectedItemSet .Where(item => item is ITreeFolder) .Select(item => item as ITreeFolder).ToArray(); //자신 내부에 이동시도시 Reject foreach (ITreeFolder folder in selectedFolders) { if (folder == target.node) { return(false); } if (IsContainsChildRecursive(folder, target.node)) { MessageOccured?.Invoke("자신의 하위 폴더로 이동할 수 없습니다."); return(false); } } //정렬 ITreeItem[] sortedSelectedItems = CollectSelectedItems(); //이동 if (target.node is ITreeFolder && target.direction == NodeDirection.Bottom && ((ITreeFolder)target.node).ChildItemCollection.Count > 0) { target.direction = NodeDirection.InnerTop; } if (target.direction == NodeDirection.Bottom || target.direction == NodeDirection.InnerTop) { sortedSelectedItems = sortedSelectedItems.Reverse().ToArray(); } foreach (ITreeItem item in sortedSelectedItems) { ITreeFolder oldParent = item.ParentItem; ITreeFolder newParent = null; int index = -1; FrameworkElement uiItem = (FrameworkElement)item; if (oldParent != null) { oldParent.ChildItemCollection.Remove(item as UIElement); } else if (uiItem.Parent != null) { ((Panel)uiItem.Parent).Children.Remove(uiItem); } if (target.direction == NodeDirection.InnerTop) { //폴더 내부로 newParent = target.node as ITreeFolder; index = 0; } else if (target.direction == NodeDirection.InnerBottom) { //폴더 내부로 newParent = target.node as ITreeFolder; index = newParent.ChildItemCollection.Count; } else { //아이템 위아래로 newParent = target.node.ParentItem; index = newParent.ChildItemCollection.IndexOf(target.node as UIElement) + (target.direction == NodeDirection.Bottom ? 1 : 0); } if (AutoApplyItemMove) { newParent.ChildItemCollection.Insert(index, item as UIElement); } item.ParentItem = newParent; ItemMoved?.Invoke(item, oldParent, newParent, index); } return(true); }
private void Move(InventoryItem fromItem, int fromSlot, ItemCollection fromCollection, int toSlot, ItemCollection toCollection) { if (!toCollection.IsAllowed(fromItem, toSlot)) { return; } if (toCollection != fromCollection && toCollection.IsReferenceCollection && toCollection.Contains(fromItem)) { return; } InventoryItem toItem = toCollection[toSlot]; if (toItem != null) { // From and to reference collections cannot be combined or swapped only replaced and destroyed.. if (!fromCollection.IsReferenceCollection && !toCollection.IsReferenceCollection) { if (toCollection.CanStackInCollection && toItem.ItemID == fromItem.ItemID && toItem.Stack < toItem.MaxStack) { Combine(fromItem, toItem, fromCollection, toCollection); return; } Swap(fromItem, fromCollection, fromSlot, toItem, toCollection, toSlot); return; } } if (!toCollection.IsReferenceCollection && !toCollection.CanStackInCollection && fromItem.Stack > 1) { fromItem.Stack--; NotifyStackChanged(fromItem, fromCollection); GameObject inst = NetworkController.Instance.Scene.CreateForClient( Identity.OwnerConnection, m_ItemDatabase.GetItem(fromItem.ItemID).gameObject, Vector3.zero, Quaternion.identity ); NetworkIdentity identity = inst.GetComponent <NetworkIdentity>(); NetworkController.Instance.RemoteProcedures.Call(Identity, RPCType.All, nameof(SharedRpcClientClaim), identity.InstanceID); SharedRpcClientClaim(identity.InstanceID); toItem = identity.GetComponent <InventoryItem>(); toCollection[toSlot] = toItem; ItemMoved?.Invoke(fromCollection, toCollection, fromSlot, toSlot, toItem); ItemAdded?.Invoke(toCollection, toItem, toSlot); NetworkController.Instance.RemoteProcedures.Call( Identity, RPCType.Target, nameof(ClientRpcMoveItem), Identity.OwnerConnection, toItem.InstanceID, GetCollectionIndex(toCollection), GetCollectionIndex(toCollection), toSlot, toSlot); return; } // You can't move an item out of a reference collection... if (fromCollection.IsReferenceCollection && fromCollection != toCollection) { return; } bool contains = toCollection.Contains(fromItem); // Do not clear the item if it's a reference collection we're dragging to. if (fromCollection == toCollection || !toCollection.IsReferenceCollection) { fromCollection[fromSlot] = null; } toCollection[toSlot] = fromItem; if (!contains) { ItemAdded?.Invoke(toCollection, fromItem, toSlot); } else { ItemMoved?.Invoke(fromCollection, toCollection, fromSlot, toSlot, fromItem); } // Only need to invoke removal if the item becomes null. if (fromCollection[fromSlot] == null && fromCollection != toCollection) { ItemRemoved?.Invoke(fromCollection, fromItem, fromSlot); } NetworkController.Instance.RemoteProcedures.Call( Identity, RPCType.Target, nameof(ClientRpcMoveItem), Identity.OwnerConnection, fromItem.InstanceID, GetCollectionIndex(fromCollection), GetCollectionIndex(toCollection), fromSlot, toSlot); }