using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using TableConfig;
|
namespace Snxxz.UI
|
{
|
public class RolePoint : Window
|
{
|
|
[SerializeField] Button closeBtn;
|
[SerializeField] Button recomBtn;
|
[SerializeField] Button confirmBtn;
|
[SerializeField] Text surplusPt;
|
[SerializeField] List<PropertyValue> m_Propertys;
|
[SerializeField] NumKeyBoard keyBoard;
|
[SerializeField] ClickScreenOtherSpace keyBoardClickOut;
|
|
private Dictionary<int, Text> ptTextDic = new Dictionary<int, Text>();
|
private int surplusCnt = 0;
|
private Dictionary<int, int> ptValDic = new Dictionary<int, int>();
|
private bool lockpak = false;
|
private bool isSpeedUp = false;
|
private static WaitForSeconds waitSpeedUp = new WaitForSeconds(0.5f);
|
private static WaitForSeconds waitSpeedFaster = new WaitForSeconds(0.05f);
|
private static WaitForSeconds waitSpeedSlow = new WaitForSeconds(0.2f);
|
private const int WAITCNT = 1;
|
private int presentAttrPoint = 0;
|
RolePointModel m_Model;
|
RolePointModel model
|
{
|
get
|
{
|
return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<RolePointModel>());
|
}
|
}
|
|
private void OnAddUp(GameObject go)
|
{
|
isSpeedUp = false;
|
StopAllCoroutines();
|
}
|
|
private void OnMinusUp(GameObject go)
|
{
|
isSpeedUp = false;
|
StopAllCoroutines();
|
}
|
|
private void OnPlayerInfoRefresh(PlayerDataRefresh refreshType)
|
{
|
switch (refreshType)
|
{
|
case PlayerDataRefresh.FreePoint:
|
{
|
OnRefreshAttr();
|
}
|
break;
|
case PlayerDataRefresh.STR:
|
case PlayerDataRefresh.PNE:
|
case PlayerDataRefresh.PHY:
|
case PlayerDataRefresh.CON:
|
{
|
OnRefreshPtAttr();
|
}
|
break;
|
default:
|
{
|
foreach (var _property in m_Propertys)
|
{
|
_property.RefreshValue();
|
}
|
}
|
break;
|
}
|
}
|
|
private void OnConfirmClick()
|
{
|
lockpak = true;
|
foreach (int key in ptValDic.Keys)
|
{
|
if (ptValDic[key] > 0)
|
{
|
model.SendAddPoint(key, ptValDic[key]);
|
}
|
}
|
}
|
|
private void OnRecomClick()
|
{
|
int freepoint = (int)PlayerDatas.Instance.baseData.FreePoint;
|
int allfreept = freepoint;
|
int pt = 0;
|
Dictionary<int, float> recomDic = model.GetPointRecom(PlayerDatas.Instance.baseData.Job);
|
Dictionary<int, int> createDic = model.GetPointCreate(PlayerDatas.Instance.baseData.Job);
|
foreach (var key in recomDic.Keys)
|
{
|
allfreept += ((int)UIHelper.GetPropertyMapPlayerData((AttrEnum)key) - createDic[key]);
|
}
|
ptValDic.Clear();
|
foreach (var key in createDic.Keys)
|
{
|
ptValDic.Add(key, 0);
|
ptTextDic[1 * 5 + key].text = ptValDic[key].ToString();
|
}
|
foreach (var key in recomDic.Keys)
|
{
|
int expectpt = Mathf.RoundToInt(recomDic[key] * allfreept);
|
int presentpt = expectpt - ((int)UIHelper.GetPropertyMapPlayerData((AttrEnum)key) - createDic[key]);
|
if (presentpt > 0)
|
{
|
if (pt + presentpt > freepoint)
|
{
|
presentpt = freepoint - pt;
|
}
|
pt += presentpt;
|
ptValDic[key] = presentpt;
|
}
|
ptTextDic[1 * 5 + key].text = ptValDic[key].ToString();
|
}
|
|
surplusCnt = freepoint - pt;
|
surplusPt.text = surplusCnt.ToString();
|
OnRefreshAdd();
|
}
|
|
private void OnMinusBtn(GameObject obj)
|
{
|
isSpeedUp = true;
|
int index = int.Parse(obj.name);
|
if (ptValDic.ContainsKey(index))
|
{
|
if (ptValDic[index] < 1) return;
|
ptValDic[index]--;
|
surplusCnt++;
|
OnUpdatePoint(index);
|
}
|
StartCoroutine(OnSpeedUp(false, index));
|
}
|
|
private void OnAddBtn(GameObject obj)
|
{
|
isSpeedUp = true;
|
int index = int.Parse(obj.name);
|
if (ptValDic.ContainsKey(index))
|
{
|
if (surplusCnt < 1) return;
|
ptValDic[index]++;
|
surplusCnt--;
|
OnUpdatePoint(index);
|
}
|
StartCoroutine(OnSpeedUp(true, index));
|
}
|
|
private void OnUpdatePoint(int index)
|
{
|
ptTextDic[1 * 5 + index].text = ptValDic[index].ToString();
|
surplusPt.text = surplusCnt.ToString();
|
OnRefreshAdd();
|
}
|
|
IEnumerator OnSpeedUp(bool up, int index)
|
{
|
yield return waitSpeedUp;
|
int upCnt = 0;
|
while (isSpeedUp)
|
{
|
if (ptValDic.ContainsKey(index))
|
{
|
if (up)
|
{
|
if (surplusCnt < 1) yield break;
|
ptValDic[index]++;
|
surplusCnt--;
|
OnUpdatePoint(index);
|
}
|
else
|
{
|
if (ptValDic[index] < 1) yield break;
|
ptValDic[index]--;
|
surplusCnt++;
|
OnUpdatePoint(index);
|
}
|
}
|
if (upCnt < WAITCNT)
|
{
|
yield return waitSpeedSlow;
|
}
|
else
|
{
|
yield return waitSpeedFaster;
|
}
|
upCnt++;
|
}
|
}
|
|
private void OnPointValChange()
|
{
|
int index = presentAttrPoint + 1;
|
surplusCnt += ptValDic[index];
|
int num = int.Parse(keyBoard.Value);
|
if (surplusCnt - num < 0) num = surplusCnt;
|
ptValDic[index] = num;
|
surplusCnt -= num;
|
OnUpdatePoint(index);
|
keyBoard.Value = num.ToString();
|
}
|
|
private void OnRefreshAdd()
|
{
|
Equation.Instance.Clear();
|
Equation.Instance.AddKeyValue("STR", ptValDic[2]);
|
Equation.Instance.AddKeyValue("PNE", ptValDic[5]);
|
Equation.Instance.AddKeyValue("PHY", ptValDic[3]);
|
Equation.Instance.AddKeyValue("CON", ptValDic[4]);
|
Dictionary<int, string> dic = model.GetPointAttrFormula(PlayerDatas.Instance.baseData.Job);
|
foreach (var _type in dic.Keys)
|
{
|
float _value = Equation.Instance.Eval<float>(dic[_type]);
|
GetProperty(_type).RefreshAdd(_value);
|
}
|
}
|
|
void OnRefreshAttr()
|
{
|
if (model.rolePointAddAttrArray != null)
|
{
|
for (int i = 0; i < model.rolePointAddAttrArray.Length; i++)
|
{
|
PlayerPropertyConfig cfg = ConfigManager.Instance.GetTemplate<PlayerPropertyConfig>(model.rolePointAddAttrArray[i]);
|
ptTextDic[2 * 5 + model.rolePointAddAttrArray[i]].text = cfg.Name;
|
ptTextDic[0 * 5 + model.rolePointAddAttrArray[i]].text = UIHelper.GetPropertyMapPlayerData((AttrEnum)model.rolePointAddAttrArray[i]).ToString();
|
ptValDic[model.rolePointAddAttrArray[i]] = 0;
|
ptTextDic[1 * 5 + model.rolePointAddAttrArray[i]].text = ptValDic[model.rolePointAddAttrArray[i]].ToString();
|
}
|
}
|
|
surplusCnt = (int)PlayerDatas.Instance.baseData.FreePoint;
|
surplusPt.text = surplusCnt.ToString();
|
|
OnRefreshAdd();
|
}
|
|
void OnRefreshPtAttr()
|
{
|
if (model.rolePointAddAttrArray != null)
|
{
|
for (int i = 0; i < model.rolePointAddAttrArray.Length; i++)
|
{
|
ptTextDic[0 * 5 + model.rolePointAddAttrArray[i]].text = UIHelper.GetPropertyMapPlayerData((AttrEnum)model.rolePointAddAttrArray[i]).ToString();
|
}
|
}
|
}
|
|
private string GetAttrStr(AttrEnum type)
|
{
|
PlayerPropertyConfig cfg = ConfigManager.Instance.GetTemplate<PlayerPropertyConfig>((int)type);
|
float value = UIHelper.GetPropertyMapPlayerData(type);
|
return UIHelper.ReplacePercentage(value, cfg.ISPercentage) + (cfg.ISPercentage == 1 ? "%" : string.Empty);
|
}
|
|
protected override void BindController()
|
{
|
Text text;
|
int i = 1;
|
foreach (var key in model.GetPointCreate(PlayerDatas.Instance.baseData.Job).Keys)
|
{
|
text = transform.Find(string.Format("Bgm/RightBox/AddAttrNumText{0}", i)).GetComponent<Text>();
|
ptTextDic.Add(0 * 5 + key, text);
|
text = transform.Find(string.Format("Bgm/RightBox/DotImg{0}/DotText{0}", i)).GetComponent<Text>();
|
text.name = (i).ToString();
|
ptTextDic.Add(1 * 5 + key, text);
|
text = transform.Find(string.Format("Bgm/RightBox/AddAttrText{0}", i)).GetComponent<Text>();
|
ptTextDic.Add(2 * 5 + key, text);
|
i++;
|
}
|
Button btn;
|
i = 1;
|
foreach (var key in model.GetPointCreate(PlayerDatas.Instance.baseData.Job).Keys)
|
{
|
btn = transform.Find(string.Format("Bgm/RightBox/MinusButton{0}", i)).GetComponent<Button>();
|
btn.name = key.ToString();
|
UIEventTrigger.Get(btn.gameObject).OnDown = OnMinusBtn;
|
UIEventTrigger.Get(btn.gameObject).OnUp = OnMinusUp;
|
i++;
|
}
|
i = 1;
|
foreach (var key in model.GetPointCreate(PlayerDatas.Instance.baseData.Job).Keys)
|
{
|
btn = transform.Find(string.Format("Bgm/RightBox/AddsButton{0}", i)).GetComponent<Button>();
|
btn.name = key.ToString();
|
UIEventTrigger.Get(btn.gameObject).OnDown = OnAddBtn;
|
UIEventTrigger.Get(btn.gameObject).OnUp = OnAddUp;
|
i++;
|
}
|
}
|
|
protected override void AddListeners()
|
{
|
closeBtn.onClick.AddListener(CloseClick);
|
confirmBtn.onClick.AddListener(OnConfirmClick);
|
recomBtn.onClick.AddListener(OnRecomClick);
|
keyBoard.onValueChange.AddListener(OnPointValChange);
|
keyBoard.onConfirm.AddListener((bool _isConfirm) =>
|
{
|
if (_isConfirm)
|
{
|
keyBoard.gameObject.SetActive(false);
|
}
|
});
|
keyBoardClickOut.AddListener(() =>
|
{
|
keyBoard.gameObject.SetActive(false);
|
});
|
foreach (var key in model.GetPointCreate(PlayerDatas.Instance.baseData.Job).Keys)
|
{
|
Text text = ptTextDic[1 * 5 + key];
|
UIEventTrigger.Get(text.gameObject).OnNoParamsClick = () =>
|
{
|
int _key = int.Parse(text.name);
|
presentAttrPoint = _key;
|
keyBoard.gameObject.SetActive(true);
|
keyBoard.max = (uint)surplusCnt + (uint)ptValDic[_key + 1];
|
keyBoard.min = 0;
|
RectTransform parent = text.rectTransform.parent as RectTransform;
|
keyBoard.transform.localPosition = parent.localPosition.SetY(parent.localPosition.y - parent.rect.height / 2);
|
};
|
}
|
}
|
|
protected override void OnPreOpen()
|
{
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent += OnPlayerInfoRefresh;
|
keyBoard.gameObject.SetActive(false);
|
var _dict = model.GetPointAttrFormula(PlayerDatas.Instance.baseData.Job);
|
int i = 0;
|
foreach (var _type in _dict.Keys)
|
{
|
m_Propertys[i].property = _type;
|
i++;
|
}
|
OnRefreshAttr();
|
isSpeedUp = false;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
HandleAchievement();
|
}
|
|
protected override void OnPreClose()
|
{
|
if (!WindowCenter.Instance.CheckOpen<RolePanel>())
|
{
|
WindowCenter.Instance.Open<MainInterfaceWin>();
|
}
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= OnPlayerInfoRefresh;
|
isSpeedUp = false;
|
StopAllCoroutines();
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
private void HandleAchievement()
|
{
|
if (AchievementGoto.achievementType == AchievementGoto.RolePoint)
|
{
|
var _effect = AchievementGuideEffectPool.Require(1);
|
_effect.transform.SetParentEx(recomBtn.transform,Vector3.zero,Vector3.zero,Vector3.one);
|
AchievementGoto.achievementType = 0;
|
}
|
}
|
|
private PropertyValue GetProperty(int _type)
|
{
|
return m_Propertys.Find((x) =>
|
{
|
return x.property == _type;
|
});
|
}
|
|
[Serializable]
|
public class PropertyValue
|
{
|
private int m_Property;
|
public int property
|
{
|
get
|
{
|
return m_Property;
|
}
|
set
|
{
|
m_Property = value;
|
Refresh();
|
}
|
}
|
[SerializeField] Text m_PropertyTypeTxt;
|
[SerializeField] Text m_PropertyValueTxt;
|
[SerializeField] Text m_PropertyAddValue;
|
|
public void Refresh()
|
{
|
var _propCfg = ConfigManager.Instance.GetTemplate<PlayerPropertyConfig>(property);
|
if (_propCfg != null)
|
{
|
m_PropertyTypeTxt.text = _propCfg.Name;
|
RefreshValue();
|
RefreshAdd(0);
|
}
|
}
|
|
public void RefreshValue()
|
{
|
var _propCfg = ConfigManager.Instance.GetTemplate<PlayerPropertyConfig>(property);
|
if ((AttrEnum)property == AttrEnum.ATK)
|
{
|
m_PropertyValueTxt.text =StringUtility.Contact(UIHelper.ReplaceLargeNum((ulong)PlayerDatas.Instance.extersion.MINATK),
|
"-", UIHelper.ReplaceLargeNum((ulong)PlayerDatas.Instance.extersion.MAXATK));
|
}
|
else
|
{
|
m_PropertyValueTxt.text = UIHelper.ReplaceLargeNum((ulong)UIHelper.GetPropertyMapPlayerData((AttrEnum)property));
|
}
|
}
|
|
public void RefreshAdd(float _value)
|
{
|
m_PropertyAddValue.gameObject.SetActive(_value != 0);
|
if (_value > 0)
|
{
|
m_PropertyAddValue.text = StringUtility.Contact("+", _value);
|
}
|
}
|
}
|
}
|
}
|