//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, April 26, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class ExpertSkillSelectWin : Window
|
{
|
[SerializeField] PositionTween m_PositionTween;
|
[SerializeField] SkillExpertWidget[] m_SkillExperts;
|
[SerializeField] UIAlphaTween m_AlphaTween;
|
[SerializeField] Image m_SkillIcon;
|
[SerializeField] Text m_SkillName;
|
[SerializeField] Text m_Reiki;
|
[SerializeField] Text m_ReikiPoint;
|
[SerializeField] ExpertSkillCyclicScroll m_CyclicScroll;
|
[SerializeField] LayoutElement m_LayoutElement;
|
[SerializeField] Button m_Active;
|
[SerializeField] Button m_Select;
|
[SerializeField] Button m_Close1;
|
[SerializeField] Button m_Close2;
|
|
public static int selectSkillId = 0;
|
|
bool m_OpenDetail = false;
|
|
int m_SelectExpert = 0;
|
int selectExpert
|
{
|
get { return m_SelectExpert; }
|
set
|
{
|
if (m_SelectExpert != value)
|
{
|
if (!m_OpenDetail)
|
{
|
m_OpenDetail = true;
|
DisplayAnimation();
|
}
|
m_SelectExpert = value;
|
DisplaySelect();
|
DisplayDetail();
|
}
|
}
|
}
|
|
int selectActiveLevel = 0;
|
|
List<int> datas = new List<int>();
|
|
TreasureSkillModel model { get { return ModelCenter.Instance.GetModel<TreasureSkillModel>(); } }
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
//m_Controller.OnRefreshCell += OnRefreshCell;
|
m_Select.AddListener(OnSelect);
|
m_Close1.AddListener(CloseClick);
|
m_Close2.AddListener(CloseClick);
|
m_Active.AddListener(OnActiveSkill);
|
}
|
|
protected override void OnPreOpen()
|
{
|
m_PositionTween.SetStartState();
|
m_AlphaTween.SetStartState();
|
|
m_OpenDetail = false;
|
|
m_CyclicScroll.enabled = false;
|
|
Display();
|
|
model.expertActiveRefresh += ExpertActiveRefresh;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
m_CyclicScroll.Dispose();
|
|
StopAllCoroutines();
|
|
model.expertActiveRefresh -= ExpertActiveRefresh;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
void Display()
|
{
|
SetDefaultSelect();
|
|
DisplayExperts();
|
DisplaySelect();
|
DisplayDetail();
|
}
|
|
void SetDefaultSelect()
|
{
|
m_SelectExpert = 0;
|
}
|
|
void DisplayExperts()
|
{
|
TreasureSkill skill;
|
if (model.TryGetSkill(selectSkillId, out skill))
|
{
|
for (int i = 0; i < m_SkillExperts.Length; i++)
|
{
|
var potential = skill.potentials[i];
|
m_SkillExperts[i].Display(potential.id, PlayerDatas.Instance.baseData.LV >= potential.limitLevel, OnSelect);
|
}
|
}
|
}
|
|
void DisplaySelect()
|
{
|
for (int i = 0; i < m_SkillExperts.Length; i++)
|
{
|
m_SkillExperts[i].SetSelect(selectExpert == m_SkillExperts[i].skillId);
|
}
|
}
|
|
void DisplayDetail()
|
{
|
if (selectExpert != 0)
|
{
|
selectActiveLevel = 0;
|
model.TryGetExpertActiveLevel(selectExpert, out selectActiveLevel);
|
|
DisplayButtonState();
|
|
var skillConfig = SkillConfig.Get(selectExpert);
|
|
m_SkillIcon.SetSprite(skillConfig.IconName);
|
m_SkillName.text = skillConfig.SkillName;
|
|
var property = skillConfig.RequireProperty();
|
var propertyConfig = PlayerPropertyConfig.Get(property);
|
m_Reiki.text = propertyConfig.Name;
|
m_Reiki.color = UIHelper.GetPropertyColor(property);
|
|
m_ReikiPoint.text = string.Format("我的{0}灵根:{1}",
|
propertyConfig.Name, UIHelper.GetPropertyValue((PropertyType)property));
|
|
datas.Clear();
|
for (int i = 1; i <= skillConfig.SkillMaxLV; i++)
|
{
|
if (i >= selectActiveLevel)
|
{
|
datas.Add(selectExpert * 100 + i);
|
}
|
}
|
|
//m_LayoutElement.preferredHeight = datas.Count > 2 ? 440 : 302;
|
|
m_CyclicScroll.enabled = true;
|
|
m_CyclicScroll.Dispose();
|
m_CyclicScroll.Init(datas);
|
StartCoroutine(Co_Arrange());
|
}
|
}
|
|
IEnumerator Co_Arrange()
|
{
|
yield return null;
|
m_CyclicScroll.ReArrange();
|
}
|
|
void DisplayButtonState()
|
{
|
TreasurePotential expert;
|
if (model.TryGetPotential(selectExpert, out expert))
|
{
|
var satisfyActive = model.SatisfyActiveExpert(selectExpert);
|
var activeLevel = 0;
|
model.TryGetExpertActiveLevel(selectExpert, out activeLevel);
|
m_Select.gameObject.SetActive(activeLevel > 0 && !satisfyActive);
|
m_Active.gameObject.SetActive(satisfyActive);
|
}
|
}
|
|
void DisplayAnimation()
|
{
|
m_PositionTween.Play();
|
m_AlphaTween.Play();
|
}
|
|
private void OnSelect()
|
{
|
if (selectExpert != 0)
|
{
|
var pak = new CA516_tagCMSelectSkillElement();
|
pak.SkillTypeID = (uint)selectExpert;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
CloseImmediately();
|
}
|
|
private void OnActiveSkill()
|
{
|
if (m_CyclicScroll.IsPlaying)
|
{
|
return;
|
}
|
var pak = new CA516_tagCMSelectSkillElement();
|
pak.SkillTypeID = (uint)selectExpert;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
private void OnSelect(int skillId)
|
{
|
if (m_CyclicScroll.IsPlaying)
|
{
|
return;
|
}
|
selectExpert = skillId;
|
}
|
|
private void ExpertActiveRefresh(int id)
|
{
|
if (selectExpert == id)
|
{
|
var level = 0;
|
if (model.TryGetExpertActiveLevel(selectExpert, out level))
|
{
|
if (level > selectActiveLevel && level > 1)
|
{
|
m_CyclicScroll.DisplayAnimation(()=>
|
{
|
DisplayDetail();
|
});
|
}
|
}
|
DisplayButtonState();
|
}
|
}
|
|
#endregion
|
|
[Serializable]
|
public class SkillExpertWidget
|
{
|
[SerializeField] ImageEx m_Bottom;
|
[SerializeField] ImageEx m_Icon;
|
[SerializeField] Text m_SkillName;
|
[SerializeField] ImageEx m_ReikiBottom;
|
[SerializeField] Text m_Reiki;
|
[SerializeField] Transform m_ContainerSelect;
|
[SerializeField] Text m_Use;
|
[SerializeField] Text m_Limit;
|
[SerializeField] RedpointBehaviour m_Redpoint;
|
[SerializeField] Button m_Select;
|
|
public int skillId { get; private set; }
|
|
TreasureSkillModel model { get { return ModelCenter.Instance.GetModel<TreasureSkillModel>(); } }
|
|
public void Display(int skillId, bool unlock, Action<int> func)
|
{
|
this.skillId = skillId;
|
|
var skillConfig = SkillConfig.Get(skillId);
|
|
m_Icon.SetSprite(skillConfig.IconName);
|
m_SkillName.text = skillConfig.SkillName;
|
|
var property = skillConfig.RequireProperty();
|
var propertyConfig = PlayerPropertyConfig.Get(property);
|
m_Reiki.text = propertyConfig.Name;
|
m_Reiki.color = unlock ? UIHelper.GetPropertyColor(property) : UIHelper.s_Gray;
|
|
var selectExpertSkill = 0;
|
model.TryGetExpertSkill(ExpertSkillSelectWin.selectSkillId, out selectExpertSkill);
|
m_Use.gameObject.SetActive(selectExpertSkill == skillId);
|
|
TreasurePotential expert;
|
model.TryGetPotential(skillId, out expert);
|
|
m_Limit.text = string.Format("{0}级可使用", expert.limitLevel);
|
|
m_Limit.gameObject.SetActive(!unlock);
|
m_Bottom.gray = !unlock;
|
m_Icon.gray = !unlock;
|
m_ReikiBottom.gray = !unlock;
|
|
m_Redpoint.redpointId = expert.activeRedpoint.id;
|
|
m_Select.SetListener(() =>
|
{
|
if (func != null)
|
{
|
func(skillId);
|
}
|
});
|
}
|
|
public void SetSelect(bool select)
|
{
|
m_ContainerSelect.gameObject.SetActive(select);
|
}
|
}
|
|
}
|
|
}
|
|
|
|
|