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

// Token: 0x02000174 RID: 372
public class ScreenKeyboardManager : MonoBehaviour
{
	// Token: 0x1700015A RID: 346
	// (get) Token: 0x06000A93 RID: 2707 RVA: 0x0002EA38 File Offset: 0x0002CC38
	private static ScreenKeyboardManager Instance
	{
		get
		{
			if (ScreenKeyboardManager.m_instance == null)
			{
				GameObject gameObject = GameObject.Find("_ScreenKeyboardManager");
				if (gameObject == null)
				{
					gameObject = new GameObject("_ScreenKeyboardManager");
				}
				ScreenKeyboardManager.m_instance = gameObject.AddComponent<ScreenKeyboardManager>();
				ScreenKeyboardManager.m_instance.m_inputText = string.Empty;
			}
			return ScreenKeyboardManager.m_instance;
		}
	}

	// Token: 0x1700015B RID: 347
	// (get) Token: 0x06000A94 RID: 2708 RVA: 0x0002EA98 File Offset: 0x0002CC98
	public static string InputText
	{
		get
		{
			return ScreenKeyboardManager.Instance.m_inputText;
		}
	}

	// Token: 0x1700015C RID: 348
	// (set) Token: 0x06000A95 RID: 2709 RVA: 0x0002EAA4 File Offset: 0x0002CCA4
	public static string DebugInputText
	{
		set
		{
			ScreenKeyboardManager.Instance.m_inputText = value;
		}
	}

	// Token: 0x1700015D RID: 349
	// (get) Token: 0x06000A96 RID: 2710 RVA: 0x0002EAB4 File Offset: 0x0002CCB4
	public static bool IsCancel
	{
		get
		{
			return false;
			//return ScreenKeyboardManager.Instance.m_keyboard.wasCanceled;
		}
	}

	// Token: 0x06000A97 RID: 2711 RVA: 0x0002EAC8 File Offset: 0x0002CCC8
	public static IEnumerator Open(string defaultString = "")
	{
		bool isKeyboardActive = true;
		int width = 350;
		int height = 50;
		int fontSize = 24;
		Color fontColor = Color.white;
		Color inputBoxColor = new Color(87f/255f,48f / 255f, 55f / 255f, 255f / 255f);

		GameObject manager= ScreenKeyboardManager.Instance.gameObject;

		Canvas canvas = manager.AddComponent<Canvas>();
		canvas.gameObject.AddComponent<CanvasScaler>();
		canvas.gameObject.AddComponent<GraphicRaycaster>();
		canvas.renderMode = RenderMode.ScreenSpaceOverlay;

		GameObject container = new GameObject();
		container.name = "InputField";
		container.transform.parent = canvas.transform;
		container.AddComponent<CanvasRenderer>();

		Image _image = container.AddComponent<Image>();
		//_image.sprite = UnityEditor.AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd");
		_image.type = Image.Type.Sliced;
		_image.color = inputBoxColor;

		Font font = (Font)Resources.Load("font/Cabin");

		GameObject textContainer = new GameObject();
		textContainer.name = "Text";
		textContainer.transform.parent = container.transform;
		Text _text = textContainer.AddComponent<Text>();
		RectTransform _textTransform = _text.GetComponent<RectTransform>();
		_textTransform.sizeDelta = new Vector2(width, height);
		_text.supportRichText = false;
		_text.color = fontColor;
		_text.font = font;
		_text.fontSize = fontSize;
		_text.horizontalOverflow = HorizontalWrapMode.Overflow;
		_text.alignment = TextAnchor.MiddleCenter;

		GameObject placeholderContainer = new GameObject();
		placeholderContainer.name = "Placeholder";
		placeholderContainer.transform.parent = container.transform;
		Text _placeholder = placeholderContainer.AddComponent<Text>();
		RectTransform _placeholderTransform = _placeholder.GetComponent<RectTransform>();
		_placeholderTransform.sizeDelta = new Vector2(width, height);
		_placeholder.color = fontColor;
		_placeholder.font = font;
		_placeholder.fontSize = fontSize;
		_placeholder.fontStyle = FontStyle.Italic;
		_placeholder.supportRichText = false;
		_placeholder.horizontalOverflow = HorizontalWrapMode.Overflow;
		_placeholder.text = "Enter your Name";
		_placeholder.alignment = TextAnchor.MiddleCenter;

		InputField _inputField = container.AddComponent<InputField>();
		_inputField.targetGraphic = _image;
		_inputField.textComponent = _text;
		_inputField.placeholder = _placeholder;
		RectTransform _inputFieldTransform = _inputField.GetComponent<RectTransform>();
		_inputFieldTransform.localPosition = new Vector3(0, 0, 0);
		_inputFieldTransform.sizeDelta = new Vector2(width, height);
		_inputField.characterLimit = 7;
		_inputField.characterValidation = InputField.CharacterValidation.Name;
		_inputField.text = defaultString;

		string nameString = _inputField.text;

		while (isKeyboardActive)
		{
			yield return 0;
            if (Input.GetKeyDown(KeyCode.Return))
            {
				nameString = _inputField.text;
				ScreenKeyboardManager.Instance.m_inputText = nameString;
				GameObject.Destroy(canvas.gameObject);
				isKeyboardActive = false;

			}
		}
		
		//TODO fix TouchScreenKeyboard issue
		/*ScreenKeyboardManager.Instance.m_inputText = defaultString;
		ScreenKeyboardManager.Instance.m_keyboard = TouchScreenKeyboard.Open(defaultString, TouchScreenKeyboardType.NamePhonePad);
		while (!ScreenKeyboardManager.Instance.m_keyboard.active)
		{
			yield return 0;
		}
		while (ScreenKeyboardManager.Instance.m_keyboard.active)
		{
			yield return 0;
		}
		if (ScreenKeyboardManager.Instance.m_keyboard.done)
		{
			ScreenKeyboardManager.Instance.m_inputText = ScreenKeyboardManager.Instance.m_keyboard.text;
		}*/
		yield break;
	}

	// Token: 0x06000A98 RID: 2712 RVA: 0x0002EAEC File Offset: 0x0002CCEC
	public static void Close()
	{
		if (ScreenKeyboardManager.m_instance != null)
		{
			UnityEngine.Object.Destroy(ScreenKeyboardManager.m_instance.gameObject);
			ScreenKeyboardManager.m_instance = null;
		}
	}

	// Token: 0x04000885 RID: 2181
	private static ScreenKeyboardManager m_instance;

	// Token: 0x04000886 RID: 2182
	//private TouchScreenKeyboard m_keyboard;

	// Token: 0x04000887 RID: 2183
	private string m_inputText;
}
