﻿
using UnityEngine;
using ORKFramework.CompassNavigatorPro;
using CompassNavigatorPro;
using System.Collections.Generic;

namespace ORKFramework.Events.Steps
{
	[ORKEditorHelp("CNP Fade In", "Fades in the Compass Navigator Pro UI.", "")]
	[ORKEventStep(typeof(BaseEvent))]
	[ORKNodeInfo("UI/Compass Navigator Pro")]
	public class CNPFadeInStep : BaseEventStep
	{
		[ORKEditorInfo(labelText="Duration")]
		public EventFloat duration = new EventFloat(1);

		[ORKEditorHelp("Wait", "Wait for the defined duration before the next node is executed", "")]
		public bool wait = false;

		public CNPFadeInStep()
		{

		}

		public override void Execute(BaseEvent baseEvent)
		{
			float tmp = this.duration.GetValue(baseEvent);
			if(CompassPro.instance != null)
			{
				CompassPro.instance.FadeIn(tmp);
			}

			if(this.wait)
			{
				baseEvent.StartTime(tmp, this.next);
			}
			else
			{
				baseEvent.StepFinished(this.next);
			}
		}


		/*
		============================================================================
		Node name functions
		============================================================================
		*/
		public override string GetNodeDetails()
		{
			return this.duration.GetInfoText() +
				(this.wait ? " s (wait)" : " s");
		}
	}

	[ORKEditorHelp("CNP Fade Out", "Fades out the Compass Navigator Pro UI.", "")]
	[ORKEventStep(typeof(BaseEvent))]
	[ORKNodeInfo("UI/Compass Navigator Pro")]
	public class CNPFadeOutStep : BaseEventStep
	{
		[ORKEditorInfo(labelText="Duration")]
		public EventFloat duration = new EventFloat(1);

		[ORKEditorHelp("Wait", "Wait for the defined duration before the next node is executed", "")]
		public bool wait = false;

		public CNPFadeOutStep()
		{

		}

		public override void Execute(BaseEvent baseEvent)
		{
			float tmp = this.duration.GetValue(baseEvent);
			if(CompassPro.instance != null)
			{
				CompassPro.instance.FadeOut(tmp);
			}

			if(this.wait)
			{
				baseEvent.StartTime(tmp, this.next);
			}
			else
			{
				baseEvent.StepFinished(this.next);
			}
		}


		/*
		============================================================================
		Node name functions
		============================================================================
		*/
		public override string GetNodeDetails()
		{
			return this.duration.GetInfoText() +
				(this.wait ? " s (wait)" : " s");
		}
	}

	[ORKEditorHelp("CNP Focus POI", "Makes a point of interest the principal POI.", "")]
	[ORKEventStep(typeof(BaseEvent))]
	[ORKNodeInfo("UI/Compass Navigator Pro")]
	public class CNPFocusPOIStep : BaseEventStep
	{
		[ORKEditorInfo(labelText="POI Object")]
		public EventObjectSetting usedObject = new EventObjectSetting();

		public CNPFocusPOIStep()
		{

		}

		public override void Execute(BaseEvent baseEvent)
		{
			CompassProPOI poi = ComponentHelper.Get<CompassProPOI>(
				this.usedObject.GetObject(baseEvent));
			if(poi != null &&
				CompassPro.instance != null)
			{
				CompassPro.instance.POIFocus(poi);
			}
			baseEvent.StepFinished(this.next);
		}


		/*
		============================================================================
		Node name functions
		============================================================================
		*/
		public override string GetNodeDetails()
		{
			return this.usedObject.GetInfoText();
		}
	}

	[ORKEditorHelp("CNP Blur POI", "Cancels focusing a point of interest.", "")]
	[ORKEventStep(typeof(BaseEvent))]
	[ORKNodeInfo("UI/Compass Navigator Pro")]
	public class CNPBlurPOIStep : BaseEventStep
	{
		public CNPBlurPOIStep()
		{

		}

		public override void Execute(BaseEvent baseEvent)
		{
			if(CompassPro.instance != null)
			{
				CompassPro.instance.POIBlur();
			}
			baseEvent.StepFinished(this.next);
		}
	}

	[ORKEditorHelp("CNP Show Beacon", "Activates a light beacon on a defined point of interest or all unvisited POIs.", "")]
	[ORKEventStep(typeof(BaseEvent))]
	[ORKNodeInfo("UI/Compass Navigator Pro")]
	public class CNPShowBeaconStep : BaseEventStep
	{
		[ORKEditorInfo(labelText="Duration")]
		public EventFloat duration = new EventFloat(1);

