2022-05-23 13:39:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
2022-06-08 13:23:44 +00:00
|
|
|
|
using DG.Tweening;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
|
|
|
|
|
public class PanelMain : BasePanel
|
|
|
|
|
|
{
|
|
|
|
|
|
public Action DelStart;
|
|
|
|
|
|
public Action DelHuman;
|
|
|
|
|
|
public Action DelMonster;
|
2022-06-08 13:23:44 +00:00
|
|
|
|
public Action DelAutoMergeAdd;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
public Action<bool> DelFocus;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] LevelDisplay mLdpLevel;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] GameObject mGobRedPoint;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] Button mBtnSettings;
|
|
|
|
|
|
[SerializeField] Button mBtnBook;
|
|
|
|
|
|
[SerializeField] Button mBtnNoAds;
|
|
|
|
|
|
[SerializeField] Button mBtnMoreGames;
|
|
|
|
|
|
[SerializeField] Button mBtnBuff;
|
2022-06-08 13:23:44 +00:00
|
|
|
|
[SerializeField] Button mBtnAdAuto;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] Text mTxtAutoCount;
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
|
|
|
|
|
[SerializeField] Button mBtnStart;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] Text mTxtHumanPrice;
|
|
|
|
|
|
[SerializeField] GameObject mGobHumanNormal;
|
|
|
|
|
|
[SerializeField] GameObject mGobHumanAd;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] Text mTxtMonsterPrice;
|
|
|
|
|
|
[SerializeField] GameObject mGobMonsterNormal;
|
|
|
|
|
|
[SerializeField] GameObject mGobMonsterAd;
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] Button mBtnHuman;
|
|
|
|
|
|
[SerializeField] Button mBtnMonster;
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
[SerializeField] RectTransform mRctBottom;
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
private int mHumanPrice;
|
|
|
|
|
|
private int mMonsterPrice;
|
|
|
|
|
|
private bool mHumanAfford;
|
|
|
|
|
|
private bool mMonsterAfford;
|
|
|
|
|
|
|
|
|
|
|
|
private static bool sHasMoreGameClicked = false;
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIUtils.BindBtn(mBtnSettings, OnClickSettings);
|
|
|
|
|
|
UIUtils.BindBtn(mBtnBook, OnClickBook);
|
|
|
|
|
|
UIUtils.BindBtn(mBtnNoAds, OnClickNoAds);
|
|
|
|
|
|
UIUtils.BindBtn(mBtnMoreGames, OnClickMoreGame);
|
|
|
|
|
|
UIUtils.BindBtn(mBtnBuff, OnClickBuff);
|
2022-06-08 13:23:44 +00:00
|
|
|
|
UIUtils.BindBtn(mBtnAdAuto, OnClickAdAuto);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
UIUtils.BindBtn(mBtnStart, OnClickStart);
|
|
|
|
|
|
UIUtils.BindBtn(mBtnHuman, OnClickHuman);
|
|
|
|
|
|
UIUtils.BindBtn(mBtnMonster, OnClickMonster);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnOpen()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnOpen();
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#if USE_IAP
|
2022-05-23 13:39:59 +00:00
|
|
|
|
IAPTool.Instance.OnPurchaseDone += OnPurchaseResult;
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#endif
|
2022-05-23 13:39:59 +00:00
|
|
|
|
|
|
|
|
|
|
mLdpLevel.Init(PlayerData.Instance.CurrentLevel);
|
2022-06-08 13:23:44 +00:00
|
|
|
|
RefreshAutoMerge();
|
2022-05-23 13:39:59 +00:00
|
|
|
|
RefreshButtons();
|
2022-06-08 13:23:44 +00:00
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
mBtnHuman.gameObject.SetActive(PlayerData.Instance.CheckGuide(0));
|
|
|
|
|
|
mBtnMonster.gameObject.SetActive(PlayerData.Instance.CheckGuide(1));
|
|
|
|
|
|
|
|
|
|
|
|
mGobRedPoint.SetActive(!sHasMoreGameClicked);
|
|
|
|
|
|
#if UNITY_IOS
|
|
|
|
|
|
mBtnMoreGames.gameObject.SetActive(true);
|
|
|
|
|
|
#else
|
|
|
|
|
|
mBtnMoreGames.gameObject.SetActive(false);
|
|
|
|
|
|
#endif
|
2022-06-08 13:23:44 +00:00
|
|
|
|
|
|
|
|
|
|
#if USE_IAP
|
2022-05-23 13:39:59 +00:00
|
|
|
|
mBtnNoAds.gameObject.SetActive(!PlayerData.Instance.IsNoAds);
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#else
|
|
|
|
|
|
mBtnNoAds.gameObject.SetActive(false);
|
|
|
|
|
|
#endif
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnFocus(bool pFocus)
|
|
|
|
|
|
{
|
|
|
|
|
|
DelFocus?.Invoke(pFocus);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnClose()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnClose();
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#if USE_IAP
|
2022-05-23 13:39:59 +00:00
|
|
|
|
IAPTool.Instance.OnPurchaseDone -= OnPurchaseResult;
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#endif
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#if USE_IAP
|
2022-05-23 13:39:59 +00:00
|
|
|
|
IAPTool.Instance.OnPurchaseDone -= OnPurchaseResult;
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RefreshAutoMerge()
|
|
|
|
|
|
{
|
|
|
|
|
|
mBtnAdAuto.gameObject.SetActive(PlayerData.Instance.IsAutoMergeEnabled);
|
|
|
|
|
|
mTxtAutoCount.text = UIUtils.NumForShort(PlayerData.Instance.AutoMergeCount);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RefreshButtons()
|
|
|
|
|
|
{
|
|
|
|
|
|
mHumanPrice = PlayerData.Instance.HumanPrice;
|
|
|
|
|
|
mTxtHumanPrice.text = UIUtils.NumForShort(mHumanPrice);
|
|
|
|
|
|
mHumanAfford = PlayerData.Instance.Coin >= mHumanPrice;
|
|
|
|
|
|
mGobHumanNormal.SetActive(mHumanAfford);
|
|
|
|
|
|
mGobHumanAd.SetActive(!mHumanAfford);
|
|
|
|
|
|
if (!mHumanAfford)
|
|
|
|
|
|
{
|
|
|
|
|
|
TKGSDKManager.Instance.LogRewardAdBtnShow(Const.AdsValue.GetHuman);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mMonsterPrice = PlayerData.Instance.MonsterPrice;
|
|
|
|
|
|
mTxtMonsterPrice.text = UIUtils.NumForShort(mMonsterPrice);
|
|
|
|
|
|
mMonsterAfford = PlayerData.Instance.Coin >= mMonsterPrice;
|
|
|
|
|
|
mGobMonsterNormal.SetActive(mMonsterAfford);
|
|
|
|
|
|
mGobMonsterAd.SetActive(!mMonsterAfford);
|
|
|
|
|
|
if (!mMonsterAfford)
|
|
|
|
|
|
{
|
|
|
|
|
|
TKGSDKManager.Instance.LogRewardAdBtnShow(Const.AdsValue.GetMonster);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
public void ShowBottom(bool pHide)
|
|
|
|
|
|
{
|
|
|
|
|
|
mRctBottom.DOAnchorPosY(pHide ? 0 : -700, 0.2f).SetEase(Ease.Linear);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void EnableRecruitBtns(bool pEnabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
mBtnHuman.enabled = pEnabled;
|
|
|
|
|
|
mBtnMonster.enabled = pEnabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
private void OnPurchaseResult(string pID, bool pResult)
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#if USE_IAP
|
2022-05-23 13:39:59 +00:00
|
|
|
|
if (pID.Equals(IAPProducts.NoAds) && pResult)
|
|
|
|
|
|
{
|
|
|
|
|
|
mBtnNoAds.gameObject.SetActive(false);
|
|
|
|
|
|
TKGSDKManager.Instance.LogEvent(Const.AdsEvent.NoAdsSuccess, Const.AdsKey.IAP, Const.AdsValue.IAPButton);
|
|
|
|
|
|
}
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#endif
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnClickSettings()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.OpenUI<PanelSettings>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnClickBook()
|
|
|
|
|
|
{
|
|
|
|
|
|
UIManager.Instance.OpenUI<PanelBook>();
|
|
|
|
|
|
TKGSDKManager.Instance.LogEvent(Const.AdsEvent.ClickBook);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnClickNoAds()
|
|
|
|
|
|
{
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#if USE_IAP
|
2022-05-23 13:39:59 +00:00
|
|
|
|
UIManager.Instance.OpenUI<PanelLoading>();
|
|
|
|
|
|
IAPTool.Instance.BuyProductByID(IAPProducts.NoAds);
|
|
|
|
|
|
TKGSDKManager.Instance.LogEvent(Const.AdsEvent.NoAdsClick, Const.AdsKey.IAP, Const.AdsValue.IAPButton);
|
2022-06-08 13:23:44 +00:00
|
|
|
|
#endif
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnClickMoreGame()
|
|
|
|
|
|
{
|
|
|
|
|
|
sHasMoreGameClicked = true;
|
|
|
|
|
|
mGobRedPoint.SetActive(!sHasMoreGameClicked);
|
|
|
|
|
|
TKGSDKManager.Instance.OpenMoreGame();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnClickBuff()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-08 13:23:44 +00:00
|
|
|
|
private void OnClickAdAuto()
|
|
|
|
|
|
{
|
2022-08-30 02:21:29 +00:00
|
|
|
|
AdsUtils.PlayReward(TKGRVPositionName.Get_AutoMerge, GetAutoMerge);
|
2022-06-08 13:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void GetAutoMerge()
|
|
|
|
|
|
{
|
2022-08-30 02:21:29 +00:00
|
|
|
|
PlayerData.Instance.AutoMergeCount += TKGSDKManager.Instance.GetConfigInt(TKGParamKey.AutoMergeAddCount);
|
2022-06-08 13:23:44 +00:00
|
|
|
|
RefreshAutoMerge();
|
|
|
|
|
|
|
|
|
|
|
|
DelAutoMergeAdd?.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-23 13:39:59 +00:00
|
|
|
|
private void OnClickStart()
|
|
|
|
|
|
{
|
|
|
|
|
|
DelStart?.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnClickHuman()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (PlayerData.Instance.IsArmyFull)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIUtils.ShowTips(LanguageConfig.Instance.GetText("ArmyFull"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mHumanAfford)
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayerData.Instance.Coin -= mHumanPrice;
|
|
|
|
|
|
PlayerData.Instance.BuyHuman();
|
|
|
|
|
|
if (Mathf.Abs(mHumanPrice) > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIUtils.DropCoin(mHumanPrice);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GetHuman();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-08-30 02:21:29 +00:00
|
|
|
|
AdsUtils.PlayReward(TKGRVPositionName.Get_Human, GetHuman);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void GetHuman()
|
|
|
|
|
|
{
|
|
|
|
|
|
DelHuman?.Invoke();
|
|
|
|
|
|
|
|
|
|
|
|
RefreshButtons();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnClickMonster()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (PlayerData.Instance.IsArmyFull)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIUtils.ShowTips(LanguageConfig.Instance.GetText("ArmyFull"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (mMonsterAfford)
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayerData.Instance.Coin -= mMonsterPrice;
|
|
|
|
|
|
PlayerData.Instance.BuyMonster();
|
|
|
|
|
|
if (Mathf.Abs(mMonsterPrice) > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
UIUtils.DropCoin(mMonsterPrice);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GetMonster();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-08-30 02:21:29 +00:00
|
|
|
|
AdsUtils.PlayReward(TKGRVPositionName.Get_Monster, GetMonster);
|
2022-05-23 13:39:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void GetMonster()
|
|
|
|
|
|
{
|
|
|
|
|
|
DelMonster?.Invoke();
|
|
|
|
|
|
|
|
|
|
|
|
RefreshButtons();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|