using Otter;

namespace GiraffeRoller.ui.PauseMenu
{
    public class PauseMenuBackground : Entity
    {
        private bool _one = true;
        public static bool IsDestroy;

        public PauseMenuBackground(float x, float y)
        {
            AddGraphic(Image.CreateRectangle(350, 240, Color.Black));
            Layer = -10;
            Group = 100;//this is my pause menu group. (i know it's weird but you have to get used to it!)
        }
        public override void Update()
        {
            base.Update();
            X = Scene.CameraX + 150;
            Y = Scene.CameraY + 100;
            if (!PauseMenuBubble.IsChangingEscape && (Global.PausePersonSession.Controller.Button("PPEscape").Pressed || IsDestroy))
                Destroy();

            if (_one)
            {
                _one = false;
                WriteWord(325, 150, "Options: ", Color.White, 1f, -10);
                WriteWord(275, 190, "Audio", Color.White, 1f, -10);
                WriteWord(275, 210, "Controls", Color.White, 1f, -10);
                WriteWord(275, 230, "Return To Game", Color.White, 1f, -10);
                WriteWord(275, 250, "Shut this game down", Color.White, 1f, -10);
            }
        }

        public void WriteWord(float x, float y, string word, Color color, float scale, int layer)
        {
            var a = 0;
            for (var i = 0; i < word.Length; i++)
            {
                Scene.Add(new PauseMenuNumbers(x + a, y, word[i].ToString(), color, scale, layer));
                a += 8;
            }
        }

        public void Destroy()
        {
            var menunumbers = Scene.GetEntities<PauseMenuNumbers>();
            foreach (var number in menunumbers)
            {
                number.RemoveSelf();
            }
            IsDestroy = false;//reset.
            RemoveSelf();
        }
    }
}
