127 lines
4.3 KiB
C#
127 lines
4.3 KiB
C#
/*
|
|
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class RedemptionCodePopupPanel : BasePanel
|
|
{
|
|
|
|
#region Field&&Property ༼ つ ◕_◕ ༽つ--ฅʕ•̫͡•ʔฅ
|
|
[SerializeField]
|
|
private TMP_InputField if_cdKey;
|
|
[SerializeField]
|
|
private Button
|
|
btn_close,
|
|
btn_waitCD,
|
|
btn_confirm;
|
|
|
|
[SerializeField]
|
|
private TMP_Text
|
|
txt_cd;
|
|
|
|
private string _redemptionKey;
|
|
|
|
private bool isRedeeming = false;
|
|
private Dictionary<RedeemCodeService.ECheckValidateResult, string> dic_toast = new();
|
|
private RedeemCodeService _redeemCodeService;
|
|
#endregion
|
|
|
|
|
|
#region Function ( =∩王∩= )m~~o(=•ェ•=)m
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
if_cdKey.onEndEdit.AsObservable().Subscribe(x => _redemptionKey = x).AddTo(disposables);
|
|
btn_confirm.OnClickAsObservable().Subscribe(_ => OnRedeem()).AddTo(disposables);
|
|
btn_close.OnClickAsObservable().Subscribe(_ => OnClose()).AddTo(disposables);
|
|
btn_waitCD.OnClickAsObservable().Subscribe(_ => ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_62"))).AddTo(disposables);
|
|
_redeemCodeService = GContext.container.Resolve<RedeemCodeService>();
|
|
|
|
dic_toast.Add(RedeemCodeService.ECheckValidateResult.invalid, "UI_ToastPanel_54");
|
|
dic_toast.Add(RedeemCodeService.ECheckValidateResult.hasRedeemed, "UI_ToastPanel_55");
|
|
dic_toast.Add(RedeemCodeService.ECheckValidateResult.expired, "UI_ToastPanel_56");
|
|
dic_toast.Add(RedeemCodeService.ECheckValidateResult.BusyServer, "UI_ToastPanel_58");
|
|
StartCoroutine(CheckRedeemCD());
|
|
}
|
|
|
|
private async void OnRedeem()
|
|
{
|
|
if ( !isRedeeming )
|
|
{
|
|
isRedeeming = true;
|
|
var redeemResult = await _redeemCodeService.CheckRedemptionKeyValidate(_redemptionKey);
|
|
|
|
//Success
|
|
if ( redeemResult.Result == RedeemCodeService.ECheckValidateResult.success )
|
|
{
|
|
GContext.container.Resolve<PlayerItemData>().AddItemByDrop(redeemResult.Code);
|
|
GContext.Publish(new ShowData());
|
|
|
|
#if AGG
|
|
using (var e = GEvent.GameEvent("redeem_code"))
|
|
{
|
|
e.AddContent("key", _redemptionKey);
|
|
};
|
|
#endif
|
|
|
|
}
|
|
else
|
|
{
|
|
if ( dic_toast.ContainsKey(redeemResult.Result) )
|
|
ToastPanel.Show(LocalizationMgr.GetText(dic_toast[redeemResult.Result]));
|
|
else if ( redeemResult.Result == RedeemCodeService.ECheckValidateResult.RegisterDayNotEnough )
|
|
ToastPanel.Show(LocalizationMgr.GetFormatTextValue("UI_ToastPanel_61", redeemResult.Code));
|
|
else
|
|
ToastPanel.Show(LocalizationMgr.GetText(dic_toast[RedeemCodeService.ECheckValidateResult.invalid]));
|
|
_redeemCodeService.nextRedeemTime = DateTime.UtcNow.AddSeconds(5);
|
|
_=StartCoroutine(CheckRedeemCD());
|
|
}
|
|
|
|
Debug.Log($"RedemptionPanel::OnRedeem : Result {redeemResult.Result};DropID{redeemResult.Code}");
|
|
isRedeeming = false;
|
|
|
|
}
|
|
|
|
}
|
|
private void OnClose()
|
|
{
|
|
if ( !isRedeeming )
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.RedemptionCodePopupPanel);
|
|
}
|
|
}
|
|
|
|
IEnumerator CheckRedeemCD()
|
|
{
|
|
var cd = _redeemCodeService.nextRedeemTime - DateTime.UtcNow;
|
|
if ( cd.TotalSeconds > 0f )
|
|
{
|
|
txt_cd.text = LocalizationMgr.GetFormatTextValue("UI_RedemptionCodePopupPanel_3", cd.TotalSeconds.ToString("F0"));
|
|
btn_waitCD.transform.parent.gameObject.SetActive(true);
|
|
btn_confirm.transform.parent.gameObject.SetActive(false);
|
|
|
|
while ( cd.TotalSeconds > 0f )
|
|
{
|
|
yield return new WaitForSeconds(0.1f) ;
|
|
txt_cd.text = LocalizationMgr.GetFormatTextValue("UI_RedemptionCodePopupPanel_3", cd.TotalSeconds.ToString("F0"));
|
|
cd = cd.Subtract(new TimeSpan(0, 0, 0, 0, 100));
|
|
}
|
|
}
|
|
btn_waitCD.transform.parent.gameObject.SetActive(false);
|
|
btn_confirm.transform.parent.gameObject.SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
*/
|