//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, October 09, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
namespace Snxxz.UI
|
{
|
|
public class TreasurePotentialBriefInfo : MonoBehaviour
|
{
|
[SerializeField] PositionTween m_DeadPotentailTween;
|
[SerializeField] Text m_PotentialName;
|
[SerializeField] Text m_Level;
|
[SerializeField] Button m_Button;
|
[SerializeField] UIEffect m_PotentialSfx;
|
[SerializeField] Image m_Select;
|
[SerializeField] Image m_Icon;
|
//[SerializeField] ScaleTween m_SelectScale;
|
|
public TreasurePotential potential { get; private set; }
|
|
int maxLevel = 10;
|
|
TreasurePotentialPanel m_TreasurePotential;
|
public TreasurePotentialPanel treasurePotential {
|
get {
|
return m_TreasurePotential;
|
}
|
set {
|
if (m_TreasurePotential != null)
|
{
|
m_TreasurePotential.potentialSelectEvent -= OnPotentialSelected;
|
}
|
m_TreasurePotential = value;
|
m_TreasurePotential.potentialSelectEvent += OnPotentialSelected;
|
}
|
}
|
|
public PositionTween potentialTween { get { return m_DeadPotentailTween; } }
|
|
TreasureModel model { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
|
public void DisplayBaseInfo(TreasurePotential _potential, int _state = 0)
|
{
|
potential = _potential;
|
var config = SkillConfig.Get(potential.id);
|
maxLevel = config.SkillMaxLV;
|
m_Select.gameObject.SetActive(false);
|
|
if (treasurePotential.selectedPotential == potential.id && _state != 2)
|
{
|
OnPotentialSelected(potential.id);
|
}
|
|
bool _unlock = potential != null && model.IsPotentialUnlock(model.selectedTreasure, potential.id);
|
if (_state == 2 || model.GetPotentialUnlockShow(model.selectedTreasure))
|
{
|
_unlock = false;
|
}
|
m_Level.text = _unlock ? StringUtility.Contact(_potential.level, "/", maxLevel) : string.Empty;
|
m_Level.transform.localScale = Vector3.one;
|
|
DisplayName(_unlock, config);
|
|
model.potentialLevelChangeEvent -= OnPotentialLevelUp;
|
model.potentialLevelChangeEvent += OnPotentialLevelUp;
|
|
DisplayStateSfx(!_unlock);
|
}
|
|
public void Dispose()
|
{
|
model.potentialLevelChangeEvent -= OnPotentialLevelUp;
|
}
|
|
private void SelectPotential()
|
{
|
if (potential == null/* || !model.IsPotentialUnlock(model.selectedTreasure, potential.id)*/)
|
{
|
return;
|
}
|
treasurePotential.selectedPotential = potential.id;
|
}
|
|
public void SelectTotal()
|
{
|
m_Select.gameObject.SetActive(false);
|
}
|
|
public void DisplayUnlock()
|
{
|
DisplayStateSfx();
|
var config = SkillConfig.Get(potential.id);
|
bool _unlock = potential != null && model.IsPotentialUnlock(model.selectedTreasure, potential.id);
|
m_Level.text = _unlock ? StringUtility.Contact(potential.level, "/", maxLevel) : string.Empty;
|
m_Level.transform.localScale = Vector3.one;
|
DisplayName(_unlock, config);
|
}
|
|
void DisplayName(bool unlock, SkillConfig config)
|
{
|
m_PotentialName.text = config.SkillName;
|
m_PotentialName.color = UIHelper.GetUIColor(TextColType.LightYellow);
|
if (!unlock)
|
{
|
var requirement = string.Empty;
|
if (config.LearnSkillReq > 0 && config.LearnSkillLV > 0)
|
{
|
var preskillConfig = SkillConfig.Get(config.LearnSkillReq);
|
requirement = Language.Get("Hallows_NeedSkillLVStart", preskillConfig.SkillName, config.LearnSkillLV, config.SkillName);
|
m_PotentialName.text = requirement;
|
m_PotentialName.color = UIHelper.GetUIColor(TextColType.Red);
|
}
|
}
|
}
|
|
public void OnPotentialSelected(int _potentialId)
|
{
|
m_Select.gameObject.SetActive(_potentialId == potential.id);
|
}
|
|
private void OnPotentialLevelUp(int _treasureId, int _potential)
|
{
|
if (potential.id != _potential)
|
{
|
return;
|
}
|
|
m_Level.text = StringUtility.Contact(potential.level, "/", maxLevel);
|
//DisplayStateSfx();
|
}
|
|
public void DisplayStateSfx(int _state)
|
{
|
m_PotentialSfx.StopImediatly();
|
m_PotentialSfx.loop = true;
|
m_DeadPotentailTween.enabled = false;
|
m_DeadPotentailTween.SetStartState();
|
m_Icon.material = MaterialUtility.GetUIDefaultGraphicMaterial();
|
switch (_state)
|
{
|
case 0:
|
m_DeadPotentailTween.enabled = true;
|
m_Icon.material = MaterialUtility.GetDefaultSpriteGrayMaterial();
|
break;
|
case 1:
|
m_PotentialSfx.effect = 5128;
|
m_PotentialSfx.Play();
|
break;
|
case 2:
|
m_PotentialSfx.effect = 5129;
|
m_PotentialSfx.Play();
|
break;
|
case 3:
|
m_PotentialSfx.effect = 5130;
|
m_PotentialSfx.Play();
|
break;
|
case 4:
|
m_PotentialSfx.effect = 5131;
|
m_PotentialSfx.Play();
|
break;
|
}
|
}
|
|
public void DisplayStateSfx(bool _animation = false)
|
{
|
if (potential == null || !model.IsPotentialUnlock(model.selectedTreasure, potential.id) || _animation)
|
{
|
DisplayStateSfx(0);
|
}
|
else if (potential.level == 0)
|
{
|
DisplayStateSfx(1);
|
}
|
else if (potential.level < 15)
|
{
|
DisplayStateSfx(2);
|
}
|
else if (potential.level < maxLevel)
|
{
|
DisplayStateSfx(3);
|
}
|
else
|
{
|
DisplayStateSfx(4);
|
}
|
}
|
|
public void StartLevelTween()
|
{
|
var tweener = m_Level.transform.DOScale(Vector3.one * 3, 0.2f);
|
tweener.OnStepComplete(() =>
|
{
|
m_Level.transform.DOScale(Vector3.one, 0.2f);
|
});
|
}
|
|
private void Awake()
|
{
|
if (m_Button != null)
|
{
|
m_Button.AddListener(SelectPotential);
|
}
|
}
|
}
|
}
|
|
|
|