408 lines
9.6 KiB
C#
408 lines
9.6 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2021-06-18
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "SettleWindow.View" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
namespace G.UI
|
|||
|
{
|
|||
|
using System.Collections;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
using Text = TMPro.TextMeshProUGUI;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
partial class SettleWindow
|
|||
|
{
|
|||
|
#region AutoGenerate
|
|||
|
|
|||
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goWin;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _goLose;
|
|||
|
|
|||
|
[KUIFlag]
|
|||
|
ScrollRect _goRewards;
|
|||
|
[KUIFlag]
|
|||
|
KUIList __listReward;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnCollect;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnLoseCollect;
|
|||
|
[KUIFlag]
|
|||
|
Text _tmpLevel;
|
|||
|
[KUIFlag]
|
|||
|
Text _tmpStage;
|
|||
|
[KUIFlag]
|
|||
|
Text _tmpRank;
|
|||
|
[KUIFlag]
|
|||
|
Text _tmpGetCoin;
|
|||
|
[KUIFlag]
|
|||
|
Text _tmpGetExp;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnAgain;
|
|||
|
[KUIFlag]
|
|||
|
Button _btnGrow;
|
|||
|
|
|||
|
[KUIFlag]
|
|||
|
Image _imgGradeExp;
|
|||
|
[KUIFlag]
|
|||
|
Text _tmpGrade;
|
|||
|
|
|||
|
[KUIFlag]
|
|||
|
Button _btnCollectTreble;
|
|||
|
[KUIFlag]
|
|||
|
Text _tmpTrebleAmount;
|
|||
|
[KUIFlag]
|
|||
|
Text _tmpTrebleRemainCount;
|
|||
|
[KUIFlag]
|
|||
|
GameObject _imgTrebleAd;
|
|||
|
|
|||
|
[KUIFlag]
|
|||
|
Button _btnCollectDouble;
|
|||
|
|
|||
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|||
|
|
|||
|
#region Field
|
|||
|
|
|||
|
int[] _qualityHelper = new int[Item.Quality.kMax];
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private BattleResult _battleResult => this.data as BattleResult;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void InitView()
|
|||
|
{
|
|||
|
SetViewData();
|
|||
|
|
|||
|
__listReward.AddTemplate<PropWidget>(true);
|
|||
|
|
|||
|
_btnCollect.onClick.AddListener(this.OnCollectBtnClick);
|
|||
|
_btnCollectDouble.onClick.AddListener(this.OnDoubleCollectBtnClick);
|
|||
|
_btnCollectTreble.onClick.AddListener(this.OnTrebleCollectBtnClick);
|
|||
|
|
|||
|
_btnLoseCollect.onClick.AddListener(this.OnCollectBtnClick);
|
|||
|
|
|||
|
_btnAgain.onClick.AddListener(this.OnAgainBtnClick);
|
|||
|
_btnGrow.onClick.AddListener(this.OnGrowBtnClick);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void RefreshView()
|
|||
|
{
|
|||
|
var result = this._battleResult;
|
|||
|
if (result == null || !result.isValid)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
result.ApplyNormal();
|
|||
|
|
|||
|
var isNormal = result.isNormal;
|
|||
|
|
|||
|
_goWin.SetActive(result.success);
|
|||
|
_goLose.SetActive(!result.success);
|
|||
|
string resultString = "";
|
|||
|
if (result.success)
|
|||
|
{
|
|||
|
if (isNormal && result.levelId > 1)
|
|||
|
{
|
|||
|
var remainCount = TimeProxy.Instance.GetTimeInfo2(TimeProxy.超级加倍);
|
|||
|
if (remainCount.remain > 0)
|
|||
|
{
|
|||
|
_btnCollectDouble.gameObject.SetActive(false);
|
|||
|
_btnCollectTreble.gameObject.SetActive(true);
|
|||
|
|
|||
|
_imgTrebleAd.SetActive(result.levelId > 2);
|
|||
|
//_tmpTrebleAmount.text = (result.coin * 2).ToString();
|
|||
|
_tmpTrebleRemainCount.text = $"超级加倍剩余次数:{remainCount.remain}/{remainCount.max}";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_btnCollectTreble.gameObject.SetActive(false);
|
|||
|
_btnCollectDouble.gameObject.SetActive(true);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_btnCollectDouble.gameObject.SetActive(false);
|
|||
|
_btnCollectTreble.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
|
|||
|
resultString = "success";
|
|||
|
LevelProxy.Instance.CompleteLevel(result.levelId, result.stageIndex);
|
|||
|
PostNotification(GlobalDefine.EVENT_SETTLE_RESULT, result, resultString);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
var restart = (this.data as string) == "restart";
|
|||
|
resultString = restart ? "uncompleted" : "fail";
|
|||
|
|
|||
|
_btnLoseCollect.gameObject.SetActive(restart || !isNormal);
|
|||
|
_btnAgain.gameObject.SetActive(!restart && isNormal);
|
|||
|
_btnGrow.gameObject.SetActive(!restart && isNormal);
|
|||
|
PostNotification(GlobalDefine.EVENT_SETTLE_RESULT, result, resultString);
|
|||
|
}
|
|||
|
|
|||
|
if (isNormal)
|
|||
|
{
|
|||
|
_tmpLevel.text = $"第{result.levelId}关";
|
|||
|
_tmpStage.text = $"{result.stageIndex}/{result.stageIndexMax}";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_tmpLevel.text = "";
|
|||
|
_tmpStage.text = "";
|
|||
|
}
|
|||
|
|
|||
|
_goRewards.verticalNormalizedPosition = 1f;
|
|||
|
__listReward.Clear();
|
|||
|
|
|||
|
for (int i = _qualityHelper.Length - 1; i > 0; i--)
|
|||
|
{
|
|||
|
_qualityHelper[i] = 0;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
result.equipments.Sort(EntityItemEquipment.SortByQuality);
|
|||
|
foreach (var equipment in result.equipments)
|
|||
|
{
|
|||
|
var quality = equipment.quality;
|
|||
|
if (quality >= Item.Quality.kMin && quality < Item.Quality.kPurple)
|
|||
|
_qualityHelper[quality]++;
|
|||
|
else
|
|||
|
__listReward.GetItem<PropWidget>().SetItem(equipment.itemId);
|
|||
|
}
|
|||
|
for (int i = _qualityHelper.Length - 1; i > 0; i--)
|
|||
|
{
|
|||
|
if (_qualityHelper[i] > 0)
|
|||
|
__listReward.GetItem<PropWidget>().SetQualityCount($"{Item.GetQualityText(i)}装备", i, _qualityHelper[i]);
|
|||
|
}
|
|||
|
//foreach (var equipment in result.equipments)
|
|||
|
//{
|
|||
|
// if (equipment != null && equipment.quality >= Item.Quality.kPurple)
|
|||
|
// __listReward.GetItem().SetData(equipment.propItem);
|
|||
|
//}
|
|||
|
//StartCoroutine(ShowRewardsWithAnim(result));
|
|||
|
|
|||
|
if (isNormal)
|
|||
|
{
|
|||
|
_tmpGetCoin.text = result.coin.ToString();
|
|||
|
//_tmpGetExp.text = result.exp.ToString();
|
|||
|
//StartCoroutine(ShowExpWithAnim(result));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
_tmpGetCoin.text = "0";
|
|||
|
//_tmpGetExp.text = "0";
|
|||
|
}
|
|||
|
|
|||
|
KStatistics.Instance.ReportEvent_Battle("普通", result.chapterId, result.levelId, result.stageIndex, result.success ? 1 : 0, result.success ? 3 : 4, result.playerDeath, "", result.duration, result.duration, result.playerHpPercent);
|
|||
|
SoundProxy.PlayFxAsync("Sounds/attack_ui_end.mp3");
|
|||
|
|
|||
|
#if !UNITY_WEBGL && UNITY_EDITOR
|
|||
|
if (KGMOptions.Instance.自动挂机)
|
|||
|
{
|
|||
|
StartCoroutine(AutoGame());
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
private IEnumerator ShowRewardsWithAnim(BattleResult result)
|
|||
|
{
|
|||
|
result.equipments.Sort(EntityItemEquipment.SortByQuality);
|
|||
|
yield return null;
|
|||
|
foreach (var equipment in result.equipments)
|
|||
|
{
|
|||
|
__listReward.GetItem().SetData(equipment.propItem);
|
|||
|
yield return null;
|
|||
|
yield return null;
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="result"></param>
|
|||
|
/// <returns></returns>
|
|||
|
private IEnumerator ShowExpWithAnim(BattleResult result)
|
|||
|
{
|
|||
|
_tmpGrade.text = result.lastGrade.ToString();
|
|||
|
_imgGradeExp.fillAmount = result.lastExpRatio;
|
|||
|
|
|||
|
while (result.lastGrade < result.currGrade)
|
|||
|
{
|
|||
|
result.lastExpRatio += 0.05f;
|
|||
|
if (result.lastExpRatio >= 1f)
|
|||
|
{
|
|||
|
result.lastExpRatio -= 1f;
|
|||
|
result.lastGrade += 1;
|
|||
|
ToastBox.ShowText("恭喜升级", 1);
|
|||
|
}
|
|||
|
yield return null;
|
|||
|
_tmpGrade.text = result.lastGrade.ToString();
|
|||
|
_imgGradeExp.fillAmount = result.lastExpRatio;
|
|||
|
}
|
|||
|
|
|||
|
while (result.lastExpRatio < result.currExpRatio)
|
|||
|
{
|
|||
|
result.lastExpRatio += 0.05f;
|
|||
|
yield return null;
|
|||
|
_imgGradeExp.fillAmount = result.lastExpRatio;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private void OnTrebleSuccess()
|
|||
|
{
|
|||
|
if (_battleResult != null)
|
|||
|
{
|
|||
|
var rewards = F.ListPool<Item.ItemInfo>.Get();
|
|||
|
_battleResult.ApplyTreble(rewards);
|
|||
|
|
|||
|
RewardWindow.ShowRewards(rewards, (error, message) =>
|
|||
|
{
|
|||
|
GameScene.Instance.EnterScene(0);
|
|||
|
OnCloseBtnClick();
|
|||
|
});
|
|||
|
|
|||
|
F.ListPool<Item.ItemInfo>.Release(rewards);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 双倍结算
|
|||
|
/// </summary>
|
|||
|
private void OnDoubleSuccess()
|
|||
|
{
|
|||
|
if (_battleResult != null)
|
|||
|
{
|
|||
|
var rewards = F.ListPool<Item.ItemInfo>.Get();
|
|||
|
_battleResult.ApplyDouble(rewards);
|
|||
|
|
|||
|
RewardWindow.ShowRewards(rewards, (error, message) =>
|
|||
|
{
|
|||
|
GameScene.Instance.EnterScene(0);
|
|||
|
OnCloseBtnClick();
|
|||
|
});
|
|||
|
F.ListPool<Item.ItemInfo>.Release(rewards);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnCollectBtnClick()
|
|||
|
{
|
|||
|
GameScene.Instance.EnterScene(0);
|
|||
|
OnCloseBtnClick();
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
private void OnTrebleCollectBtnClick()
|
|||
|
{
|
|||
|
if (_battleResult.levelId > 2)
|
|||
|
{
|
|||
|
if (TimeProxy.Instance.CheckTimes(TimeProxy.超级加倍))
|
|||
|
{
|
|||
|
AdProxy.Instance.PlayAd("battle", "settle", _battleResult.stageIndex.ToString(), (error, message) =>
|
|||
|
{
|
|||
|
if (error == 0)
|
|||
|
{
|
|||
|
TimeProxy.Instance.CostTimes(TimeProxy.超级加倍);
|
|||
|
this.OnTrebleSuccess();
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
ToastBox.ShowText(KLocalization.GetLocalString(18));
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.OnTrebleSuccess();
|
|||
|
}
|
|||
|
//SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
private void OnDoubleCollectBtnClick()
|
|||
|
{
|
|||
|
if (PlayerProxy.Instance.CheckEnergyForLevel())
|
|||
|
{
|
|||
|
AdProxy.Instance.PlayAd("battle", "settle", _battleResult.stageIndex.ToString(), (error, message) =>
|
|||
|
{
|
|||
|
if (error == 0)
|
|||
|
{
|
|||
|
PlayerProxy.Instance.UseEnergyForLevel();
|
|||
|
this.OnDoubleSuccess();
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
AdMoneyBox.ShowAdMoney(Item.Id.kEnergy, true);
|
|||
|
ToastBox.ShowText("体力不足,无法双倍结算");
|
|||
|
}
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private void OnAgainBtnClick()
|
|||
|
{
|
|||
|
GameScene.Instance.EnterScene(0);
|
|||
|
//GameScene.Instance.EnterScene(0, "again_level");
|
|||
|
OnCloseBtnClick();
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private void OnGrowBtnClick()
|
|||
|
{
|
|||
|
GameScene.Instance.EnterScene(0, "Cha");
|
|||
|
OnCloseBtnClick();
|
|||
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|||
|
}
|
|||
|
|
|||
|
private void OnCloseBtnClick()
|
|||
|
{
|
|||
|
CloseWindow(this);
|
|||
|
}
|
|||
|
|
|||
|
#if UNITY_EDITOR
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
private IEnumerator AutoGame()
|
|||
|
{
|
|||
|
yield return new WaitForSeconds(1f);
|
|||
|
OnCollectBtnClick();
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|