//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Friday, January 05, 2018
|
//--------------------------------------------------------
|
|
using LitJson;
|
using vnxbqy.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
//坐骑面板
|
namespace vnxbqy.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;
|
|
[SerializeField] Transform starUpObj;
|
[SerializeField] Text fromStar;
|
[SerializeField] Image arrowImg;
|
[SerializeField] Text toStar;
|
[SerializeField] List<ItemCell> itemCells;
|
[SerializeField] ButtonEx starUpBtn;
|
[SerializeField] Transform maxObj;
|
[SerializeField] UIEffect starEffect;
|
|
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();
|
if (FuncOpen.Instance.IsFuncOpen(8))
|
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();
|
if (mountModel.horseStarDict.ContainsKey(signHorseID) && mountModel.horseStarDict[signHorseID] > 0)
|
{
|
starEffect.Play();
|
}
|
else
|
{
|
ridingAndPetActivationModel.RidingAndPetActivationSet(RidingAndPetActivation.MountActivation, signHorseID);
|
}
|
sortMountlist.Clear();
|
ToAddSorting();
|
}
|
|
protected override void OnPreOpen()
|
{
|
FuncOpen.Instance.IsFuncOpen(8, true);
|
|
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()
|
{
|
WindowJumpMgr.Instance.ClearJumpData();
|
}
|
|
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));
|
|
int star = 0;
|
mountModel.horseStarDict.TryGetValue(horseID, out star);
|
selectThemount.starText.text = star > 0 ? Language.Get("EquipStarLevel", star) : string.Empty;
|
|
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);
|
}
|
if (HorseStarUpConfig.horseIDToIDs.ContainsKey(signHorseID))
|
{
|
starUpObj.SetActive(true);
|
int star = 0;
|
mountModel.horseStarDict.TryGetValue(signHorseID, out star);
|
int maxStar = HorseStarUpConfig.horseIDToIDs[signHorseID].Count;
|
|
if (star < maxStar)
|
{
|
fromStar.text = Language.Get("EquipStarLevel", star);
|
toStar.text = Language.Get("EquipStarLevel", star + 1);
|
arrowImg.SetActive(true);
|
}
|
else
|
{
|
fromStar.text = Language.Get("EquipStarLevel", star);
|
toStar.text = string.Empty;
|
arrowImg.SetActive(false);
|
}
|
|
int[][] awards = new int[][] { };
|
if (star != maxStar)
|
{
|
var id = HorseStarUpConfig.horseIDToIDs[signHorseID][star];
|
var nextStarConfig = HorseStarUpConfig.Get(id);
|
awards = nextStarConfig.StarUpNeedItemList;
|
}
|
|
int hasCnt = 0;
|
int needCnt = 0;
|
for (int i = 0; i < itemCells.Count; i++)
|
{
|
if (i < awards.Length)
|
{
|
itemCells[i].SetActive(true);
|
int itemID = awards[i][0];
|
needCnt = awards[i][1];
|
hasCnt = playerPack.GetItemCountByID(PackType.Item, itemID);
|
itemCells[i].Init(new ItemCellModel(itemID, false, 1));
|
itemCells[i].button.AddListener(() =>
|
{
|
ItemTipUtility.Show(itemID);
|
});
|
|
var cntTxt = itemCells[i].FindComponent("Text", "count") as Text;
|
if (hasCnt >= needCnt)
|
{
|
cntTxt.text = UIHelper.AppendColor(TextColType.Green, hasCnt.ToString()) + "/" + needCnt.ToString();
|
}
|
else
|
{
|
cntTxt.text = UIHelper.AppendColor(TextColType.Red, hasCnt.ToString()) + "/" + needCnt.ToString();
|
}
|
}
|
else
|
{
|
itemCells[i].SetActive(false);
|
}
|
}
|
starUpBtn.SetActive(star != maxStar);
|
maxObj.SetActive(star == maxStar);
|
starUpBtn.AddListener(() =>
|
{
|
if (hasCnt < needCnt)
|
{
|
SysNotifyMgr.Instance.ShowTip("StarLevelUp5");
|
return;
|
}
|
CA535_tagCMHorseStarUp pak = new CA535_tagCMHorseStarUp();
|
pak.HorseID = (uint)signHorseID;
|
GameNetSystem.Instance.SendInfo(pak);
|
});
|
}
|
else
|
{
|
starUpObj.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);
|
starUpObj.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++;
|
}
|
|
int star = 0;
|
mountModel.horseStarDict.TryGetValue(signHorseID, out star);
|
Dictionary<int, int> addAttr = new Dictionary<int, int>();
|
if (mountModel.isMountSkinActive(signHorseID) && HorseStarUpConfig.horseIDToIDs.ContainsKey(signHorseID))
|
{
|
int[] starTypeArr = new int[] { };
|
int[] starValueArr = new int[] { };
|
if (star > 0)
|
{
|
var id = HorseStarUpConfig.horseIDToIDs[signHorseID][star - 1];
|
var starConfig = HorseStarUpConfig.Get(id);
|
showIndex = 0;
|
starTypeArr = starConfig.StarAttrType;
|
starValueArr = starConfig.StarAttrValue;
|
foreach (var attrID in starTypeArr)
|
{
|
if (allAttr.ContainsKey(attrID))
|
{
|
allAttr[attrID] = allAttr[attrID] + starValueArr[showIndex];
|
}
|
else
|
{
|
allAttr[attrID] = starValueArr[showIndex];
|
}
|
showIndex++;
|
}
|
}
|
|
|
if (star < HorseStarUpConfig.horseIDToIDs[signHorseID].Count)
|
{
|
var id = HorseStarUpConfig.horseIDToIDs[signHorseID][star];
|
var nextStarConfig = HorseStarUpConfig.Get(id);
|
for (int i = 0; i < nextStarConfig.StarAttrType.Length; i++)
|
{
|
if (!allAttr.ContainsKey(nextStarConfig.StarAttrType[i]))
|
{
|
//预览用
|
allAttr[nextStarConfig.StarAttrType[i]] = 0;
|
}
|
if (Array.IndexOf(starTypeArr, nextStarConfig.StarAttrType[i]) >= 0)
|
{
|
addAttr[nextStarConfig.StarAttrType[i]] = nextStarConfig.StarAttrValue[i] - starValueArr[i];
|
}
|
else
|
{
|
addAttr[nextStarConfig.StarAttrType[i]] = nextStarConfig.StarAttrValue[i];
|
}
|
}
|
}
|
}
|
|
showIndex = 0;
|
foreach (var attrID in allAttr.Keys)
|
{
|
AttrNameList[showIndex].text = PlayerPropertyConfig.Get(attrID).ShowName;
|
if (addAttr.ContainsKey(attrID))
|
{
|
AttrValueList[showIndex].text = PlayerPropertyConfig.GetValueDescription(attrID, allAttr[attrID]) + UIHelper.AppendColor(TextColType.Green, string.Format(" +{0}", PlayerPropertyConfig.GetValueDescription(attrID, addAttr[attrID])));
|
}
|
else
|
{
|
AttrValueList[showIndex].text = PlayerPropertyConfig.GetValueDescription(attrID, allAttr[attrID]);
|
}
|
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()//解锁按钮
|
{
|
if (!FuncOpen.Instance.IsFuncOpen(8, true))
|
{
|
return;
|
}
|
|
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)
|
{
|
}
|
}
|
}
|
|
|
|
|