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

252 lines
5.7 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-12-07
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "BoxShopPanel" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using PureMVC.Interfaces;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
/// <summary>
///
/// </summary>
partial class BoxShopPanel : KUIWidget
{
#region Auto Generate
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
GameObject __goGiftBoxes;
[KUIFlag]
GameObject __goNBoxes;
[KUIFlag]
GameObject __goHBoxes;
[KUIFlag]
KUIList __goExchange;
[KUIFlag]
TextMeshProUGUI _tmpExchangeTips;
[KUIFlag]
Button _btnExchangeRefresh;
[KUIFlag]
TextMeshProUGUI _tmpExchangeRefreshCount;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
#endregion
#region Field
PropBoxWidget _nPropBoxWidget1;
PropBoxWidget _nPropBoxWidget2;
PropBoxWidget _sPropBoxWidget1;
PropBoxWidget _sPropBoxWidget2;
GiftBoxWidget _giftBoxWidget;
SmartCostWidget _exchangeRefreshSmartCostWidget;
#endregion
#region Method
public override void Refresh()
{
RefreshGiftBox();
_nPropBoxWidget1.SetData(BoxShopProxy.Instance.GetPropBoxInfo(1));
_nPropBoxWidget2.SetData(BoxShopProxy.Instance.GetPropBoxInfo(2));
_sPropBoxWidget1.SetData(BoxShopProxy.Instance.GetPropBoxInfo(3));
if (FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.Beauty))
{
_sPropBoxWidget2.gameObject.SetActive(true);
_sPropBoxWidget2.SetData(BoxShopProxy.Instance.GetPropBoxInfo(4));
}
else
{
_sPropBoxWidget2.gameObject.SetActive(false);
}
RefreshExchange();
}
void RefreshGiftBox()
{
if (_giftBoxWidget)
{
var giftBoxInfos = RmbShopProxy.Instance.GetGiftBoxInfos();
RmbShopProxy.GiftBoxInfo selectGiftBoxInfo = null;
foreach (var item in giftBoxInfos)
{
if (item.type == 1)
{
selectGiftBoxInfo = item;
if (item.remainTimes > 0)
break;
}
}
_giftBoxWidget.SetData(selectGiftBoxInfo);
}
}
void RefreshExchange()
{
var timeInfo3 = TimeProxy.Instance.GetTimeInfo3(503);
_tmpExchangeRefreshCount.text = "x" + timeInfo3.remain;
if (timeInfo3.free > 0)
{
_exchangeRefreshSmartCostWidget.SetFree();
}
else
{
_exchangeRefreshSmartCostWidget.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
}
__goExchange.Clear();
var exchangeInfos = BoxShopProxy.Instance.GetExchangeInfos();
foreach (var item in exchangeInfos)
{
__goExchange.GetItem().SetData(item);
}
}
void UpdateState()
{
var seconds = BoxShopProxy.Instance.exchangeRefreshRemainSecond;
_tmpExchangeTips.text = F.Utils.Time.ToTimeString2(seconds);
}
void OnExchangeRefreshBtnClick()
{
var timeInfo3 = TimeProxy.Instance.GetTimeInfo3(503);
if (timeInfo3.free > 0)
{
OnExchangeRefreshCallback(0, "");
}
else if (timeInfo3.remain > 0)
{
AdProxy.Instance.PlayAd("box_shop", "refresh_exchange", this.OnExchangeRefreshCallback);
}
else
{
OnExchangeRefreshCallback(1, KLocalization.GetLocalString(33));
}
}
void OnExchangeRefreshCallback(int error, string message)
{
if (error == 0)
{
if (TimeProxy.Instance.CostTimes(503))
{
BoxShopProxy.Instance.ResetExchange();
RefreshExchange();
}
}
else
{
ToastBox.ShowText(message);
}
}
#endregion
#region Unity
/// <summary>
///
/// </summary>
private void Awake()
{
SetViewData();
if (KPlatform.Instance.QueryPay())
_giftBoxWidget = __goGiftBoxes.transform.GetChild(0).gameObject.AddComponent<GiftBoxWidget>();
else
__goGiftBoxes.SetActive(false);
_nPropBoxWidget1 = __goNBoxes.transform.GetChild(0).gameObject.AddComponent<PropBoxWidget>();
_nPropBoxWidget2 = __goNBoxes.transform.GetChild(1).gameObject.AddComponent<PropBoxWidget>();
_sPropBoxWidget1 = __goHBoxes.transform.GetChild(0).gameObject.AddComponent<PropBoxWidget>();
_sPropBoxWidget2 = __goHBoxes.transform.GetChild(1).gameObject.AddComponent<PropBoxWidget>();
__goExchange.AddTemplate<ExchangeWidget>(true);
_btnExchangeRefresh.onClick.AddListener(this.OnExchangeRefreshBtnClick);
_exchangeRefreshSmartCostWidget = _btnExchangeRefresh.gameObject.AddComponent<SmartCostWidget>();
}
private void OnEnable()
{
RegisterThis();
//if (_start)
{
Refresh();
PostNotification(GlobalDefine.EVENT_WINDOW_OPENED, 5, "");
}
}
private void OnDisable()
{
UnregisterThis();
}
float _lastUpdateTime;
private void Update()
{
if (Time.time - _lastUpdateTime > 1f)
{
_lastUpdateTime = Time.deltaTime;
UpdateState();
}
}
#endregion
#region Meditor
readonly int[] _notificationInterests = new int[] {
GlobalDefine.EVENT_SHOP_SLOT_CHANGED,
GlobalDefine.EVENT_SHOP_PET_BOX_CHANGED,
GlobalDefine.EVENT_SHOP_GIFT_BOX_CHANGED
};
public override IList<int> ListNotificationInterests()
{
return _notificationInterests;
}
public override void HandleNotification(INotification notification)
{
if (notification.Name == GlobalDefine.EVENT_SHOP_GIFT_BOX_CHANGED)
{
Refresh();
}
else if (notification.Name == GlobalDefine.EVENT_SHOP_SLOT_CHANGED)
{
}
else if (notification.Name == GlobalDefine.EVENT_SHOP_PET_BOX_CHANGED)
{
}
}
#endregion
}
}