using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class RealmLevelUpBehaviour : MonoBehaviour { [SerializeField] Transform m_ContainerCondition; [SerializeField] RealmUpCondition m_LevelCondition; [SerializeField] RealmUpCondition m_BossCondition; [SerializeField] RealmEquipCondition m_EquipCondition; [SerializeField] Transform m_ContainerCost; [SerializeField] ItemBehaviour m_Item; [SerializeField] Text m_RequireRealmLevel; [SerializeField] Button m_LevelUp; int realmLevel = 0; RealmModel model { get { return ModelCenter.Instance.GetModel(); } } PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } private void Awake() { m_LevelUp.AddListener(OnLevelUp); } public void Display(int realmLevel) { this.realmLevel = realmLevel; var currentRealmLevel = model.displayRealmLevel; var isNext = realmLevel == currentRealmLevel + 1; m_ContainerCondition.gameObject.SetActive(isNext); m_ContainerCost.gameObject.SetActive(isNext); m_LevelUp.gameObject.SetActive(isNext); m_RequireRealmLevel.gameObject.SetActive(!isNext); if (isNext) { DisplayCondition(); DisplayCost(); } else { var config = RealmConfig.Get(realmLevel - 1); m_RequireRealmLevel.text = Language.Get("RealmLevelUpRequire", config.Img); } } public void DisplayCondition() { var config = RealmConfig.Get(realmLevel - 1); m_LevelCondition.DisplayLevel(realmLevel - 1); m_BossCondition.SetActive(config.BossID != 0); m_EquipCondition.SetActive(model.HasEquipCondition(realmLevel - 1)); if (config.BossID != 0) { m_BossCondition.DisplayBoss(realmLevel - 1); } if (model.HasEquipCondition(realmLevel - 1)) { m_EquipCondition.DisplayLevel(realmLevel - 1); } } public void DisplayCost() { var config = RealmConfig.Get(realmLevel - 1); m_ContainerCost.gameObject.SetActive(config.NeedGood != 0 && config.NeedNum != 0); m_Item.SetItem(config.NeedGood, config.NeedNum); } private void OnLevelUp() { var error = 0; if (model.TryLevelUp(out error)) { CA523_tagCMRealmLVUp pak = new CA523_tagCMRealmLVUp(); GameNetSystem.Instance.SendInfo(pak); } else { DisplayErrorTip(error); } } void DisplayErrorTip(int error) { switch (error) { case 1: SysNotifyMgr.Instance.ShowTip("RealmLevelUpError_1"); break; case 2: SysNotifyMgr.Instance.ShowTip("RealmLevelUpError_2"); break; case 3: var config = RealmConfig.Get(PlayerDatas.Instance.baseData.realmLevel); ItemTipUtility.Show(config.NeedGood); break; case 4: WindowCenter.Instance.Open(); break; } } } [Serializable] public class RealmUpCondition { [SerializeField] Transform m_Container; [SerializeField] Text m_Condition; [SerializeField] Text m_Progress; RealmModel model { get { return ModelCenter.Instance.GetModel(); } } public void DisplayLevel(int realmLevel) { var config = RealmConfig.Get(realmLevel); m_Condition.text = Language.Get("RealmConditionLevel", config.NeedLV); var level = PlayerDatas.Instance.baseData.LV; var satisfy = level >= config.NeedLV; m_Progress.text = StringUtility.Contact(level, "/", config.NeedLV); m_Progress.color = satisfy ? UIHelper.s_LightGreen : UIHelper.s_DarkRedColor; } public void DisplayBoss(int realmLevel) { var config = RealmConfig.Get(realmLevel + 1); var label = UIHelper.GetRealmColorByLv(realmLevel + 1, StringUtility.Contact("[", config.Name, "]")); m_Condition.text = Language.Get("RealmConditionBoss", label); var progress = model.isBossPass ? 1 : 0; m_Progress.text = StringUtility.Contact(progress, "/", 1); m_Progress.color = model.isBossPass ? UIHelper.s_LightGreen : UIHelper.s_DarkRedColor; } public void SetActive(bool active) { m_Container.gameObject.SetActive(active); } } [Serializable] public class RealmEquipCondition { [SerializeField] Transform m_Container; [SerializeField] Text m_Condition; [SerializeField] Text m_Progress; [SerializeField] Text[] m_EquipPlaceNames; readonly Color s_Gray = new Color32(189, 189, 189, 255); RealmModel model { get { return ModelCenter.Instance.GetModel(); } } EquipModel equipModel { get { return ModelCenter.Instance.GetModel(); } } PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } public void DisplayLevel(int realmLevel) { RealmLevelUpEquipCondition equipCondition; if (model.TryGetRealmEquipCondition(realmLevel, out equipCondition)) { var equipSet = equipModel.GetEquipSet(equipCondition.level); var realmConfig = RealmConfig.Get(equipSet.realm); if (!equipCondition.isSuit) { var colorName = UIHelper.GetColorNameByItemColor(equipCondition.itemColor); m_Condition.text = Language.Get("RealmNeedEquipCondition_1", 8, colorName, realmConfig.Name); } else { m_Condition.text = Language.Get("RealmNeedEquipCondition_2", 8, realmConfig.Name); } List notSatisfyPlaces; model.SatisfyEquipCondition(realmLevel, out notSatisfyPlaces); var progress = 8 - notSatisfyPlaces.Count; for (int i = 0; i < m_EquipPlaceNames.Length; i++) { var place = i + 1; m_EquipPlaceNames[i].text = UIHelper.GetEquipPlaceName(place); bool satisfy = !notSatisfyPlaces.Contains(place); m_EquipPlaceNames[i].color = satisfy ? UIHelper.s_LightGreen : s_Gray; } m_Progress.text = StringUtility.Contact(progress, "/", 8); m_Progress.color = progress >= 8 ? UIHelper.s_LightGreen : UIHelper.s_DarkRedColor; } } public void SetActive(bool active) { m_Container.gameObject.SetActive(active); } } }