//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, October 27, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using System.Text;
|
|
namespace Snxxz.UI
|
{
|
|
public class AttributePromoteShowWin : Window
|
{
|
const int MAX_GROUP = 5;
|
|
[SerializeField]
|
float m_Interval;
|
|
[SerializeField]
|
AttributePromoteBehaviour[] m_PromoteBehaviours;
|
|
[SerializeField]
|
Transform[] m_ShowPoints;
|
|
[SerializeField]
|
Transform m_StartPoint;
|
[SerializeField]
|
Transform m_EndPoint;
|
|
float nextShowTime = 0f;
|
List<AttributePromote> attributePromoteList = new List<AttributePromote>();
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
for (int i = 0; i < m_PromoteBehaviours.Length; i++)
|
{
|
m_PromoteBehaviours[i].transform.localPosition = m_StartPoint.localPosition;
|
m_PromoteBehaviours[i].gameObject.SetActive(false);
|
}
|
|
PlayerDatas.Instance.attributePromoteEvent += OnAttributePromote;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
PlayerDatas.Instance.attributePromoteEvent -= OnAttributePromote;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
|
if (nextShowTime < Time.time && attributePromoteList.Count > 0)
|
{
|
|
var buffMin = new AttributePromote();
|
var findMin = false;
|
for (int i = attributePromoteList.Count - 1; i >= 0; i--)
|
{
|
if (attributePromoteList[i].type == PlayerDataType.MINATK)
|
{
|
buffMin = attributePromoteList[i];
|
findMin = true;
|
break;
|
}
|
}
|
|
var buffMax = new AttributePromote();
|
var findMax = false;
|
if (findMin)
|
{
|
for (int i = attributePromoteList.Count - 1; i >= 0; i--)
|
{
|
if (attributePromoteList[i].type == PlayerDataType.MAXATK)
|
{
|
buffMax = attributePromoteList[i];
|
findMax = true;
|
break;
|
}
|
}
|
}
|
|
for (int i = attributePromoteList.Count - 1; i >= 0; i--)
|
{
|
if (attributePromoteList[i].type == PlayerDataType.MAXATK
|
|| attributePromoteList[i].type == PlayerDataType.MINATK)
|
{
|
attributePromoteList.RemoveAt(i);
|
}
|
}
|
|
if (findMax && findMin)
|
{
|
attributePromoteList.Add(new AttributePromote(PlayerDataType.MAXATK, buffMin.value1, buffMax.value1));
|
}
|
|
for (int i = 0; i < attributePromoteList.Count && i < MAX_GROUP; i++)
|
{
|
var from = m_ShowPoints[i].localPosition;
|
var to = m_EndPoint.localPosition;
|
m_PromoteBehaviours[i].transform.localPosition = m_StartPoint.localPosition;
|
m_PromoteBehaviours[i].gameObject.SetActive(true);
|
m_PromoteBehaviours[i].Display(attributePromoteList[i].ToString(), from, to, 0.35f * i, OnPromoteShowEnd);
|
}
|
|
attributePromoteList.Clear();
|
nextShowTime = Time.time + m_Interval;
|
}
|
}
|
|
#endregion
|
|
private void OnPromoteShowEnd(Transform _transform)
|
{
|
_transform.localPosition = m_StartPoint.localPosition;
|
_transform.gameObject.SetActive(false);
|
}
|
|
private void OnAttributePromote(PlayerDataType _type, int _value)
|
{
|
attributePromoteList.Add(new AttributePromote(_type, _value));
|
}
|
|
struct AttributePromote
|
{
|
public PlayerDataType type;
|
public int value1;
|
public int value2;
|
|
public AttributePromote(PlayerDataType _type, int _value)
|
{
|
this.type = _type;
|
this.value1 = _value;
|
this.value2 = 0;
|
}
|
|
public AttributePromote(PlayerDataType _type, int _value1, int _value2)
|
{
|
this.type = _type;
|
this.value1 = _value1;
|
this.value2 = _value2;
|
}
|
|
string ConvertToArtFont(string _key, int _num)
|
{
|
var config = DamageNumConfig.Get(_key);
|
var stringBuild = new StringBuilder();
|
stringBuild.Append((char)config.plus);
|
stringBuild.Append((char)config.prefix);
|
|
var chars = _num.ToString();
|
for (var i = 0; i < chars.Length; i++)
|
{
|
var numChar = config.nums[(int)chars[i] - 48];
|
if (numChar > 0)
|
{
|
stringBuild.Append((char)numChar);
|
}
|
}
|
|
return stringBuild.ToString();
|
}
|
|
string ConvertToArtFont(string _key, float _num)
|
{
|
var config = DamageNumConfig.Get(_key);
|
var stringBuild = new StringBuilder();
|
stringBuild.Append((char)config.plus);
|
stringBuild.Append((char)config.prefix);
|
|
var chars = _num.ToString("f1");
|
for (var i = 0; i < chars.Length; i++)
|
{
|
int numChar = 0;
|
if (chars[i] == '.')
|
{
|
numChar = config.nums[10];
|
}
|
else
|
{
|
numChar = config.nums[(int)chars[i] - 48];
|
}
|
|
if (numChar > 0)
|
{
|
stringBuild.Append((char)numChar);
|
}
|
}
|
|
return stringBuild.ToString();
|
}
|
|
|
string ConvertToArtFont(string _key, int _num1, int _num2)
|
{
|
var config = DamageNumConfig.Get(_key);
|
var stringBuild = new StringBuilder();
|
stringBuild.Append((char)config.plus);
|
stringBuild.Append((char)config.prefix);
|
|
var chars = _num1.ToString();
|
for (var i = 0; i < chars.Length; i++)
|
{
|
var numChar = config.nums[(int)chars[i] - 48];
|
if (numChar > 0)
|
{
|
stringBuild.Append((char)numChar);
|
}
|
}
|
|
stringBuild.Append((char)config.minus);
|
|
chars = _num2.ToString();
|
for (var i = 0; i < chars.Length; i++)
|
{
|
var numChar = config.nums[(int)chars[i] - 48];
|
if (numChar > 0)
|
{
|
stringBuild.Append((char)numChar);
|
}
|
}
|
|
return stringBuild.ToString();
|
}
|
|
public override string ToString()
|
{
|
switch (type)
|
{
|
case PlayerDataType.MaxHP:
|
return ConvertToArtFont("BuffAddMaxHp", value1);
|
case PlayerDataType.MAXATK:
|
case PlayerDataType.MINATK:
|
return ConvertToArtFont("BuffAddAttack", value1, value2);
|
case PlayerDataType.DEF:
|
return ConvertToArtFont("BuffAddDefense", value1);
|
case PlayerDataType.HIT:
|
return ConvertToArtFont("BuffAddAccurate", value1 );
|
case PlayerDataType.Miss:
|
return ConvertToArtFont("BuffAddDodge", value1);
|
case PlayerDataType.BattleValEx1:
|
return ConvertToArtFont("BuffAddAttackSpeed", value1 * 0.01f);
|
case PlayerDataType.Speed:
|
return ConvertToArtFont("BuffAddMoveSpeed", value1);
|
default:
|
return "";
|
}
|
}
|
|
}
|
|
}
|
|
}
|