using System;
using Cute;
using UnityEngine;

public class FadeUtility
{
	private static readonly AnimationCurve FADE_ALPHA_ANIM_CURVE = AnimationCurve.Linear(0f, 0f, 1f, 1f);

	private const float FADE_FROM_ALPHA = 1f;

	private const float FADE_TO_ALPHA = 0f;

	private const float FADE_DURATION = 0.3f;

	private const float FADE_DELAY = 0f;

	public static void FadeInGameObject(GameObject obj, Action onFinish = null)
	{
		FadeFinish(obj);
		FadeInObject(obj.AddMissingComponent<UITweenAlpha>(), delegate
		{
			onFinish.Call();
		});
	}

	public static void FadeOutGameObject(GameObject obj, Action onFinish = null)
	{
		FadeFinish(obj);
		FadeOut(obj, delegate
		{
			onFinish.Call();
		});
	}

	public static void FadeOutObjectAndNonActive(GameObject obj)
	{
		FadeFinish(obj);
		FadeOut(obj, delegate
		{
			obj.SetActive(value: false);
		});
	}

	private static void FadeOut(GameObject obj, Action onFinish)
	{
		UIButtonColor button = obj.GetComponent<UIButtonColor>();
		float originalDuration = 0f;
		if (button != null)
		{
			originalDuration = button.duration;
			button.duration = 0f;
		}
		TweenColor component = obj.GetComponent<TweenColor>();
		if (component != null)
		{
			component.enabled = false;
		}
		FadeOutObject(obj.AddMissingComponent<UITweenAlpha>(), delegate
		{
			if (button != null)
			{
				button.duration = originalDuration;
			}
			onFinish();
		});
	}

	public static void ShowSoon(GameObject obj)
	{
		FadeFinish(obj);
		UISprite component = obj.GetComponent<UISprite>();
		if (component != null)
		{
			component.alpha = 1f;
		}
		obj.gameObject.SetActive(value: true);
	}

	public static void RemoveFadeObject(GameObject obj)
	{
		UITweenAlpha component = obj.GetComponent<UITweenAlpha>();
		if (component != null)
		{
			UnityEngine.Object.Destroy(component);
		}
	}

	public static void FadeFinish(GameObject obj)
	{
		UITweenAlpha component = obj.GetComponent<UITweenAlpha>();
		if (!(component == null))
		{
			component.End();
		}
	}

	public static void FadeOutObject(UITweenAlpha tweenAlpha, Action onFinish = null)
	{
		if (!(tweenAlpha == null))
		{
			if (tweenAlpha._curve == null)
			{
				tweenAlpha._curve = FADE_ALPHA_ANIM_CURVE;
				tweenAlpha._curve.postWrapMode = WrapMode.Once;
				tweenAlpha._curve.preWrapMode = WrapMode.Once;
			}
			tweenAlpha._from = 1f;
			tweenAlpha._to = 0f;
			tweenAlpha._endTime = 0.3f;
			tweenAlpha._delayTime = 0f;
			tweenAlpha._finishCallBack = delegate
			{
				onFinish.Call();
			};
			tweenAlpha.PlayForward(isReset: true);
		}
	}

	public static void FadeInObject(UITweenAlpha tweenAlpha, Action onFinish = null)
	{
		if (!(tweenAlpha == null))
		{
			if (tweenAlpha._curve == null)
			{
				tweenAlpha._curve = FADE_ALPHA_ANIM_CURVE;
				tweenAlpha._curve.postWrapMode = WrapMode.Once;
				tweenAlpha._curve.preWrapMode = WrapMode.Once;
			}
			tweenAlpha._from = 0f;
			tweenAlpha._to = 1f;
			tweenAlpha._endTime = 0.3f;
			tweenAlpha._delayTime = 0f;
			tweenAlpha._finishCallBack = delegate
			{
				onFinish.Call();
			};
			tweenAlpha.PlayForward(isReset: true);
		}
	}
}
