315 lines
		
	
	
		
			8.3 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			315 lines
		
	
	
		
			8.3 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | |
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| using UnityEngine.UI;
 | |
| using DG.Tweening;
 | |
| 
 | |
| public class PanelMain : BasePanel
 | |
| {
 | |
|     public Action DelStart;
 | |
|     public Action DelHuman;
 | |
|     public Action DelMonster;
 | |
|     public Action DelAutoMergeAdd;
 | |
|     public Action<bool> DelFocus;
 | |
| 
 | |
|     [SerializeField] LevelDisplay mLdpLevel;
 | |
| 
 | |
|     [SerializeField] GameObject mGobRedPoint;
 | |
| 
 | |
|     [SerializeField] Button mBtnSettings;
 | |
|     [SerializeField] Button mBtnBook;
 | |
|     [SerializeField] Button mBtnNoAds;
 | |
|     [SerializeField] Button mBtnMoreGames;
 | |
|     [SerializeField] Button mBtnVip;
 | |
|     [SerializeField] Button mBtnShop;
 | |
|     [SerializeField] Button mBtnMMO;
 | |
|     [SerializeField] Button mBtnBuff;
 | |
|     [SerializeField] Button mBtnAdAuto;
 | |
| 
 | |
|     [SerializeField] Text mTxtAutoCount;
 | |
| 
 | |
|     [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;
 | |
| 
 | |
|     [SerializeField] RectTransform mRctBottom;
 | |
| 
 | |
|     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(mBtnVip, OnClickVip);
 | |
|         UIUtils.BindBtn(mBtnShop, OnClickShop);
 | |
|         UIUtils.BindBtn(mBtnMMO, OnClickMMO);
 | |
|         UIUtils.BindBtn(mBtnBuff, OnClickBuff);
 | |
|         UIUtils.BindBtn(mBtnAdAuto, OnClickAdAuto);
 | |
|         UIUtils.BindBtn(mBtnStart, OnClickStart);
 | |
|         UIUtils.BindBtn(mBtnHuman, OnClickHuman);
 | |
|         UIUtils.BindBtn(mBtnMonster, OnClickMonster);
 | |
|     }
 | |
| 
 | |
|     public override void OnOpen()
 | |
|     {
 | |
|         base.OnOpen();
 | |
| 
 | |
| #if USE_IAP
 | |
|         IAPTool.Instance.OnPurchaseDone += OnPurchaseResult;
 | |
| #endif
 | |
|         MMOModule.Instance.OnExit += OnMMOExit;
 | |
| 
 | |
|         mLdpLevel.Init(PlayerData.Instance.CurrentLevel);
 | |
|         RefreshAutoMerge();
 | |
|         RefreshButtons();
 | |
| 
 | |
|         mBtnHuman.gameObject.SetActive(true);
 | |
|         mBtnMonster.gameObject.SetActive(PlayerData.Instance.CheckGuide(0));
 | |
|         mBtnMMO.gameObject.SetActive(PlayerData.Instance.IsMMOUser);
 | |
| 
 | |
|         //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
 | |
| 
 | |
|         if (TKGSDKManager.Instance.IsIAPEnabled)
 | |
|         {
 | |
|             mBtnVip.gameObject.SetActive(false);
 | |
|             mBtnNoAds.gameObject.SetActive(!PlayerData.Instance.IsNoAds);
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|             mBtnVip.gameObject.SetActive(false);
 | |
|             mBtnNoAds.gameObject.SetActive(false);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public override void OnFocus(bool pFocus)
 | |
|     {
 | |
|         DelFocus?.Invoke(pFocus);
 | |
|     }
 | |
| 
 | |
|     public override void OnClose()
 | |
|     {
 | |
|         base.OnClose();
 | |
| 
 | |
| #if USE_IAP
 | |
|         IAPTool.Instance.OnPurchaseDone -= OnPurchaseResult;
 | |
| #endif
 | |
|         MMOModule.Instance.OnExit -= OnMMOExit;
 | |
|     }
 | |
| 
 | |
|     private void OnDestroy()
 | |
|     {
 | |
| #if USE_IAP
 | |
|         IAPTool.Instance.OnPurchaseDone -= OnPurchaseResult;
 | |
| #endif
 | |
|     }
 | |
| 
 | |
|     public void RefreshAutoMerge()
 | |
|     {
 | |
|         mBtnAdAuto.gameObject.SetActive(PlayerData.Instance.IsAutoMergeEnabled);
 | |
|         mTxtAutoCount.text = UIUtils.NumForShort(PlayerData.Instance.AutoMergeCount);
 | |
|     }
 | |
| 
 | |
|     public void RefreshButtons()
 | |
|     {
 | |
|         mHumanPrice = PlayerData.Instance.HumanPrice;
 | |
|         mTxtHumanPrice.text = mHumanPrice == 0 ? LanguageConfig.Instance.GetText("Free") : 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 = mMonsterPrice == 0 ? LanguageConfig.Instance.GetText("Free") : UIUtils.NumForShort(mMonsterPrice);
 | |
|         mMonsterAfford = PlayerData.Instance.Coin >= mMonsterPrice;
 | |
|         mGobMonsterNormal.SetActive(mMonsterAfford);
 | |
|         mGobMonsterAd.SetActive(!mMonsterAfford);
 | |
|         if (!mMonsterAfford)
 | |
|         {
 | |
|             TKGSDKManager.Instance.LogRewardAdBtnShow(Const.AdsValue.GetMonster);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     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;
 | |
|     }
 | |
| 
 | |
|     private void OnPurchaseResult(string pID, bool pResult)
 | |
|     {
 | |
| #if USE_IAP
 | |
|         if (pID.Equals(IAPProducts.NoAds) && pResult)
 | |
|         {
 | |
|             mBtnNoAds.gameObject.SetActive(false);
 | |
|             TKGSDKManager.Instance.LogEvent(Const.AdsEvent.NoAdsSuccess, Const.AdsKey.IAP, Const.AdsValue.IAPButton);
 | |
|         }
 | |
| #endif
 | |
|     }
 | |
| 
 | |
|     private void OnClickSettings()
 | |
|     {
 | |
|         UIManager.Instance.OpenUI<PanelSettings>();
 | |
|     }
 | |
| 
 | |
|     private void OnClickBook()
 | |
|     {
 | |
|         UIManager.Instance.OpenUI<PanelBook>();
 | |
|         TKGSDKManager.Instance.LogEvent(Const.AdsEvent.ClickBook);
 | |
|     }
 | |
| 
 | |
|     private void OnClickNoAds()
 | |
|     {
 | |
| #if USE_IAP
 | |
|         IAPTool.Instance.BuyProductByID(IAPProducts.NoAds);
 | |
|         TKGSDKManager.Instance.LogEvent(Const.AdsEvent.NoAdsClick, Const.AdsKey.IAP, Const.AdsValue.IAPButton);
 | |
| #endif
 | |
|     }
 | |
| 
 | |
|     private void OnClickMoreGame()
 | |
|     {
 | |
|         sHasMoreGameClicked = true;
 | |
|         mGobRedPoint.SetActive(!sHasMoreGameClicked);
 | |
|         TKGSDKManager.Instance.OpenMoreGame();
 | |
|     }
 | |
| 
 | |
|     private void OnClickVip()
 | |
|     {
 | |
|         UIManager.Instance.OpenUI<PanelVip>();
 | |
|     }
 | |
| 
 | |
|     private void OnClickShop()
 | |
|     {
 | |
|         UIManager.Instance.OpenUI<PanelShop>();
 | |
|     }
 | |
| 
 | |
|     private void OnClickBuff()
 | |
|     {
 | |
| 
 | |
|     }
 | |
| 
 | |
|     private void OnClickAdAuto()
 | |
|     {
 | |
|         AdsUtils.PlayReward(Const.AdsValue.GetAutoMerge, GetAutoMerge);
 | |
|     }
 | |
| 
 | |
|     private void GetAutoMerge()
 | |
|     {
 | |
|         PlayerData.Instance.AutoMergeCount += TKGSDKManager.Instance.GetConfigInt(TKGParamKey.AutoMergeAddCount.ToString());
 | |
|         RefreshAutoMerge();
 | |
| 
 | |
|         DelAutoMergeAdd?.Invoke();
 | |
|     }
 | |
| 
 | |
|     private void OnClickMMO()
 | |
|     {
 | |
|         OnFocus(false);
 | |
|         MMOModule.Instance.Enter(PlayerData.Instance.Diamond, PlayerData.Instance.CurrentLevel);
 | |
|     }
 | |
| 
 | |
|     private void OnMMOExit()
 | |
|     {
 | |
|         OnFocus(true);
 | |
|     }
 | |
| 
 | |
|     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
 | |
|         {
 | |
|             AdsUtils.PlayReward(Const.AdsValue.GetHuman, GetHuman);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     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
 | |
|         {
 | |
|             AdsUtils.PlayReward(Const.AdsValue.GetMonster, GetMonster);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void GetMonster()
 | |
|     {
 | |
|         DelMonster?.Invoke();
 | |
| 
 | |
|         RefreshButtons();
 | |
|     }
 | |
| } |