using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
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;
|
[SerializeField] Text addAttrText;
|
|
private int _curStarsCount;
|
private PlayerPropertyConfig _playerProModel;
|
private Dictionary<int, ItemModel> _itemDict;
|
private RoleEquipStarsConfig activeStarsConfig = null;
|
private RoleEquipStarsConfig nextActiveStarsConfig = null;
|
private int nextActiveCnt = 0;
|
|
PackModel _playerPack;
|
PackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
|
}
|
|
protected override void AddListeners()
|
{
|
closeBtn.AddListener(CloseClick);
|
}
|
|
protected override void BindController()
|
{
|
|
}
|
|
protected override void OnPreOpen()
|
{
|
playerPack.RefreshActiveAttrAct += RefreshUI;
|
SinglePack singlePack = playerPack.GetSinglePack(PackType.Equip);
|
if (singlePack != null)
|
{
|
_itemDict = singlePack.GetAllItems();
|
}
|
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.config.StarLevel;
|
}
|
}
|
|
curSumStarText.text = Language.Get("KnapS124").Replace("{0}", _curStarsCount.ToString());
|
int realActiveStars = 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 = PlayerPropertyConfig.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 = PlayerPropertyConfig.Get(nextActiveStarsConfig.attType[i]);
|
if (_playerProModel != null)
|
{
|
attrStr.Append(SetIsPercentShow(_playerProModel, nextActiveStarsConfig.attValue[i]) + "\n");
|
}
|
|
}
|
nextAttrText.text = attrStr.ToString();
|
if(nextActiveStarsConfig.countNeed <= serverActiveCnt)
|
{
|
RefreshActiveBtnUI(false);
|
nextEffectText.text = Language.Get("BagWin_NextText_1", Language.Get("KnapS143"));
|
}
|
else
|
{
|
nextEffectText.text = Language.Get("BagWin_NextText_1", Language.Get("KnapS144"));
|
if (_curStarsCount >= nextActiveStarsConfig.countNeed)
|
{
|
nextActiveCnt = nextActiveStarsConfig.countNeed;
|
RefreshActiveBtnUI(true);
|
}
|
else
|
{
|
RefreshActiveBtnUI(false);
|
}
|
}
|
}
|
else
|
{
|
nextActObj.SetActive(false);
|
nextNoActObj.SetActive(true);
|
RefreshActiveBtnUI(false);
|
}
|
|
int addAttrStarsNum = 0;
|
List<int> addIdlist = playerPack.GetAddAttrIdByStars(_curStarsCount,out addAttrStarsNum);
|
if(addIdlist.Count > 0)
|
{
|
addAttrText.gameObject.SetActive(true);
|
string addAttr = "";
|
for(int i = 0; i < addIdlist.Count; i++)
|
{
|
PlayerPropertyConfig propertyConfig = PlayerPropertyConfig.Get(addIdlist[i]);
|
if(propertyConfig != null)
|
{
|
addAttr = StringUtility.Contact(addAttr, propertyConfig.Name);
|
}
|
}
|
addAttrText.text = Language.Get("KnapS148",addAttrStarsNum,addAttr);
|
}
|
else
|
{
|
addAttrText.gameObject.SetActive(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 serverActiveCnt = playerPack.GetActiveCntByType(1);
|
List<int> starslist = RoleEquipStarsConfig.GetEquipStarsCntlist();
|
if (starslist == null || starslist.Count < 1) return serverActiveCnt;
|
|
int realActiveStars = _curStarsCount > serverActiveCnt ? serverActiveCnt : _curStarsCount;
|
for (int i = starslist.Count - 1; i > -1 ; i--)
|
{
|
if (i == 0 && starslist[i] > realActiveStars)
|
{
|
realActiveStars = 0;
|
break;
|
}
|
if (starslist[i] <= realActiveStars)
|
{
|
realActiveStars = starslist[i];
|
break;
|
}
|
}
|
|
|
if (realActiveStars < starslist[0])
|
{
|
activeStarsConfig = null;
|
nextActiveStarsConfig = RoleEquipStarsConfig.GetEquipStarsModel(starslist[0]);
|
}
|
else
|
{
|
int nextActiveStars = 0;
|
for (int i = 0; i < starslist.Count; i++)
|
{
|
if(starslist[i] > realActiveStars)
|
{
|
nextActiveStars = starslist[i];
|
break;
|
}
|
}
|
|
activeStarsConfig = RoleEquipStarsConfig.GetEquipStarsModel(realActiveStars);
|
if (nextActiveStars != 0)
|
{
|
nextActiveStarsConfig = RoleEquipStarsConfig.GetEquipStarsModel(nextActiveStars);
|
}
|
else
|
{
|
nextActiveStarsConfig = null;
|
}
|
}
|
|
return realActiveStars;
|
}
|
|
//判断属性是否百分比显示
|
public string SetIsPercentShow(PlayerPropertyConfig _playerProModel, int proValue)
|
{
|
string strPro = "";
|
if (!_playerProModel.Name.Contains("%s"))
|
{
|
if (_playerProModel.ISPercentage == 0)
|
{
|
strPro = _playerProModel.Name + "<color=#109D06FF>" + " +" + proValue + "</color>";
|
}
|
else if (_playerProModel.ISPercentage == 1)
|
{
|
strPro = _playerProModel.Name + "<color=#109D06FF>" + " +" + (float)Math.Round(proValue / 100f, 1) + "%" + "</color>";
|
}
|
}
|
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;
|
}
|
}
|
}
|