2025-05-18 01:04:31 +08:00

399 lines
9.7 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2022-04-03
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "RideWindow.View" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G.UI
{
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using PureMVC.Interfaces;
using System.Collections.Generic;
/// <summary>
///
/// </summary>
partial class RideWindow
{
class SettlementPanle : KUIWidget
{
#region Auto Generate
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
#endregion
#region Field
#endregion
#region Method
#endregion
}
#region Auto Generate
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
TextMeshProUGUI _tmpItemNumber;//游戏中显示
[KUIFlag]
Slider _sliderComplete;
[KUIFlag]
GameObject _goFinal;
[KUIFlag]
GameObject _goRewardIcon;
[KUIFlag]
TextMeshProUGUI _tmpRewardNumber;//结算时显示
[KUIFlag]
GameObject _goKill;
[KUIFlag]
TextMeshProUGUI _tmpKiller;
[KUIFlag]
GameObject _goGet;
[KUIFlag]
TextMeshProUGUI _tmpGet;
[KUIFlag]
GameObject _goDamage;
[KUIFlag]
TextMeshProUGUI _tmpSettleDamage;
[KUIFlag]
Toggle _tgDouble;
[KUIFlag]
Button _btnReward;
//[KUIFlag]
//Button _btnBack;
//[KUIFlag]
//Button _btnClose;
//[KUIFlag]
//Button _btnBg;
[KUIFlag]
GameObject _goHpHint;
[KUIFlag]
Button _btnMenu;
[KUIFlag]
Button _btnQuit;
[KUIFlag]
Button _btnContinue;
[KUIFlag]
GameObject _goStop;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private int _killerNumber;
private int _rewardNumber;
private int _injuredNumver;
private SmartCostWidget _smartCostWidget;
#endregion
#region Field
#endregion
#region Method
/// <summary>
///
/// </summary>
public void InitView()
{
SetViewData();
_btnReward.onClick.AddListener(this.OnAgainBtnClick);
_smartCostWidget = _btnReward.gameObject.AddComponent<SmartCostWidget>();
_tgDouble.onValueChanged.AddListener(this.OnRewardShowTgClick);
//_btnBack.onClick.AddListener(this.OnBackBtnClick);
//_btnClose.onClick.AddListener(this.OnBackBtnClick);
//_btnBg.onClick.AddListener(this.OnBackBtnClick);
_btnMenu.onClick.AddListener(this.OnMenuBtnClick);
_btnQuit.onClick.AddListener(this.OnQuitBtnClick);
_btnContinue.onClick.AddListener(this.OnContinueBtnClick);
}
/// <summary>
///
/// </summary>
public void RefreshView()
{
_goFinal.SetActive(false);
_goStop.SetActive(false);
_tgDouble.interactable = true;
_sliderComplete.value = 0;
_tmpItemNumber.text = "0";
_rewardNumber = 0;
_killerNumber = 0;
_injuredNumver = 0;
}
private void RefreshComplete(float num) //进度条显示
{
num = Mathf.Max(num, 0);
num = Mathf.Min(num, 1);
_sliderComplete.value = num;
}
private void RefreshKiller(int num) //杀敌奖励
{
_killerNumber += num;
}
private void RefreshReward(int num) //奖励道具数
{
_rewardNumber = num;
}
private void RefreshInjured(int num) //被攻击计数
{
_injuredNumver = num;
}
private void RefreshShow() //奖励总数显示
{
_tmpItemNumber.text = (Mathf.Max((_rewardNumber + _killerNumber - _injuredNumver), 0)).ToString();
}
private void ShowInjured()
{
_goHpHint.SetActive(true);
_goHpHint.GetComponent<Animator>().Play("hp_hint", -1, 0f);
}
private void CopyEndShow() //显示结算
{
_goFinal.SetActive(true);
_goGet.SetActive(false);
_goDamage.SetActive(false);
_goKill.SetActive(false);
_goRewardIcon.SetActive(false);
StartCoroutine(RefreshShowFinal());
}
private IEnumerator RefreshShowFinal()
{
_btnReward.gameObject.SetActive(false);
yield return StartCoroutine(RefreshShowDamage());
yield return StartCoroutine(RefreshShowKill());
yield return StartCoroutine(RefreshShowGet());
yield return StartCoroutine(RefreshShowReward());
}
private IEnumerator RefreshShowDamage()
{
_goDamage.SetActive(true);
for (int i = 0; i < _injuredNumver; i++)
{
_tmpSettleDamage.text = $"-{(int)Mathf.Lerp(0, _injuredNumver,i/ (float)_injuredNumver)}";
yield return null;
yield return null;
yield return null;
}
yield return null;
_tmpSettleDamage.text = $"-{_injuredNumver}";
}
private IEnumerator RefreshShowKill()
{
_goKill.SetActive(true);
for (int i = 0; i < _killerNumber; i++)
{
_tmpKiller.text = $"{(int)Mathf.Lerp(0, _killerNumber, i / (float)_killerNumber)}";
yield return null;
yield return null;
yield return null;
}
yield return null;
_tmpKiller.text = _killerNumber.ToString();
}
private IEnumerator RefreshShowGet()
{
_goGet.SetActive(true);
for (int i = 0; i < 15; i++)
{
_tmpGet.text = $"{(int)Mathf.Lerp(0, _rewardNumber, i / 15.0f)}";
yield return null;
yield return null;
yield return null;
}
yield return null;
_tmpGet.text = _rewardNumber.ToString();
}
private IEnumerator RefreshShowReward()
{
_goRewardIcon.SetActive(true);
int allReward = Mathf.Max((_rewardNumber + _killerNumber - _injuredNumver), 0);
if (_tgDouble.isOn)
{
for (int i = 0; i < 15; i++)
{
_tmpRewardNumber.text = $"{(int)Mathf.Lerp(0, allReward*2, i / 15.0f)}";
yield return null;
yield return null;
yield return null;
}
yield return null;
_tmpRewardNumber.text = (allReward * 2).ToString();
}
else
{
for (int i = 0; i < 15; i++)
{
_tmpRewardNumber.text = $"{(int)Mathf.Lerp(0, allReward, i / 15.0f)}";
yield return null;
yield return null;
yield return null;
}
yield return null;
_tmpRewardNumber.text = allReward.ToString();
}
_smartCostWidget.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
_btnReward.gameObject.SetActive(true);
}
private void CopyEndReward(int IsAd) //获得结算奖励
{
int allReward = Mathf.Max((_rewardNumber + _killerNumber - _injuredNumver), 0);
Item.ItemInfo reward = new Item.ItemInfo(3001, allReward * IsAd);
RewardProxy.Instance.GetReward(reward);
}
private void OnBackBtnClick() //退出按钮
{
RefreshView();
GameScene.Instance.EnterScene(0);
}
private void OnRewardShowTgClick(bool tg)
{
StartCoroutine(ChangeShowReward());
}
private IEnumerator ChangeShowReward()
{
_tgDouble.interactable = false;
int allReward = Mathf.Max((_rewardNumber + _killerNumber - _injuredNumver), 0);
if (_tgDouble.isOn)
{
for (int i = 0; i < 15; i++)
{
_tmpRewardNumber.text = $"{(int)Mathf.Lerp(allReward, allReward * 2, i / 15.0f)}";
yield return null;
yield return null;
yield return null;
}
yield return null;
_tmpRewardNumber.text = (allReward * 2).ToString();
}
else
{
for (int i = 0; i < 15; i++)
{
_tmpRewardNumber.text = $"{(int)Mathf.Lerp(allReward * 2, allReward, i / 15.0f)}";
yield return null;
yield return null;
yield return null;
}
yield return null;
_tmpRewardNumber.text = allReward.ToString();
}
yield return null;
_tgDouble.interactable = true;
}
private void OnAgainBtnClick() //领取奖励按钮
{
UI_InRide.Instance.OnClickContinue();
if (_tgDouble.isOn)
{
AdProxy.Instance.PlayAd("Copy", "QingMing", (error, message) =>
{
if (error == 0)
{
CopyEndReward(2);
RefreshView();
GameScene.Instance.EnterScene(0,"copy");
}
});
}
else
{
CopyEndReward(1);
RefreshView();
GameScene.Instance.EnterScene(0, "copy");
}
}
private void OnMenuBtnClick()//暂停
{
UI_InRide.Instance.PauseOn();
_goStop.SetActive(true);
}
private void OnQuitBtnClick()//退出
{
_goStop.SetActive(false);
UI_InRide.Instance.OnClickQuit();
}
private void OnContinueBtnClick()//继续
{
_goStop.SetActive(false);
UI_InRide.Instance.OnClickContinue();
}
#endregion
#region Mediator
readonly int[] _notificationInterests = new int[]
{
GlobalDefine.EVENT_COPY_COMPLETE,
GlobalDefine.EVENT_COPY_KILLER,
GlobalDefine.EVENT_COPY_PROP,
GlobalDefine.EVENT_COPY_INJURED,
GlobalDefine.EVENT_COPY_END
};
public override IList<int> ListNotificationInterests()
{
return _notificationInterests;
}
public override void HandleNotification(INotification notification)
{
if (notification.Name == GlobalDefine.EVENT_COPY_COMPLETE)
{
if (notification.Body is float num)
{
RefreshComplete(num);
}
}
else if (notification.Name == GlobalDefine.EVENT_COPY_INJURED)
{
if (notification.Body is int num)
{
ShowInjured();
RefreshInjured(num);
RefreshShow();
}
}
else if (notification.Name == GlobalDefine.EVENT_COPY_KILLER)
{
if (notification.Body is int num)
{
RefreshKiller(num);
RefreshShow();
}
}
else if (notification.Name == GlobalDefine.EVENT_COPY_PROP)
{
if (notification.Body is int num)
{
RefreshReward(num);
RefreshShow();
}
}
else if (notification.Name == GlobalDefine.EVENT_COPY_END)
{
//CopyEndReward();
CopyEndShow();
}
}
#endregion
}
}