//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, February 28, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class EquipStarWin : Window
|
{
|
[SerializeField] CyclicScroll m_CandidateScroll;
|
[SerializeField] ImageCouple[] m_Stars;
|
[SerializeField] ItemCell m_TargetEquip;
|
[SerializeField] Materials m_Materials;
|
[SerializeField] Text m_SuccessRate;
|
[SerializeField] BaseProperty[] m_BasePropertys;
|
[SerializeField] Text[] m_LevelUpPropertys;
|
[SerializeField] Button m_StarUpgrade;
|
[SerializeField] EquipStarMaterialCandidateWidget m_MaterialCandidateWidget;
|
|
EquipStarModel model { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
#region Built-in
|
protected override void BindController()
|
{
|
m_StarUpgrade.SetListener(StarUpgrade);
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
DisplayBaseInfo();
|
DisplayDynamicInfo(true);
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
DisplayDynamicInfo(false);
|
}
|
|
#endregion
|
|
private void DisplayBaseInfo()
|
{
|
var equip = packModel.GetItemByGuid(model.selectedEquip.Fetch());
|
var currentStarLevel = model.GetEquipStarLevel(equip.config.LV, equip.config.EquipPlace);
|
var starConfig = EquipStarConfig.Get(equip.config.LV, equip.config.EquipPlace, currentStarLevel);
|
for (var i = 1; i <= 5; i++)
|
{
|
m_Materials[i].Display(i >= starConfig.CostEquipCnt);
|
}
|
|
m_Materials[6].Display(starConfig.CostItemDict.x == 0);
|
}
|
|
private void DisplayDynamicInfo(bool force)
|
{
|
if (force || model.selectedEquip.dirty)
|
{
|
var equip = packModel.GetItemByGuid(model.selectedEquip.Fetch());
|
m_TargetEquip.Init(equip);
|
|
var currentStarLevel = model.GetEquipStarLevel(equip.config.LV, equip.config.EquipPlace);
|
DisplayStars(equip.config.LV, equip.config.EquipPlace, currentStarLevel);
|
DisplayBaseProperty(equip.config.LV, equip.config.EquipPlace, currentStarLevel);
|
DisplayLevelUpProperty(equip.config.LV, equip.config.EquipPlace, currentStarLevel);
|
}
|
|
if (force || model.starUpgradeProbability.dirty)
|
{
|
m_SuccessRate.text = string.Format("成功率 {0}", model.starUpgradeProbability.Fetch());
|
}
|
|
if (force || equipModel.selectedLevel.dirty)
|
{
|
var level = equipModel.selectedLevel.Fetch();
|
var candidates = model.GetCandidateEquips();
|
m_CandidateScroll.Init(candidates);
|
}
|
|
if (force || model.operateMaterialIndex.dirty)
|
{
|
var index = model.operateMaterialIndex.Fetch();
|
DisplayMaterialCandidates(index);
|
}
|
}
|
|
private void DisplayStars(int level, int equipPlace, int currentStarLevel)
|
{
|
var maxStarLevel = model.GetMaxStarLevel(level);
|
for (var i = 0; i < m_Stars.Length; i++)
|
{
|
if (i < maxStarLevel)
|
{
|
m_Stars[i].Display(i < currentStarLevel);
|
}
|
else
|
{
|
m_Stars[i].Hide();
|
}
|
}
|
}
|
|
private void DisplayBaseProperty(int level, int equipPlace, int currentStarLevel)
|
{
|
var nowConfig = EquipStarConfig.Get(level, equipPlace, currentStarLevel);
|
var nextConfig = EquipStarConfig.Get(level, equipPlace, currentStarLevel + 1);
|
var count = nextConfig.BaseAttrInfo.Length;
|
for (var i = 0; i < m_BasePropertys.Length; i++)
|
{
|
var behaviour = m_BasePropertys[i];
|
if (i < count)
|
{
|
var current = nowConfig == null ? 0 : nowConfig.BaseAttrInfo[i].y;
|
var next = nextConfig == null ? 0 : nextConfig.BaseAttrInfo[i].y;
|
behaviour.Display(nextConfig == null ? 0 : nextConfig.BaseAttrInfo[i].x, current, next);
|
}
|
else
|
{
|
behaviour.Hide();
|
}
|
}
|
}
|
|
private void DisplayLevelUpProperty(int level, int equipPlace, int currentStarLevel)
|
{
|
var configs = EquipStarConfig.GetConfigs(level, equipPlace);
|
var levelUpProperties = new Dictionary<int, Int2>();
|
var prePropertiesCount = 0;
|
foreach (var config in configs)
|
{
|
if (config.StarAttrInfo.Length > prePropertiesCount)
|
{
|
var length = config.StarAttrInfo.Length;
|
levelUpProperties[config.Star] = config.StarAttrInfo[length - 1];
|
prePropertiesCount = config.StarAttrInfo.Length;
|
}
|
}
|
|
var keys = new List<int>(levelUpProperties.Keys);
|
for (var i = 0; i < m_LevelUpPropertys.Length; i++)
|
{
|
var behaviour = m_LevelUpPropertys[i];
|
if (i < keys.Count)
|
{
|
var property = levelUpProperties[keys[i]];
|
var config = PlayerPropertyConfig.Get(property.x);
|
behaviour.gameObject.SetActive(true);
|
behaviour.text = string.Format("【{0}星】{1}+{2}", config.Name, PlayerPropertyConfig.GetPropertyDescription(property.x, property.y));
|
behaviour.color = UIHelper.GetUIColor(keys[i] == currentStarLevel + 1 ? TextColType.Green : TextColType.Gray);
|
}
|
else
|
{
|
behaviour.gameObject.SetActive(false);
|
}
|
}
|
}
|
|
private void DisplayMaterialCandidates(int materialIndex)
|
{
|
if (materialIndex == 0)
|
{
|
m_MaterialCandidateWidget.gameObject.SetActive(false);
|
}
|
else
|
{
|
m_MaterialCandidateWidget.gameObject.SetActive(true);
|
|
var targetEquip = model.selectedEquip.value;
|
var item = packModel.GetItemByGuid(targetEquip);
|
var starLevel = model.GetEquipStarLevel(item.config.lv, item.config.EquipPlace);
|
m_MaterialCandidateWidget.Display(item.config.LV, item.config.EquipPlace, starLevel);
|
|
var position = Vector3.zero;
|
m_MaterialCandidateWidget.transform.localPosition = position;
|
}
|
}
|
|
private void StarUpgrade()
|
{
|
var equip = packModel.GetItemByGuid(model.selectedEquip.value);
|
var level = equip.config.LV;
|
var place = equip.config.EquipPlace;
|
var currentStarLevel = model.GetEquipStarLevel(level, place);
|
model.DoStarUpgrade(level, place, currentStarLevel);
|
}
|
|
[System.Serializable]
|
public class ImageCouple
|
{
|
public RectTransform container;
|
public Image imageBase;
|
public Image imageStar;
|
|
public void Display(bool active)
|
{
|
container.gameObject.SetActive(true);
|
imageStar.gameObject.SetActive(active);
|
}
|
|
public void Hide()
|
{
|
container.gameObject.SetActive(false);
|
}
|
}
|
|
[System.Serializable]
|
public class Materials
|
{
|
public EquipStarUpgradeMaterialBehaviour m_Material1;
|
public EquipStarUpgradeMaterialBehaviour m_Material2;
|
public EquipStarUpgradeMaterialBehaviour m_Material3;
|
public EquipStarUpgradeMaterialBehaviour m_Material4;
|
public EquipStarUpgradeMaterialBehaviour m_Material5;
|
public EquipStarUpgradeMaterialBehaviour m_MaterialSpecial;
|
|
public EquipStarUpgradeMaterialBehaviour this[int index]
|
{
|
get
|
{
|
switch (index)
|
{
|
case 1:
|
return m_Material1;
|
case 2:
|
return m_Material2;
|
case 3:
|
return m_Material3;
|
case 4:
|
return m_Material4;
|
case 5:
|
return m_Material5;
|
case 6:
|
return m_MaterialSpecial;
|
default:
|
return null;
|
}
|
}
|
}
|
|
}
|
|
[System.Serializable]
|
public class BaseProperty
|
{
|
public RectTransform container;
|
public Text current;
|
public Text next;
|
|
public void Display(int propertyId, int currentValue, int nextValue)
|
{
|
container.gameObject.SetActive(true);
|
var config = PlayerPropertyConfig.Get(propertyId);
|
if (config != null)
|
{
|
this.current.text = StringUtility.Contact(config.Name, ":", PlayerPropertyConfig.GetPropertyDescription(propertyId, currentValue));
|
this.next.text = PlayerPropertyConfig.GetPropertyDescription(propertyId, nextValue);
|
}
|
}
|
|
public void Hide()
|
{
|
container.gameObject.SetActive(false);
|
}
|
}
|
|
|
}
|
|
}
|