365 lines
8.1 KiB
C#
365 lines
8.1 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2020-12-07
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "ShopPanel" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using System.Collections.Generic;
|
|
using PureMVC.Interfaces;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace G.UI
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
partial class ShopPanel : KUIWidget
|
|
{
|
|
#region Field
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
[KUIFlag]
|
|
GameObject _goGift;
|
|
[KUIFlag]
|
|
Button _btnSpeedUp;
|
|
[KUIFlag]
|
|
Button _btnGiftTips;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpGiftTips;
|
|
[KUIFlag]
|
|
GameObject _goGiftAdIcon;
|
|
[KUIFlag]
|
|
GameObject _goGiftFreeIcon;
|
|
[KUIFlag]
|
|
GameObject __goGiftBoxes;
|
|
|
|
[KUIFlag]
|
|
GameObject __goSlot;
|
|
[KUIFlag]
|
|
KUIList __goShopSlots;
|
|
[KUIFlag]
|
|
Button _btnSlotGetAll;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpSlotTips;
|
|
[KUIFlag]
|
|
GameObject _goSlotAdIcon;
|
|
[KUIFlag]
|
|
GameObject _goSlotFreeIcon;
|
|
|
|
[KUIFlag]
|
|
GameObject _goKey;
|
|
[KUIFlag]
|
|
KUIList __goKeyBoxes;
|
|
|
|
[KUIFlag]
|
|
GameObject _goPet;
|
|
[KUIFlag]
|
|
Button _btnPetGetAll;
|
|
[KUIFlag]
|
|
GameObject _goPetAdIcon;
|
|
[KUIFlag]
|
|
GameObject _goPetFreeIcon;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpPetTips;
|
|
[KUIFlag]
|
|
KUIList __goPetBoxes;
|
|
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
private TimeBoxWidget[] _shopTimeBoxWidgets;
|
|
private CoinBoxWidget[] _shopCoinBoxWidgets;
|
|
private KeyBoxWidget[] _shopKeyBoxWidgets;
|
|
private PetBoxWidget[] _shopPetBoxWidgets;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
public override void Refresh()
|
|
{
|
|
RefreshGiftBoxes();
|
|
RefreshShopSlots();
|
|
if (FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.Beauty))
|
|
{
|
|
_goKey.SetActive(true);
|
|
RefreshKeyBoxes();
|
|
}
|
|
else
|
|
{
|
|
_goKey.SetActive(false);
|
|
}
|
|
|
|
//if (FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.Pet))
|
|
//{
|
|
// _goPet.SetActive(true);
|
|
// RefreshPetBoxes();
|
|
//}
|
|
//else
|
|
//{
|
|
_goPet.SetActive(false);
|
|
//}
|
|
}
|
|
|
|
private void RefreshGiftBoxes()
|
|
{
|
|
if (ShopProxy.Instance.giftUseFree)
|
|
{
|
|
_goGiftAdIcon.SetActive(false);
|
|
_goGiftFreeIcon.SetActive(true);
|
|
_tmpGiftTips.SetText("每日首次免广告");
|
|
}
|
|
else
|
|
{
|
|
_goGiftFreeIcon.SetActive(false);
|
|
_goGiftAdIcon.SetActive(true);
|
|
_tmpGiftTips.text = @"饰品宝箱缩短<color=#FF0606>12</color>小时";
|
|
}
|
|
|
|
var giftBoxs = ShopProxy.Instance.giftBoxes;
|
|
for (int i = 0; i < giftBoxs.Length; i++)
|
|
{
|
|
_shopTimeBoxWidgets[i].SetData(giftBoxs[i]);
|
|
}
|
|
}
|
|
|
|
private void RefreshShopSlots()
|
|
{
|
|
int times = ShopProxy.Instance.freeGetTimes;
|
|
int maxTimes = ShopProxy.Instance.freeGetMaxTimes;
|
|
|
|
if (times < maxTimes)
|
|
{
|
|
_goSlotFreeIcon.SetActive(false);
|
|
_goSlotAdIcon.SetActive(true);
|
|
_tmpSlotTips.text = $"今日广告领取次数:{times}/{maxTimes}";
|
|
}
|
|
else
|
|
{
|
|
_goSlotAdIcon.SetActive(false);
|
|
_goSlotFreeIcon.SetActive(true);
|
|
_tmpSlotTips.text = "每日首次免广告";
|
|
}
|
|
|
|
var slotInfos = ShopProxy.Instance.slotBoxes;
|
|
for (int i = 0; i < slotInfos.Length; i++)
|
|
{
|
|
_shopCoinBoxWidgets[i].SetData(slotInfos[i]);
|
|
}
|
|
}
|
|
|
|
private void RefreshKeyBoxes()
|
|
{
|
|
var keyBoxes = ShopProxy.Instance.keyBoxes;
|
|
for (int i = 0; i < keyBoxes.Length; i++)
|
|
{
|
|
_shopKeyBoxWidgets[i].SetData(keyBoxes[i]);
|
|
}
|
|
}
|
|
|
|
private void RefreshPetBoxes()
|
|
{
|
|
}
|
|
|
|
public void UpdateState()
|
|
{
|
|
for (int i = 0; i < _shopTimeBoxWidgets.Length; i++)
|
|
{
|
|
_shopTimeBoxWidgets[i].UpdateState();
|
|
}
|
|
|
|
for (int i = 0; i < _shopKeyBoxWidgets.Length; i++)
|
|
{
|
|
_shopKeyBoxWidgets[i].UpdateState();
|
|
}
|
|
}
|
|
|
|
private void OnSpeedupBtnClick()
|
|
{
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
|
|
var useFree = ShopProxy.Instance.giftUseFree;
|
|
if (!useFree)
|
|
{
|
|
//看广告
|
|
KPlatform.Instance.PlayRewardAd("shop", "shop_speed_up", (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
ShopProxy.Instance.GiftBoxSpeedUp();
|
|
RefreshGiftBoxes();
|
|
ToastBox.ShowText("饰品宝箱缩短<color=#FF0606>12</color>小时");
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
ShopProxy.Instance.GiftBoxSpeedUp();
|
|
ShopProxy.Instance.giftUseFree = true;
|
|
RefreshGiftBoxes();
|
|
ToastBox.ShowText("饰品宝箱缩短<color=#FF0606>12</color>小时");
|
|
}
|
|
}
|
|
|
|
private void OnRefreshBtnClick()
|
|
{
|
|
int times = ShopProxy.Instance.freeGetTimes;
|
|
int maxTimes = ShopProxy.Instance.freeGetMaxTimes;
|
|
|
|
if (times <= 0)
|
|
{
|
|
ToastBox.ShowText("广告领取次数已达到每日上限.");
|
|
return;
|
|
}
|
|
else if (times < maxTimes)
|
|
{
|
|
//看广告
|
|
KPlatform.Instance.PlayRewardAd("shop", "shop_refresh", (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
ShopProxy.Instance.SlotFreeGetAll();
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
ShopProxy.Instance.SlotFreeGetAll();
|
|
}
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
private void OnPetGetAllBtnClick()
|
|
{
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
private void OnTipsBtnClick()
|
|
{
|
|
MessageBox.ShowMessage(KLocalization.GetLocalString(52), KLocalization.GetLocalString(53));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void Awake()
|
|
{
|
|
SetViewData();
|
|
var timeBoxCount = ShopProxy.Instance.giftBoxes.Length;
|
|
_shopTimeBoxWidgets = new TimeBoxWidget[timeBoxCount];
|
|
for (int i = 0; i < timeBoxCount; i++)
|
|
{
|
|
var child = __goGiftBoxes.transform.GetChild(i);
|
|
_shopTimeBoxWidgets[i] = child.gameObject.AddComponent<TimeBoxWidget>();
|
|
}
|
|
|
|
__goShopSlots.AddTemplate<CoinBoxWidget>(true);
|
|
var coinBoxCount = ShopProxy.Instance.slotBoxes.Length;
|
|
_shopCoinBoxWidgets = new CoinBoxWidget[coinBoxCount];
|
|
for (int i = 0; i < coinBoxCount; i++)
|
|
{
|
|
_shopCoinBoxWidgets[i] = __goShopSlots.GetItem<CoinBoxWidget>();
|
|
}
|
|
|
|
__goKeyBoxes.AddTemplate<KeyBoxWidget>(true);
|
|
var keyBoxCount = ShopProxy.Instance.keyBoxes.Length;
|
|
_shopKeyBoxWidgets = new KeyBoxWidget[keyBoxCount];
|
|
for (int i = 0; i < keyBoxCount; i++)
|
|
{
|
|
_shopKeyBoxWidgets[i] = __goKeyBoxes.GetItem<KeyBoxWidget>();
|
|
}
|
|
|
|
__goPetBoxes.AddTemplate<PetBoxWidget>(true);
|
|
var petBoxCount = ShopProxy.Instance.petBoxes.Length;
|
|
_shopPetBoxWidgets = new PetBoxWidget[petBoxCount];
|
|
for (int i = 0; i < petBoxCount; i++)
|
|
{
|
|
_shopPetBoxWidgets[i] = __goPetBoxes.GetItem<PetBoxWidget>();
|
|
}
|
|
|
|
_btnSpeedUp.onClick.AddListener(this.OnSpeedupBtnClick);
|
|
_btnSlotGetAll.onClick.AddListener(this.OnRefreshBtnClick);
|
|
_btnGiftTips.onClick.AddListener(this.OnTipsBtnClick);
|
|
|
|
_btnPetGetAll.onClick.AddListener(this.OnPetGetAllBtnClick);
|
|
}
|
|
|
|
//private bool _start;
|
|
//private void Start()
|
|
//{
|
|
// if (!_start)
|
|
// {
|
|
// _start = true;
|
|
// Refresh();
|
|
// PostNotification(GlobalDefine.EVENT_WINDOW_OPEN, 5, "");
|
|
// }
|
|
//}
|
|
|
|
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
|
|
};
|
|
|
|
public override IList<int> ListNotificationInterests()
|
|
{
|
|
return _notificationInterests;
|
|
}
|
|
|
|
public override void HandleNotification(INotification notification)
|
|
{
|
|
if (notification.Name == GlobalDefine.EVENT_SHOP_SLOT_CHANGED)
|
|
{
|
|
RefreshShopSlots();
|
|
}
|
|
else if (notification.Name == GlobalDefine.EVENT_SHOP_PET_BOX_CHANGED)
|
|
{
|
|
RefreshPetBoxes();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|