using LOoSE_sLOTS.entities;
using LOoSE_sLOTS.objects;
using LOoSE_sLOTS.UI;
using LOoSE_sLOTS.Utilities;
using Otter;
using System;

namespace LOoSE_sLOTS.Scenes
{
    class TitleScreen : Scene
    {
        public Image TitleImage = new Image(Assets.TITLESCREEN);

        private Color _colorOption;
        private bool _one = true;
        public static bool isTitleAllowed = false;
        private bool justonce;
        private bool justOneMessage;

        public TitleScreen()
        {
            AddGraphic(TitleImage);
            SoundManager.PlayRequestedSound("_introCreepy");
        }

        public override void Update()
        {
            base.Update();
            if (Timer >= 450)
            {
                if (_one)
                {
                    _one = false;
                    Add(new IntroCharacter(750, 380));
                }
            }
            if (isTitleAllowed)
            {
                isTitleAllowed = false;
                for (var i = 0; i < 100; i++)
                {
                    var randColor = Rand.Int(1, 3);
                    if (randColor == 1)
                        _colorOption = Color.Magenta;
                    else if (randColor == 2)
                        _colorOption = Color.Mix(Color.Gold, Color.Orange);
                    //WriteWord(Rand.Float(0, 360), Rand.Float(-20, 480), "MONEYyyyyyyyyyyyyyyyyyyyyyyyyyyyy", _colorOption, 1f, 1);
                }
                WriteWord(121, 102, "Welcome To", Color.Gold, 2f, 1, 15);//shadow first
                WriteWord(120, 100, "Welcome To", Color.White, 2f, 1, 15);//regular text on top(second)
                WriteWord(111, 172, " LOoSE sLOTS!", Color.Orange, 6f, 1, 40);
                WriteWord(110, 170, " LOoSE sLOTS!", Color.White, 6f, 1, 40);
                WriteWord(120, 300, "Press Enter to start!", Color.Cyan, 4f, 1, 25);
                WriteWord(100, 400, "By Commanderstitch!", Color.Cyan, 3f, 1, 20);
                var incrementer = 10;
                for (var i = 0; i < 30; i++)
                {
                    Add(new SlotMachineMenu(incrementer, -50));
                    incrementer += Rand.Int(30, 50);
                }
            }
            if (Global.GiveHimTheMoney)
            {
                Global.GiveHimTheMoney = false;
                Add(new SlotMachine(Global.GAME.Scene.MouseX, Global.GAME.Scene.MouseY));
                var entities = GetEntities<Numbers>(); //remove intercom previous message.
                foreach (var item in entities)
                {
                    item.Destroy();
                }
                Global.WriteWord(300, 10, "Give him the money!", Color.Gold, 2f, 1, Global.GAME.Scene, 0);//shadow first
                Global.WriteWord(300 - 2, 10 - 2, "Give him the money!", Color.White, 2f, 1, Global.GAME.Scene, 0);//regular text on top(second)
                Add(new wall(0, 380 + 16, Global.I_MW, 16));
            }
            if (Global.NumberOfSlotMachinesDropped >= 4 && !justOneMessage)
            {
                justOneMessage = true;
                Global.WriteWord(200, 40, "Do it! Drop a Slot Machine on him!", Color.Gold, 2f, 1, Global.GAME.Scene, 0);//shadow first
                Global.WriteWord(200 - 2, 40 - 2, "Do it! Drop a Slot Machine on him!", Color.White, 2f, 1, Global.GAME.Scene, 0);//regular text on top(second)
            }
            if (Global.GaveHimHisMoney && !justonce)
            {
                justonce = true;
                var entities = GetEntities<Numbers>(); //remove intercom previous message.
                foreach (var item in entities)
                {
                    item.Destroy();
                }
                var entities2 = GetEntities<IntroCharacter>(); //remove intercom previous message.
                foreach (var item in entities2)
                {
                    item.Destroy();
                }
                var entities3 = GetEntities<SlotMachine>(); //remove intercom previous message.
                foreach (var item in entities3)
                {
                    item.Destroy();
                }
                var entities4 = GetEntities<Coin>(); //remove intercom previous message.
                foreach (var item in entities4)
                {
                    item.Destroy();
                }
                isTitleAllowed = true;
            }
            if ((Global.PlayerSession.Controller.Button("LeftMouseClick").Pressed || Global.PlayerSession.Controller.Button("Start").Pressed) && Global.GaveHimHisMoney)
            {
                SoundManager.PlayRequestedSound("_click");
                Global.GAME.RemoveScene();
                Global.GAME.AddScene(new PickupTruck());
            }
        }

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

