using System.Collections.Generic; using SM.Base.Contexts; namespace SM.Base.Scene { /// /// Contains a list of show items. /// /// The type of show items. public abstract class GenericItemCollection : List, IShowItem, IShowCollection where TItem : IShowItem { /// public List Objects => this; /// public object Parent { get; set; } /// public string Name { get; set; } = "Unnamed Item Collection"; /// public ICollection Flags { get; set; } = new[] {"collection"}; /// /// Adds a item. /// public new void Add(TItem item) { base.Add(item); item.Parent = this; item.OnAdded(this); } /// /// Removes a item. /// /// public new void Remove(TItem item) { base.Remove(item); item.Parent = null; item.OnRemoved(this); } /// public virtual void Update(UpdateContext context) { for(int i = 0; i < Objects.Count; i++) this[i].Update(context); } /// public virtual void Draw(DrawContext context) { for (int i = 0; i < Objects.Count; i++) this[i].Draw(context); } /// public virtual void OnAdded(object sender) { } /// public virtual void OnRemoved(object sender) { } /// /// Returns a object with this name or the default, if not available. /// Not reclusive. /// /// /// public TItem GetItemByName(string name) { TItem obj = default; for (var i = 0; i < this.Count; i++) { if (this[i].Name == name) { obj = this[i]; break; } } return obj; } /// /// Returns a object with this name or the default if not available. /// Not reclusive. /// /// Type of return public TGetItem GetItemByName(string name) where TGetItem : TItem { return (TGetItem)GetItemByName(name); } /// /// Returns all object that have this flag. /// Only in this list. /// public ICollection GetItemsWithFlag(string flag) { List list = new List(); for (var i = 0; i < this.Count; i++) { TItem obj = this[i]; if (obj.Flags.Contains(flag)) list.Add(obj); } return list; } } /// /// Contains a list of show items with transformation. /// /// The type of show items. /// The type of transformation. public abstract class GenericItemCollection : GenericItemCollection where TItem : IShowItem where TTransformation : GenericTransformation, new() { /// /// Transformation of the collection /// public TTransformation Transform = new TTransformation(); /// public override void Draw(DrawContext context) { context.ModelMaster = Transform.GetMatrix() * context.ModelMaster; base.Draw(context); } } }