using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using TableConfig;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public enum PetMatType
|
{
|
None,
|
Pet,
|
Mount,
|
}
|
|
public class PetMatInfoWin : Window
|
{
|
[SerializeField] ModelShowPerfab modelShow;
|
[SerializeField] GameObject topObj;
|
[Header("顶部UI")]
|
[SerializeField] Text nameText;
|
[SerializeField] List<Text> attrNamelist = new List<Text>();
|
[SerializeField] List<Text> attrValuelist = new List<Text>();
|
[SerializeField] Button closeBtn;
|
[SerializeField] RectTransform bgObj;
|
[SerializeField] RectTransform skillContent;
|
|
[Header("中部UI")]
|
[SerializeField] List<PetSkillCell> skillCelllist = new List<PetSkillCell>();
|
|
[Header("底部UI")]
|
[SerializeField] Text sourceText;
|
[SerializeField] RectTransform btnGroup;
|
[SerializeField] GameObject operateBtn;
|
[SerializeField] CanvasGroup tipAlpha;
|
|
ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
PlayerPetDatas petmodel { get { return ModelCenter.Instance.GetModel<PlayerPetDatas>(); } }
|
PlayerMountDatas mountModel { get { return ModelCenter.Instance.GetModel<PlayerMountDatas>(); } }
|
|
Dictionary<int, int> petSkillDict;
|
Dictionary<int, List<int>> mountSkillDict;
|
private List<GameObject> tempObjlist = new List<GameObject>();
|
PetMatType matType = PetMatType.None;
|
|
protected override void BindController()
|
{
|
|
}
|
protected override void AddListeners()
|
{
|
closeBtn.AddListener(CloseClick);
|
}
|
protected override void OnPreOpen()
|
{
|
topObj.SetActive(false);
|
InitUI();
|
}
|
protected override void OnAfterOpen()
|
{
|
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;
|
topObj.SetActive(true);
|
StartCoroutine(SetPanelScale());
|
}
|
|
IEnumerator SetPanelScale()
|
{
|
yield return null;
|
tipAlpha.alpha = 1;
|
}
|
|
private void InitUI()
|
{
|
tipAlpha.alpha = 0;
|
petSkillDict = null;
|
mountSkillDict = null;
|
matType = PetMatType.None;
|
if (tipsModel.curAttrData == null) return;
|
|
if (tipsModel.unlockPetDict.ContainsKey(tipsModel.curAttrData.itemId))
|
{
|
matType = PetMatType.Pet;
|
}
|
else if (tipsModel.unlockMountDict.ContainsKey(tipsModel.curAttrData.itemId))
|
{
|
matType = PetMatType.Mount;
|
}
|
|
SetTopUI();
|
SetMidUI();
|
sourceText.text = tipsModel.curAttrData.itemConfig.Description;
|
operateBtn.SetActive(false);
|
CreateFuncBtn();
|
skillContent.localPosition = Vector3.zero;
|
}
|
|
private void SetTopUI()
|
{
|
Dictionary<int, int> itemEffectDict = null;
|
switch (matType)
|
{
|
case PetMatType.Pet:
|
PetInfoConfig petInfo = tipsModel.unlockPetDict[tipsModel.curAttrData.itemId];
|
itemEffectDict = petmodel.GetPetAttrAddDict(petInfo.ID);
|
break;
|
case PetMatType.Mount:
|
HorseConfig horseConfig = tipsModel.unlockMountDict[tipsModel.curAttrData.itemId];
|
itemEffectDict = mountModel.GetMountAttrAddDict(horseConfig.HorseID);
|
break;
|
}
|
nameText.color = UIHelper.GetUIColor(tipsModel.curAttrData.itemConfig.ItemColor);
|
nameText.text = tipsModel.curAttrData.itemConfig.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 ((AttrEnum)attrIdlist[i])
|
{
|
case AttrEnum.MinAtk:
|
break;
|
case AttrEnum.PetMinAtk:
|
break;
|
case AttrEnum.PetMaxAtk:
|
case AttrEnum.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 PetMatType.Pet:
|
PetInfoConfig petInfo = tipsModel.unlockPetDict[tipsModel.curAttrData.itemId];
|
petSkillDict = tipsModel.GetPetSkillDict(tipsModel.curAttrData.itemId);
|
modelShow.SetModelShow(petInfo.ID, ModelShowType.pet, Language.Get("TreasureEffect103"), petInfo.ShowFightPower);
|
break;
|
case PetMatType.Mount:
|
HorseConfig horseConfig = tipsModel.unlockMountDict[tipsModel.curAttrData.itemId];
|
mountSkillDict = tipsModel.GetMountSkillDict(tipsModel.curAttrData.itemId);
|
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 CreateFuncBtn()
|
{
|
btnGroup.anchoredPosition3D = Vector3.zero;
|
if (tipsModel.curAttrData.tipsFuncBtnDic.Count > 0)
|
{
|
foreach (ItemWinBtnType key in tipsModel.curAttrData.tipsFuncBtnDic.Keys)
|
{
|
Button btn = OnGUIButton(btnGroup.gameObject, operateBtn, key.ToString(), Language.Get(StringUtility.Contact("ItemHandle_", key.ToString())));
|
btn.RemoveAllListeners();
|
btn.onClick.AddListener(() =>
|
{
|
CloseImmediately();
|
tipsModel.curAttrData.tipsFuncBtnDic[key](key, "");
|
});
|
}
|
}
|
}
|
|
private Button OnGUIButton(GameObject parent, GameObject sourceBtn, string btnName, string textName)
|
{
|
GameObject go = Instantiate(sourceBtn);
|
go.name = btnName;
|
go.transform.SetParent(parent.transform);
|
go.transform.Find("BtnText").GetComponent<Text>().text = textName;
|
go.transform.localPosition = Vector3.zero;
|
go.transform.localScale = Vector3.one;
|
Button btn = go.GetComponent<Button>();
|
go.SetActive(true);
|
tempObjlist.Add(go);
|
return btn;
|
}
|
}
|
}
|