using System; using System.Collections.Generic; using System.Linq; using System.Text; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class PlayerStrengtheningLVWin : Window { [SerializeField] Text curSumStrengthLvText; [SerializeField] GameObject nowActObj; [SerializeField] GameObject nowNoActObj; [SerializeField] Text nowStrengthLvText; [SerializeField] Text nowAttrText; [SerializeField] GameObject nextActObj; [SerializeField] GameObject nextNoActObj; [SerializeField] Text nextEffectText; [SerializeField] Text nextStrengthLvText; [SerializeField] Text nextAttrText; [SerializeField] Button closeBtn; [SerializeField] Button activityBtn; [SerializeField] Text activeBtnText; [SerializeField] UIEffect successEffect; private int _curStrengthLv; private PlayerPropertyConfig _playerProModel; private Dictionary _haveStrengthInfoDict; private ItemPlusSumAttrConfig activeSTRConfig = null; private ItemPlusSumAttrConfig nextActiveSTRConfig = null; private int nextActiveCnt = 0; PlayerStrengthengDatas m_StrengthengModel; PlayerStrengthengDatas strengthengmodel { get { return m_StrengthengModel ?? (m_StrengthengModel = ModelCenter.Instance.GetModel()); } } PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } protected override void AddListeners() { closeBtn.AddListener(CloseClick); activityBtn.AddListener(ClickActivityBtn); } protected override void BindController() { } protected override void OnPreOpen() { playerPack.RefreshActiveAttrAct += RefreshUI; _haveStrengthInfoDict = strengthengmodel._EqInfo; RefreshUI(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { playerPack.RefreshActiveAttrAct -= RefreshUI; } protected override void OnAfterClose() { } private void RefreshUI() { _curStrengthLv = 0; foreach (var value in _haveStrengthInfoDict.Values) { ItemModel itemModel = playerPack.GetItemModelByIndex(PackType.rptEquip,value.EquipIndex); if(itemModel != null) { _curStrengthLv += value.EquipPartStarLV; } } curSumStrengthLvText.text = Language.Get("KnapS122").Replace("{0}", _curStrengthLv.ToString()); int activeCnt = GetActiveSTRAttr(); int serverActiveCnt = playerPack.GetActiveCntByType(0); StringBuilder attrStr = new StringBuilder(); if (activeSTRConfig != null) { attrStr.Length = 0; nowNoActObj.SetActive(false); nowActObj.SetActive(true); nowStrengthLvText.text = Language.Get("KnapS121").Replace("{0}", activeSTRConfig.countNeed.ToString()); int i = 0; for (i = 0; i < activeSTRConfig.attType.Length; i++) { attrStr.Append(SetIsPercentShow(activeSTRConfig.attType[i], activeSTRConfig.attValue[i]) + "\n"); } nowAttrText.text = attrStr.ToString(); } else { nowNoActObj.SetActive(true); nowActObj.SetActive(false); } if (nextActiveSTRConfig != null) { nextActObj.SetActive(true); nextNoActObj.SetActive(false); attrStr.Length = 0; nextStrengthLvText.text = Language.Get("KnapS121").Replace("{0}", nextActiveSTRConfig.countNeed.ToString()); int i = 0; for (i = 0; i < nextActiveSTRConfig.attType.Length; i++) { attrStr.Append(SetIsPercentShow(nextActiveSTRConfig.attType[i], nextActiveSTRConfig.attValue[i]) + "\n"); } nextAttrText.text = attrStr.ToString(); nextEffectText.text = Language.Get("BagWin_NextText_1", Language.Get("KnapS144")); if (activeCnt < serverActiveCnt) { RefreshActiveBtnUI(false); nextEffectText.text = Language.Get("BagWin_NextText_1", Language.Get("KnapS143")); } else { if (_curStrengthLv >= nextActiveSTRConfig.countNeed) { nextActiveCnt = nextActiveSTRConfig.countNeed; RefreshActiveBtnUI(true); } else { RefreshActiveBtnUI(false); } } } else { nextActObj.SetActive(false); nextNoActObj.SetActive(true); RefreshActiveBtnUI(false); } } private void RefreshActiveBtnUI(bool isActive) { activityBtn.RemoveAllListeners(); if (isActive) { activeBtnText.text = Language.Get("MountPanel_UnlockBtn_1"); activityBtn.AddListener(ClickActivityBtn); } else { activeBtnText.text = Language.Get("MountPanel_ConfirmTxt_1"); activityBtn.AddListener(CloseClick); } } private void ClickActivityBtn() { playerPack.SendActiveAttrQuest(0, nextActiveCnt); successEffect.Play(); } private int GetActiveSTRAttr() { activeSTRConfig = null; nextActiveSTRConfig = null; int cnt = playerPack.GetActiveCntByType(0); List strenlist = Config.Instance.GetAllKeys(); int activeCnt = cnt; if (strenlist == null || strenlist.Count < 1) return activeCnt; if (cnt > _curStrengthLv) { for (int i = strenlist.Count - 1; i > -1; i--) { if(i == 0 && int.Parse(strenlist[i]) > _curStrengthLv) { activeCnt = 0; break; } if (int.Parse(strenlist[i]) <= _curStrengthLv) { activeCnt = int.Parse(strenlist[i]); break; } } } if (activeCnt < int.Parse(strenlist[0])) { activeSTRConfig = null; nextActiveSTRConfig = Config.Instance.Get(strenlist[0]); } else { int nextActiveSTR = 0; for (int i = 0; i < strenlist.Count; i++) { if ( int.Parse(strenlist[i]) == activeCnt) { if (i < strenlist.Count - 1) { nextActiveSTR = int.Parse(strenlist[i + 1]); } break; } } activeSTRConfig = Config.Instance.Get(activeCnt); if (nextActiveSTR != 0) { nextActiveSTRConfig = Config.Instance.Get(nextActiveSTR); } else { nextActiveSTRConfig = null; } } return activeCnt; } //判断属性是否百分比显示 public string SetIsPercentShow(int proId, int proValue) { _playerProModel = Config.Instance.Get(proId); string strPro = ""; if (_playerProModel == null) { DebugEx.LogError("不存在此属性" + proId); return ""; } if (!_playerProModel.Name.Contains("%s")) { if (_playerProModel.ISPercentage == 0) { strPro = _playerProModel.Name + "" + " +" + proValue + ""; } else if (_playerProModel.ISPercentage == 1) { strPro = _playerProModel.Name + "" + " +" + (float)Math.Round(proValue / 100f, 1) + "%" + ""; } } else { if (_playerProModel.ISPercentage == 0) { strPro = _playerProModel.Name.Replace("%s", proValue.ToString()); } else if (_playerProModel.ISPercentage == 1) { strPro = _playerProModel.Name.Replace("%s", (float)Math.Round(proValue / 100f, 1) + "%"); } } return strPro; } } }