using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using System.Linq;
|
using System.Collections;
|
|
namespace vnxbqy.UI
|
{
|
|
public class FashionSumAttrWin : Window
|
{
|
[SerializeField] GameObject container;
|
[SerializeField] CanvasGroup alpha;
|
[Header("时装总加成")]
|
[SerializeField] Text activateNumText;
|
[SerializeField] GameObject noneActivate;
|
[SerializeField] List<Text> activateAttrs = new List<Text>();
|
[SerializeField] List<GameObject> activateAttrObjs = new List<GameObject>();
|
[Header("衣柜等级加成")]
|
[SerializeField] Text wardrobeLvText;
|
[SerializeField] GameObject noneLvAdd;
|
[SerializeField] List<Text> lvAddAttrs = new List<Text>();
|
[SerializeField] List<GameObject> lvAddAttrObjs = new List<GameObject>();
|
|
FashionDressModel fashionModel { get { return ModelCenter.Instance.GetModel<FashionDressModel>(); } }
|
#region Built-in
|
protected override void BindController()
|
{
|
|
}
|
protected override void AddListeners()
|
{
|
|
}
|
protected override void OnPreOpen()
|
{
|
SetDisplay();
|
}
|
protected override void OnActived()
|
{
|
base.OnActived();
|
StartCoroutine(DelayShow());
|
}
|
protected override void OnAfterOpen()
|
{
|
|
}
|
|
protected override void OnPreClose()
|
{
|
|
}
|
protected override void OnAfterClose()
|
{
|
|
}
|
#endregion
|
|
private void SetDisplay()
|
{
|
alpha.alpha = 0;
|
container.SetActive(false);
|
SetActivateFashionAdd();
|
SetWardrobeLvAdd();
|
}
|
|
private void SetActivateFashionAdd()
|
{
|
List<int> activateIds = null;
|
bool isActivate = fashionModel.TryGetActiveFashionDress(out activateIds);
|
int sumNum = fashionModel.fashoinDressCount;
|
int activateNum = activateIds.Count;
|
string actvivateNumSB = string.Empty;
|
if (activateNum > 0)
|
{
|
actvivateNumSB = UIHelper.AppendColor(TextColType.Green, activateNum.ToString());
|
}
|
else
|
{
|
actvivateNumSB = UIHelper.AppendColor(TextColType.Red, activateNum.ToString());
|
}
|
activateNumText.text = StringUtility.Contact(actvivateNumSB, "/", sumNum);
|
Dictionary<int, int> attrDict = GetActivateAttr();
|
if (attrDict != null && attrDict.Count > 0)
|
{
|
noneActivate.SetActive(false);
|
List<int> attrIds = attrDict.Keys.ToList();
|
for (int i = 0; i < activateAttrObjs.Count; i++)
|
{
|
var attrObj = activateAttrObjs[i];
|
attrObj.SetActive(i < attrIds.Count);
|
if (i < attrIds.Count)
|
{
|
var attrText = activateAttrs[i];
|
int attrId = attrIds[i];
|
int attrValue = attrDict[attrId];
|
var attrConfig = PlayerPropertyConfig.Get(attrId);
|
string attrSB = string.Empty;
|
string attrValueSB = UIHelper.AppendColor(TextColType.Green, PlayerPropertyConfig.GetValueDescription(attrId, attrValue));
|
if (attrConfig.Name.Contains("%s"))
|
{
|
attrSB = attrConfig.Name.Replace("%s", attrValueSB);
|
}
|
else
|
{
|
attrSB = StringUtility.Contact(attrConfig.Name, "+", attrValueSB);
|
}
|
attrText.text = attrSB;
|
}
|
}
|
}
|
else
|
{
|
noneActivate.SetActive(true);
|
for (int i = 0; i < activateAttrObjs.Count; i++)
|
{
|
var attrObj = activateAttrObjs[i];
|
attrObj.SetActive(false);
|
}
|
}
|
}
|
|
private Dictionary<int, int> GetActivateAttr()
|
{
|
var sumAttrDict = new Dictionary<int, int>();
|
List<int> fashionIds = null;
|
bool isActivate = fashionModel.TryGetActiveFashionDress(out fashionIds);
|
if (isActivate)
|
{
|
foreach (var id in fashionIds)
|
{
|
int fashionLevel = fashionModel.GetFashionDressLevel(id);
|
Dictionary<int, int> attrDict = null;
|
bool isAttr = fashionModel.TryGetFashionDressProperty(id, fashionLevel, out attrDict);
|
if (isAttr)
|
{
|
foreach (var attrId in attrDict.Keys)
|
{
|
var attrValue = attrDict[attrId];
|
if (!sumAttrDict.ContainsKey(attrId))
|
{
|
sumAttrDict.Add(attrId, attrValue);
|
}
|
else
|
{
|
sumAttrDict[attrId] += attrValue;
|
}
|
}
|
}
|
}
|
}
|
return sumAttrDict;
|
}
|
|
private void SetWardrobeLvAdd()
|
{
|
int wardrobeLevel = fashionModel.cabinetLevel;
|
string wardrobeLevelSB = string.Empty;
|
if (wardrobeLevel > 0)
|
{
|
wardrobeLevelSB = UIHelper.AppendColor(TextColType.Green, wardrobeLevel.ToString());
|
}
|
else
|
{
|
wardrobeLevelSB = UIHelper.AppendColor(TextColType.Red, wardrobeLevel.ToString());
|
}
|
wardrobeLvText.text = Language.Get("FashionDress106", wardrobeLevelSB);
|
Dictionary<int, int> attrDict = null;
|
fashionModel.TryGetCabinetProperty(fashionModel.cabinetLevel, out attrDict);
|
if (attrDict != null && attrDict.Count > 0)
|
{
|
noneLvAdd.SetActive(false);
|
List<int> attrIds = attrDict.Keys.ToList();
|
for (int i = 0; i < lvAddAttrObjs.Count; i++)
|
{
|
var attrObj = lvAddAttrObjs[i];
|
attrObj.SetActive(i < attrIds.Count);
|
if (i < attrIds.Count)
|
{
|
var attrText = lvAddAttrs[i];
|
int attrId = attrIds[i];
|
int attrValue = attrDict[attrId];
|
var attrConfig = PlayerPropertyConfig.Get(attrId);
|
string attrSB = string.Empty;
|
string attrValueSB = UIHelper.AppendColor(TextColType.Green, PlayerPropertyConfig.GetValueDescription(attrId, attrValue));
|
if (attrConfig.Name.Contains("%s"))
|
{
|
attrSB = attrConfig.Name.Replace("%s", attrValueSB);
|
}
|
else
|
{
|
attrSB = StringUtility.Contact(attrConfig.Name, "+", attrValueSB);
|
}
|
attrText.text = attrSB;
|
}
|
}
|
}
|
else
|
{
|
noneLvAdd.SetActive(true);
|
for (int i = 0; i < lvAddAttrObjs.Count; i++)
|
{
|
var attrObj = lvAddAttrObjs[i];
|
attrObj.SetActive(false);
|
}
|
}
|
}
|
|
IEnumerator DelayShow()
|
{
|
yield return null;
|
container.SetActive(true);
|
StartCoroutine(DelayAlpha());
|
}
|
|
IEnumerator DelayAlpha()
|
{
|
yield return null;
|
alpha.alpha = 1;
|
}
|
}
|
}
|