//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, October 10, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Text;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class PwdKeyboardWin : Window
|
{
|
|
[SerializeField] List<Button> numBtns;
|
[SerializeField] Button clearBtn;
|
[SerializeField] Button okBtn;
|
[SerializeField] Text value;
|
[SerializeField] GameObject valueTip;
|
|
private readonly int limit = 6;
|
|
private static StringBuilder textBuilder = new StringBuilder();
|
|
public static event Action<bool> OnPwdWinClose;
|
|
private bool hasClose = false;
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
for (int i = 0; i < numBtns.Count; i++)
|
{
|
var _index = i;
|
numBtns[_index].onClick.AddListener(() =>
|
{
|
OnNumClick(_index);
|
});
|
}
|
clearBtn.onClick.AddListener(OnClearBtn);
|
okBtn.onClick.AddListener(OnOkBtn);
|
}
|
|
protected override void OnPreOpen()
|
{
|
textBuilder.Length = 0;
|
textBuilder.Append(PwdKeyboard.Instance.pwd);
|
value.text = textBuilder.ToString();
|
if (textBuilder.Length == 0)
|
{
|
valueTip.SetActive(true);
|
}
|
else
|
{
|
valueTip.SetActive(false);
|
}
|
hasClose = false;
|
|
transform.SetAsLastSibling();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
PwdKeyboard.Instance.pwd = textBuilder.ToString();
|
if (OnPwdWinClose != null)
|
{
|
OnPwdWinClose(hasClose);
|
}
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
#endregion
|
|
private void OnNumClick(int num)
|
{
|
if (textBuilder.Length < limit)
|
{
|
textBuilder.Append(num);
|
value.text = textBuilder.ToString();
|
}
|
if (valueTip.activeSelf)
|
{
|
valueTip.SetActive(false);
|
}
|
}
|
private void OnOkBtn()
|
{
|
hasClose = true;
|
CloseImmediately();
|
}
|
|
private void OnClearBtn()
|
{
|
textBuilder.Length = 0;
|
value.text = textBuilder.ToString();
|
valueTip.SetActive(true);
|
PwdKeyboard.Instance.pwd = string.Empty;
|
}
|
}
|
}
|