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] 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<RealmModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
private void Awake()
|
{
|
m_LevelUp.AddListener(OnLevelUp);
|
}
|
|
public void Display(int realmLevel)
|
{
|
this.realmLevel = realmLevel;
|
var currentRealmLevel = PlayerDatas.Instance.baseData.realmLevel;
|
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);
|
if (config.BossID != 0)
|
{
|
m_BossCondition.DisplayBoss(realmLevel - 1);
|
}
|
}
|
|
public void DisplayCost()
|
{
|
var config = RealmConfig.Get(realmLevel - 1);
|
m_ContainerCost.gameObject.SetActive(config.NeedGood != 0);
|
m_Item.SetItem(config.NeedGood, config.NeedNum);
|
}
|
|
private void OnLevelUp()
|
{
|
var error = 0;
|
if (TryLevelUp(out error))
|
{
|
CA523_tagCMRealmLVUp pak = new CA523_tagCMRealmLVUp();
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
else
|
{
|
DisplayErrorTip(error);
|
}
|
}
|
|
bool TryLevelUp(out int error)
|
{
|
error = 0;
|
var config = RealmConfig.Get(realmLevel - 1);
|
if (PlayerDatas.Instance.baseData.LV < config.NeedLV)
|
{
|
error = 1;
|
return false;
|
}
|
if (config.BossID != 0 && !model.isBossPass)
|
{
|
error = 2;
|
return false;
|
}
|
if (config.NeedGood != 0)
|
{
|
var count = packModel.GetItemCountByID(PackType.Item, config.NeedGood);
|
if (count < config.NeedNum)
|
{
|
error = 3;
|
return false;
|
}
|
}
|
return true;
|
}
|
|
void DisplayErrorTip(int error)
|
{
|
switch (error)
|
{
|
case 1:
|
break;
|
case 2:
|
break;
|
case 3:
|
break;
|
}
|
}
|
}
|
|
[Serializable]
|
public class RealmUpCondition
|
{
|
[SerializeField] Transform m_Container;
|
[SerializeField] Text m_Condition;
|
[SerializeField] Text m_Progress;
|
|
RealmModel model { get { return ModelCenter.Instance.GetModel<RealmModel>(); } }
|
|
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);
|
var label = UIHelper.GetRealmColorByLv(realmLevel, 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);
|
}
|
}
|
}
|