using System;
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

// Token: 0x020000DF RID: 223
public class Tooltip : MonoBehaviour
{
	// Token: 0x060014BD RID: 5309 RVA: 0x00191404 File Offset: 0x0018F604
	private void Start()
	{
		this.txt.text = "";
		this.tr = this.tooltip.GetComponent<RectTransform>();
		this.anim = base.gameObject.GetComponent<Animator>();
		this.v = new Vector3[4];
		this.anim.SetBool("Open", false);
		this.startParent = this.tr.parent;
	}

	// Token: 0x060014BE RID: 5310 RVA: 0x00191471 File Offset: 0x0018F671
	public void AddHoverText(string add, GameObject hoverObj, string direction)
	{
		this.currText = add;
		this.DoHover(add, hoverObj, direction);
	}

	// Token: 0x060014BF RID: 5311 RVA: 0x00191484 File Offset: 0x0018F684
	public Vector3 WorldToUISpace(Canvas parentCanvas, Vector3 worldPos)
	{
		if (this.dir == "Character" && !Links.x.worldCamera.orthographic)
		{
			Vector3 vector = Links.x.worldCamera.WorldToViewportPoint(worldPos);
			vector.x -= 0.5f;
			worldPos.x += vector.x * 2f;
		}
		Vector3 vector2 = Links.x.worldCamera.WorldToScreenPoint(worldPos);
		Vector2 vector3;
		RectTransformUtility.ScreenPointToLocalPointInRectangle(parentCanvas.transform as RectTransform, vector2, parentCanvas.worldCamera, out vector3);
		return parentCanvas.transform.TransformPoint(vector3);
	}

	// Token: 0x060014C0 RID: 5312 RVA: 0x00191530 File Offset: 0x0018F730
	public void DoHover(string add, GameObject hoverObj, string direction)
	{
		bool flag = false;
		if (this.coroutine != null)
		{
			base.StopCoroutine(this.coroutine);
			flag = true;
		}
		this.coroutine = this.StartHoverCoroutine(add, hoverObj, direction, flag);
		base.StartCoroutine(this.coroutine);
	}

