//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, July 18, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using DG.Tweening;
|
|
namespace vnxbqy.UI
|
{
|
|
public class EquipStarSuccessWin : Window
|
{
|
[SerializeField] ScrollRect m_ScrollRect;
|
[SerializeField] Star[] m_Stars;
|
[SerializeField] ItemCell m_ItemCell;
|
[SerializeField] Text m_EquipStar;
|
[SerializeField] BaseProperty[] m_BaseProperties;
|
|
[SerializeField] RectTransform m_CloseTip;
|
[SerializeField] Button m_Close;
|
|
List<EquipStarSuccessActiveItemBehaviour> activeItemBehaviours = new List<EquipStarSuccessActiveItemBehaviour>();
|
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
EquipStarModel starModel { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
|
EquipStarSuccessModel model { get { return ModelCenter.Instance.GetModel<EquipStarSuccessModel>(); } }
|
EquipStrengthModel strengthModel { get { return ModelCenter.Instance.GetModel<EquipStrengthModel>(); } }
|
EquipTrainModel equipTrainModel { get { return ModelCenter.Instance.GetModel<EquipTrainModel>(); } }
|
|
int ActiveSuit = -1;
|
string ActiveSuitString = string.Empty;
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_Close.SetListener(() => { WindowCenter.Instance.Close<EquipStarSuccessWin>(); });
|
}
|
|
protected override void OnPreOpen()
|
{
|
m_CloseTip.SetActive(false);
|
m_Close.SetActive(false);
|
foreach (var behaviour in activeItemBehaviours)
|
{
|
behaviour.SetActive(false);
|
}
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
}
|
|
protected override void OnAfterClose()
|
{
|
if (ActiveSuit < 0) return;
|
ActiveSuit = -1;
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("ActiveSuitEff", ActiveSuitString), (bool isOk) =>
|
{
|
if (isOk)
|
{
|
equipModel.SelectSet(model.equipPosition.x);
|
equipModel.selectedStarLevel.value = ActiveSuit;
|
equipModel.isOpenSuiteAttrRect = true;
|
WindowCenter.Instance.Close<EquipFrameWin>();
|
WindowCenter.Instance.Open<KnapSackWin>(false, 0);
|
|
}
|
});
|
equipModel.UpdateSuitRedPoint(model.equipPosition.x);
|
|
ActiveSuitString = string.Empty;
|
return;
|
}
|
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
|
Clock.AlarmAfter(1f, () =>
|
{
|
m_Close.SetActive(true);
|
m_CloseTip.SetActive(true);
|
});
|
|
DisplayItem();
|
DisplayStars();
|
DisplayBaseProperty();
|
DisplaySpecialEffects();
|
}
|
|
#endregion
|
|
private void DisplayItem()
|
{
|
var equip = equipModel.GetEquip(model.equipPosition);
|
m_ItemCell.SetActive(true);
|
m_ItemCell.Init(packModel.GetItemByGuid(equip));
|
|
m_EquipStar.SetActive(true);
|
m_EquipStar.text = Language.Get("EquipStarLevel", model.star);
|
}
|
|
private void DisplayStars()
|
{
|
var maxStarLevel = EquipStarModel.GetMaxStarLevel(model.equipPosition.x);
|
var currentStar = model.star;
|
|
var iconCnt = m_Stars.Length;
|
for (int i = 0; i < iconCnt; i++)
|
{
|
var behaviour = m_Stars[i];
|
if (i < maxStarLevel)
|
{
|
if (i < currentStar)
|
{
|
var loopIndex = (currentStar / iconCnt * iconCnt + i < currentStar ? currentStar / iconCnt * iconCnt + i : i) / iconCnt;
|
behaviour.Display(true, loopIndex);
|
if (i == (currentStar - 1) % iconCnt)
|
{
|
behaviour.Display(false, loopIndex);
|
Clock.AlarmAfter(1f, () =>
|
{
|
behaviour.Display(true, loopIndex);
|
behaviour.PlayScaleAnimation();
|
});
|
}
|
}
|
else
|
{
|
behaviour.Display(false, 0);
|
}
|
}
|
else
|
{
|
behaviour.Hide();
|
}
|
}
|
|
}
|
|
private void DisplayBaseProperty()
|
{
|
var configs = EquipStarConfig.GetConfigs(model.equipPosition.x, model.equipPosition.y);
|
EquipStarConfig beforeConfig = null;
|
EquipStarConfig nowConfig = null;
|
|
for (int i = 0; i < configs.Count; i++)
|
{
|
var config = configs[i];
|
if (config.Star == model.star - 1)
|
{
|
beforeConfig = config;
|
}
|
else if (config.Star == model.star)
|
{
|
nowConfig = config;
|
}
|
}
|
|
var nowValues = nowConfig.BaseAttrInfo;
|
var beforeValues = new Int2[nowValues.Length];
|
if (beforeConfig != null)
|
{
|
for (var i = 0; i < beforeConfig.BaseAttrInfo.Length; i++)
|
{
|
beforeValues[i] = beforeConfig.BaseAttrInfo[i];
|
}
|
}
|
|
for (int i = 0; i < m_BaseProperties.Length; i++)
|
{
|
var behaviour = m_BaseProperties[i];
|
if (i < nowValues.Length)
|
{
|
behaviour.Display(nowValues[i].x, beforeValues[i].y, nowValues[i].y);
|
}
|
else
|
{
|
behaviour.Hide();
|
}
|
}
|
}
|
|
private void DisplaySpecialEffects()
|
{
|
m_ScrollRect.verticalNormalizedPosition = 0f;
|
DisplaySuitEffect();
|
DisplayStarProperty();
|
DisplayGemHole();
|
//DisplayStrengthLevel();
|
DisplayTrainLevel();
|
}
|
|
private void DisplaySuitEffect()
|
{
|
var star = starModel.GetStarLevel(model.equipPosition);
|
if (!equipModel.IsDressedInSuit(model.equipPosition))
|
{
|
return;
|
}
|
|
if (model.star % 3 == 0)
|
{
|
var count = 0;
|
if (model.equipPosition.y <= 8)
|
{
|
for (int i = 1; i <= 8; i++)
|
{
|
var equipPosition = new Int2(model.equipPosition.x, i);
|
var curStar = starModel.GetStarLevel(equipPosition);
|
var isSuit = equipModel.IsDressedInSuit(equipPosition);
|
if (isSuit && curStar >= model.star)
|
{
|
count++;
|
}
|
}
|
}
|
var behaviour = GetStarSuccessActiveItemBehaviour();
|
var job = PlayerDatas.Instance.baseData.Job;
|
|
switch (count)
|
{
|
case 2:
|
ActiveSuit = model.star;
|
var twoConfigs = EquipSuitConfig.GetConfigs(job, model.equipPosition.x, EquipSuitType.TwoSuit);
|
var twoConfig = twoConfigs.Find(x => { return x.star == model.star; });
|
behaviour.DisplaySuitEffect(model.star, EquipSuitType.TwoSuit, twoConfig.attr);
|
ActiveSuitString = behaviour.GetContent();
|
break;
|
case 5:
|
ActiveSuit = model.star;
|
var fiveConfigs = EquipSuitConfig.GetConfigs(job, model.equipPosition.x, EquipSuitType.FiveSuit);
|
var fiveConfig = fiveConfigs.Find(x => { return x.star == model.star; });
|
behaviour.DisplaySuitEffect(model.star, EquipSuitType.FiveSuit, fiveConfig.attr);
|
ActiveSuitString = behaviour.GetContent();
|
break;
|
case 8:
|
ActiveSuit = model.star;
|
var eightConfigs = EquipSuitConfig.GetConfigs(job, model.equipPosition.x, EquipSuitType.EightSuit);
|
var eightConfig = eightConfigs.Find(x => { return x.star == model.star; });
|
if (eightConfig.skillID > 0)
|
{
|
behaviour.DisplaySuitEffect(model.star, eightConfig.description);
|
}
|
else
|
{
|
behaviour.DisplaySuitEffect(model.star, EquipSuitType.EightSuit, eightConfig.attr);
|
}
|
ActiveSuitString = behaviour.GetContent();
|
break;
|
default:
|
behaviour.SetActive(false);
|
break;
|
|
}
|
}
|
|
}
|
|
private void DisplayStarProperty()
|
{
|
var beforeConfig = EquipStarConfig.Get(model.equipPosition.x, model.equipPosition.y, model.star - 1);
|
var nowConfig = EquipStarConfig.Get(model.equipPosition.x, model.equipPosition.y, model.star);
|
|
var behaviour = GetStarSuccessActiveItemBehaviour();
|
if (beforeConfig == null || beforeConfig.StarAttrInfo.Length != nowConfig.StarAttrInfo.Length)
|
{
|
behaviour.DisplayStarProperty(model.star, nowConfig.StarAttrInfo[nowConfig.StarAttrInfo.Length - 1]);
|
}
|
else
|
behaviour.SetActive(false);
|
}
|
|
private void DisplayGemHole()
|
{
|
var behaviour = GetStarSuccessActiveItemBehaviour();
|
if (model.star == 2 || model.star == 5)
|
{
|
behaviour.DisplayGemHole(model.star);
|
}
|
else
|
behaviour.SetActive(false);
|
}
|
|
//private void DisplayStrengthLevel()
|
//{
|
// var type = EquipStrengthModel.GetEquipStrengthType(model.equipPosition.y);
|
// var beforeLevel = strengthModel.GetEquipLevelMax(type, model.star - 1);
|
// var nowLevel = strengthModel.GetEquipLevelMax(type, model.star);
|
// var behaviour = GetStarSuccessActiveItemBehaviour();
|
// if (beforeLevel != nowLevel)
|
// {
|
// behaviour.DisplayStrengthLevelLimit(model.star, nowLevel);
|
// }
|
// else
|
// behaviour.SetActive(false);
|
//}
|
|
private void DisplayTrainLevel()
|
{
|
if (model.equipPosition.x < equipTrainModel.limitLevel)
|
return;
|
var type = EquipTrainModel.GetTrainType(model.equipPosition.y);
|
var beforeConfig = WashLevelMaxConfig.Get(type, model.star - 1);
|
var nowConfig = WashLevelMaxConfig.Get(type, model.star);
|
var behaviour = GetStarSuccessActiveItemBehaviour();
|
if (beforeConfig == null || beforeConfig.levelMax != nowConfig.levelMax)
|
{
|
behaviour.DisplayTrainLevelLimit(model.star, nowConfig.levelMax);
|
}
|
else
|
behaviour.SetActive(false);
|
}
|
|
private EquipStarSuccessActiveItemBehaviour GetStarSuccessActiveItemBehaviour()
|
{
|
foreach (var item in activeItemBehaviours)
|
{
|
if (!item.gameObject.activeInHierarchy)
|
{
|
item.SetActive(true);
|
return item;
|
}
|
}
|
|
var instance = UIUtility.CreateWidget("EquipStarSuccessActiveItemBehaviour", "EquipStarSuccessActiveItemBehaviour");
|
instance.transform.SetParentEx(m_ScrollRect.content, Vector3.zero, Quaternion.identity, Vector3.one);
|
var behaviour = instance.GetComponent<EquipStarSuccessActiveItemBehaviour>();
|
activeItemBehaviours.Add(behaviour);
|
return behaviour;
|
}
|
|
[System.Serializable]
|
public class Star
|
{
|
public RectTransform container;
|
public Image imageBase;
|
public Image imageStar;
|
|
public void Display(bool active, int loopIndex)
|
{
|
container.SetActive(true);
|
imageStar.SetActive(active);
|
imageStar.transform.localScale = Vector3.one;
|
imageStar.SetSprite("ImgStar_" + loopIndex);
|
}
|
|
public void Hide()
|
{
|
container.SetActive(false);
|
}
|
|
public void PlayScaleAnimation()
|
{
|
imageStar.transform.localScale = Vector3.one * 5;
|
imageStar.transform.DOScale(Vector3.one, 0.5f);
|
}
|
|
}
|
|
[System.Serializable]
|
public class BaseProperty
|
{
|
public RectTransform container;
|
public Text title;
|
public Text before;
|
public Text now;
|
|
public void Hide()
|
{
|
container.SetActive(false);
|
}
|
|
public void Display(int id, int beforeValue, int nowValue)
|
{
|
container.SetActive(true);
|
|
var config = PlayerPropertyConfig.Get(id);
|
title.text = string.Format("{0}:", config.Name);
|
|
before.text = beforeValue.ToString();
|
now.text = nowValue.ToString();
|
}
|
}
|
|
|
}
|
|
}
|