// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-03-26
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
partial class PetWindow
{
class RecastPanel : KUIWidget
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Button _btnClose;
[KUIFlag]
Button _btnTips;
[KUIFlag]
GameObject __goLockCost;
[KUIFlag]
TextMeshProUGUI _tmpLockHint;
[KUIFlag]
Button _btnReset;
[KUIFlag]
Button _btnReplace;
[KUIFlag]
KUIList __listSkills;
[KUIFlag]
Button _btnUpgrade;
[KUIFlag]
Button _btnUpgrade2;
[KUIFlag]
GameObject __goUpgradeCost;
[KUIFlag]
GameObject __goUpgradeCost2;
[KUIFlag]
TextMeshProUGUI _tmpCV;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private CostWidget _recastCostWidget1;
private CostWidget _recastCostWidget2;
private CostWidget _lockCostWidget;
private bool[] _lockFilter = new bool[8];
private readonly List _skillWidgets = new List(8);
private Item.ItemInfo _lockCost;
#endregion
#region Method
public override void Refresh()
{
if (this.data is PetProxy.PetInfo petInfo)
{
var recastSkills = petInfo.recastSkills;
if (recastSkills != null)
{
RefreshSkills(recastSkills);
RefreshCost();
}
else
{
RefreshSkills(petInfo.skills);
RefreshCost();
_btnReset.interactable = false;
_btnReplace.interactable = false;
}
}
}
void RefreshSkills(IList petSkills)
{
__listSkills.Clear();
_skillWidgets.Clear();
int combatValue = 0;
for (int i = 0; i < 8; i++)
{
var widget = __listSkills.GetItem();
if (i < petSkills.Count && petSkills[i] != null)
{
widget.SetData(petSkills[i]);
_skillWidgets.Add(widget);
combatValue += petSkills[i].item.combatValue;
}
else
{
widget.SetData(null);
}
}
_tmpCV.text = combatValue.ToString();
RefreshLock();
}
void RefreshLock()
{
for (int i = 0; i < 8; i++)
{
_lockFilter[i] = false;
}
int lockCount = 0;
for (int i = 0; i < _skillWidgets.Count; i++)
{
if (_skillWidgets[i].IsRecastLocked())
{
lockCount++;
_lockFilter[i] = true;
}
}
if (lockCount > 0)
{
var petConst = ItemProxy.Instance.GetStaticItem(1);
var lockCosts = petConst.lockCostInfos;
if (lockCount <= lockCosts.Length)
_lockCost = lockCosts[lockCount - 1];
else
_lockCost = lockCosts[lockCosts.Length - 1];
_lockCostWidget.gameObject.SetActive(true);
_lockCostWidget.SetAndCheckPrice(_lockCost);
_tmpLockHint.text = string.Format(KLocalization.GetLocalString(72), lockCount);
}
else
{
_lockCost.Set(1, 0);
_lockCostWidget.gameObject.SetActive(false);
_tmpLockHint.text = KLocalization.GetLocalString(71);
}
}
public void RefreshCost()
{
if (this.data is PetProxy.PetInfo petInfo)
{
//var cost1 = petInfo.recastCostLow;
//_recastCostWidget1.SetPriceWithMax(cost1.id, cost1.count);
var cost2 = petInfo.recastCostHigh;
_recastCostWidget2.SetPriceWithMax(cost2.id, cost2.count);
}
}
public void ResetLock()
{
foreach (var skillWidget in _skillWidgets)
{
skillWidget.SetRecastLock(false);
}
}
///
/// 检查更好
///
///
bool CheckBetter()
{
if (this.data is PetProxy.PetInfo petInfo)
{
int oldCV = 0;
var oldSkills = petInfo.skills;
for (int i = 0; i < oldSkills.Count; i++)
{
var skill = oldSkills[i];
if (skill != null)
{
oldCV += skill.combatValue;
}
}
int newCV = 0;
var newSkills = petInfo.recastSkills;
if (newSkills != null)
for (int i = 0; i < newSkills.Count; i++)
{
var skill = newSkills[i];
if (skill != null)
{
newCV += skill.combatValue;
}
}
return newCV > oldCV;
}
return false;
}
void Recast(bool high)
{
if (this.data is PetProxy.PetInfo petInfo)
{
RefreshLock();
var enough = MoneyProxy.Instance.CheckMoney(_lockCost);
if (!enough)
{
ToastBox.ShowText("铜币不足,无法锁定");
return;
}
var cost = high ? petInfo.recastCostHigh : petInfo.recastCostLow;
enough = MoneyProxy.Instance.CheckMoney(cost);
if (!enough)
{
ToastBox.ShowText("洗练丹不足,无法洗练");
OpenWindow(ItemProxy.Instance.GetStaticItem(19));
//AdMoneyBox.ShowAdMoney(19, true);
return;
}
MoneyProxy.Instance.CostMoney(_lockCost);
MoneyProxy.Instance.CostMoney(cost);
var skills = petInfo.RecastSkills(high, _lockFilter);
RefreshSkills(skills);
RefreshCost();
_btnReset.interactable = true;
_btnReplace.interactable = true;
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
}
}
public bool LockSkill(SkillWidget skillWidget)
{
if (this.data is PetProxy.PetInfo petInfo)
{
if (skillWidget.IsRecastLocked())
{
int lockCount = 0;
for (int i = 0; i < _skillWidgets.Count; i++)
{
if (_skillWidgets[i].IsRecastLocked())
{
lockCount++;
}
}
if (lockCount >= petInfo.skills.Count)
return false;
}
}
RefreshLock();
return true;
}
void OnRecastBtnClick()
{
var better = CheckBetter();
if (better)
{
MessageBox.ShowMessage("提示", "当前拥有更高战力技能尚未保存,是否继续洗练?", "继续洗练", "取消洗练",
() => Recast(false),
() => { }
);
}
else
Recast(false);
}
void OnRecast2BtnClick()
{
var better = CheckBetter();
if (better)
{
MessageBox.ShowMessage("提示", "当前拥有更高战力技能尚未保存,是否继续洗练?", "继续洗练", "取消洗练",
() => Recast(true),
() => { }
);
}
else
Recast(true);
}
void OnResetBtnClick()
{
if (this.data is PetProxy.PetInfo petInfo)
{
petInfo.ResetRecast();
Refresh();
}
}
void OnReplaceBtnClick()
{
if (this.data is PetProxy.PetInfo petInfo)
{
this.Close();
GetWindow().ShowReplacePanel();
}
}
void OnTipsBtnClick()
{
MessageBox.ShowMessage(KLocalization.GetLocalString(68), KLocalization.GetLocalString(69));
}
void OnCloseBtnClick()
{
var better = CheckBetter();
if (better)
{
MessageBox.ShowMessage("提示", "您确定是直接关闭而不是替换技能,直接关闭后洗练出的技能将不生效.", "关闭洗练", "继续洗练",
() =>
{
this.Close();
GetWindow().RefreshPetSelect();
},
() =>
{
}
);
}
else
{
this.Close();
GetWindow().RefreshPetSelect();
}
}
#endregion
#region Unity
private void Awake()
{
SetViewData();
__listSkills.AddTemplate(true);
//_recastCostWidget1 = __goUpgradeCost.AddComponent();
_recastCostWidget2 = __goUpgradeCost2.AddComponent();
_lockCostWidget = __goLockCost.AddComponent();
_btnClose.onClick.AddListener(this.OnCloseBtnClick);
_btnReset.onClick.AddListener(this.OnResetBtnClick);
_btnReplace.onClick.AddListener(this.OnReplaceBtnClick);
//_btnUpgrade.onClick.AddListener(this.OnRecastBtnClick);
_btnUpgrade2.onClick.AddListener(this.OnRecast2BtnClick);
_btnTips.onClick.AddListener(this.OnTipsBtnClick);
}
private void OnEnable()
{
}
private void OnDisable()
{
}
#endregion
#region Mediator
readonly int[] _notificationInterests = new int[]
{
};
public override IList ListNotificationInterests()
{
return _notificationInterests;
}
public override void HandleNotification(PureMVC.Interfaces.INotification notification)
{
if (notification.Name == GlobalDefine.EVENT_PET_SKILL_LOCKED)
{
RefreshLock();
}
}
#endregion
}
}
}