public void Add(int productId, int quantity = 1) { var item = Items.SingleOrDefault(x => x.ProductId == productId); if (item == null) { item = new ShoppingCartItem(productId, quantity); ItemsInternal.Add(item); } else { item.Quantity += quantity; } }
public virtual bool AddChildNode(SceneNode2D node) { if (!itemHashSet.ContainsKey(node.GUID)) { itemHashSet.Add(node.GUID, node); ItemsInternal.Add(node); node.Parent = this; if (IsAttached) { node.Attach(RenderHost); } return(true); } else { return(false); } }
public void AddItem(Item item) { item.StateChanged += (ii, state) => { if (!ii.IsTransferEnd() || !ItemsInternal.All(iii => iii.IsTransferEnd())) { return; } TransferState = ItemsInternal.Any(iii => iii.TransferState == TransferState.Error) ?TransferState.Error : TransferState.Completed; if (TransferState == TransferState.Completed) { TransferredLength = Length; } }; ItemsInternal.Add(item); }
/// <summary> /// Adds the child node. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> /// <exception cref="System.ArgumentException">SceneNode already attach to a different node</exception> public bool AddChildNode(SceneNode node) { if (node != null && !itemHashSet.ContainsKey(node.GUID)) { itemHashSet.Add(node.GUID, node); ItemsInternal.Add(node); if (node.Parent != NullSceneNode.NullNode && node.Parent != this) { throw new ArgumentException("SceneNode already attach to a different node"); } node.Parent = this; if (IsAttached) { node.Attach(EffectsManager); InvalidateSceneGraph(); } ChildNodeAdded?.Invoke(this, new OnChildNodeChangedArgs(node, Operation.Add)); return(true); } else { return(false); } }
protected virtual void Sort(IList <SceneNode> nodes, RenderContext context) { sortingTransparentCache.Clear(); sortingOpaqueCache.Clear(); notSorted.Clear(); Vector3 cameraPosition = context.Camera.Position; if (SortTransparentOnly) { for (int i = 0; i < nodes.Count; ++i) { if (nodes[i].RenderCore.RenderType == RenderType.Transparent) { sortingTransparentCache.Add(new SortStruct(GetDistance(nodes[i], ref cameraPosition), nodes[i])); } else { notSorted.Add(nodes[i]); } } sortingTransparentCache.Sort(delegate(SortStruct a, SortStruct b) { return(a.Key > b.Key ? -1 : a.Key < b.Key ? 1 : 0); }); } else { for (int i = 0; i < nodes.Count; ++i) { if (nodes[i].RenderCore.RenderType == RenderType.Transparent) { sortingTransparentCache.Add(new SortStruct(GetDistance(nodes[i], ref cameraPosition), nodes[i])); } else if (nodes[i].RenderCore.RenderType == RenderType.Opaque) { sortingOpaqueCache.Add(new SortStruct(GetDistance(nodes[i], ref cameraPosition), nodes[i])); } else { notSorted.Add(nodes[i]); } } if (sortingTransparentCache.Count > 50 && sortingOpaqueCache.Count > 50) { Parallel.Invoke(() => { sortingTransparentCache.Sort(delegate(SortStruct a, SortStruct b) { return(a.Key > b.Key ? -1 : a.Key < b.Key ? 1 : 0); }); }, () => { sortingOpaqueCache.Sort(delegate(SortStruct a, SortStruct b) { return(a.Key > b.Key ? 1 : a.Key < b.Key ? -1 : 0); }); }); } else { sortingTransparentCache.Sort(delegate(SortStruct a, SortStruct b) { return(a.Key > b.Key ? -1 : a.Key < b.Key ? 1 : 0); }); sortingOpaqueCache.Sort(delegate(SortStruct a, SortStruct b) { return(a.Key > b.Key ? 1 : a.Key < b.Key ? -1 : 0); }); } } ItemsInternal.Clear(); for (int i = 0; i < notSorted.Count; ++i) { ItemsInternal.Add(notSorted[i]); } for (int i = 0; i < sortingOpaqueCache.Count; ++i) { ItemsInternal.Add(sortingOpaqueCache[i].Value); } for (int i = 0; i < sortingTransparentCache.Count; ++i) { ItemsInternal.Add(sortingTransparentCache[i].Value); } sortingTransparentCache.Clear(); sortingOpaqueCache.Clear(); notSorted.Clear(); InvalidateSceneGraph(); }