using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
namespace Snxxz.UI
|
{
|
public class ReikiRootPointBehaviour : MonoBehaviour
|
{
|
[SerializeField] Text m_PropertyName;
|
[SerializeField] Text m_Point;
|
[SerializeField] Button m_Add;
|
[SerializeField] Button m_Sub;
|
[SerializeField] Button m_OpenKeyboard;
|
|
public int id { get; private set; }
|
|
int m_CachePoint = 0;
|
public int point
|
{
|
get { return m_CachePoint; }
|
set
|
{
|
if (m_CachePoint != value)
|
{
|
m_CachePoint = value;
|
DisplayPoint();
|
}
|
}
|
}
|
|
public RectTransform openKeyboardBottom
|
{
|
get { return m_OpenKeyboard.transform as RectTransform; }
|
}
|
|
ReikiRootWin parent = null;
|
|
Coroutine m_Coroutine = null;
|
|
bool isPointAdd = false;
|
bool isPointSub = false;
|
|
int cacheQuality = 0;
|
|
int coroutineCount = 0;
|
|
static WaitForSeconds waitSpeedFaster = new WaitForSeconds(0.05f);
|
static WaitForSeconds waitSpeedSlow = new WaitForSeconds(0.2f);
|
|
ReikiRootModel model { get { return ModelCenter.Instance.GetModel<ReikiRootModel>(); } }
|
|
private void Awake()
|
{
|
UIEventTrigger.Get(m_Sub.gameObject).OnDown = OnSubDown;
|
UIEventTrigger.Get(m_Sub.gameObject).OnUp = OnSubUp;
|
UIEventTrigger.Get(m_Add.gameObject).OnDown = OnAddDown;
|
UIEventTrigger.Get(m_Add.gameObject).OnUp = OnAddUp;
|
m_OpenKeyboard.AddListener(OpenKeyboard);
|
}
|
|
public void Display(ReikiRootWin win, int id)
|
{
|
parent = win;
|
this.id = id;
|
|
cacheQuality = 0;
|
|
DisplayPoint();
|
|
model.onReikiRootPointRefresh += OnReikiRootPointRefresh;
|
}
|
|
void DisplayPoint()
|
{
|
var original = model.GetReikiRootPoint(id);
|
var addLabel = point == 0 ? string.Empty : UIHelper.AppendColor(TextColType.Green, "+" + point, true);
|
var quality = model.GetReikiRootQuality(id, original + point);
|
var areaPoint = model.GetQualityPoint(id, quality + 1);
|
if (areaPoint == 0)
|
{
|
m_Point.text = StringUtility.Contact(original, addLabel);
|
}
|
else
|
{
|
m_Point.text = StringUtility.Contact(original, addLabel, "/", areaPoint);
|
}
|
|
if (cacheQuality != quality)
|
{
|
var propertyConfig = PlayerPropertyConfig.Get(id);
|
m_PropertyName.text = StringUtility.Contact(propertyConfig.Name, ReikiRootModel.GetQualityLabel(quality));
|
m_PropertyName.color = UIHelper.GetUIColor(model.GetQualityColor(quality), true);
|
cacheQuality = quality;
|
}
|
}
|
|
private void OnAddDown(GameObject go)
|
{
|
isPointAdd = true;
|
coroutineCount = 0;
|
if (m_Coroutine != null)
|
{
|
StopCoroutine(m_Coroutine);
|
}
|
m_Coroutine = StartCoroutine(Co_PointRefresh(true));
|
}
|
|
private void OnAddUp(GameObject go)
|
{
|
isPointAdd = false;
|
}
|
|
private void OnSubDown(GameObject go)
|
{
|
if (m_Coroutine != null)
|
{
|
StopCoroutine(m_Coroutine);
|
}
|
coroutineCount = 0;
|
isPointSub = true;
|
m_Coroutine = StartCoroutine(Co_PointRefresh(false));
|
}
|
|
private void OnSubUp(GameObject go)
|
{
|
isPointSub = false;
|
}
|
|
IEnumerator Co_PointRefresh(bool pointUp)
|
{
|
while (pointUp ? isPointAdd : isPointSub)
|
{
|
if (pointUp && model.cacheFreePoint > 0)
|
{
|
point += 1;
|
model.cacheFreePoint -= 1;
|
}
|
else if (!pointUp && point > 0)
|
{
|
point -= 1;
|
model.cacheFreePoint += 1;
|
}
|
if (coroutineCount == 0)
|
{
|
yield return waitSpeedSlow;
|
}
|
else
|
{
|
yield return waitSpeedFaster;
|
}
|
coroutineCount++;
|
}
|
}
|
|
private void OnReikiRootPointRefresh()
|
{
|
if (point == 0)
|
{
|
DisplayPoint();
|
}
|
else
|
{
|
point = 0;
|
}
|
}
|
|
private void OpenKeyboard()
|
{
|
if (parent != null)
|
{
|
parent.OpenKeyboard(this);
|
}
|
}
|
|
public void Dispose()
|
{
|
model.onReikiRootPointRefresh -= OnReikiRootPointRefresh;
|
|
if (m_Coroutine != null)
|
{
|
StopCoroutine(m_Coroutine);
|
}
|
isPointAdd = false;
|
isPointSub = false;
|
point = 0;
|
}
|
}
|
}
|