using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using System;
|
|
using DG.Tweening;
|
|
namespace vnxbqy.UI
|
{
|
public class TreasureProperty : MonoBehaviour
|
{
|
[SerializeField] Text m_FightPower;
|
[SerializeField] Image m_Bottom;
|
[SerializeField] RectTransform[] m_PropertyComs;
|
[SerializeField] Property[] m_Properties;
|
[SerializeField] RectTransform m_ContainerProperty;
|
[SerializeField] RectTransform m_ContainerName;
|
[SerializeField] Image m_TreasureName;
|
[SerializeField] PositionTween m_TreasureNameTween;
|
|
Treasure treasure;
|
TreasureStage m_TreasureStage;
|
|
TreasureModel m_Model;
|
TreasureModel model
|
{
|
get
|
{
|
return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<TreasureModel>());
|
}
|
}
|
|
public RectTransform containerName
|
{
|
get
|
{
|
return m_ContainerName;
|
}
|
}
|
|
public RectTransform containerProperty
|
{
|
get
|
{
|
return m_ContainerProperty;
|
}
|
}
|
|
public PositionTween treasureNameTween
|
{
|
get
|
{
|
return m_TreasureNameTween;
|
}
|
}
|
|
Dictionary<int, int> m_PropertyDict = new Dictionary<int, int>();
|
|
Dictionary<int, int> m_BeforeProperty = new Dictionary<int, int>();
|
|
public void Display(int _treasure, bool _stageUp = false)
|
{
|
if (!model.TryGetTreasure(_treasure, out treasure))
|
{
|
return;
|
}
|
var config = TreasureConfig.Get(treasure.id);
|
if (treasure.level < treasure.treasureStages.Count)
|
{
|
m_TreasureStage = treasure.treasureStages[treasure.level];
|
}
|
m_PropertyDict.Clear();
|
if (config.Category == (int)TreasureCategory.Human)
|
{
|
for (int i = 0; i < treasure.treasureStages.Count; i++)
|
{
|
TreasureStage _treasureStage = treasure.treasureStages[i];
|
if (treasure.level >= _treasureStage.stage
|
&& _treasureStage.unlockType == TreasureStageUnlock.Property)
|
{
|
foreach (var _key in _treasureStage.propertyDict.Keys)
|
{
|
if (m_PropertyDict.ContainsKey(_key))
|
{
|
m_PropertyDict[_key] += _treasureStage.propertyDict[_key];
|
}
|
else
|
{
|
m_PropertyDict[_key] = _treasureStage.propertyDict[_key];
|
}
|
}
|
}
|
}
|
}
|
|
|
int _index = 0;
|
foreach (var _key in m_PropertyDict.Keys)
|
{
|
if (_index < m_PropertyComs.Length && _index < m_Properties.Length)
|
{
|
m_PropertyComs[_index].SetActive(true);
|
m_Properties[_index].Display(_key, m_PropertyDict[_key]);
|
if (_stageUp && !m_BeforeProperty.ContainsKey(_key))
|
{
|
m_Properties[_index].StartAlphaTween(0, 1);
|
}
|
else if (_stageUp && m_BeforeProperty.ContainsKey(_key)
|
&& m_BeforeProperty[_key] < m_PropertyDict[_key])
|
{
|
StartCoroutine(Co_NumberClock(m_Properties[_index], m_BeforeProperty[_key], m_PropertyDict[_key]));
|
}
|
}
|
_index++;
|
}
|
m_Bottom.SetActive(_index > 0);
|
for (int i = _index; i < m_PropertyComs.Length; i++)
|
{
|
m_PropertyComs[i].SetActive(false);
|
}
|
|
m_BeforeProperty.Clear();
|
foreach (var _key in m_PropertyDict.Keys)
|
{
|
m_BeforeProperty.Add(_key, m_PropertyDict[_key]);
|
}
|
|
if (treasure.state != TreasureState.Collected)
|
{
|
m_FightPower.text = treasure.treasureStages.Count > 0 ? treasure.treasureStages[0].GetFightPower().ToString() : string.Empty;
|
}
|
else
|
{
|
m_FightPower.text = model.GetTreasureFightPower(_treasure).ToString();
|
}
|
m_ContainerProperty.SetActive(config.Category == 1);
|
m_TreasureName.SetSprite(config.TreasureNameIcon);
|
}
|
|
public void SetActive(bool _active)
|
{
|
if (!_active)
|
{
|
m_Bottom.SetActive(_active);
|
}
|
m_ContainerProperty.SetActive(_active);
|
m_ContainerName.SetActive(_active);
|
}
|
|
IEnumerator Co_NumberClock(Property _property, int _before, int _target)
|
{
|
float _timer = 0f;
|
int _value = _before;
|
while (_timer < 0.5f)
|
{
|
_timer += Time.deltaTime;
|
_property.propertyValue.text = StringUtility.Contact("+", _value);
|
yield return null;
|
_value = (int)((_target - _before) * _timer / 0.5f) + _before;
|
}
|
_property.propertyValue.text = StringUtility.Contact("+", _target);
|
}
|
}
|
|
[Serializable]
|
public class Property
|
{
|
[SerializeField] Text m_Property;
|
[SerializeField] Text m_Value;
|
|
public Text propertyValue
|
{
|
get
|
{
|
return m_Value;
|
}
|
}
|
|
public void Display(int _property, float _value)
|
{
|
var _cfg = PlayerPropertyConfig.Get(_property);
|
m_Property.text = _cfg.Name;
|
m_Value.text = StringUtility.Contact("+", _value);
|
}
|
|
public void StartAlphaTween(float _from, float _to)
|
{
|
m_Property.color = m_Property.color.SetA(_from);
|
m_Property.DOColor(m_Property.color.SetA(_to), 1.0f);
|
}
|
}
|
}
|
|