/// <summary>The update element position.</summary>
        /// <param name="unitOverlayElement">The unit overlay element.</param>
        /// <param name="basePosition">The base position.</param>
        /// <returns>The <see cref="Vector2" />.</returns>
        public virtual Vector2 UpdateElementPosition(IUnitOverlayElement unitOverlayElement, Vector2 basePosition)
        {
            if (!unitOverlayElement.Enabled)
            {
                return(Vector2.Zero);
            }

            var addition = Vector2.Zero;

            if (this.PositionFromElementHealthbarFunc != null)
            {
                addition += this.PositionFromElementHealthbarFunc.Invoke(unitOverlayElement);
            }

            unitOverlayElement.Position = addition + basePosition;

            // if (this.Vertical)
            // {
            // unitOverlayElement.Position +=
            // new Vector2(this.Unit.ScreenInfo.HealthBarSize.X / 2 - unitOverlayElement.Size.X / 2, 0);
            // }
            if (this.PositionFromLastElementFunc != null)
            {
                addition += this.PositionFromLastElementFunc.Invoke(unitOverlayElement);
            }

            return(addition);
        }
        /// <summary>
        ///     The remove element.
        /// </summary>
        /// <param name="element">
        ///     The element.
        /// </param>
        public void RemoveElement(IUnitOverlayElement element)
        {
            var tempList = this.StoredElements.ToList();

            element.Panel = null;
            tempList.Remove(element);
            this.StoredElements = tempList;
        }
 /// <summary>Initializes a new instance of the <see cref="LeftPanelField" /> class.</summary>
 /// <param name="unit">The unit.</param>
 /// <param name="parent">The parent.</param>
 public LeftPanelField(IAbilityUnit unit, IUnitOverlayElement parent)
     : base(
         unit,
         parent,
         () => unit.Overlay.HealthBar.Position,
         PanelDirection.Left,
         element => - new Vector2(element.Size.X, 0))
 {
 }
 /// <summary>Initializes a new instance of the <see cref="RightPanelField" /> class.</summary>
 /// <param name="unit">The unit.</param>
 /// <param name="parent">The parent.</param>
 public RightPanelField(IAbilityUnit unit, IUnitOverlayElement parent)
     : base(
         unit,
         parent,
         () => unit.Overlay.HealthBar.Position + new Vector2(unit.Overlay.HealthBar.Size.X, 0),
         PanelDirection.Right,
         null,
         element => new Vector2(element.Size.X, 0))
 {
 }
 protected PanelField(
     IAbilityUnit unit,
     IUnitOverlayElement parent,
     Func <Vector2> basePosition,
     PanelDirection panelDirection,
     Func <IUnitOverlayElement, Vector2> positionFromHealthbar   = null,
     Func <IUnitOverlayElement, Vector2> positionFromLastElement = null)
 {
     this.Unit           = unit;
     this.BasePosition   = basePosition;
     this.PanelDirection = panelDirection;
     this.ParentElement  = parent;
     this.StoredElements = new List <IUnitOverlayElement>();
     this.Position       = this.BasePosition.Invoke();
     this.PositionFromElementHealthbarFunc = positionFromHealthbar;
     this.PositionFromLastElementFunc      = positionFromLastElement;
     this.Vertical = panelDirection == PanelDirection.Top || panelDirection == PanelDirection.Bottom;
     this.Size     = parent.Size;
 }
        /// <summary>
        ///     The add element.
        /// </summary>
        /// <param name="element">
        ///     The element.
        /// </param>
        public void AddElement(IUnitOverlayElement element)
        {
            var tempList = this.StoredElements.ToList();

            element.Panel = this;
            tempList.Add(element);
            this.StoredElements = tempList.OrderByDescending(this.ElementPriority).ToList();

            // switch (this.PanelDirection)
            // {
            // case PanelDirection.Left:
            // this.StoredElements = tempList.OrderByDescending(x => x.Size.Y + x.Size.X / 2).ToList();
            // break;
            // case PanelDirection.Right:
            // this.StoredElements = tempList.OrderByDescending(x => x.Size.Y + x.Size.X / 2).ToList();
            // break;
            // case PanelDirection.Bottom:
            // this.StoredElements = tempList.OrderByDescending(x => x.Size.X + x.Size.Y / 2).ToList();
            // break;
            // default:
            // this.StoredElements = tempList.OrderByDescending(x => x.Size.X + x.Size.Y / 2).ToList();
            // break;
            // }
        }
 /// <summary>The element priority.</summary>
 /// <param name="element">The element.</param>
 /// <returns>The <see cref="float" />.</returns>
 public override float ElementPriority(IUnitOverlayElement element)
 {
     return(element.Size.Y + element.Size.X / 2);
 }
 /// <summary>The element priority.</summary>
 /// <param name="element">The element.</param>
 /// <returns>The <see cref="float" />.</returns>
 public abstract float ElementPriority(IUnitOverlayElement element);
 /// <summary>Initializes a new instance of the <see cref="TopPanelField" /> class.</summary>
 /// <param name="unit">The unit.</param>
 /// <param name="parent">The parent.</param>
 public TopPanelField(IAbilityUnit unit, IUnitOverlayElement parent)
     : base(unit, parent, () => parent.Position, PanelDirection.Top, element => - new Vector2(0, element.Size.Y))
 {
 }