//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, February 20, 2019
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
[XLua.Hotfix]
|
public class TreasureSkillWin : Window
|
{
|
[SerializeField] ScrollerController m_Controller;
|
|
[SerializeField] Text m_SkillName;
|
[SerializeField] Text m_SkillLevel;
|
[SerializeField] Text m_SkillCoolDown;
|
[SerializeField] Transform m_ContainerNow;
|
[SerializeField] Text m_SkillDescNow;
|
[SerializeField] Transform m_ContainerNext;
|
[SerializeField] Text m_SkillDescNext;
|
[SerializeField] Transform m_ContainerLevelUp;
|
[SerializeField] ItemBehaviour m_Item;
|
[SerializeField] Button m_GetWay;
|
[SerializeField] Button m_LevelUp;
|
[SerializeField] RedpointBehaviour m_LevelRedpoint;
|
[SerializeField] UIEffect m_LevelUpEffect;
|
[SerializeField] Transform m_ContainerMax;
|
[SerializeField] TreasurePotentialBehaviour[] m_TreasurePotentials;
|
|
List<Clock> clocks = new List<Clock>();
|
|
TreasureSkillModel model
|
{
|
get { return ModelCenter.Instance.GetModel<TreasureSkillModel>(); }
|
}
|
|
PackModel packModel
|
{
|
get { return ModelCenter.Instance.GetModel<PackModel>(); }
|
}
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_Controller.OnRefreshCell += OnRefreshCell;
|
m_LevelUp.AddListener(LevelUp);
|
}
|
|
protected override void OnPreOpen()
|
{
|
SetDefaultSelect();
|
|
Display();
|
|
List<int> list;
|
if (model.TryGetSkills(out list))
|
{
|
var index = list.IndexOf(model.selectSkill);
|
if (index != -1)
|
{
|
m_Controller.JumpIndex(index);
|
}
|
}
|
|
model.treasureSkillRefresh += TreasureSkillRefresh;
|
model.selectRefresh += SelectRefresh;
|
model.skillLevelUpRefresh += SkillLevelUpRefresh;
|
packModel.refreshItemCountEvent += RefreshItemCountEvent;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
model.treasureSkillRefresh -= TreasureSkillRefresh;
|
model.selectRefresh -= SelectRefresh;
|
model.skillLevelUpRefresh -= SkillLevelUpRefresh;
|
packModel.refreshItemCountEvent -= RefreshItemCountEvent;
|
model.SetAlreadyRemind();
|
|
for (int i = 0; i < m_TreasurePotentials.Length; i++)
|
{
|
m_TreasurePotentials[i].StopUnlock();
|
}
|
|
foreach (var clock in clocks)
|
{
|
Clock.Stop(clock);
|
}
|
clocks.Clear();
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
void SetDefaultSelect()
|
{
|
var selectSkill = 0;
|
List<int> list;
|
if (model.TryGetSkills(out list))
|
{
|
foreach (var skillId in list)
|
{
|
TreasureSkill skill;
|
if (model.TryGetSkill(skillId, out skill))
|
{
|
if (selectSkill == 0 && skill.level > 0)
|
{
|
selectSkill = skillId;
|
}
|
if (skill.redpoint.state == RedPointState.Simple)
|
{
|
selectSkill = skillId;
|
}
|
}
|
}
|
if (selectSkill == 0)
|
{
|
selectSkill = list[0];
|
}
|
}
|
model.selectSkill = selectSkill;
|
}
|
|
private void Display()
|
{
|
DisplaySkills();
|
DisplaySkillDetial();
|
DisplayPotentials();
|
}
|
|
private void DisplaySkills()
|
{
|
List<int> list;
|
m_Controller.Refresh();
|
if (model.TryGetSkills(out list))
|
{
|
for (int i = 0; i < list.Count; i++)
|
{
|
m_Controller.AddCell(ScrollerDataType.Header, list[i]);
|
}
|
}
|
m_Controller.Restart();
|
}
|
|
void DisplaySkillDetial()
|
{
|
TreasureSkill skill;
|
m_GetWay.RemoveAllListeners();
|
if (model.TryGetSkill(model.selectSkill, out skill))
|
{
|
var config = skill.GetSkillConfig(skill.level);
|
if (config == null)
|
{
|
return;
|
}
|
m_SkillName.text = config.SkillName;
|
m_SkillLevel.text = Language.Get("SkillActLevel", skill.level);
|
m_SkillCoolDown.text = Language.Get("L1065", config.CoolDownTime / 1000);
|
m_SkillDescNow.text = config.Description;
|
m_LevelRedpoint.redpointId = skill.levelUpRedpoint.id;
|
|
bool isMax = skill.level >= skill.maxLevel;
|
m_ContainerNext.gameObject.SetActive(!isMax);
|
m_ContainerLevelUp.gameObject.SetActive(!isMax);
|
m_ContainerMax.gameObject.SetActive(isMax);
|
|
if (!isMax)
|
{
|
var nextSkillConfig = SkillConfig.Get(skill.skillId + skill.level);
|
m_SkillDescNext.text = nextSkillConfig.Description;
|
m_Item.SetItem(nextSkillConfig.ExAttr4, nextSkillConfig.ExAttr5);
|
m_GetWay.AddListener(() =>
|
{
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.Daily_EmperorRelic);
|
});
|
}
|
}
|
}
|
|
private void DisplayPotentials()
|
{
|
for (int i = 0; i < m_TreasurePotentials.Length; i++)
|
{
|
DisplayPotential(i);
|
}
|
}
|
|
private void DisplayPotential(int index)
|
{
|
TreasureSkill skill;
|
if (!model.TryGetSkill(model.selectSkill, out skill))
|
{
|
return;
|
}
|
if (index < m_TreasurePotentials.Length)
|
{
|
m_TreasurePotentials[index].gameObject.SetActive(index < skill.potentials.Count);
|
m_TreasurePotentials[index].Display(skill.potentials[index].id);
|
}
|
}
|
|
private void LevelUp()
|
{
|
var error = 0;
|
if (model.TryLevelUpTreasureSkill(model.selectSkill, out error))
|
{
|
var pak = new C0304_tagCAddSkillPoint();
|
pak.SkillID = (ushort)model.selectSkill;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
else
|
{
|
model.DisplayLevelUpError(error);
|
}
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
var skillCell = cell as TreasureSkillCell;
|
skillCell.Display(cell.index);
|
}
|
|
private void TreasureSkillRefresh(int skillId)
|
{
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
if (skillId == model.selectSkill)
|
{
|
DisplaySkillDetial();
|
}
|
}
|
|
private void SelectRefresh()
|
{
|
for (int i = 0; i < m_TreasurePotentials.Length; i++)
|
{
|
m_TreasurePotentials[i].StopUnlock();
|
}
|
|
foreach (var clock in clocks)
|
{
|
Clock.Stop(clock);
|
}
|
clocks.Clear();
|
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
DisplaySkillDetial();
|
DisplayPotentials();
|
}
|
|
private void SkillLevelUpRefresh(int id)
|
{
|
if (model.selectSkill == id)
|
{
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
DisplaySkillDetial();
|
|
m_LevelUpEffect.Play();
|
|
TreasureSkill skill;
|
if (model.TryGetSkill(model.selectSkill, out skill))
|
{
|
for (int i = 0; i < skill.potentials.Count; i++)
|
{
|
var index = i;
|
if (index < m_TreasurePotentials.Length &&
|
skill.potentials[index].openLevel == skill.level)
|
{
|
m_TreasurePotentials[index].StartUnlock();
|
Clock clock = null;
|
clock = Clock.AlarmAfter(1, () =>
|
{
|
DisplayPotential(index);
|
if (clock != null && clocks.Contains(clock))
|
{
|
clocks.Remove(clock);
|
}
|
});
|
clocks.Add(clock);
|
}
|
}
|
}
|
}
|
else
|
{
|
var skillId = 0;
|
if (model.ContainsSkill(id, out skillId))
|
{
|
if (skillId == model.selectSkill)
|
{
|
DisplayPotentials();
|
}
|
}
|
}
|
}
|
|
private void RefreshItemCountEvent(PackType packType, int arg2, int itemId)
|
{
|
if (packType == PackType.Item && model.skillLevelUpItems.Contains(itemId))
|
{
|
DisplaySkillDetial();
|
}
|
}
|
}
|
|
}
|
|
|
|
|