501 lines
16 KiB
C#
501 lines
16 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2021-02-05
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "AdMoneyBox.View" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G.UI
|
|
{
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
partial class AdMoneyBox
|
|
{
|
|
#region Auto Generate
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
[KUIFlag]
|
|
Button _btnBlack;
|
|
[KUIFlag]
|
|
Button _btnClose;
|
|
[KUIFlag]
|
|
Button __btnReward;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpTitle;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpRemainCount;
|
|
//[KUIFlag]
|
|
//KUIList __listRewards;
|
|
[KUIFlag]
|
|
KUIImage _imgIcon;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpCount;
|
|
[KUIFlag]
|
|
GameObject _goGem;
|
|
[KUIFlag]
|
|
Button __btnBuy;
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
#endregion
|
|
|
|
#region Field
|
|
|
|
SmartCostWidget _smartCostWidget;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void InitView()
|
|
{
|
|
SetViewData();
|
|
_btnBlack.onClick.AddListener(this.OnCloseBtnClick);
|
|
_btnClose.onClick.AddListener(this.OnCloseBtnClick);
|
|
__btnBuy.onClick.AddListener(this.OnGemBuyBtnClick);
|
|
|
|
__btnReward.onClick.AddListener(this.OnAdBtnClick);
|
|
//__listRewards.AddTemplate<PropWidget>(true);
|
|
_smartCostWidget = __btnReward.gameObject.AddComponent<SmartCostWidget>();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void RefreshView()
|
|
{
|
|
var id = (int)this.data;
|
|
if (id == Item.Id.kCoin)
|
|
{
|
|
_goGem.SetActive(KPlatform.Instance.QueryPay());
|
|
|
|
_tmpTitle.text = "免费金币";
|
|
_imgIcon.ShowSprite(0);
|
|
|
|
var chapterItem = LevelProxy.Instance.currentChapterItem;
|
|
if (chapterItem != null)
|
|
_tmpCount.text = "x" + chapterItem.adCoinRewardInfo.count;
|
|
//__listRewards.Clear();
|
|
//__listRewards.GetItem<PropWidget>().SetItem(reward);
|
|
|
|
SetTimes(TimeProxy.免费金币);
|
|
}
|
|
else if (id == Item.Id.kChip)
|
|
{
|
|
_goGem.SetActive(KPlatform.Instance.QueryPay());
|
|
|
|
_tmpTitle.text = "免费晶石";
|
|
_imgIcon.ShowSprite(2);
|
|
|
|
var chapterItem = LevelProxy.Instance.currentChapterItem;
|
|
if (chapterItem != null)
|
|
_tmpCount.text = "x" + chapterItem.adChipRewardInfo.count;
|
|
//__listRewards.Clear();
|
|
//__listRewards.GetItem<PropWidget>().SetItem(reward);
|
|
|
|
SetTimes(TimeProxy.免费晶石);
|
|
}
|
|
else if (id == Item.Id.kEnergy)
|
|
{
|
|
_goGem.SetActive(false);
|
|
|
|
_tmpTitle.text = "免费体力";
|
|
_imgIcon.ShowSprite(1);
|
|
|
|
var reward = new Item.ItemInfo(Item.Id.kEnergy, 10);
|
|
_tmpCount.text = "x" + reward.count;
|
|
//__listRewards.Clear();
|
|
//__listRewards.GetItem<PropWidget>().SetItem(reward);
|
|
|
|
SetTimes(TimeProxy.免费体力);
|
|
}
|
|
else if (id == Item.Id.kMotility)
|
|
{
|
|
_goGem.SetActive(false);
|
|
|
|
_tmpTitle.text = "免费活力";
|
|
_imgIcon.ShowSprite(3);
|
|
|
|
var reward = new Item.ItemInfo(Item.Id.kMotility, 3);
|
|
_tmpCount.text = "x" + reward.count;
|
|
//__listRewards.Clear();
|
|
//__listRewards.GetItem<PropWidget>().SetItem(reward);
|
|
|
|
SetTimes(TimeProxy.免费活力);
|
|
}
|
|
else if (id == Item.Id.kGem)
|
|
{
|
|
_goGem.SetActive(false);
|
|
|
|
_tmpTitle.text = "免费元宝";
|
|
_imgIcon.ShowSprite(4);
|
|
|
|
var chapterItem = LevelProxy.Instance.currentChapterItem;
|
|
if (chapterItem != null)
|
|
_tmpCount.text = "x" + chapterItem.adGemRewardInfo.count;
|
|
//__listRewards.Clear();
|
|
//__listRewards.GetItem<PropWidget>().SetItem(reward);
|
|
|
|
SetTimes(TimeProxy.免费元宝);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="timeId"></param>
|
|
private void SetTimes(int timeId)
|
|
{
|
|
var timesInfo = TimeProxy.Instance.GetTimeInfo3(timeId);
|
|
if (IsFreeTime(timesInfo))
|
|
{
|
|
_tmpRemainCount.text = "每日首次免广告";
|
|
_smartCostWidget.SetFree();
|
|
}
|
|
else
|
|
{
|
|
if (IsShareTime(timesInfo))
|
|
{
|
|
_smartCostWidget.SetShare();
|
|
}
|
|
else
|
|
{
|
|
_smartCostWidget.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
|
|
}
|
|
_tmpRemainCount.text = $"今日剩余次数: {timesInfo.remain}";
|
|
}
|
|
}
|
|
|
|
private void OnCloseBtnClick()
|
|
{
|
|
CloseWindow(this);
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
private void OnGemBuyBtnClick()
|
|
{
|
|
var id = (int)this.data;
|
|
if (id == Item.Id.kCoin)
|
|
{
|
|
if (MoneyProxy.Instance.CheckAndCostMoney(new Item.ItemInfo() { id = Item.Id.kGem, count = 100 }))
|
|
{
|
|
var chapterItem = LevelProxy.Instance.currentChapterItem;
|
|
if (chapterItem != null)
|
|
RewardProxy.Instance.GetRewardWithUI(chapterItem.adCoinRewardInfo, (error, message) =>
|
|
{
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(KLocalization.GetLocalString(3));
|
|
}
|
|
}
|
|
else if (id == Item.Id.kChip)
|
|
{
|
|
if (MoneyProxy.Instance.CheckAndCostMoney(new Item.ItemInfo() { id = Item.Id.kGem, count = 100 }))
|
|
{
|
|
var chapterItem = LevelProxy.Instance.currentChapterItem;
|
|
if (chapterItem != null)
|
|
RewardProxy.Instance.GetRewardWithUI(chapterItem.adChipRewardInfo, (error, message) =>
|
|
{
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(KLocalization.GetLocalString(3));
|
|
}
|
|
}
|
|
}
|
|
|
|
private void GetCoin(int err, string msg)
|
|
{
|
|
if (err == 0)
|
|
{
|
|
if (TimeProxy.Instance.CostTimes(TimeProxy.免费金币))
|
|
{
|
|
var chapterItem = LevelProxy.Instance.currentChapterItem;
|
|
if (chapterItem != null)
|
|
RewardProxy.Instance.GetRewardWithUI(chapterItem.adCoinRewardInfo, (error, message) =>
|
|
{
|
|
SetTimes(TimeProxy.免费金币);
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
}
|
|
|
|
if (msg == "free")
|
|
RefreshView();
|
|
else
|
|
CloseWindow(this);
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(msg);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="amount"></param>
|
|
private void GetChip(int err, string msg)
|
|
{
|
|
if (err == 0)
|
|
{
|
|
if (TimeProxy.Instance.CostTimes(TimeProxy.免费晶石))
|
|
{
|
|
var chapterItem = LevelProxy.Instance.currentChapterItem;
|
|
if (chapterItem != null)
|
|
RewardProxy.Instance.GetRewardWithUI(chapterItem.adChipRewardInfo, (error, message) =>
|
|
{
|
|
SetTimes(TimeProxy.免费晶石);
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
}
|
|
|
|
if (msg == "free")
|
|
RefreshView();
|
|
else
|
|
CloseWindow(this);
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(msg);
|
|
}
|
|
}
|
|
|
|
private void GetGem(int err, string msg)
|
|
{
|
|
if (err == 0)
|
|
{
|
|
if (TimeProxy.Instance.CostTimes(TimeProxy.免费元宝))
|
|
{
|
|
var chapterItem = LevelProxy.Instance.currentChapterItem;
|
|
if (chapterItem != null)
|
|
RewardProxy.Instance.GetRewardWithUI(chapterItem.adGemRewardInfo, (error, message) =>
|
|
{
|
|
SetTimes(TimeProxy.免费元宝);
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
});
|
|
}
|
|
|
|
if (msg == "free")
|
|
RefreshView();
|
|
else
|
|
CloseWindow(this);
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(msg);
|
|
}
|
|
}
|
|
|
|
private void GetEnergy(int err, string msg)
|
|
{
|
|
if (err == 0)
|
|
{
|
|
if (TimeProxy.Instance.CostTimes(TimeProxy.免费体力))
|
|
{
|
|
var add = GlobalProxy.Instance.GetInt("ads_energy");
|
|
RewardProxy.Instance.GetRewardWithUI(new Item.ItemInfo(Item.Id.kEnergy, add),
|
|
(error, message) =>
|
|
{
|
|
SetTimes(TimeProxy.免费体力);
|
|
});
|
|
}
|
|
|
|
if (msg == "free")
|
|
RefreshView();
|
|
else
|
|
CloseWindow(this);
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(msg);
|
|
}
|
|
}
|
|
|
|
private void GetMotion(int err, string msg)
|
|
{
|
|
if (err == 0)
|
|
{
|
|
if (TimeProxy.Instance.CostTimes(TimeProxy.免费活力))
|
|
{
|
|
RewardProxy.Instance.GetRewardWithUI(new Item.ItemInfo(Item.Id.kMotility, 3),
|
|
(error, message) =>
|
|
{
|
|
SetTimes(TimeProxy.免费活力);
|
|
});
|
|
}
|
|
|
|
if (msg == "free")
|
|
RefreshView();
|
|
else
|
|
CloseWindow(this);
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(msg);
|
|
}
|
|
}
|
|
|
|
private bool IsFreeTime(TimeProxy.TimeInfo3 timesInfo)
|
|
{
|
|
return timesInfo.free > 0;
|
|
}
|
|
|
|
private bool IsShareTime(TimeProxy.TimeInfo3 timesInfo)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
private bool IsValidTime(TimeProxy.TimeInfo3 timesInfo)
|
|
{
|
|
return timesInfo.remain > 0;
|
|
}
|
|
|
|
private void OnAdBtnClick()
|
|
{
|
|
var id = (int)this.data;
|
|
if (id == Item.Id.kCoin)
|
|
{
|
|
var timesInfo = TimeProxy.Instance.GetTimeInfo3(TimeProxy.免费金币);
|
|
if (IsFreeTime(timesInfo))
|
|
{
|
|
GetCoin(0, "free");
|
|
RefreshView();
|
|
}
|
|
else
|
|
if (IsValidTime(timesInfo))
|
|
{
|
|
if (IsShareTime(timesInfo))
|
|
{
|
|
ShareProxy.Instance.ShareAppWithFreeAd("type=ads_coin", this.GetCoin);
|
|
}
|
|
else
|
|
{
|
|
AdProxy.Instance.PlayAd("money", "ads_coin", this.GetCoin);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText("每日领取金币次数已达上限,请明日再来");
|
|
}
|
|
}
|
|
else if (id == Item.Id.kChip)
|
|
{
|
|
var timesInfo = TimeProxy.Instance.GetTimeInfo3(TimeProxy.免费晶石);
|
|
if (IsFreeTime(timesInfo))
|
|
{
|
|
GetChip(0, "free");
|
|
}
|
|
else
|
|
if (IsValidTime(timesInfo))
|
|
{
|
|
if (IsShareTime(timesInfo))
|
|
{
|
|
ShareProxy.Instance.ShareAppWithFreeAd("type=ads_chip", this.GetChip);
|
|
}
|
|
else
|
|
{
|
|
AdProxy.Instance.PlayAd("money", "ads_chip", this.GetChip);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText("每日领取晶石次数已达上限,请明日再来");
|
|
}
|
|
}
|
|
else if (id == Item.Id.kGem)
|
|
{
|
|
var timesInfo = TimeProxy.Instance.GetTimeInfo3(TimeProxy.免费元宝);
|
|
if (IsFreeTime(timesInfo))
|
|
{
|
|
GetGem(0, "free");
|
|
}
|
|
else
|
|
if (IsValidTime(timesInfo))
|
|
{
|
|
if (IsShareTime(timesInfo))
|
|
{
|
|
ShareProxy.Instance.ShareAppWithFreeAd("type=ads_gem", this.GetGem);
|
|
}
|
|
else
|
|
{
|
|
AdProxy.Instance.PlayAd("money", "ads_gem", this.GetGem);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText("每日领取元宝次数已达上限,请明日再来");
|
|
}
|
|
}
|
|
|
|
else if (id == Item.Id.kEnergy)
|
|
{
|
|
var timesInfo = TimeProxy.Instance.GetTimeInfo3(TimeProxy.免费体力);
|
|
if (IsFreeTime(timesInfo))
|
|
{
|
|
GetEnergy(0, "free");
|
|
}
|
|
else
|
|
if (IsValidTime(timesInfo))
|
|
{
|
|
if (IsShareTime(timesInfo))
|
|
{
|
|
ShareProxy.Instance.ShareAppWithFreeAd("type=ads_energy", this.GetEnergy);
|
|
}
|
|
else
|
|
{
|
|
AdProxy.Instance.PlayAd("money", "ads_energy", this.GetEnergy);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText("每日领取体力次数已达上限,请明日再来");
|
|
}
|
|
}
|
|
else if (id == Item.Id.kMotility)
|
|
{
|
|
var timesInfo = TimeProxy.Instance.GetTimeInfo3(TimeProxy.免费活力);
|
|
if (IsFreeTime(timesInfo))
|
|
{
|
|
GetMotion(0, "free");
|
|
}
|
|
else
|
|
if (IsValidTime(timesInfo))
|
|
{
|
|
if (IsShareTime(timesInfo))
|
|
{
|
|
ShareProxy.Instance.ShareAppWithFreeAd("type=ads_motion", this.GetMotion);
|
|
}
|
|
else
|
|
{
|
|
AdProxy.Instance.PlayAd("money", "ads_motion", this.GetMotion);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText("每日领取活力次数已达上限,请明日再来");
|
|
}
|
|
}
|
|
|
|
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
|
|
}
|
|
|
|
|
|
#endregion
|
|
}
|
|
}
|