using System.Collections.Generic;
using System.Globalization;
using System.Linq;

using Turbo.Plugins.Default;

namespace Turbo.Plugins.User
{

    public class FDragonPlugin : BasePlugin, IInGameTopPainter
    {

        public HorizontalTopLabelList LabelList { get; private set; }

        public FDragonPlugin()
            : base()
        {
            Enabled = true;
        }

        public override void Load(IController hud)
        {
            base.Load(hud);

            LabelList = new HorizontalTopLabelList(hud);

            LabelList.LeftFunc = () =>
            {
                var ui = Hud.Render.GetUiElement("Root.NormalLayer.game_dialog_backgroundScreenPC.game_window_hud_overlay");
                return ui.Rectangle.Left + ui.Rectangle.Width * 0.500f;
            };
            LabelList.TopFunc = () =>
            {
                var ui = Hud.Render.GetUiElement("Root.NormalLayer.game_dialog_backgroundScreenPC.game_window_hud_overlay");
                return ui.Rectangle.Top + ui.Rectangle.Height * 0.318f;
            };
            LabelList.WidthFunc = () =>
            {
                var ui = Hud.Render.GetUiElement("Root.NormalLayer.game_dialog_backgroundScreenPC.game_window_hud_overlay");
                return Hud.Window.Size.Height * 0.0621f;
            };
            LabelList.HeightFunc = () =>
            {
                var ui = Hud.Render.GetUiElement("Root.NormalLayer.game_dialog_backgroundScreenPC.game_window_hud_overlay");
                return Hud.Window.Size.Height * 0.025f;
            };

            LabelList.LabelDecorators.Add(new TopLabelDecorator(Hud)
            {
                TextFont = Hud.Render.CreateFont("tahoma", 10, 255, 255, 255, 255, false, false, true),
                BackgroundTexture1 = Hud.Texture.ButtonTextureOrange,
                BackgroundTexture2 = Hud.Texture.BackgroundTextureYellow,
                BackgroundTextureOpacity2 = 1f,
                TextFunc = () => "!!FD!!",
                HintFunc = () => "Flying Dragon",
            });

        }

        public void PaintTopInGame(ClipState clipState)
        {
            if (clipState != ClipState.BeforeClip) return;

            var actors = Hud.Game.Actors;
            foreach (var actor in actors)
            { if (Hud.Game.Me.Powers.BuffIsActive(246562, 1))
                            {
                                LabelList.Paint();
                            }
            }
            
        }

    }

}