using DG.Tweening;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class GetPetMatPathWin : Window
|
{
|
[SerializeField] RectTransform _itemInfoTips;
|
[SerializeField] RectTransform _getWaysTips;
|
[Header("顶部UI")]
|
[SerializeField] GameObject topPart;
|
[SerializeField] Text nameText;
|
[SerializeField] List<Text> attrNamelist = new List<Text>();
|
[SerializeField] List<Text> attrValuelist = new List<Text>();
|
[SerializeField] Button closeBtn;
|
[SerializeField] RectTransform skillContent;
|
|
[Header("中部UI")]
|
[SerializeField] List<PetSkillCell> skillCelllist = new List<PetSkillCell>();
|
|
[Header("底部UI")]
|
[SerializeField] Text sourceText;
|
[SerializeField] CanvasGroup tipAlpha;
|
[SerializeField] Button _getItemBtn;
|
|
[Header("获取途径UI")]
|
[SerializeField] protected CanvasGroup _getWaysCanvas;
|
[SerializeField] private ScrollerController _waysCtrl;
|
[SerializeField] private Transform waysLineCell;
|
[SerializeField] private Button _closeWaysBtn;
|
|
[SerializeField] ModelShowPerfab modelShow;
|
|
[SerializeField]
|
[Header("初始移动坐标")]
|
protected float startPosX = -476;
|
[SerializeField]
|
[Header("结束坐标")]
|
protected float endPosX = -668;
|
[SerializeField]
|
[Header("移动时间")]
|
protected float _moveTime = 0.3f;
|
|
ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
GetItemPathModel _itemPathModel;
|
protected GetItemPathModel itemPathModel
|
{
|
get
|
{
|
return _itemPathModel ?? (_itemPathModel = ModelCenter.Instance.GetModel<GetItemPathModel>());
|
}
|
}
|
|
DailyQuestModel _questModel;
|
protected DailyQuestModel QuestModel
|
{
|
get { return _questModel ?? (_questModel = ModelCenter.Instance.GetModel<DailyQuestModel>()); }
|
}
|
|
|
Dictionary<int, int> petSkillDict;
|
Dictionary<int, List<int>> mountSkillDict;
|
private List<GameObject> tempObjlist = new List<GameObject>();
|
PetOrMount matType = PetOrMount.None;
|
PetModel petmodel { get { return ModelCenter.Instance.GetModel<PetModel>(); } }
|
MountModel mountModel { get { return ModelCenter.Instance.GetModel<MountModel>(); } }
|
|
protected override void BindController()
|
{
|
_waysCtrl.OnRefreshCell += RefreshWayCell;
|
}
|
protected override void AddListeners()
|
{
|
closeBtn.AddListener(CloseWin);
|
_getItemBtn.onClick.AddListener(OnClickGetItemBtn);
|
_closeWaysBtn.onClick.AddListener(CloseWin);
|
}
|
protected override void OnPreOpen()
|
{
|
topPart.SetActive(false);
|
InitUI();
|
}
|
protected override void OnAfterOpen()
|
{
|
transform.SetAsLastSibling();
|
StartCoroutine(SetTopShow());
|
}
|
protected override void OnPreClose()
|
{
|
for (int i = 0; i < tempObjlist.Count; i++)
|
{
|
Destroy(tempObjlist[i]);
|
}
|
}
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
IEnumerator SetTopShow()
|
{
|
yield return null;
|
topPart.SetActive(true);
|
StartCoroutine(SetPanelScale());
|
}
|
|
IEnumerator SetPanelScale()
|
{
|
yield return null;
|
yield return null;
|
_itemInfoTips.anchoredPosition3D = new Vector3(startPosX, 0, 0);
|
_itemPathModel.SetInfoTipsPos(_itemInfoTips,_getWaysTips);
|
tipAlpha.alpha = 1;
|
}
|
|
private void InitUI()
|
{
|
matType = PetOrMount.None;
|
petSkillDict = null;
|
mountSkillDict = null;
|
if (itemPathModel.chinItemModel == null) return;
|
|
if (tipsModel.unlockPetDict.ContainsKey(itemPathModel.chinItemModel.ID))
|
{
|
matType = PetOrMount.Pet;
|
}
|
else if (tipsModel.unlockMountDict.ContainsKey(itemPathModel.chinItemModel.ID))
|
{
|
matType = PetOrMount.Mount;
|
}
|
|
tipAlpha.alpha = 0;
|
_getWaysCanvas.alpha = 0;
|
closeBtn.gameObject.SetActive(true);
|
SetTopUI();
|
SetMidUI();
|
sourceText.text = itemPathModel.GetAllInfoDes();
|
skillContent.localPosition = Vector3.zero;
|
}
|
|
#region iteminfoTips逻辑
|
private void SetTopUI()
|
{
|
Dictionary<int, int> itemEffectDict = null;
|
switch (matType)
|
{
|
case PetOrMount.Pet:
|
PetInfoConfig petInfo = tipsModel.unlockPetDict[itemPathModel.chinItemModel.ID];
|
itemEffectDict = petmodel.GetPetAttrAddDict(petInfo.ID);
|
break;
|
case PetOrMount.Mount:
|
HorseConfig horseConfig = tipsModel.unlockMountDict[itemPathModel.chinItemModel.ID];
|
itemEffectDict = mountModel.GetMountAttrAddDict(horseConfig.HorseID);
|
break;
|
}
|
|
nameText.color = UIHelper.GetUIColor(itemPathModel.chinItemModel.ItemColor);
|
nameText.text = itemPathModel.chinItemModel.ItemName;
|
List<int> attrIdlist = itemEffectDict.Keys.ToList();
|
|
for (int i = 0;i < attrNamelist.Count; i++)
|
{
|
attrNamelist[i].gameObject.SetActive(false);
|
attrValuelist[i].gameObject.SetActive(false);
|
}
|
|
int code = 0;
|
for(int i = 0; i < attrIdlist.Count; i++)
|
{
|
string attrName = "";
|
string attrValue = "";
|
string minAtkName = "";
|
string minAtkValue = "";
|
attrNamelist[code].gameObject.SetActive(true);
|
attrValuelist[code].gameObject.SetActive(true);
|
switch ((PropertyType)attrIdlist[i])
|
{
|
case PropertyType.MinAtk:
|
break;
|
case PropertyType.PetMinAtk:
|
break;
|
case PropertyType.PetMaxAtk:
|
case PropertyType.MaxAtk:
|
tipsModel.SetPetAttrStr(attrIdlist[i - 1], itemEffectDict[attrIdlist[i - 1]], out minAtkName, out minAtkValue);
|
tipsModel.SetPetAttrStr(attrIdlist[i], itemEffectDict[attrIdlist[i]], out attrName, out attrValue, minAtkValue);
|
code += 1;
|
break;
|
default:
|
tipsModel.SetPetAttrStr(attrIdlist[i], itemEffectDict[attrIdlist[i]], out attrName, out attrValue);
|
code += 1;
|
break;
|
}
|
|
if (code > 0)
|
{
|
attrNamelist[code - 1].text = UIHelper.GetSuitNameByName(attrName);
|
attrValuelist[code - 1].text = attrValue;
|
}
|
}
|
}
|
|
private void SetMidUI()
|
{
|
switch (matType)
|
{
|
case PetOrMount.Pet:
|
PetInfoConfig petInfo = tipsModel.unlockPetDict[itemPathModel.chinItemModel.ID];
|
petSkillDict = tipsModel.GetPetSkillDict(itemPathModel.chinItemModel.ID);
|
modelShow.SetModelShow(petInfo.ID, ModelShowType.Pet, Language.Get("TreasureEffect103"), petInfo.ShowFightPower);
|
break;
|
case PetOrMount.Mount:
|
HorseConfig horseConfig = tipsModel.unlockMountDict[itemPathModel.chinItemModel.ID];
|
mountSkillDict = tipsModel.GetMountSkillDict(itemPathModel.chinItemModel.ID);
|
modelShow.SetModelShow(horseConfig.Model, ModelShowType.Mount, Language.Get("TreasureEffect103"), horseConfig.ShowFightPower);
|
break;
|
}
|
|
List<int> unlockLvlist = null;
|
if (petSkillDict != null)
|
{
|
unlockLvlist = petSkillDict.Keys.ToList();
|
}
|
else if (mountSkillDict != null)
|
{
|
unlockLvlist = mountSkillDict.Keys.ToList();
|
}
|
|
for (int i = 0; i < skillCelllist.Count; i++)
|
{
|
skillCelllist[i].gameObject.SetActive(false);
|
}
|
|
int code = 0;
|
for (int i = 0; i < unlockLvlist.Count; i++)
|
{
|
if (petSkillDict != null)
|
{
|
skillCelllist[code].gameObject.SetActive(true);
|
skillCelllist[code].SetModel(petSkillDict[unlockLvlist[i]], unlockLvlist[i]);
|
code += 1;
|
}
|
else if (mountSkillDict != null)
|
{
|
for (int j = 0; j < mountSkillDict[unlockLvlist[i]].Count; j++)
|
{
|
skillCelllist[code].gameObject.SetActive(true);
|
skillCelllist[code].SetModel(mountSkillDict[unlockLvlist[i]][j], unlockLvlist[i]);
|
code += 1;
|
}
|
}
|
}
|
}
|
|
private void OnClickGetItemBtn()
|
{
|
if(_getWaysCanvas.alpha <= 0)
|
{
|
Vector3 pos = new Vector3(endPosX,_itemInfoTips.anchoredPosition3D.y,0);
|
_itemInfoTips.DOAnchorPos3D(pos, _moveTime);
|
_getWaysCanvas.DOFade(1, _moveTime);
|
closeBtn.gameObject.SetActive(false);
|
CreateWayCell();
|
}
|
else
|
{
|
Vector3 pos = new Vector3(startPosX, _itemInfoTips.anchoredPosition3D.y, 0);
|
_itemInfoTips.DOAnchorPos3D(pos, _moveTime);
|
_getWaysCanvas.DOFade(0, _moveTime);
|
closeBtn.gameObject.SetActive(true);
|
}
|
|
}
|
#endregion
|
|
#region getWaysTips逻辑
|
private List<GetItemWaysConfig> getWayslist;
|
protected virtual void CreateWayCell()
|
{
|
getWayslist = itemPathModel.GetWaysList(itemPathModel.chinItemModel);
|
_waysCtrl.Refresh();
|
int i = 0;
|
int remain = getWayslist.Count % waysLineCell.childCount;
|
int line = (int)getWayslist.Count / waysLineCell.childCount;
|
if (remain > 0)
|
{
|
line += 1;
|
}
|
|
for (i = 0; i < line; i++)
|
{
|
_waysCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
_waysCtrl.Restart();
|
}
|
|
private void RefreshWayCell(ScrollerDataType type, CellView cell)
|
{
|
int i = 0;
|
for (i = 0; i < cell.transform.childCount; i++)
|
{
|
WayCell wayCell = cell.transform.GetChild(i).GetComponent<WayCell>();
|
if (wayCell == null)
|
wayCell = cell.transform.GetChild(i).gameObject.AddComponent<WayCell>();
|
|
int index = (cell.transform.childCount) * cell.index + i;
|
if (index <= getWayslist.Count - 1)
|
{
|
cell.transform.GetChild(i).gameObject.SetActive(true);
|
GetItemWaysConfig itemWaysModel = getWayslist[index];
|
wayCell.icon.SetSprite(itemWaysModel.Icon);
|
wayCell.wayName.text = itemWaysModel.Text;
|
wayCell.funcName.text = itemWaysModel.name;
|
wayCell.wayButton.RemoveAllListeners();
|
wayCell.wayButton.AddListener(() => {
|
ClickWayCell(itemWaysModel);
|
});
|
}
|
else
|
{
|
cell.transform.GetChild(i).gameObject.SetActive(false);
|
}
|
}
|
}
|
|
public void ClickWayCell(GetItemWaysConfig itemWaysModel)
|
{
|
CloseImmediately();
|
itemPathModel.ClickGetWay(itemWaysModel.ID);
|
}
|
|
#endregion
|
|
private void CloseWin()
|
{
|
itemPathModel.ResetAllModel();
|
CloseImmediately();
|
}
|
}
|
}
|