//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, April 26, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
public class ExpertSkillSelectBehaviour : MonoBehaviour
|
{
|
[SerializeField] ExpertSkillCyclicScroll m_CyclicScroll;
|
[SerializeField] Button m_Active;
|
[SerializeField] Button m_Learn;
|
[SerializeField] UIEffect m_LearnEffect;
|
[SerializeField] Text m_SkillName;
|
|
public int skillId = 0;
|
|
int m_CacheExpertLevel = 0;
|
|
List<int> datas = new List<int>();
|
|
Coroutine m_CacheCoroutine;
|
|
TreasureSkillModel model { get { return ModelCenter.Instance.GetModel<TreasureSkillModel>(); } }
|
#region Built-in
|
|
public void OnShow()
|
{
|
m_Active.SetListener(OnUseSkill);
|
m_Learn.SetListener(OnLearnSkill);
|
model.expertActiveRefresh += ExpertActiveRefresh;
|
skillId = model.selecttExpertSkill;
|
Display();
|
}
|
|
public void OnClose()
|
{
|
m_CyclicScroll.Dispose();
|
|
StopAllCoroutines();
|
|
m_CacheCoroutine = null;
|
|
model.expertActiveRefresh -= ExpertActiveRefresh;
|
}
|
|
void Display()
|
{
|
DisplayDetail();
|
}
|
|
void DisplayDetail()
|
{
|
if (m_CacheCoroutine != null)
|
{
|
StopCoroutine(m_CacheCoroutine);
|
m_CacheCoroutine = null;
|
}
|
|
m_CacheExpertLevel = 0;
|
model.TryGetExpertActiveLevel(skillId, out m_CacheExpertLevel);
|
|
DisplayButtonState();
|
|
var skillConfig = SkillConfig.Get(skillId);
|
|
datas.Clear();
|
|
for (int i = 1; i <= skillConfig.SkillMaxLV; i++)
|
{
|
datas.Add(skillId * 100 + i);
|
}
|
|
m_CyclicScroll.Dispose();
|
m_CyclicScroll.Display(skillId, skillConfig.SkillMaxLV);
|
|
if (m_CacheExpertLevel >= 2)
|
{
|
m_CacheCoroutine = StartCoroutine(Co_MoveToCenter2(m_CacheExpertLevel));
|
}
|
|
m_SkillName.text = skillConfig.SkillName;
|
}
|
|
void DisplayButtonState()
|
{
|
//TreasurePotential expert;
|
//if (model.TryGetPotential(skillId, out expert))
|
//m_ActiveEffect.Play();
|
var error = 0;
|
var satisfyActive = model.SatisfyActiveExpert(skillId, out error);
|
if (satisfyActive)
|
m_LearnEffect.Play();
|
else
|
m_LearnEffect.StopImediatly();
|
|
m_Learn.SetActive(error != 2);
|
var level = 0;
|
model.TryGetExpertActiveLevel(skillId, out level);
|
|
var tmpSkillId = 0; // 当前使用专精
|
model.TryGetExpertSkill(model.selectSkill, out tmpSkillId);
|
m_Active.SetActive(tmpSkillId != this.skillId && level != 0);
|
if (tmpSkillId == 0 && level != 0)
|
//若已学习专精 但未使用 则自动使用
|
OnUseSkill();
|
}
|
|
private void OnUseSkill()
|
{
|
var level = 0;
|
model.TryGetExpertActiveLevel(skillId, out level);
|
if (level == 0)
|
return;
|
|
var pak = new CA516_tagCMSelectSkillElement();
|
pak.SkillTypeID = (uint)skillId;
|
pak.DoType = 1;
|
GameNetSystem.Instance.SendInfo(pak);
|
|
m_Active.SetActive(false);
|
|
}
|
|
private void OnLearnSkill()
|
{
|
var error = 0;
|
var satisfyActive = model.SatisfyActiveExpert(skillId, out error);
|
if (!satisfyActive)
|
{
|
ExpertSkillActiveRemindWin.skillId = skillId;
|
WindowCenter.Instance.Open<ExpertSkillActiveRemindWin>();
|
return;
|
}
|
var pak = new CA516_tagCMSelectSkillElement();
|
pak.SkillTypeID = (uint)skillId;
|
pak.DoType = 0;
|
GameNetSystem.Instance.SendInfo(pak);
|
|
}
|
|
|
private void ExpertActiveRefresh(int id)
|
{
|
if (skillId == id)
|
{
|
var level = 0;
|
if (model.TryGetExpertActiveLevel(id, out level))
|
{
|
if (level > m_CacheExpertLevel && level >= 2)
|
{
|
if (m_CacheCoroutine != null)
|
{
|
StopCoroutine(m_CacheCoroutine);
|
m_CacheCoroutine = null;
|
}
|
m_CacheCoroutine = StartCoroutine(Co_MoveToCenter1(level));
|
}
|
}
|
|
DisplayButtonState();
|
}
|
}
|
|
IEnumerator Co_MoveToCenter2(int level)
|
{
|
yield return null;
|
m_CyclicScroll.MoveToCenter(level);
|
}
|
|
IEnumerator Co_MoveToCenter1(int level)
|
{
|
yield return WaitingForSecondConst.WaitMS500;
|
m_CyclicScroll.MoveToCenter(level);
|
}
|
#endregion
|
|
|
}
|
|
}
|