/*
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 MicroControllerXCues : MicroController
    {
        protected AudioManager audioManager;
        private EyeSkillsCameraRigEditMode parentManager;
        public GameObject leftCue, rightCue;
        private bool active = false;

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

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

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

        private void activateCues()
        {
            leftCue.SetActive(true);
            rightCue.SetActive(true);
        }

        private void deactivateCues()
        {
            leftCue.SetActive(false);
            rightCue.SetActive(false);
        }

        public void Update()
        {
            // Here we have our actual control interface - to add and remove our cues.
            // This is really annoying having this extra Update logic here, but enabling/disabling the script was making
            // life really complex- it doesn't happen instantaneously, but requires waiting for a full iteration AFAIK
            if (active)
            {
                if (Input.GetButton("EyeSkills Up"))
                {
                    Debug.Log("Activating Cues");
                    activateCues();
                }
                else if (Input.GetButton("EyeSkills Down"))
                {
                    Debug.Log("Deactivating Cues");
                    deactivateCues();
                }
                else if (Input.GetButton("EyeSkills Confirm") || (Input.GetButton("EyeSkills Cancel")))
                {
                    Shutdown();
                }
            }
        }
    }
}