using Otter;

namespace PpbbffttMiningHa.ui.PauseMenu
{
    public class PauseMenuControlOptions : Entity
    {
        private bool _one = true;
        public static bool IsDestroy;
        private Session _app = Global.PlayerSession;
        private Session _pp = Global.PausePersonSession;

        public PauseMenuControlOptions(float x, float y)
        {
            AddGraphic(Image.CreateRectangle(690, 300, 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!)
            _app.Data.Import();
            _pp.Data.Import();
        }
        public override void Update()
        {
            base.Update();
            X = Scene.CameraX + 10;
            Y = Scene.CameraY + 100;
            if (!PauseMenuBubble.IsChangingEscape && (Global.PausePersonSession.Controller.Button("PPEscape").Pressed || IsDestroy))
                Destroy();
            if (_one)
            {
                _one = false;
                WriteWord(275, 110, "Controller Options: ", Color.White, 1f, -10);
                WriteWord(25, 150, "Player 1 Controls:", Color.Green, 1f, -10);
                WriteWord(25, 170, "Up:   " + _app.Data.GetStringOrDefault("P1Up"), Color.Green, 1f, -10);
                WriteWord(25, 190, "Down: " + _app.Data.GetStringOrDefault("P1Down"), Color.Green, 1f, -10);
                WriteWord(25, 210, "Left: " + _app.Data.GetStringOrDefault("P1Left"), Color.Green, 1f, -10);
                WriteWord(25, 230, "Right:" + _app.Data.GetStringOrDefault("P1Right"), Color.Green, 1f, -10);
                WriteWord(25, 250, "Jump: " + _app.Data.GetStringOrDefault("P1Jump"), Color.Green, 1f, -10);
                WriteWord(25, 270, "Fire: " + _app.Data.GetStringOrDefault("P1Fire"), Color.Green, 1f, -10);
                WriteWord(25, 290, "Start:" + _app.Data.GetStringOrDefault("P1Start"), Color.Green, 1f, -10);
                WriteWord(25, 310, "Escape:" + _app.Data.GetStringOrDefault("P1Escape"), Color.Green, 1f, -10);
                WriteWord(25, 350, "Set P1 to Defaults", Color.Green, 1f, -10);
                WriteWord(325, 370, "Go Back", 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();
        }
    }
}
