using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
[XLua.Hotfix]
|
public class JadeDynastyEquipBeh : MonoBehaviour
|
{
|
[SerializeField] RoleEquipType equipType = RoleEquipType.retMax;
|
[SerializeField] GameObject lockObj;
|
[SerializeField] ItemCell itemCell;
|
[SerializeField] Text lockText;
|
[SerializeField] Text nameText;
|
[SerializeField] Button equipBtn;
|
[SerializeField] GameObject equipLvObj;
|
[SerializeField] Text equipLvText;
|
[SerializeField] GameObject composeImg;
|
[SerializeField] UIEffect effect;
|
|
ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
JadeDynastyEquipModel equipModel { get { return ModelCenter.Instance.GetModel<JadeDynastyEquipModel>(); } }
|
|
private void OnEnable()
|
{
|
playerPack.itemCntAddEvent += PutOnEquip;
|
playerPack.itemCntReduceEvent += PutOffEquip;
|
SetDisplay();
|
}
|
|
private void OnDisable()
|
{
|
playerPack.itemCntAddEvent -= PutOnEquip;
|
playerPack.itemCntReduceEvent -= PutOffEquip;
|
}
|
|
public void SetDisplay()
|
{
|
bool islock = equipModel.IsLockEquipPlace((int)equipType);
|
nameText.gameObject.SetActive(true);
|
nameText.text = Language.Get(equipType.ToString());
|
lockText.gameObject.SetActive(false);
|
lockObj.SetActive(islock);
|
equipBtn.RemoveAllListeners();
|
itemCell.cellBtn.RemoveAllListeners();
|
equipLvObj.SetActive(false);
|
composeImg.SetActive(false);
|
if(islock)
|
{
|
itemCell.gameObject.SetActive(false);
|
equipBtn.AddListener(ClickEquipBtn);
|
}
|
else
|
{
|
ItemModel itemModel = playerPack.GetItemByIndex(PackType.JadeDynastyEquip, (int)equipType);
|
itemCell.gameObject.SetActive(itemModel != null);
|
if (itemModel != null)
|
{
|
equipLvObj.SetActive(true);
|
nameText.gameObject.SetActive(false);
|
itemCell.Init(itemModel);
|
itemCell.cellBtn.AddListener(() => { ClickItemCell(itemModel); });
|
string equipLvSB = Language.Get(StringUtility.Contact("Num_CHS_", itemModel.config.LV));
|
equipLvText.text = Language.Get("L1091",equipLvSB);
|
}
|
else
|
{
|
equipBtn.AddListener(ClickEquipBtn);
|
if (equipModel.equipPlaceComposes.Contains((int)equipType))
|
{
|
composeImg.SetActive(true);
|
}
|
}
|
}
|
|
UpdatePlayerEffect();
|
}
|
|
private void ClickEquipBtn()
|
{
|
equipModel.SetLookEquipGetPath((int)equipType);
|
}
|
|
private void PutOffEquip(PackType type, int index, int id)
|
{
|
int equipIndex = 0;
|
equipModel.TryGetJadeDynastyEquipIndex((int)equipType, out equipIndex);
|
if (type != PackType.JadeDynastyEquip || index != equipIndex) return;
|
|
SetDisplay();
|
}
|
|
private void PutOnEquip(PackType type, int index, int id)
|
{
|
int equipIndex = 0;
|
equipModel.TryGetJadeDynastyEquipIndex((int)equipType, out equipIndex);
|
if (type != PackType.JadeDynastyEquip || index != equipIndex) return;
|
|
SetDisplay();
|
}
|
|
private void UpdatePlayerEffect()
|
{
|
bool isLocalSaveUnLock = equipModel.IsLocalSaveUnLock((int)equipType);
|
if (isLocalSaveUnLock) return;
|
|
int towerLayer = 0;
|
bool isLimit = equipModel.TryGetLockTowerLayer((int)equipType,out towerLayer);
|
bool islock = equipModel.IsLockEquipPlace((int)equipType);
|
bool isPutOn = playerPack.GetItemByIndex(PackType.JadeDynastyEquip,(int)equipType) != null;
|
bool isPlayer = !islock && isLimit && !isPutOn;
|
if(isPlayer)
|
{
|
if(!effect.IsPlaying)
|
{
|
effect.Play();
|
equipModel.SetLockLocalSaveUnlockEquip((int)equipType);
|
}
|
}
|
else
|
{
|
if (effect.IsPlaying)
|
{
|
effect.Stop();
|
}
|
}
|
}
|
|
private void ClickItemCell(ItemModel item)
|
{
|
if (item == null) return;
|
|
tipsModel.SetItemTipsModel(item.packType,item.guid,false);
|
tipsModel.SetJadeDynastyPutOnTipsBtn(tipsModel.curAttrData);
|
tipsModel.ShowUICtrl();
|
}
|
}
|
}
|