143 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			143 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| using UnityEngine.UI;
 | |
| using DG.Tweening;
 | |
| 
 | |
| namespace MMO
 | |
| {
 | |
|     public class MMOInviteTask : MonoBehaviour
 | |
|     {
 | |
|         [SerializeField] Text mTxtReward;
 | |
|         [SerializeField] Image mImgProgress;
 | |
|         [SerializeField] Text mTxtProgress;
 | |
| 
 | |
|         [SerializeField] Text mTxtDesc1;
 | |
|         [SerializeField] Text mTxtDesc2;
 | |
| 
 | |
|         [SerializeField] GameObject mGobInvite;
 | |
|         [SerializeField] GameObject mGobRedeem;
 | |
|         [SerializeField] GameObject mGobDone;
 | |
| 
 | |
|         [SerializeField] Button mBtnProgress;
 | |
|         [SerializeField] Button mBtnProgress2;
 | |
|         [SerializeField] Button mBtnHelp;
 | |
|         [SerializeField] Button mBtnShare;
 | |
|         [SerializeField] Button mBtnRedeem;
 | |
| 
 | |
|         private const int INVITE_TASKID = -2;
 | |
|         private int mFinishedCount = 0;
 | |
| 
 | |
|         private MMODataTask mData;
 | |
|         private MMOTaskRecord mTaskRecord;
 | |
| 
 | |
|         private int mInviteCount = 0;
 | |
|         private int mInviteLevel = 0;
 | |
| 
 | |
|         private void Awake()
 | |
|         {
 | |
|             mBtnProgress.onClick.AddListener(OnClickProgress);
 | |
|             mBtnProgress2.onClick.AddListener(OnClickProgress);
 | |
|             mBtnHelp.onClick.AddListener(OnClickHelp);
 | |
|             mBtnShare.onClick.AddListener(OnClickShare);
 | |
|             mBtnRedeem.onClick.AddListener(OnClickRedeem);
 | |
|         }
 | |
| 
 | |
|         private void OnEnable()
 | |
|         {
 | |
|             mData = MMOTableTask.Instance.GetData(INVITE_TASKID);
 | |
| 
 | |
|             mInviteCount = MMOInnerSDKManager.Instance.GetConfigInt(MMOConstConfig.Instance.InviteCountParam);
 | |
|             mInviteLevel = MMOInnerSDKManager.Instance.GetConfigInt(MMOConstConfig.Instance.InviteLevelParam);
 | |
| 
 | |
|             mTxtDesc1.text = string.Format("Invite {0} users to get 400 Robux", mInviteCount);
 | |
|             mTxtDesc2.text = string.Format("*Invited users need to complete at least {0} levels", mInviteLevel);
 | |
| 
 | |
|             MMORespondInviteProgress tProgressData = MMOAPIRequestManager.Instance.GetData<MMORespondInviteProgress>();
 | |
| 
 | |
|             mFinishedCount = 0;
 | |
|             int tUserCount = 0;
 | |
|             if (tProgressData != null && tProgressData.UserList != null && tProgressData.UserList.Length > 0)
 | |
|             {
 | |
|                 tUserCount = tProgressData.UserList.Length;
 | |
|                 for (int i = 0; i < tProgressData.UserList.Length; i++)
 | |
|                 {
 | |
|                     if (tProgressData.UserList[i].Level >= mInviteLevel)
 | |
|                     {
 | |
|                         mFinishedCount++;
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             if (tUserCount > 0)
 | |
|             {
 | |
|                 MMOInnerSDKManager.Instance.LogInviteNum(MMOEventKey.AcceptNum, tUserCount);
 | |
|             }
 | |
| 
 | |
|             if (mFinishedCount > 0)
 | |
|             {
 | |
|                 MMOInnerSDKManager.Instance.LogInviteNum(MMOEventKey.SuccessNum, mFinishedCount);
 | |
|             }
 | |
| 
 | |
|             mTxtReward.text = mData.RewardNum.ToString();
 | |
| 
 | |
|             mImgProgress.fillAmount = mFinishedCount / (float)mInviteCount;
 | |
|             mTxtProgress.text = string.Format("{0}/{1}", mFinishedCount, mInviteCount);
 | |
|             mBtnProgress.enabled = tUserCount > 0;
 | |
|             mBtnProgress2.enabled = tUserCount > 0;
 | |
| 
 | |
|             RefreshRecord();
 | |
|         }
 | |
| 
 | |
|         private void RefreshRecord()
 | |
|         {
 | |
|             mTaskRecord = MMOUserData.Instance.TaskRecordList.Find(pItem => pItem.TaskID == INVITE_TASKID);
 | |
|             if (mTaskRecord != null)//has task
 | |
|             {
 | |
|                 MMOUserData.Instance.SetTaskValue(mTaskRecord.RecordKey, mFinishedCount);
 | |
|                 bool tIsTaskFinished = mTaskRecord.IsFinished;
 | |
| 
 | |
|                 mGobInvite.SetActive(!tIsTaskFinished);
 | |
|                 mGobRedeem.SetActive(tIsTaskFinished);
 | |
|                 mGobDone.SetActive(false);
 | |
| 
 | |
|                 if (mGobRedeem.activeSelf)
 | |
|                 {
 | |
|                     mBtnRedeem.transform.DOScale(1.2f, 0.3f).SetLoops(-1, LoopType.Yoyo).SetEase(Ease.Linear);
 | |
|                 }
 | |
|             }
 | |
|             else if (MMOUserData.Instance.HasFinishedTask(mData.TaskType))
 | |
|             {
 | |
|                 mGobInvite.SetActive(false);
 | |
|                 mGobRedeem.SetActive(false);
 | |
|                 mGobDone.SetActive(true);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void OnClickProgress()
 | |
|         {
 | |
|             MMOUIInviteProgress tUI = MMOModule.Instance.UIMgr.OpenUI<MMOUIInviteProgress>();
 | |
|             tUI.Init(mFinishedCount, mInviteCount);
 | |
|         }
 | |
| 
 | |
|         private void OnClickHelp()
 | |
|         {
 | |
|             MMOModule.Instance.UIMgr.OpenUI<MMOUIInviteHelp>();
 | |
|         }
 | |
| 
 | |
|         private void OnClickShare()
 | |
|         {
 | |
|             MMOModule.Instance.UIMgr.OpenUI<MMOUIInviteCode>();
 | |
|             MMOInnerSDKManager.Instance.LogInviteAction(MMOEventValue.Code_Copy);
 | |
|         }
 | |
| 
 | |
|         private void OnClickRedeem()
 | |
|         {
 | |
|             MMOModule.Instance.UIMgr.OpenUI<MMOUIRedeemDone>();
 | |
|             MMOUserData.Instance.FinishTask(mData.TaskType);
 | |
|             MMOUserData.Instance.RemoveTaskRecord(mTaskRecord.RecordID);
 | |
| 
 | |
|             RefreshRecord();
 | |
|         }
 | |
|     }
 | |
| } |