224 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			224 lines
		
	
	
		
			5.8 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Collections; | |||
|  | using System.Collections.Generic; | |||
|  | using UnityEngine; | |||
|  | using UnityEngine.UI; | |||
|  | 
 | |||
|  | public class PanelMain : BasePanel | |||
|  | { | |||
|  |     public Action DelStart; | |||
|  |     public Action DelHuman; | |||
|  |     public Action DelMonster; | |||
|  |     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; | |||
|  | 
 | |||
|  |     [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; | |||
|  | 
 | |||
|  |     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); | |||
|  |         UIUtils.BindBtn(mBtnStart, OnClickStart); | |||
|  |         UIUtils.BindBtn(mBtnHuman, OnClickHuman); | |||
|  |         UIUtils.BindBtn(mBtnMonster, OnClickMonster); | |||
|  |     } | |||
|  | 
 | |||
|  |     public override void OnOpen() | |||
|  |     { | |||
|  |         base.OnOpen(); | |||
|  | 
 | |||
|  |         IAPTool.Instance.OnPurchaseDone += OnPurchaseResult; | |||
|  | 
 | |||
|  |         mLdpLevel.Init(PlayerData.Instance.CurrentLevel); | |||
|  |         RefreshButtons(); | |||
|  | 
 | |||
|  |         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 | |||
|  |         mBtnNoAds.gameObject.SetActive(!PlayerData.Instance.IsNoAds); | |||
|  |     } | |||
|  | 
 | |||
|  |     public override void OnFocus(bool pFocus) | |||
|  |     { | |||
|  |         DelFocus?.Invoke(pFocus); | |||
|  |     } | |||
|  | 
 | |||
|  |     public override void OnClose() | |||
|  |     { | |||
|  |         base.OnClose(); | |||
|  | 
 | |||
|  |         IAPTool.Instance.OnPurchaseDone -= OnPurchaseResult; | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnDestroy() | |||
|  |     { | |||
|  |         IAPTool.Instance.OnPurchaseDone -= OnPurchaseResult; | |||
|  |     } | |||
|  | 
 | |||
|  |     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); | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnPurchaseResult(string pID, bool pResult) | |||
|  |     { | |||
|  |         if (pID.Equals(IAPProducts.NoAds) && pResult) | |||
|  |         { | |||
|  |             mBtnNoAds.gameObject.SetActive(false); | |||
|  |             TKGSDKManager.Instance.LogEvent(Const.AdsEvent.NoAdsSuccess, Const.AdsKey.IAP, Const.AdsValue.IAPButton); | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnClickSettings() | |||
|  |     { | |||
|  |         UIManager.Instance.OpenUI<PanelSettings>(); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnClickBook() | |||
|  |     { | |||
|  |         UIManager.Instance.OpenUI<PanelBook>(); | |||
|  |         TKGSDKManager.Instance.LogEvent(Const.AdsEvent.ClickBook); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnClickNoAds() | |||
|  |     { | |||
|  |         UIManager.Instance.OpenUI<PanelLoading>(); | |||
|  |         IAPTool.Instance.BuyProductByID(IAPProducts.NoAds); | |||
|  |         TKGSDKManager.Instance.LogEvent(Const.AdsEvent.NoAdsClick, Const.AdsKey.IAP, Const.AdsValue.IAPButton); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnClickMoreGame() | |||
|  |     { | |||
|  |         sHasMoreGameClicked = true; | |||
|  |         mGobRedPoint.SetActive(!sHasMoreGameClicked); | |||
|  |         TKGSDKManager.Instance.OpenMoreGame(); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnClickBuff() | |||
|  |     { | |||
|  | 
 | |||
|  |     } | |||
|  | 
 | |||
|  |     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(); | |||
|  |     } | |||
|  | } |