		[ORKEditorHelp("Wait", "Wait for the defined duration before the next node is executed", "")]
		public bool wait = false;

		[ORKEditorInfo(labelText="Horizontal Scale")]
		public EventFloat horizontalScale = new EventFloat(1);

		[ORKEditorHelp("All Unvisited", "Shows the light beacon on all unvisited points of interest.", "")]
		[ORKEditorInfo(separator=true, labelText="POI Object")]
		public bool allUnvisited = true;

		[ORKEditorLayout("allUnvisited", false, endCheckGroup=true)]
		public EventObjectSetting usedObject = new EventObjectSetting();

		public CNPShowBeaconStep()
		{

		}

		public override void Execute(BaseEvent baseEvent)
		{
			float tmp = this.duration.GetValue(baseEvent);
			if(this.allUnvisited)
			{
				if(CompassPro.instance != null)
				{
					CompassPro.instance.POIShowBeacon(
						tmp, this.horizontalScale.GetValue(baseEvent));
				}
			}
			else
			{
				CompassProPOI poi = ComponentHelper.Get<CompassProPOI>(
				this.usedObject.GetObject(baseEvent));
				if(poi != null &&
					CompassPro.instance != null)
				{
					CompassPro.instance.POIShowBeacon(poi,
						tmp, this.horizontalScale.GetValue(baseEvent));
				}
			}

			if(this.wait)
			{
				baseEvent.StartTime(tmp, this.next);
			}
			else
			{
				baseEvent.StepFinished(this.next);
			}
		}


		/*
		============================================================================
		Node name functions
		============================================================================
		*/
		public override string GetNodeDetails()
		{
			return (this.allUnvisited ?
					"All Unvisited: " : this.usedObject.GetInfoText() + ": ") +
				this.duration.GetInfoText() + (this.wait ? " s (wait)" : " s");
		}
	}

	[ORKEditorHelp("CNP Show Text", "Triggers CNP text appearing animation with a custom text.", "")]
	[ORKEventStep(typeof(BaseEvent))]
	[ORKNodeInfo("UI/Compass Navigator Pro")]
	public class CNPShowTextStep : BaseEventStep
	{
		[ORKEditorInfo(labelText="Text")]
		public StringValue text = new StringValue();

		public CNPShowTextStep()
		{

		}

		public override void Execute(BaseEvent baseEvent)
		{
			if(CompassPro.instance != null)
			{
				CompassPro.instance.ShowAnimatedText(this.text.GetValue());
			}
			baseEvent.StepFinished(this.next);
		}


		/*
		============================================================================
		Node name functions
		============================================================================
		*/
		public override string GetNodeDetails()
		{
			return this.text.GetInfoText();
		}
	}

	[ORKEditorHelp("CNP Clear POI States", "Removes all point of interest states stored by ORK Framework.", "")]
	[ORKEventStep(typeof(BaseEvent))]
	[ORKNodeInfo("UI/Compass Navigator Pro")]
	public class CNPClearPOIStatesStep : BaseEventStep
	{
		public CNPClearPOIStatesStep()
		{

		}

		public override void Execute(BaseEvent baseEvent)
		{
			Settings.Instance.ClearPOIStates();

			baseEvent.StepFinished(this.next);
		}
	}

	[ORKEditorHelp("CNP Visit POI", "Sets a point of interest to be visited or unvisited.", "")]
	[ORKEventStep(typeof(BaseEvent))]
	[ORKNodeInfo("UI/Compass Navigator Pro")]
	public class CNPVisitPOIStep : BaseEventStep
	{
		[ORKEditorHelp("Visit/Unvisit", "If enabled, the POI is set to visited.\n" +
			"If disabled, the POI is set to unvisited.", "")]
		public bool visited = false;

		[ORKEditorInfo(separator=true, labelText="POI Object")]
		public EventObjectSetting usedObject = new EventObjectSetting();

		public CNPVisitPOIStep()
		{

		}

		public override void Execute(BaseEvent baseEvent)
		{
			List<CompassProPOI> poi = ComponentHelper.GetAll<CompassProPOI>(
				this.usedObject.GetObject(baseEvent));
			for(int i = 0; i < poi.Count; i++)
			{
				if(poi[i] != null)
				{
					Settings.Instance.VisitPOI(poi[i], this.visited);
				}
			}
			baseEvent.StepFinished(this.next);
		}


		/*
		============================================================================
		Node name functions
		============================================================================
		*/
		public override string GetNodeDetails()
		{
			return this.usedObject.GetInfoText() +
				(this.visited ? ": Visit" : ": Unvisit");
		}
	}
}
