using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Igdc.Scenes.UI.Controls;
using System.Collections.Generic;

namespace Igdc.Scenes
{
    public partial class UiScene : SceneBase<UiPackage>
    {
        private List<ControlBase> _controls;
        private int _focus;
        private FocusDirection _direction = FocusDirection.Next;

        public UiScene(GraphicsDeviceManager manager, GraphicsDevice device, UiPackage package) : base(manager, device, package)
        {
            _controls = new List<ControlBase>(package.Controls);
        }

        protected override void Draw(SceneIterationArgument e) => _controls.ForEach(c => c.Draw(e));
        protected override void Update(SceneIterationArgument e)
        {
            var control = _controls[_focus];
            control.Update(e);
            var direction = control.FocusDirection;
            if (direction == FocusDirection.Auto) direction = _direction;
            if (direction == FocusDirection.Next)
            {
                _direction = direction;
                _focus++;
                if (_focus == _controls.Count)
                    _focus = 0;
            }
            if (direction == FocusDirection.Prev)
            {
                _direction = direction;
                _focus--;
                if (_focus < 0)
                    _focus = _controls.Count - 1;
            }
        }

        public override void Dispose()
        {
        }
    }
}