using System; using System.Collections; using System.Collections.Generic; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { [XLua.Hotfix] public class GatherSoulHoleBehaviour : MonoBehaviour { [SerializeField] int hole; [SerializeField] RectTransform m_ContainreItem; [SerializeField] RectTransform m_ContainerEquipSign; [SerializeField] RectTransform m_ContainerLock; [SerializeField] RectTransform m_ContaienrRedpoint; [SerializeField] Image m_Icon; [SerializeField] Text m_ItemName; [SerializeField] Text m_Level; [SerializeField] Text m_Condition; [SerializeField] Button m_Func; GatheringSoulModel model { get { return ModelCenter.Instance.GetModel(); } } GatherSoulComposeModel composeModel { get { return ModelCenter.Instance.GetModel(); } } bool existItem = false; private void Awake() { m_Func.onClick.AddListener(OnFunc); } public void Display() { model.gatherSoulHoleRefresh -= GatherSoulHoleRefresh; model.gatherSoulHoleRefresh += GatherSoulHoleRefresh; RedpointCenter.Instance.redpointValueChangeEvent -= RedpointValueChangeEvent; RedpointCenter.Instance.redpointValueChangeEvent += RedpointValueChangeEvent; DisplayBase(); DisplayRedpoint(); } void DisplayBase() { bool unlockHole = model.IsHoleUnlock(hole); GatherSoulItem item; bool equiped = model.TryGetItem(hole, out item); m_ContainreItem.gameObject.SetActive(equiped); m_ContainerLock.gameObject.SetActive(!unlockHole); m_ContainerEquipSign.gameObject.SetActive(!equiped && unlockHole); existItem = equiped; if (equiped) { var config = Config.Instance.Get(item.id); m_Icon.SetSprite(config.IconKey); m_ItemName.text = config.ItemName; m_Level.text = item.level.ToString(); m_ItemName.color = UIHelper.GetUIColor(config.ItemColor); } if (!unlockHole) { DisplayCondition(); } } void DisplayCondition() { GatherSoulHoleCondition condition; if (model.TryGetHoleCondition(hole, out condition)) { m_Condition.text = Language.Get("GatherSoulHoleOpenCondition", condition.level); } } private void OnFunc() { if (!model.IsHoleUnlock(hole)) { GatherSoulHoleCondition condition; if (model.TryGetHoleCondition(hole, out condition)) { SysNotifyMgr.Instance.ShowTip("GatherSoulHoleOpenCondition", condition.level); } } else { GatherSoulItem item; if (model.TryGetItem(hole, out item)) { var itemTipsModel = ModelCenter.Instance.GetModel(); var data = new ItemAttrData(item.id); data.SetGatherSoul(item.level, hole); GatherSoulComposeModel.Compose compose; bool requireCompose = composeModel.ExistInComposeMat(item.id, out compose); data.SetTipsFuncBtn(ItemWinBtnType.putOff, OnTipFunc); if (requireCompose) { data.SetTipsFuncBtn(ItemWinBtnType.compose, OnTipFunc); } if (!model.IsGatherSoulMaxLevel(item.id, item.level)) { data.SetTipsFuncBtn(ItemWinBtnType.LevelUp, OnTipFunc); } List list = new List(); model.TryGetSatisfyReplaceSouls(hole, ref list); if (list.Count > 0) { data.SetTipsFuncBtn(ItemWinBtnType.Replace, OnTipFunc); list = null; } itemTipsModel.SetItemTipsModel(data); } else { if (!model.ContainsEquipSoul(hole)) { SysNotifyMgr.Instance.ShowTip("NoneSoulSatisfyEquip"); } else { GatherSoulEquipListWin.selectHole = hole; WindowCenter.Instance.Open(); } } } } private void RedpointValueChangeEvent(int id) { if (id == model.equipRedpoint.id || id == model.levelUpRedpoint.id || id == model.replaceRedpoint.id) { DisplayRedpoint(); } } void DisplayRedpoint() { bool requireRedpoint = (model.equipRedpoint.state == RedPointState.Simple && model.equipRedpointHole == hole) || (model.levelUpRedpoint.state == RedPointState.Simple && model.levelUpRedpointHole == hole); m_ContaienrRedpoint.gameObject.SetActive(requireRedpoint); } private void OnTipFunc(ItemWinBtnType funcType, string arg2) { switch (funcType) { case ItemWinBtnType.compose: { GatherSoulItem item; if (model.TryGetItem(hole, out item)) { model.HandleSoulTipFunc(funcType, item); } } break; case ItemWinBtnType.putOff: { WindowCenter.Instance.CloseImmediately(); GatherSoulItem item; if (model.TryGetItem(hole, out item)) { model.ExecutePutOffSoul(item); } } break; case ItemWinBtnType.LevelUp: WindowCenter.Instance.CloseImmediately(); GatherSoulLevelUpWin.selectHole = hole; WindowCenter.Instance.Open(); break; case ItemWinBtnType.Replace: WindowCenter.Instance.CloseImmediately(); GatherSoulEquipListWin.selectHole = hole; WindowCenter.Instance.Open(); break; } } private void GatherSoulHoleRefresh(int hole) { if (this.hole == hole) { bool exist = existItem; DisplayBase(); if (!exist && existItem && model.serverInited) { EffectMgr.Instance.PlayUIEffect(3079, 2100, transform, false); } } } public void Dispose() { model.gatherSoulHoleRefresh -= GatherSoulHoleRefresh; RedpointCenter.Instance.redpointValueChangeEvent -= RedpointValueChangeEvent; } } }