using Otter;

namespace PpbbffttMiningHa.ui
{
    class GemsInHand : Entity
    {
        public MovingNumbers place_units;
        public MovingNumbers place_tens;
        public MovingNumbers place_hundreds;
        public long holdingNumber = 0;
        public int size = 0;
        public bool isUnit = false;
        public bool isTens = false;
        public bool isHundreds = false;
        private int unitsStart = 0;
        private int tensStart = 0;
        private int hunStart = 0;

        private int startingPositionX = -100;
        private int startingPositionY = 462;

        public GemsInHand(int spX, int spY)
        {
            startingPositionX = spX;
            startingPositionY = spY;
        }
        public override void Added()
        {
            base.Added();
            Global.GAME.Scene.Add(place_units = new MovingNumbers(startingPositionX + 112, startingPositionY, "0", Color.FromBytes(3, 153, 209, 255)));
            Global.GAME.Scene.Add(place_tens = new MovingNumbers(startingPositionX + 104, startingPositionY, " ", Color.FromBytes(3, 153, 209, 255)));
            Global.GAME.Scene.Add(place_hundreds = new MovingNumbers(startingPositionX + 96, startingPositionY, " ", Color.FromBytes(3, 153, 209, 255)));
        }
        public override void Update()
        {
            base.Update();
            if (holdingNumber != Global.GemsInHand)
            {
                size = (Global.GemsInHand.ToString()).Length;
                if (size == 1) Units();
                if (size == 2) Tens();
                if (size == 3) Hundreds();
                if (isUnit) place_units.c = (Global.GemsInHand.ToString()).Substring(unitsStart, 1);
                else place_units.c = "";
                if (isTens) place_tens.c = (Global.GemsInHand.ToString()).Substring(tensStart, 1);
                else place_tens.c = "";
                if (isHundreds) place_hundreds.c = (Global.GemsInHand.ToString()).Substring(hunStart, 1);
                else place_hundreds.c = "";

                holdingNumber = Global.GemsInHand;
            }
        }
        public void Units()
        {
            isUnit = true; unitsStart = 0;
            isTens = false;
            isHundreds = false;
        }
        public void Tens()
        {
            isUnit = true; unitsStart = 1;
            isTens = true; tensStart = 0;
            isHundreds = false;
        }
        public void Hundreds()
        {
            isUnit = true; unitsStart = 2;
            isTens = true; tensStart = 1;
            isHundreds = true; hunStart = 0;
        }
    }
}


