using System; using System.Collections.Generic; using System.Text; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class PlayerStarNumWin : Window { [SerializeField] Text curSumStarText; [SerializeField] GameObject nowActObj; [SerializeField] GameObject nowNoActObj; [SerializeField] Text nowStarNumText; [SerializeField] Text nowAttrText; [SerializeField] GameObject nextActObj; [SerializeField] GameObject nextNoActObj; [SerializeField] Text nextEffectText; [SerializeField] Text nextStarNumText; [SerializeField] Text nextAttrText; [SerializeField] Button closeBtn; [SerializeField] Button activityBtn; [SerializeField] Text activeBtnText; [SerializeField] UIEffect successEffect; private int _curStarsCount; private PlayerPropertyConfig _playerProModel; private Dictionary _itemDict; private RoleEquipStarsConfig activeStarsConfig = null; private RoleEquipStarsConfig nextActiveStarsConfig = null; private int nextActiveCnt = 0; PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } protected override void AddListeners() { closeBtn.AddListener(CloseClick); } protected override void BindController() { } protected override void OnPreOpen() { playerPack.RefreshActiveAttrAct += RefreshUI; SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.rptEquip); if (singlePack != null) { _itemDict = singlePack.GetPackModelIndexDict(); } RefreshUI(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { playerPack.RefreshActiveAttrAct -= RefreshUI; } protected override void OnAfterClose() { } private void RefreshUI() { _curStarsCount = 0; if (_itemDict != null) { foreach (var model in _itemDict.Values) { _curStarsCount += model.chinItemModel.StarLevel; } } curSumStarText.text = Language.Get("KnapS124").Replace("{0}", _curStarsCount.ToString()); int activeCnt = GetActiveStarsAttr(); int serverActiveCnt = playerPack.GetActiveCntByType(1); StringBuilder attrStr = new StringBuilder(); if (activeStarsConfig != null) { attrStr.Length = 0; nowNoActObj.SetActive(false); nowActObj.SetActive(true); nowStarNumText.text = Language.Get("KnapS123").Replace("{0}",activeStarsConfig.countNeed.ToString()); int i = 0; for (i = 0; i < activeStarsConfig.attType.Length; i++) { _playerProModel = Config.Instance.Get(activeStarsConfig.attType[i]); if (_playerProModel != null) { attrStr.Append(SetIsPercentShow(_playerProModel, activeStarsConfig.attValue[i]) + "\n"); } } nowAttrText.text = attrStr.ToString(); } else { nowNoActObj.SetActive(true); nowActObj.SetActive(false); } if(nextActiveStarsConfig != null) { nextActObj.SetActive(true); nextNoActObj.SetActive(false); attrStr.Length = 0; nextStarNumText.text = Language.Get("KnapS123").Replace("{0}", nextActiveStarsConfig.countNeed.ToString()); int i = 0; for (i = 0; i < nextActiveStarsConfig.attType.Length; i++) { _playerProModel = Config.Instance.Get(nextActiveStarsConfig.attType[i]); if (_playerProModel != null) { attrStr.Append(SetIsPercentShow(_playerProModel, nextActiveStarsConfig.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 (_curStarsCount >= nextActiveStarsConfig.countNeed) { nextActiveCnt = nextActiveStarsConfig.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(1,nextActiveCnt); successEffect.Play(); } private int GetActiveStarsAttr() { activeStarsConfig = null; nextActiveStarsConfig = null; int cnt = playerPack.GetActiveCntByType(1); List starslist = RoleEquipStarsConfig.GetEquipStarsCntlist(); int activeCnt = cnt; if (starslist == null || starslist.Count < 1) return activeCnt; if (cnt > _curStarsCount) { for (int i = starslist.Count - 1; i > -1; i--) { if(i== 0 && starslist[i] > _curStarsCount) { activeCnt = 0; break; } if (starslist[i] <= _curStarsCount) { activeCnt = starslist[i]; break; } } } if (activeCnt < starslist[0]) { activeStarsConfig = null; nextActiveStarsConfig = RoleEquipStarsConfig.GetEquipStarsModel(starslist[0]); } else { int nextActiveStars = 0; for (int i = 0; i < starslist.Count; i++) { if(starslist[i] == activeCnt) { if(i < starslist.Count - 1) { nextActiveStars = starslist[i + 1]; } break; } } activeStarsConfig = RoleEquipStarsConfig.GetEquipStarsModel(activeCnt); if (nextActiveStars != 0) { nextActiveStarsConfig = RoleEquipStarsConfig.GetEquipStarsModel(nextActiveStars); } else { nextActiveStarsConfig = null; } } return activeCnt; } //判断属性是否百分比显示 public string SetIsPercentShow(PlayerPropertyConfig _playerProModel, int proValue) { string strPro = ""; 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; } } }