//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, June 19, 2018
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
using System.Linq;
|
namespace Snxxz.UI {
|
|
public class TitleTotalGetWin : Window
|
{
|
[SerializeField] Text m_TitleTotal;
|
[SerializeField] List<PropertyBehaviour> m_Propertys;
|
[SerializeField] ScrollerController m_Controller;
|
[SerializeField] RectTransform m_ContainerSkill;
|
[SerializeField] Text m_SkillTitle;
|
[SerializeField] Text m_SkillText;
|
|
[SerializeField] float skillContentMinSize = 0;
|
[SerializeField] float skillContentMaxSize = 0;
|
|
TitleModel m_TitleModel;
|
TitleModel model
|
{
|
get
|
{
|
return m_TitleModel ?? (m_TitleModel = ModelCenter.Instance.GetModel<TitleModel>());
|
}
|
}
|
|
private Dictionary<int, int> propertys = new Dictionary<int, int>();
|
private List<int> skills = new List<int>();
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_Controller.OnRefreshCell += OnRefreshCell;
|
m_Controller.OnGetDynamicSize += OnGetDynamicSize;
|
}
|
|
protected override void OnPreOpen()
|
{
|
if (m_SkillText.font == null)
|
{
|
m_SkillText.font = FontUtility.preferred;
|
}
|
var _dict = model.GetAllGainTitle();
|
m_TitleTotal.text = Language.Get("L1086", _dict.Count);
|
DisplayProperty();
|
DisplaySkills();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
private void DisplayProperty()
|
{
|
propertys.Clear();
|
var _dict = model.GetAllGainTitle();
|
foreach (int id in _dict.Keys)
|
{
|
var config = DienstgradConfig.Get(id);
|
if (config == null)
|
{
|
continue;
|
}
|
int[] _propertys = config.LightType;
|
int[] _values = config.LightAttribute;
|
if (_propertys != null && _values != null && _propertys.Length == _values.Length)
|
{
|
for (int i = 0; i < _propertys.Length; i++)
|
{
|
if (!propertys.ContainsKey(_propertys[i]))
|
{
|
propertys.Add(_propertys[i], _values[i]);
|
}
|
else
|
{
|
propertys[_propertys[i]] += _values[i];
|
}
|
}
|
}
|
}
|
int index = 0;
|
foreach (int key in propertys.Keys)
|
{
|
m_Propertys[index].gameObject.SetActive(true);
|
m_Propertys[index].Display(key, propertys[key]);
|
index++;
|
}
|
for (int i = index; i < m_Propertys.Count; i++)
|
{
|
m_Propertys[i].gameObject.SetActive(false);
|
}
|
}
|
|
private void DisplaySkills()
|
{
|
skills.Clear();
|
m_Controller.Refresh();
|
var _dict = model.GetAllGainTitle();
|
foreach (int id in _dict.Keys)
|
{
|
var config = DienstgradConfig.Get(id);
|
if (config == null)
|
{
|
continue;
|
}
|
if (config.Skills != null && config.Skills.Length > 0)
|
{
|
skills.AddRange(config.Skills);
|
}
|
}
|
float _height = 0;
|
for (int i = 0; i < skills.Count; i++)
|
{
|
m_Controller.AddCell(ScrollerDataType.Header, skills[i]);
|
var config = SkillConfig.Get(skills[i]);
|
var info = StringUtility.Contact(config.SkillName, ":", config.Description);
|
_height += m_SkillText.cachedTextGeneratorForLayout.GetPreferredHeight(info, m_SkillText.GetGenerationSettings(new Vector2(m_SkillText.rectTransform.rect.size.x, 0.0f))) / m_SkillText.pixelsPerUnit;
|
}
|
m_Controller.Restart();
|
_height += skills.Count > 0 ? 60 : 0;
|
m_SkillTitle.gameObject.SetActive(skills.Count > 0);
|
m_ContainerSkill.gameObject.SetActive(skills.Count > 0);
|
_height = Mathf.Max(skillContentMinSize, _height);
|
_height = Mathf.Min(skillContentMaxSize, _height);
|
var _sizeDelta = m_ContainerSkill.sizeDelta;
|
m_ContainerSkill.sizeDelta = _sizeDelta.SetY(_height);
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
(cell as TitleSkillCell).Display(cell.index);
|
}
|
|
private bool OnGetDynamicSize(ScrollerDataType type, int index, out float height)
|
{
|
height = 28;
|
var config = SkillConfig.Get(index);
|
if (config != null)
|
{
|
var info = StringUtility.Contact(config.SkillName, ":", config.Description);
|
height = m_SkillText.cachedTextGeneratorForLayout.GetPreferredHeight(info, m_SkillText.GetGenerationSettings(new Vector2(m_SkillText.rectTransform.rect.size.x, 0.0f))) / m_SkillText.pixelsPerUnit;
|
}
|
return true;
|
}
|
|
}
|
|
}
|
|
|
|
|