using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class DungeonReturnBloodBehaviour : MonoBehaviour
|
{
|
[SerializeField] Button m_MoneyReturnBlood;
|
[SerializeField] ReturnBloodBeha m_MoneyReturnBeha;
|
[SerializeField] Button m_FreeReturnBlood;
|
[SerializeField] ReturnBloodBeha m_FreeReturnBeha;
|
|
int mapId = 0;
|
|
int moneyReturnId = 0;
|
int freeReturnId = 0;
|
|
DungeonUseBuffModel model
|
{
|
get { return ModelCenter.Instance.GetModel<DungeonUseBuffModel>(); }
|
}
|
|
private void Awake()
|
{
|
m_FreeReturnBlood.AddListener(FreeReturnBlood);
|
m_MoneyReturnBlood.AddListener(MoneyReturnBlood);
|
}
|
|
public void Display(int mapId)
|
{
|
this.mapId = mapId;
|
|
moneyReturnId = 0;
|
freeReturnId = 0;
|
|
var list = model.GetDungeonUseBuffs(mapId);
|
for (int i = 0; i < list.Count; i++)
|
{
|
var config = DungeonUseBuffConfig.Get(list[i]);
|
if (config.MoneyCnt != 0)
|
{
|
moneyReturnId = list[i];
|
}
|
else
|
{
|
freeReturnId = list[i];
|
}
|
}
|
|
m_MoneyReturnBlood.gameObject.SetActive(moneyReturnId != 0);
|
if (moneyReturnId != 0)
|
{
|
m_MoneyReturnBeha.Display(moneyReturnId);
|
}
|
m_FreeReturnBlood.gameObject.SetActive(freeReturnId != 0);
|
if (freeReturnId != 0)
|
{
|
m_FreeReturnBeha.Display(freeReturnId);
|
}
|
|
DisplayTime();
|
|
model.onUseBuffTimeRefresh += OnUseBuffTimeRefresh;
|
}
|
|
void DisplayTime()
|
{
|
if (moneyReturnId != 0)
|
{
|
var seconds = GetBuffSeconds(moneyReturnId);
|
m_MoneyReturnBeha.SetCoolDown(seconds);
|
}
|
|
if (freeReturnId != 0)
|
{
|
var seconds = GetBuffSeconds(freeReturnId);
|
m_FreeReturnBeha.SetCoolDown(seconds);
|
}
|
}
|
|
private void LateUpdate()
|
{
|
if (m_FreeReturnBlood.gameObject.activeSelf)
|
{
|
m_FreeReturnBeha.OnUpdate();
|
}
|
if (m_MoneyReturnBlood.gameObject.activeSelf)
|
{
|
m_MoneyReturnBeha.OnUpdate();
|
}
|
}
|
|
float GetBuffSeconds(int id)
|
{
|
var config = DungeonUseBuffConfig.Get(id);
|
var tick = model.GetUseBuffTime(config.DataMapId, config.MoneyCnt);
|
var useTime = TimeUtility.GetTime(tick);
|
var seconds = Mathf.Max(0f, config.CD - (float)(TimeUtility.ServerNow - useTime).TotalSeconds);
|
return seconds;
|
}
|
|
private void MoneyReturnBlood()
|
{
|
if (moneyReturnId != 0)
|
{
|
var config = DungeonUseBuffConfig.Get(moneyReturnId);
|
var seconds = GetBuffSeconds(moneyReturnId);
|
if (seconds <= 0)
|
{
|
if (model.moneyCostRemind)
|
{
|
var skillConfig = SkillConfig.Get(config.BuffID);
|
ConfirmCancel.ToggleConfirmCancel(Language.Get("Mail101"),
|
Language.Get("HazyReturnBloodRemind", config.MoneyCnt, skillConfig.EffectValue11 / 100),
|
Language.Get("InspireNoMention"),
|
(bool isOk, bool toggle) =>
|
{
|
if (toggle)
|
{
|
model.moneyCostRemind = false;
|
}
|
if (isOk)
|
{
|
if (PlayerDatas.Instance.baseData.diamond < config.MoneyCnt)
|
{
|
WindowCenter.Instance.Open<RechargeTipWin>();
|
return;
|
}
|
var pak = new CB10A_tagCMFBBuyBuff();
|
pak.MapID = (uint)config.DataMapId;
|
pak.MoneyCnt = (ushort)config.MoneyCnt;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
});
|
}
|
else
|
{
|
var pak = new CB10A_tagCMFBBuyBuff();
|
pak.MapID = (uint)config.DataMapId;
|
pak.MoneyCnt = (ushort)config.MoneyCnt;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
}
|
}
|
}
|
|
private void FreeReturnBlood()
|
{
|
if (freeReturnId != 0)
|
{
|
var config = DungeonUseBuffConfig.Get(freeReturnId);
|
var seconds = GetBuffSeconds(freeReturnId);
|
if (seconds <= 0)
|
{
|
var pak = new CB10A_tagCMFBBuyBuff();
|
pak.MapID = (uint)config.DataMapId;
|
pak.MoneyCnt = (ushort)config.MoneyCnt;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
}
|
}
|
|
private void OnUseBuffTimeRefresh()
|
{
|
DisplayTime();
|
}
|
|
public void Dispose()
|
{
|
model.onUseBuffTimeRefresh -= OnUseBuffTimeRefresh;
|
}
|
|
[Serializable]
|
public class ReturnBloodBeha
|
{
|
[SerializeField] Image m_Mask;
|
[SerializeField] Text m_Time;
|
[SerializeField] Text m_Cost;
|
[SerializeField] Text m_Effect;
|
|
int id = 0;
|
float seconds = 0f;
|
|
public void Display(int id)
|
{
|
this.id = id;
|
var config = DungeonUseBuffConfig.Get(id);
|
if (config.MoneyCnt != 0)
|
{
|
m_Cost.text = config.MoneyCnt.ToString();
|
}
|
|
var skillConfig = SkillConfig.Get(config.BuffID);
|
m_Effect.text = Language.Get("HazyReturnBlood", skillConfig.EffectValue11 / 100);
|
|
m_Mask.gameObject.SetActive(false);
|
}
|
|
public void SetCoolDown(float seconds)
|
{
|
this.seconds = seconds;
|
if (seconds <= 0 && m_Mask.gameObject.activeSelf)
|
{
|
m_Mask.gameObject.SetActive(false);
|
}
|
}
|
|
void DisplayMask()
|
{
|
var config = DungeonUseBuffConfig.Get(id);
|
var progress = Mathf.Clamp01(seconds / config.CD);
|
m_Mask.fillAmount = progress;
|
if (!m_Mask.gameObject.activeSelf)
|
{
|
m_Mask.gameObject.SetActive(true);
|
}
|
m_Time.text = ((int)seconds).ToString();
|
}
|
|
public void OnUpdate()
|
{
|
if (seconds > 0f)
|
{
|
seconds -= Time.deltaTime;
|
DisplayMask();
|
|
if (seconds <= 0f)
|
{
|
m_Mask.gameObject.SetActive(false);
|
}
|
}
|
}
|
}
|
}
|
}
|