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 m_Propertys; [SerializeField] NumKeyBoard keyBoard; [SerializeField] ClickScreenOtherSpace keyBoardClickOut; private Dictionary ptTextDic = new Dictionary(); private int surplusCnt = 0; private Dictionary ptValDic = new Dictionary(); 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()); } } 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 recomDic = model.GetPointRecom(PlayerDatas.Instance.baseData.Job); Dictionary 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 dic = model.GetPointAttrFormula(PlayerDatas.Instance.baseData.Job); foreach (var _type in dic.Keys) { float _value = Equation.Instance.Eval(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(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((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(); ptTextDic.Add(0 * 5 + key, text); text = transform.Find(string.Format("Bgm/RightBox/DotImg{0}/DotText{0}", i)).GetComponent(); text.name = (i).ToString(); ptTextDic.Add(1 * 5 + key, text); text = transform.Find(string.Format("Bgm/RightBox/AddAttrText{0}", i)).GetComponent(); 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