/*
Copyright 2019 Dr. Thomas Benjamin Senior, Michael Zoeller 

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EyeSkills;

namespace EyeSkills
{
    /// <summary>
    /// Micro controller XCues.  Introduce some visual cues (at different locations and preferably with different colours) to help the participant report whether or not they are seeing with both eys or only one.
    /// Add this as a child script of the EyeSkills Camera Rig in the Unity Editor.
    /// </summary>
    public class MicroControllerAssetSwap : MicroController
    {
        protected AudioManager audioManager;
        private EyeSkillsCameraRigEditMode parentManager;
        private EyeSkillsInput esInput;
        private bool active = false;
        public AssetSwitcher assetSwitcher;

        public void Start()
        {
            audioManager = AudioManager.instance;
            esInput = EyeSkillsInput.instance;
        }

        public override void Shutdown()
        {
            active = false;
            parentManager.MicroControllerShutdown();
        }

        public override void Startup(EyeSkillsCameraRigEditMode _parent)
        {
            active = true;
            audioManager.Say("AssetSwapAvailable");
            parentManager = _parent;
        }


        public void Update()
        {
            /*
             * At the very least, this needs a list of possible states we can enter into in this scene.
             * It should hunt through the camera object to build a list of them.
             * Moving the cursor up/down moves through that list... we just say "next/last asset".
             */

            if (active)
            {
                if (esInput.GetShortButtonPress("EyeSkills Up"))
                {
                    Debug.Log("Next asset Switch");
                    audioManager.Say("SwappingAsset");
                    assetSwitcher.SwitchAssetsToNext();
                    //Shutdown();
                }
                else if (esInput.GetShortButtonPress("EyeSkills Confirm") || (esInput.GetShortButtonPress("EyeSkills Cancel")))
                {
                    Shutdown();
                }               
            }
        }
    }
}