using System;
using DarkTonic.MasterAudio;
using UnityEngine;
using UnityEngine.EventSystems;

// Token: 0x020000E3 RID: 227
public class WindowHandles : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler
{
	// Token: 0x060014E6 RID: 5350 RVA: 0x001937F2 File Offset: 0x001919F2
	private void Awake()
	{
		if (this.window)
		{
			this.window.linkedPortrait;
		}
	}

	// Token: 0x060014E7 RID: 5351 RVA: 0x00193814 File Offset: 0x00191A14
	public void OnPointerEnter(PointerEventData eventData)
	{
		if (Input.GetMouseButton(0))
		{
			this.canClick = false;
			return;
		}
		Links.x.gameplay.uiCanClick = true;
		this.canClick = true;
		if (this.forResizing || this.forDragging)
		{
			Links.x.gameplay.resizing = true;
		}
		if (this.left && !this.up && !this.down)
		{
			Links.x.SetCursor("Resize Left", true);
		}
		if (this.right && !this.up && !this.down)
		{
			Links.x.SetCursor("Resize Right", true);
		}
		if ((this.down || this.up) && !this.right && !this.left)
		{
			Links.x.SetCursor("Resize Up", true);
		}
		if (this.left && this.up)
		{
			Links.x.SetCursor("Resize LeftUp", true);
		}
		if (this.right && this.up)
		{
			Links.x.SetCursor("Resize RightUp", true);
		}
		if (this.left && this.down)
		{
			Links.x.SetCursor("Resize RightUp", true);
		}
		if (this.right && this.down)
		{
			Links.x.SetCursor("Resize LeftUp", true);
		}
		if (this.forDragging)
		{
			this.window.linkedPortrait;
		}
		if (this.forStartingResizeMode && !Records.x.movingWindows && this.window.linkedPortrait)
		{
			this.window.linkedPortrait.skillBag.TooltipOn(null, base.gameObject, "Resize/Move Windows", true);
		}
		if (this.forStartingResizeMode && Records.x.movingWindows && this.window.linkedPortrait && !this.window.dragging && !this.window.resizing && !Links.x.gameplay.resizing)
		{
			this.window.linkedPortrait.skillBag.TooltipOn(null, base.gameObject, "Resizing Complete", true);
		}
	}

	// Token: 0x060014E8 RID: 5352 RVA: 0x00193A3C File Offset: 0x00191C3C
	public void OnPointerExit(PointerEventData eventData)
	{
		if (!this.window.dragging && !this.window.resizing)
		{
			Links.x.gameplay.uiCanClick = false;
			Links.x.gameplay.resizing = false;
			if (!this.forStartingResizeMode || (this.forStartingResizeMode && !Records.x.movingWindows))
			{
				Links.x.SetCursor("Point", true);
			}
		}
		if (this.forStartingResizeMode && this.window.linkedPortrait)
		{
			this.window.linkedPortrait.skillBag.TooltipOff();
		}
		this.canClick = false;
	}

	// Token: 0x060014E9 RID: 5353 RVA: 0x00193AE8 File Offset: 0x00191CE8
	public void OnPointerDown(PointerEventData eventData)
	{
		this.clickedDown = true;
		this.clickTime = Time.realtimeSinceStartup;
		this.window.tr.SetAsLastSibling();
		if (this.forDragging)
		{
			this.window.StartDrag();
		}
		if (this.forResizing)
		{
			this.window.OnResizeBegins(this.left, this.right, this.up, this.down);
		}
		bool flag = this.forDragging;
		if (this.forStartingResizeMode && this.canClick && this.clickedDown)
		{
			this.window.ToggleResizeDrag();
			this.window.linkedPortrait.skillBag.TooltipOff();
			if (Records.x.movingWindows)
			{
				this.window.portraitHandle = this;
				this.window.checkForDrag = true;
			}
		}
		if (this.forMinimizing)
		{
			this.window.ToggleMinimize();
		}
		this.window.currentHandle = this;
		Links.x.gameplay.StoneSoundQuieter();
	}

	// Token: 0x060014EA RID: 5354 RVA: 0x00193BE8 File Offset: 0x00191DE8
	public void CheckForDrag()
	{
		if (Time.realtimeSinceStartup > this.clickTime + 0.75f && Input.GetMouseButton(0) && Links.x.mk)
		{
			this.window.OnDragBegins();
			this.clickTime = 0f;
			this.window.checkForDrag = false;
		}
		if (!Input.GetMouseButton(0) && Links.x.mk)
		{
			this.clickTime = 0f;
			this.window.checkForDrag = false;
		}
	}

	// Token: 0x060014EB RID: 5355 RVA: 0x00193C6C File Offset: 0x00191E6C
	public void OnPointerUp(PointerEventData eventData)
	{
		if (Input.GetMouseButton(0))
		{
			return;
		}
		if (this.forDragging && !this.window.linkedPortrait)
		{
			Links.x.SetCursor("Point", true);
		}
		this.clickTime = 0f;
		this.clickedDown = false;
		MasterAudio.PlaySoundAndForget("Click up", Random.Range(0.8f, 1f), new float?(Random.Range(0.97f, 1f)), 0f, "", null);
		Links.x.gameplay.uiCanClick = false;
	}

	// Token: 0x04002453 RID: 9299
	public bool forDragging;

	// Token: 0x04002454 RID: 9300
	public bool forResizing;

	// Token: 0x04002455 RID: 9301
	public bool forMinimizing;

	// Token: 0x04002456 RID: 9302
	public bool forStartingResizeMode;

	// Token: 0x04002457 RID: 9303
	public Windows window;

	// Token: 0x04002458 RID: 9304
	public string soundName = "Clicks Stone A";

	// Token: 0x04002459 RID: 9305
	public bool left;

	// Token: 0x0400245A RID: 9306
	public bool right;

	// Token: 0x0400245B RID: 9307
	public bool up;

	// Token: 0x0400245C RID: 9308
	public bool down;

	// Token: 0x0400245D RID: 9309
	private bool clickedDown;

	// Token: 0x0400245E RID: 9310
	private bool canClick;

	// Token: 0x0400245F RID: 9311
	private Color startColor;

	// Token: 0x04002460 RID: 9312
	private float clickTime;
}
