using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
namespace Snxxz.UI
|
{
|
public class ReikiRootPointBehaviour : MonoBehaviour
|
{
|
[SerializeField] Image m_Icon;
|
[SerializeField] Text m_Quality;
|
[SerializeField] Text m_Point;
|
[SerializeField] Button m_Add;
|
[SerializeField] Button m_Sub;
|
[SerializeField] Button m_Max;
|
[SerializeField] Text m_MaxLabel;
|
[SerializeField] Button m_OpenKeyboard;
|
[SerializeField] UIEffect m_QualityEffect;
|
[SerializeField] UIEffect m_ResetEffect;
|
[SerializeField] UIEffect m_SelectEffect;
|
|
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(true);
|
}
|
}
|
}
|
|
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_Max.AddListener(OnMax);
|
m_OpenKeyboard.AddListener(OpenKeyboard);
|
}
|
|
public void Display(ReikiRootWin win, int id)
|
{
|
parent = win;
|
this.id = id;
|
|
cacheQuality = 0;
|
|
m_Icon.SetSprite("XT_LG_" + id);
|
|
DisplayPoint();
|
DisplayButtonState();
|
|
model.onReikiRootPointRefresh += OnReikiRootPointRefresh;
|
model.onReikiRootPointReset += OnReikiRootPointReset;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent;
|
}
|
|
public void DisplaySelectEffect(bool selected)
|
{
|
m_SelectEffect.gameObject.SetActive(selected);
|
}
|
|
void DisplayPoint(bool showQualityEffect = false)
|
{
|
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_Quality.text = ReikiRootModel.GetQualityLabel(quality);
|
m_Quality.color = UIHelper.GetUIColor(model.GetQualityColor(quality), true);
|
if (showQualityEffect && quality > cacheQuality)
|
{
|
m_QualityEffect.Play();
|
}
|
cacheQuality = quality;
|
}
|
}
|
|
void DisplayButtonState()
|
{
|
var isResetOpen = PlayerDatas.Instance.baseData.LV >= model.resetReikiLimitLevel;
|
var isPreReikiRoot = model.IsPreReikiRoot(id);
|
if (!isResetOpen && !isPreReikiRoot)
|
{
|
m_Add.SetColorful(null, isPreReikiRoot);
|
m_Sub.SetColorful(null, isPreReikiRoot);
|
m_Max.SetColorful(m_MaxLabel, isPreReikiRoot);
|
return;
|
}
|
|
m_Add.SetInteractable(null, model.freePoint > 0);
|
m_Sub.SetInteractable(null, model.freePoint > 0);
|
m_Max.SetInteractable(m_MaxLabel, model.freePoint > 0);
|
}
|
|
private void OnAddDown(GameObject go)
|
{
|
if (PlayerDatas.Instance.baseData.LV < model.resetReikiLimitLevel
|
&& !model.IsPreReikiRoot(id))
|
{
|
SysNotifyMgr.Instance.ShowTip("NotSatisfyPreReikiRoot", model.resetReikiLimitLevel);
|
return;
|
}
|
|
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 (PlayerDatas.Instance.baseData.LV < model.resetReikiLimitLevel
|
&& !model.IsPreReikiRoot(id))
|
{
|
SysNotifyMgr.Instance.ShowTip("NotSatisfyPreReikiRoot", model.resetReikiLimitLevel);
|
return;
|
}
|
if (m_Coroutine != null)
|
{
|
StopCoroutine(m_Coroutine);
|
}
|
coroutineCount = 0;
|
isPointSub = true;
|
m_Coroutine = StartCoroutine(Co_PointRefresh(false));
|
}
|
|
private void OnSubUp(GameObject go)
|
{
|
isPointSub = false;
|
}
|
|
private void OnMax()
|
{
|
if (PlayerDatas.Instance.baseData.LV < model.resetReikiLimitLevel
|
&& !model.IsPreReikiRoot(id))
|
{
|
SysNotifyMgr.Instance.ShowTip("NotSatisfyPreReikiRoot", model.resetReikiLimitLevel);
|
return;
|
}
|
point += model.cacheFreePoint;
|
model.cacheFreePoint = 0;
|
}
|
|
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 (PlayerDatas.Instance.baseData.LV < model.resetReikiLimitLevel
|
&& !model.IsPreReikiRoot(id))
|
{
|
SysNotifyMgr.Instance.ShowTip("NotSatisfyPreReikiRoot", model.resetReikiLimitLevel);
|
return;
|
}
|
if (parent != null)
|
{
|
parent.OpenKeyboard(this);
|
}
|
}
|
|
private void PlayerDataRefreshEvent(PlayerDataType dataType)
|
{
|
if (dataType == PlayerDataType.FreePoint || dataType == PlayerDataType.LV)
|
{
|
DisplayButtonState();
|
}
|
}
|
|
private void OnReikiRootPointReset(int id)
|
{
|
if (this.id == id)
|
{
|
m_ResetEffect.Play();
|
parent.resetAnimationTime = DateTime.Now;
|
}
|
}
|
|
public void Dispose()
|
{
|
model.onReikiRootPointRefresh -= OnReikiRootPointRefresh;
|
model.onReikiRootPointReset -= OnReikiRootPointReset;
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
|
|
if (m_Coroutine != null)
|
{
|
StopCoroutine(m_Coroutine);
|
}
|
isPointAdd = false;
|
isPointSub = false;
|
point = 0;
|
}
|
}
|
}
|