//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, July 27, 2018
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI {
|
|
public class ViewPetDetailWin : Window ,SecondWindowInterface
|
{
|
[SerializeField] ScrollerController m_Controller;
|
[SerializeField] Text m_FightPower;
|
[SerializeField] Text m_PetAtk;
|
[SerializeField] Text m_PetAtkSpeed;
|
[SerializeField] PetSkill[] m_PetSkills;
|
[SerializeField] ScrollerController m_SkillController;
|
[SerializeField] RawImage m_RawModel;
|
[SerializeField] Button m_PetStone;
|
|
[SerializeField, Header("技能一行个数")] int m_LineCount = 3;
|
|
public int selectPet { get; private set; }
|
|
public int lineCount { get { return m_LineCount; } }
|
|
List<int> skills = new List<int>();
|
|
[NonSerialized] public List<int> displayTotalSkills = new List<int>();
|
[NonSerialized] public List<int> unlockTotalSkills = new List<int>();
|
|
RoleParticularModel model { get { return ModelCenter.Instance.GetModel<RoleParticularModel>(); } }
|
PetModel petModel { get { return ModelCenter.Instance.GetModel<PetModel>(); } }
|
#region Built-in
|
public Button close { get; set; }
|
|
protected override void BindController()
|
{
|
if (this is SecondWindowInterface)
|
{
|
var frame = this.GetComponentInChildren<SecondFrameLoader>();
|
frame.Create();
|
close = frame.GetComponentInChildren<Button>();
|
}
|
}
|
|
protected override void AddListeners()
|
{
|
m_Controller.OnRefreshCell += OnRefreshCell;
|
m_SkillController.OnRefreshCell += OnRefreshSkillCell;
|
m_PetStone.onClick.AddListener(OnPetStone);
|
close.onClick.AddListener(CloseClick);
|
}
|
|
protected override void OnPreOpen()
|
{
|
Display();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
void Display()
|
{
|
RoleParticularModel.ViewPlayerData data = model.GetViewPlayerData(model.viewPlayer);
|
if (data == null)
|
{
|
return;
|
}
|
var pets = data.rolePlusData.pets;
|
selectPet = pets[0].id;
|
m_Controller.Refresh();
|
for (int i = 0; i < pets.Count; i++)
|
{
|
CellInfo info = CellInfo.Default;
|
info.infoInt1 = pets[i].lv;
|
m_Controller.AddCell(ScrollerDataType.Header, pets[i].id, info);
|
}
|
m_Controller.Restart();
|
m_FightPower.text = model.GetPetFightPower(pets).ToString();
|
DisplayModel(selectPet);
|
DisplayProperty(pets, data.rolePlusData.AtkSpeed);
|
DisplaySkills(pets[0].id, pets[0].lv);
|
DisplayTotalSkills(pets);
|
}
|
|
public void SelectPet(int _id)
|
{
|
selectPet = _id;
|
RoleParticularModel.ViewPlayerData data = model.GetViewPlayerData(model.viewPlayer);
|
if (data == null)
|
{
|
return;
|
}
|
var pets = data.rolePlusData.pets;
|
var pet = pets.Find((x) =>
|
{
|
return x.id == selectPet;
|
});
|
if (!pet.Equals(default(RoleParticularModel.PetInfo)))
|
{
|
DisplaySkills(pet.id, pet.lv);
|
DisplayModel(pet.id);
|
}
|
m_Controller.m_Scorller.RefreshActiveCellViews();
|
}
|
|
void DisplayProperty(List<RoleParticularModel.PetInfo> pets,int AtkSpeed)
|
{
|
m_PetAtk.text = model.GetPetAtkProperty(pets).ToString();
|
m_PetAtkSpeed.text = ((float)AtkSpeed / 100).ToString();
|
}
|
|
void DisplaySkills(int id, int lv)
|
{
|
PetInfoConfig.GetPetSkills(id, lv, false,ref skills);
|
for (int i = 0; i < m_PetSkills.Length; i++)
|
{
|
if (i < skills.Count)
|
{
|
m_PetSkills[i].SetActive(true);
|
var condition = PetInfoConfig.GetPetSkillCondition(id, skills[i]);
|
m_PetSkills[i].Display(id, skills[i], lv >= condition ? 0 : condition);
|
}
|
else
|
{
|
m_PetSkills[i].SetActive(false);
|
}
|
}
|
}
|
|
void DisplayTotalSkills(List<RoleParticularModel.PetInfo> pets)
|
{
|
displayTotalSkills.Clear();
|
unlockTotalSkills.Clear();
|
|
for (int i = 0; i < pets.Count; i++)
|
{
|
PetInfoConfig.GetPetSkills(pets[i].id, pets[i].lv, true, ref skills);
|
unlockTotalSkills.AddRange(skills);
|
foreach (var id in skills)
|
{
|
var config = SkillConfig.Get(id);
|
var skillId = 0;
|
var effect = SkillConfig.GetSkillEffectValue(config);
|
if (petModel.TryGetIntegrationSkill(effect, out skillId))
|
{
|
if (!displayTotalSkills.Contains(skillId))
|
{
|
displayTotalSkills.Add(skillId);
|
}
|
continue;
|
}
|
displayTotalSkills.Add(id);
|
}
|
}
|
|
displayTotalSkills.Sort(Compare);
|
|
m_SkillController.Refresh();
|
var line = Mathf.CeilToInt((float)displayTotalSkills.Count / m_LineCount);
|
for (int i = 0; i < line; i++)
|
{
|
m_SkillController.AddCell(ScrollerDataType.Header, i);
|
}
|
m_SkillController.Restart();
|
}
|
|
private void OnPetStone()
|
{
|
model.viewPetStone = true;
|
WindowCenter.Instance.Open<ViewPetHorseStoneWin>();
|
}
|
|
void DisplayModel(int id)
|
{
|
m_RawModel.SetActive(true);
|
var npcConfig = NPCConfig.Get(id);
|
UI3DModelExhibition.Instance.ShowNPC(id, npcConfig.UIModeLOffset, npcConfig.UIModelRotation, m_RawModel);
|
if (UI3DModelExhibition.Instance.NpcModelPet != null)
|
{
|
var animator = UI3DModelExhibition.Instance.NpcModelPet.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.Play(GAStaticDefine.State_Dance);
|
}
|
}
|
}
|
|
private void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
ViewPetSelectCell selectCell = cell as ViewPetSelectCell;
|
var lv = cell.info.HasValue ? cell.info.Value.infoInt1 : 0;
|
selectCell.Display(cell.index, lv, this);
|
}
|
|
private void OnRefreshSkillCell(ScrollerDataType type, CellView cell)
|
{
|
ViewPetSkillCell skillCell = cell as ViewPetSkillCell;
|
skillCell.Display(cell.index, this);
|
}
|
|
int Compare(int lhs, int rhs)
|
{
|
var lhs_config = SkillConfig.Get(lhs);
|
var rhs_config = SkillConfig.Get(rhs);
|
var lhs_Id = 0;
|
var rhs_Id = 0;
|
var lhs_effect = SkillConfig.GetSkillEffectValue(lhs_config);
|
var rhs_effect = SkillConfig.GetSkillEffectValue(rhs_config);
|
var lhs_integration = petModel.TryGetIntegrationSkill(lhs_effect, out lhs_Id);
|
var rhs_integration = petModel.TryGetIntegrationSkill(rhs_effect, out rhs_Id);
|
if (lhs_integration != rhs_integration)
|
{
|
return -lhs_integration.CompareTo(rhs_integration);
|
}
|
if (lhs_integration && rhs_integration)
|
{
|
return lhs_config.Effect1.CompareTo(rhs_config.Effect1);
|
}
|
var lhs_petId = 0;
|
var rhs_petId = 0;
|
petModel.TryGetPetId(lhs, out lhs_petId);
|
petModel.TryGetPetId(rhs, out rhs_petId);
|
var lhs_petconfig = PetInfoConfig.Get(lhs_petId);
|
var rhs_petconfig = PetInfoConfig.Get(rhs_petId);
|
return lhs_petconfig.Sort.CompareTo(rhs_petconfig.Sort);
|
}
|
|
[Serializable]
|
public class PetSkill
|
{
|
[SerializeField] RectTransform m_Container;
|
[SerializeField] Button m_SkillBtn;
|
[SerializeField] RectTransform m_ContainerLock;
|
[SerializeField] Text m_Condition;
|
[SerializeField] Image m_SkillIcon;
|
[SerializeField] UIEffect m_Effect;
|
|
int petId = 0;
|
int skillId = 0;
|
|
public void Display(int id, int _skillId, int condition)
|
{
|
var config = SkillConfig.Get(_skillId);
|
if (config != null)
|
{
|
m_SkillIcon.SetSprite(config.IconName);
|
}
|
petId = id;
|
skillId = _skillId;
|
m_ContainerLock.SetActive(condition > 0);
|
if (condition > 0)
|
{
|
m_Condition.text = Language.Get("LoadIconLV", condition);
|
}
|
m_SkillBtn.RemoveAllListeners();
|
m_SkillBtn.AddListener(OnClickSkill);
|
|
m_Effect.StopImediatly();
|
var model = ModelCenter.Instance.GetModel<PetModel>();
|
if (model.ListEffectSkill != null
|
&& model.ListEffectSkill.Contains(_skillId))
|
{
|
m_Effect.Play();
|
}
|
}
|
|
private void OnClickSkill()
|
{
|
PetInfoConfig petInfo = PetInfoConfig.Get(petId);
|
if (petInfo != null)
|
{
|
var skillConfig = SkillConfig.Get(skillId);
|
var label1 = skillConfig.Description;
|
var label2 = Language.Get("pet_SkillTipLv", petInfo.Name, PetInfoConfig.GetPetSkillCondition(petId, skillId));
|
SkillDetails.ShowSkillDetails(skillId, SkillDetails.SkillSourceType.ViewHorsePet,
|
skillConfig == null ? 0 : skillConfig.FightPower, label1, label2);
|
}
|
}
|
|
public void SetActive(bool active)
|
{
|
m_Container.SetActive(active);
|
}
|
}
|
}
|
|
}
|
|
|
|
|