//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, November 01, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using TableConfig;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class DungeonInspireWin : Window
|
{
|
[SerializeField]
|
Button coinInspireBtn;
|
[SerializeField]
|
GameObject coinInspireMark;
|
[SerializeField]
|
Button fairyInspireBtn;
|
[SerializeField]
|
GameObject fairyInspireMark;
|
[SerializeField]
|
Text coinInspireInfoText;
|
[SerializeField]
|
Text fairyInspireInfoText;
|
[SerializeField] Text m_InpsireLvTxt;
|
[SerializeField]
|
Button confirmBtn;
|
[SerializeField]
|
Button cancelBtn;
|
[SerializeField]
|
Button m_CloseBtn;
|
|
DungeonModel m_Model;
|
DungeonModel model
|
{
|
get
|
{
|
return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<DungeonModel>());
|
}
|
}
|
|
private bool isCoinInspire = false;
|
private bool isFairyInspire = false;
|
private DungeonInspireConfig coinInspireCfg = null;
|
private DungeonInspireConfig fairyInspireCfg = null;
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
coinInspireBtn.onClick.AddListener(OnCoinInspire);
|
fairyInspireBtn.onClick.AddListener(OnFairyInspire);
|
confirmBtn.onClick.AddListener(OnConfirmBtn);
|
cancelBtn.onClick.AddListener(OnCancelBtn);
|
m_CloseBtn.onClick.AddListener(CloseClick);
|
}
|
|
protected override void OnPreOpen()
|
{
|
var _list = model.GetDungeonInspire(PlayerDatas.Instance.baseData.MapID);
|
if (_list == null)
|
{
|
return;
|
}
|
coinInspireCfg = null;
|
fairyInspireCfg = null;
|
for (int i = 0; i < _list.Count; i++)
|
{
|
if (_list[i].InspireType == 1)
|
{
|
coinInspireCfg = _list[i];
|
}
|
else if (_list[i].InspireType == 2)
|
{
|
fairyInspireCfg = _list[i];
|
}
|
}
|
|
coinInspireBtn.gameObject.SetActive(coinInspireCfg != null);
|
isCoinInspire = coinInspireCfg == null ? false : true;
|
isFairyInspire = !isCoinInspire;
|
InitData();
|
UpdateInspireType();
|
|
model.dungeonInspireLvEvent += DungeonEncourageEvent;
|
}
|
|
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
model.dungeonInspireLvEvent -= DungeonEncourageEvent;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
private void DungeonEncourageEvent()
|
{
|
var lv = model.dungeonCoinInspireCount + model.dungeonJadeInspireCount;
|
if (lv >= fairyInspireCfg.InspireCount && !InFairyLandGuiding())
|
{
|
CloseImmediately();
|
return;
|
}
|
UpdateInspireType();
|
}
|
|
private void OnCoinInspire()
|
{
|
if (!isCoinInspire)
|
{
|
if (model.dungeonCoinInspireCount >= coinInspireCfg.InspireCount)
|
{
|
SysNotifyMgr.Instance.ShowTip("Xjmj_CopperInspireFull");
|
return;
|
}
|
isCoinInspire = true;
|
isFairyInspire = false;
|
}
|
else
|
{
|
isCoinInspire = false;
|
}
|
UpdateInspireType();
|
}
|
private void OnFairyInspire()
|
{
|
if (coinInspireCfg == null)
|
{
|
return;
|
}
|
isCoinInspire = false;
|
isFairyInspire = !isFairyInspire;
|
UpdateInspireType();
|
}
|
|
private void OnConfirmBtn()
|
{
|
if (isFairyInspire)
|
{
|
if (PlayerDatas.Instance.baseData.GoldPaper + PlayerDatas.Instance.baseData.Gold < fairyInspireCfg.MoneyCount
|
&& !InFairyLandGuiding())
|
{
|
SysNotifyMgr.Instance.ShowTip("Xjmj_InspireNoEnoughFairy");
|
}
|
else
|
{
|
CA508_tagCMDoFBAction inspirepack = new CA508_tagCMDoFBAction();
|
inspirepack.ActionType = 0;
|
inspirepack.ActionInfo = (uint)fairyInspireCfg.InspireType;
|
GameNetSystem.Instance.SendInfo(inspirepack);
|
}
|
}
|
else if (isCoinInspire)
|
{
|
if (PlayerDatas.Instance.baseData.Silver < coinInspireCfg.MoneyCount
|
&& !InFairyLandGuiding())
|
{
|
SysNotifyMgr.Instance.ShowTip("Xjmj_InspireNoEnoughGold");
|
}
|
else
|
{
|
CA508_tagCMDoFBAction inspirepack = new CA508_tagCMDoFBAction();
|
inspirepack.ActionType = 0;
|
inspirepack.ActionInfo = (uint)coinInspireCfg.InspireType;
|
GameNetSystem.Instance.SendInfo(inspirepack);
|
}
|
}
|
}
|
|
private void OnCancelBtn()
|
{
|
CloseImmediately();
|
}
|
|
private void InitData()
|
{
|
if (coinInspireCfg != null)
|
{
|
coinInspireInfoText.text = Language.Get("FairyLand_Func9", coinInspireCfg.MoneyCount, coinInspireCfg.InspireCount);
|
}
|
fairyInspireInfoText.text = Language.Get("FairyLand_Func10", fairyInspireCfg.MoneyCount);
|
}
|
|
bool InFairyLandGuiding()
|
{
|
if (NewBieCenter.Instance.inGuiding && NewBieCenter.Instance.currentGuide == GeneralConfig.Instance.fairyLandGuideId)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
private void UpdateInspireType()
|
{
|
var lv = model.dungeonJadeInspireCount + model.dungeonCoinInspireCount;
|
m_InpsireLvTxt.text = lv == 0 ? Language.Get("FairyLand_Func4")
|
: Language.Get("HaveInspired", StringUtility.Contact("<color=#109d06>", lv * model.dungeonInspireUper, "%</color>"));
|
coinInspireMark.SetActive(isCoinInspire);
|
fairyInspireMark.SetActive(isFairyInspire);
|
}
|
}
|
|
}
|
|
|
|
|