	// Token: 0x060014C1 RID: 5313 RVA: 0x00191572 File Offset: 0x0018F772
	private IEnumerator StartHoverCoroutine(string add, GameObject hoverObj, string direction, bool immediate)
	{
		this.open = true;
		yield return new WaitForSecondsRealtime(0.1f);
		this.txt.text = "";
		this.dir = direction;
		this.savedObj = hoverObj;
		this.txt.spriteAsset = Links.x.GetSpriteSheetAsset(Links.x.gameplay.currentSpriteSheetAsset);
		if (!this.anim.GetCurrentAnimatorStateInfo(0).IsName("TooltipOnLoop"))
		{
			if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("TooltipOffLoop"))
			{
				this.anim.Play("TooltipOn");
			}
			else
			{
				this.anim.Play("TooltipOn", 0, 0.5f);
			}
		}
		if (!add.Contains("voffset"))
		{
			if (direction == "Down")
			{
				this.txt.margin = new Vector4(0f, 22f, 0f, 19f);
				RectOffset rectOffset = new RectOffset(this.horizontalLayoutGroup.padding.left, this.horizontalLayoutGroup.padding.right, this.horizontalLayoutGroup.padding.top, this.horizontalLayoutGroup.padding.bottom);
				rectOffset.top = -10;
				rectOffset.bottom = -10;
				this.horizontalLayoutGroup.padding = rectOffset;
			}
			else
			{
				add += "<voffset=.4em><size=0><sprite=62></size></voffset>\n";
				this.txt.margin = new Vector4(7f, 7f, 7f, 7f);
				RectOffset rectOffset2 = new RectOffset(this.horizontalLayoutGroup.padding.left, this.horizontalLayoutGroup.padding.right, this.horizontalLayoutGroup.padding.top, this.horizontalLayoutGroup.padding.bottom);
				rectOffset2.top = 15;
				rectOffset2.bottom = 12;
				this.horizontalLayoutGroup.padding = rectOffset2;
			}
		}
		else if (add.Contains("Rest"))
		{
			this.txt.margin = new Vector4(0f, 6f, 0f, 19f);
			RectOffset rectOffset3 = new RectOffset(this.horizontalLayoutGroup.padding.left, this.horizontalLayoutGroup.padding.right, this.horizontalLayoutGroup.padding.top, this.horizontalLayoutGroup.padding.bottom);
			rectOffset3.top = -10;
			rectOffset3.bottom = -10;
			this.horizontalLayoutGroup.padding = rectOffset3;
		}
		else
		{
			this.txt.margin = new Vector4(0f, -19f, -23f, 0f);
			RectOffset rectOffset4 = new RectOffset(this.horizontalLayoutGroup.padding.left, this.horizontalLayoutGroup.padding.right, this.horizontalLayoutGroup.padding.top, this.horizontalLayoutGroup.padding.bottom);
			rectOffset4.top = -10;
			rectOffset4.bottom = -10;
			this.horizontalLayoutGroup.padding = rectOffset4;
		}
		this.txt.text = add;
		if (this.open)
		{
			this.anim.SetBool("Open", true);
		}
		if (hoverObj)
		{
			if (direction == "World")
			{
				this.obj = hoverObj;
				this.tr.position = this.WorldToUISpace(this.canvas, hoverObj.transform.GetChild(0).position + new Vector3(0f, 3f, 0f));
			}
			else if (direction == "Interact")
			{
				this.obj = hoverObj;
				this.tr.position = this.WorldToUISpace(this.canvas, Vector3.zero);
			}
			else if (direction == "Character")
			{
				this.obj = hoverObj;
				this.tr.position = this.WorldToUISpace(this.canvas, Vector3.zero);
			}
			else
			{
				this.obj = null;
				RectTransform component = hoverObj.GetComponent<RectTransform>();
				if (component)
				{
					this.tr.SetParent(component.parent, true);
					this.tr.anchoredPosition3D = component.anchoredPosition3D + new Vector3(0f, this.mapAdd, 0f);
					if (direction == "UpMap")
					{
						float num = this.mapAdd;
						if (Links.x.joy)
						{
							this.mapAdd += 15f;
						}
						this.tr.anchoredPosition3D = component.anchoredPosition3D + new Vector3(0f, this.mapAdd, 0f);
					}
					if (direction == "Up")
					{
						this.tr.anchoredPosition3D = component.anchoredPosition3D + new Vector3(0f, this.upAdd, 0f);
					}
					if (direction == "UpMenuButtons")
					{
						this.tr.anchoredPosition3D = component.anchoredPosition3D + new Vector3(0f, this.upMenuBtnAdd, 0f);
					}
					if (direction == "UpMenuButtonsRight")
					{
						this.tr.anchoredPosition3D = component.anchoredPosition3D + new Vector3(50f, this.upMenuBtnAdd, 0f);
					}
					if (direction == "UpMenuButtonsLeft")
					{
						this.tr.anchoredPosition3D = component.anchoredPosition3D + new Vector3(-50f, this.upMenuBtnAdd + 50f, 0f);
					}
					if (direction == "UpEffects")
					{
						this.tr.position = hoverObj.transform.position + new Vector3(0f, this.upAdd, 0f);
					}
					if (direction == "Down")
					{
						this.tr.anchoredPosition3D = component.anchoredPosition3D + new Vector3(0f, this.upAdd * -0.5f, 0f);
					}
					if (direction == "PortraitUp")
					{
						this.tr.anchoredPosition3D = component.anchoredPosition3D + new Vector3(0f, this.portraitAdd, 0f);
					}
					if (direction == "Center")
					{
						this.tr.position = component.gameObject.transform.position;
					}
					this.tr.SetParent(this.startParent, true);
					this.img.sprite = this.activeImg;
				}
			}
		}
		this.coroutine = null;
		yield return new WaitForSecondsRealtime(0.01f);
		yield break;
	}

	// Token: 0x060014C2 RID: 5314 RVA: 0x00191598 File Offset: 0x0018F798
	public void EndHoverText(GameObject endObj, bool overrideEnd)
	{
		this.open = false;
		this.twoLines = false;
		if (!overrideEnd && endObj != this.savedObj)
		{
			return;
		}
		if (!this.anim)
		{
			return;
		}
		this.anim.SetBool("Open", false);
		if (this.coroutine != null)
		{
			base.StopCoroutine(this.coroutine);
		}
	}

	// Token: 0x040023E5 RID: 9189
	public TextMeshProUGUI txt;

	// Token: 0x040023E6 RID: 9190
	public bool hovering;

	// Token: 0x040023E7 RID: 9191
	public Image img;

	// Token: 0x040023E8 RID: 9192
	public Canvas canvas;

	// Token: 0x040023E9 RID: 9193
	private Animator anim;

	// Token: 0x040023EA RID: 9194
	private RectTransform tr;

	// Token: 0x040023EB RID: 9195
	public RectTransform rt;

	// Token: 0x040023EC RID: 9196
	public GameObject tooltip;

	// Token: 0x040023ED RID: 9197
	private Vector3[] v;

	// Token: 0x040023EE RID: 9198
	private string currText;

	// Token: 0x040023EF RID: 9199
	private IEnumerator coroutine;

	// Token: 0x040023F0 RID: 9200
	public Interact interact;

	// Token: 0x040023F1 RID: 9201
	private string dir;

	// Token: 0x040023F2 RID: 9202
	private GameObject obj;

	// Token: 0x040023F3 RID: 9203
	private GameObject savedObj;

	// Token: 0x040023F4 RID: 9204
	public bool open;

	// Token: 0x040023F5 RID: 9205
	public Sprite activeImg;

	// Token: 0x040023F6 RID: 9206
	public Sprite inactiveImg;

	// Token: 0x040023F7 RID: 9207
	public Character character;

	// Token: 0x040023F8 RID: 9208
	public bool twoLines;

	// Token: 0x040023F9 RID: 9209
	public Character player;

	// Token: 0x040023FA RID: 9210
	public HorizontalLayoutGroup horizontalLayoutGroup;

	// Token: 0x040023FB RID: 9211
	private Transform startParent;

	// Token: 0x040023FC RID: 9212
	public float portraitAdd = 15f;

	// Token: 0x040023FD RID: 9213
	public float mapAdd = 10f;

	// Token: 0x040023FE RID: 9214
	public float upAdd = 15f;

	// Token: 0x040023FF RID: 9215
	public float upMenuBtnAdd = 12f;
}
