//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, January 05, 2018
|
//--------------------------------------------------------
|
|
using Snxxz.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
//坐骑面板
|
namespace Snxxz.UI
|
{
|
|
public class MountSkinWin : Window, SecondWindowInterface
|
{
|
[SerializeField] ScrollerController m_ScrollerController;
|
[SerializeField] Button m_DeblockingBtton;//解锁按钮
|
[SerializeField] Button m_RideBtton;//骑乘
|
[SerializeField] RawImage m_Mount3D;
|
[SerializeField] Text m_FightPower;
|
[SerializeField] Text m_MountName;//被选中的坐骑名
|
[SerializeField] ItemCell MountItem;
|
[SerializeField] Text MountItemName;
|
[SerializeField] List<Text> AttrNameList;
|
[SerializeField] List<Text> AttrValueList;
|
|
List<Int3> sortMountlist = new List<Int3>();//坐骑顺序排列
|
public int signHorseID = 0;//用来标记坐骑ID
|
|
public Button close { get; set; }
|
#region Built-in
|
|
PackModel _playerPack;
|
PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); } }
|
MountModel m_MountModel;
|
MountModel mountModel { get { return m_MountModel ?? (m_MountModel = ModelCenter.Instance.GetModel<MountModel>()); } }
|
|
RidingAndPetActivationModel ridingAndPetActivationModel { get { return ModelCenter.Instance.GetModel<RidingAndPetActivationModel>(); } }
|
|
|
protected override void BindController()
|
{
|
if (this is SecondWindowInterface)
|
{
|
var frame = this.GetComponentInChildren<SecondFrameLoader>();
|
frame.Create();
|
close = frame.GetComponentInChildren<Button>();
|
}
|
|
}
|
|
protected override void AddListeners()
|
{
|
m_DeblockingBtton.SetListener(OnClickDeblockingBtton);
|
close.SetListener(() =>
|
{
|
CloseClick();
|
WindowCenter.Instance.Open<PetWin>(false, 0);
|
});
|
|
m_RideBtton.SetListener(() => {
|
mountModel.AppearanceSwitch((byte)mountModel.mountSkin[signHorseID], 2);
|
});
|
}
|
|
private void onMountSkinActive()
|
{
|
m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
RefreshMountSkinPanel();
|
ridingAndPetActivationModel.RidingAndPetActivationSet(RidingAndPetActivation.MountActivation, signHorseID);
|
sortMountlist.Clear();
|
ToAddSorting();
|
}
|
|
protected override void OnPreOpen()
|
{
|
MountModel.Event_MountHA301A += OnMountSkinAdd;
|
m_ScrollerController.OnRefreshCell += OnRefreshGridCell;
|
mountModel.onMountSkinActive += onMountSkinActive;
|
MountModel.Event_MountAlteration += Event_MountAlteration;
|
ToAddSorting();
|
int jumpIndex = JumpSelect(OpenChooseIndex());
|
OnCreateGridLineCell(m_ScrollerController);
|
m_ScrollerController.JumpIndex(JumpSelect(jumpIndex));
|
|
RefreshMountSkinPanel();
|
}
|
protected override void OnActived()
|
{
|
base.OnActived();
|
}
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
MountModel.Event_MountHA301A -= OnMountSkinAdd;
|
m_ScrollerController.OnRefreshCell -= OnRefreshGridCell;
|
mountModel.onMountSkinActive -= onMountSkinActive;
|
MountModel.Event_MountAlteration -= Event_MountAlteration;
|
UI3DModelExhibition.Instance.StopShow();
|
signHorseID = 0;
|
}
|
|
|
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
|
private int JumpIndex(int HorseID = 0)
|
{
|
int Index = 0;
|
Index = sortMountlist.FindIndex((x) =>
|
{
|
return x.x == signHorseID;
|
});
|
if (Index == -1)
|
{
|
Index = 0;
|
}
|
return JumpSelect(Index);
|
}
|
|
|
private int OpenChooseIndex()
|
{
|
// 红点-骑乘中-第一个
|
int selectIndex = 0;
|
int ridingHorseSkinID = -1;
|
if (mountModel.mountSkin.ContainsKey(mountModel.HorseIDNow))
|
{
|
ridingHorseSkinID = mountModel.mountSkin[mountModel.HorseIDNow];
|
}
|
int index = 0;
|
foreach (var sortInfo in sortMountlist)
|
{
|
if (ridingHorseSkinID != -1 && ridingHorseSkinID == sortInfo[0])
|
{
|
selectIndex = index;
|
}
|
if (mountModel.DeblockingRedPoint[sortInfo[0]].state != RedPointState.None)
|
{
|
signHorseID = HorseSkinPlusConfig.Get(sortInfo[0]).HorseID;
|
return index;
|
}
|
index++;
|
}
|
|
signHorseID = HorseSkinPlusConfig.Get(sortMountlist[selectIndex][0]).HorseID;
|
return selectIndex;
|
}
|
|
void OnCreateGridLineCell(ScrollerController gridCtrl)
|
{
|
gridCtrl.Refresh();
|
for (int i = 0; i < sortMountlist.Count; i++)
|
{
|
gridCtrl.AddCell(ScrollerDataType.Header, HorseSkinPlusConfig.Get(sortMountlist[i].x).HorseID);
|
}
|
gridCtrl.Restart();
|
}
|
private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
|
{
|
SelectThemount selectThemount = cell.GetComponent<SelectThemount>();
|
int horseID = cell.index;
|
var horseConfig = HorseConfig.Get(horseID);
|
selectThemount.QualityTxt1.text = ProductOrder(horseConfig.Quality.ToString());
|
selectThemount.MountNameTxt.text = horseConfig.Name;
|
selectThemount.MountLvActivation.SetActive(!mountModel.isMountSkinActive(horseID));
|
|
if (horseID == signHorseID)
|
{
|
selectThemount.ChoosenImg.SetActive(true);
|
selectThemount.DarkImage.SetActive(false);
|
}
|
else
|
{
|
selectThemount.ChoosenImg.SetActive(false);
|
selectThemount.DarkImage.SetActive(true);
|
}
|
selectThemount.HidingTips.SetActive(mountModel.HorseIDNow == horseID ? true : false);
|
|
selectThemount.MountButton.SetListener(()=> {
|
if (signHorseID == horseID)
|
return;
|
signHorseID = horseID;
|
m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
RefreshMountSkinPanel();
|
});
|
|
selectThemount.RedPoint.redpointId = mountModel.DeblockingRedPoint[mountModel.mountSkin[horseID]].id;
|
}
|
|
private void RefreshMountSkinPanel()
|
{
|
if (signHorseID == 0)
|
return;
|
HorseConfig _model = HorseConfig.Get(signHorseID);
|
m_MountName.text = _model.Name;
|
|
if (!m_Mount3D.gameObject.activeSelf)
|
{
|
m_Mount3D.SetActive(true);
|
}
|
|
UI3DModelExhibition.Instance.ShowHourse(_model.Model, m_Mount3D);
|
if (UI3DModelExhibition.Instance.NpcModelHorse != null)
|
{
|
var animator = UI3DModelExhibition.Instance.NpcModelHorse.GetComponent<Animator>();
|
if (animator != null)
|
{
|
animator.Play(GAStaticDefine.State_Dance);
|
|
}
|
}
|
|
ShowAttrText();
|
DisplayButton();
|
}
|
|
private void Event_MountAlteration()
|
{
|
DisplayButton();
|
|
m_ScrollerController.m_Scorller.RefreshActiveCellViews();//刷新可见
|
}
|
|
private void DisplayButton()
|
{
|
if (mountModel.isMountSkinActive(signHorseID))
|
{
|
m_DeblockingBtton.SetActive(false);
|
m_RideBtton.SetActive(true);
|
if (signHorseID == mountModel.HorseIDNow)
|
{
|
m_RideBtton.SetActive(false);
|
}
|
|
return;
|
}
|
//AppearanceSwitch
|
HorseConfig horsefig = HorseConfig.Get(signHorseID);
|
|
ItemCellModel cellModel = new ItemCellModel(horsefig.UnlockItemID, false, 1);
|
MountItem.Init(cellModel);
|
MountItem.countText.SetActive(true);
|
MountItem.countText.text = playerPack.GetItemCountByID(PackType.Item, horsefig.UnlockItemID).ToString();
|
var itemConfig = ItemConfig.Get(horsefig.UnlockItemID);
|
MountItemName.text = UIHelper.AppendColor(itemConfig.ItemColor, itemConfig.ItemName);
|
MountItem.button.SetListener(() =>
|
{
|
ItemTipUtility.Show(horsefig.UnlockItemID);
|
});
|
|
m_DeblockingBtton.SetActive(true);
|
m_RideBtton.SetActive(false);
|
}
|
|
private void ShowAttrText()
|
{
|
ClearAttrText();
|
var config = HorseSkinPlusConfig.Get(mountModel.mountSkin[signHorseID]);
|
int showIndex = 0;
|
Dictionary<int, int> allAttr = new Dictionary<int, int>();
|
foreach (var attrID in config.AttrType)
|
{
|
allAttr[attrID] = config.AttrValue[showIndex];
|
AttrNameList[showIndex].text = PlayerPropertyConfig.Get(attrID).ShowName;
|
AttrValueList[showIndex].text = PlayerPropertyConfig.GetValueDescription(attrID, config.AttrValue[showIndex]);
|
showIndex++;
|
}
|
|
m_FightPower.text = (UIHelper.GetFightPower(allAttr) + config.InitFightPower).ToString();
|
}
|
|
private void ClearAttrText()
|
{
|
for (int i = 0; i < AttrNameList.Count; i++)
|
{
|
AttrNameList[i].text = string.Empty;
|
AttrValueList[i].text = string.Empty;
|
|
}
|
|
}
|
|
|
private void OnClickDeblockingBtton()//解锁按钮
|
{
|
HorseConfig horsefig = HorseConfig.Get(signHorseID);
|
int MaterialNumber = playerPack.GetItemCountByID(PackType.Item, horsefig.UnlockItemID);//获取背包解锁材料的数量
|
if (MaterialNumber >= horsefig.UnlockItemCnt)
|
{
|
CA501_tagPlayerActivateHorse _tagA501 = new CA501_tagPlayerActivateHorse();
|
_tagA501.HorseID = (uint)mountModel.mountSkin[signHorseID];
|
GameNetSystem.Instance.SendInfo(_tagA501);
|
|
}
|
else
|
{
|
ScrollTip.ShowTip(Language.Get("Z1063"));//所需材料不足
|
}
|
}
|
|
|
#endregion
|
|
void ToAddSorting()//坐骑的列表排序
|
{
|
|
if (sortMountlist.Count <= 0)
|
{
|
|
foreach (var mountSkin in mountModel.MountSkinActive)
|
{
|
var config = HorseSkinPlusConfig.Get(mountSkin.Key);
|
sortMountlist.Add(new Int3(mountSkin.Key, mountSkin.Value, config.sortIndex));
|
}
|
}
|
sortMountlist.Sort(Compare);
|
}
|
int Compare(Int3 skin1, Int3 skin2)//数组排列
|
{
|
|
var xActive = skin1.y;
|
var yActive = skin2.y;
|
|
if (xActive != yActive)
|
{
|
return yActive.CompareTo(xActive);
|
}
|
return skin1.z.CompareTo(skin2.z);
|
}
|
|
|
string ProductOrder(string _petProductOrder)//坐骑品质
|
{
|
FuncConfigConfig _PetQuality = FuncConfigConfig.Get("PetQuality");
|
string[] _productlist = _PetQuality.Numerical1.Split('|');
|
for (int i = 0; i < _productlist.Length; i++)
|
{
|
if (_petProductOrder == _productlist[i])
|
{
|
string[] _productText = _PetQuality.Numerical2.Split('|');
|
string str = _productText[i];
|
return str;
|
}
|
}
|
return null;
|
}
|
private int JumpSelect(int Index)
|
{
|
if (Index <= 4)
|
{
|
return 0;
|
}
|
return Index;
|
}
|
|
private void OnMountSkinAdd(int id)
|
{
|
}
|
}
|
}
|