Files
taptap2024_GJ_chidouren/Assets/Scripts/Views/OfflineAwardPanel.cs

137 lines
6.4 KiB
C#
Raw Normal View History

2024-10-16 00:03:41 +08:00
using System;
using System.Collections.Generic;
using System.OfflineSystem;
using System.RandomPool;
using Framework.Audio;
using Framework.Save;
using Framework.Timer;
using Framework.UI;
using Game;
using Game.Component;
using UnityEngine;
using UnityEngine.UI;
using IcecreamView;
using Runtime.ADAggregator;
using Script.Core.Utils.Extend;
using TMPro;
using Unity.Mathematics;
using Random = UnityEngine.Random;
namespace Views
{
public class OfflineAwardPanel : IcecreamView.IC_AbstractModule
{
[SerializeField] private Button _closeBtn;
[SerializeField] private Button _getBtn;
[SerializeField] private Button _upLevelBtn;
[SerializeField] private GameSlider _upLevelSlider;
[SerializeField] private TMP_Text _levelText;
[SerializeField] private TMP_Text _award1Text;
[SerializeField] private TMP_Text _award2Text;
[SerializeField] private TMP_Text _onlineTimeText;
[SerializeField] private TMP_Text _onlineAwardText;
[SerializeField] private TMP_Text _upLevelText;
[SerializeField] private TMP_Text _adUseCountText;
[SerializeField] private GameObject _mask;
private string award1text;
private string award2text;
public override void OnInitView ()
{
this._closeBtn.onClick.AddListener (this.ViewConnector.CloseView , SeAudio.Btn_Close);
this._getBtn.onClick.AddListener (OnClick_GetAward, SeAudio.Btn_Click);
this._upLevelBtn.onClick.AddListener (OnClick_UpLevel, SeAudio.Btn_Click);
}
public override void OnOpenView (IC_ViewData parameters)
{
this._upLevelText.gameObject.SetActive (true);
this._upLevelSlider.gameObject.SetActive (false);
this._mask.SetActive (false);
GameUpdateMgr.Instance.AddUpdater (DoUpdate);
this.award1text = this._award1Text.text;
this.award2text = this._award2Text.text;
RefreshText ();
}
public override void OnCloseView ()
{
GameUpdateMgr.Instance.RemoveUpdater (DoUpdate);
}
private void RefreshText ()
{
this._adUseCountText.text = $"今日可用:{Account.Instance.AccountGameData.CurHangUpLevelCount.Read}/{GameConstConfig.Instance.MaxHangUpLevelAdCount}";
this._levelText.text = $"LV{Account.Instance.AccountGameData.HangLevel}";
var hangLevel = Account.Instance.AccountGameData.HangLevel;
this._award1Text.text = string.Format (this.award1text, Account.Instance.AccountGameData.OnlineAwardUnit (hangLevel).ToString ("F1") ,
(Account.Instance.AccountGameData.GetMaxOnlineDuration * 60).ShowSecondsTime ());
this._award2Text.text = string.Format (this.award2text, Account.Instance.AccountGameData.OfflineAwardUnit ().ToString ("F1"),
(Account.Instance.AccountGameData.GetMaxOfflineDuration * 60).ShowSecondsTime ());
}
private void DoUpdate ()
{
var hangLevel = Account.Instance.AccountGameData.HangLevel;
var curTotalOnlineDuration = Account.Instance.AccountGameData.GetCurTotalOnlineDuration ();
this._getBtn.interactable = curTotalOnlineDuration >= 1;
this._onlineTimeText.text = $"在线时长:{(curTotalOnlineDuration * 60).ShowSecondsTime ()}";
this._onlineAwardText.text = $"领取在线奖励\n<sprite name=xin><b>{Account.Instance.AccountGameData.GetCurTotalOnlineAward ().ShowText ()}</b>";
}
private void OnClick_UpLevel ()
{
if (Account.Instance.AccountGameData.CurHangUpLevelCount.Read <= 0)
{
UIManager.Instance.OpenPropTip ("以达到今日最大观看次数,明天再试!");
return;
}
Account.Instance.AccountGameData.CurHangUpLevelCount.Add (-1);
Account.Instance.Save(SaveData.Game);
ADManager.Instance.AsyncPlayAD (AD_Type.AwardVideo , AD_SceneCode.HangUplevel,(isSuccess) =>
{
if (isSuccess)
{
var hangLevel = Random.Range (1 , 5);
Account.Instance.AccountGameData.RefreshOfflineAwardLog ();
Account.Instance.AccountGameData.HangLevel = math.clamp (Account.Instance.AccountGameData.HangLevel + hangLevel , 1 , GameConstConfig.Instance.MaxHangUpLevel);
Account.Instance.AccountGameData.OnlineAwardDuration.AddExtraTime (600);
Account.Instance.Save (SaveData.Game);
//动画特效
this._mask.SetActive (true);
this._upLevelSlider.Value = 0;
this._upLevelSlider.ToValue (1 , 0.5f);
this._upLevelText.gameObject.SetActive (false);
this._upLevelSlider.gameObject.SetActive (true);
GameUpdateMgr.Instance.CreateTimer (0.5f , () =>
{
EventManager.Instance.SendEvent (GameEventCode.OnScreenFlicker , (int)(hangLevel * 0.7f) + 1);
GameManager.Instance.Vibrator (hangLevel > 3 ? VibratorScale.Normal : VibratorScale.Small);
AudioManager.Instance.PlaySoundEffect (SeAudio.OverGame_History);
this._mask.SetActive (false);
this._upLevelText.text = $"随机等级: <color=yellow><b>+{hangLevel}</b></color> 在线时长: <color=yellow><b>+10分钟";
this._upLevelText.gameObject.SetActive (true);
this._upLevelSlider.gameObject.SetActive (false);
this.RefreshText ();
});
}
this.RefreshText ();
});
}
private void OnClick_GetAward ()
{
//此处可以播放特效以及音效
var diamondAward = (long)Account.Instance.AccountGameData.GetCurTotalOnlineAward ();
Account.Instance.AccountGameData.OnlineAwardDurationList.Clear ();
Account.Instance.AccountGameData.OnlineAwardDuration = OfflineMgr.Instance.CreateTimeHandler (0);
Account.Instance.Save (SaveData.Game);
AudioManager.Instance.PlaySoundEffect (SeAudio.OverGame_History);
RefreshText ();
}
}
}