184 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			184 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| using UnityEngine.UI;
 | |
| using DG.Tweening;
 | |
| 
 | |
| namespace MMO
 | |
| {
 | |
|     public class MMOTaskList : MMOListView<MMOTaskCell>
 | |
|     {
 | |
|         private Action<string, Action<bool>> mDelWatchRV;
 | |
| 
 | |
|         [SerializeField] MMODailyTask mDailyTask;
 | |
|         [SerializeField] GameObject mGobInviteTask;
 | |
|         [SerializeField] GameObject mGobInviteProgress;
 | |
|         [SerializeField] GameObject mGobEmptyTip;
 | |
|         [SerializeField] Scrollbar mScbProgress;
 | |
|         [SerializeField] Text mTxtProgress;
 | |
| 
 | |
|         public override int Count => mList == null? 0 : mList.Count;
 | |
| 
 | |
|         private List<MMOTaskRecord> mList;
 | |
| 
 | |
|         public void Init(Action<string, Action<bool>> pDelWatchRV)
 | |
|         {
 | |
|             mDelWatchRV = pDelWatchRV;
 | |
| 
 | |
|             bool tShowInvite = MMOInnerSDKManager.Instance.GetConfigBool(MMOConstConfig.Instance.InvitableParam);
 | |
| 
 | |
|             mGobInviteTask.SetActive(tShowInvite);
 | |
|             mGobInviteProgress.SetActive(tShowInvite);
 | |
| 
 | |
|             if (tShowInvite)
 | |
|             {
 | |
|                 RefreshProgress();
 | |
| 
 | |
|                 MMORespondLogin tLoginData = MMOAPIRequestManager.Instance.GetData<MMORespondLogin>();
 | |
|                 if (tLoginData != null && !string.IsNullOrEmpty(tLoginData.MyInviteCode))
 | |
|                 {
 | |
|                     MMOAPIRequestManager.Instance.SendRequest<MMORequestInviteProgress, MMORespondInviteProgress>(new MMORequestInviteProgress(tLoginData.MyInviteCode), (pRespond) =>
 | |
|                     {
 | |
|                         MMOAPIRequestManager.Instance.SetData(pRespond);
 | |
| 
 | |
|                         RefreshProgress();
 | |
|                     });
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         public void OpenDaily()
 | |
|         {
 | |
|             mDailyTask.OpenDaily();
 | |
|         }
 | |
| 
 | |
|         protected override void BeforeLoad()
 | |
|         {
 | |
|             base.BeforeLoad();
 | |
| 
 | |
|             mList = MMOUserData.Instance.TaskRecordList.FindAll(pItem => pItem.TaskType > 0);
 | |
|         }
 | |
| 
 | |
|         protected override void ConfigCell(MMOTaskCell pCell)
 | |
|         {
 | |
|             pCell.DelRedeem = Redeem;
 | |
|             pCell.DelWatchRV = WatchRV;
 | |
|             pCell.ConfigTask(mList[pCell.Index]);
 | |
|         }
 | |
| 
 | |
|         private void RefreshProgress()
 | |
|         {
 | |
|             MMORespondInviteProgress tProgressData = MMOAPIRequestManager.Instance.GetData<MMORespondInviteProgress>();
 | |
|             bool tHasProgress = false;
 | |
|             int tTotalCount = 0;
 | |
|             if (tProgressData != null && tProgressData.UserList != null && tProgressData.UserList.Length > 0)
 | |
|             {
 | |
|                 tHasProgress = true;
 | |
|                 string tProgressStr = "";
 | |
|                 string tUserMask = "";
 | |
|                 tTotalCount = tProgressData.UserList.Length;
 | |
|                 for (int i = 0; i < tTotalCount; i++)
 | |
|                 {
 | |
|                     tUserMask = MMOUtils.GetMaskedID(tProgressData.UserList[i].PlayerID);
 | |
| 
 | |
|                     if (tProgressData.UserList[i].Level == 0)
 | |
|                     {
 | |
|                         tProgressStr += string.Format("User {0} has accepted the invitation", tUserMask);
 | |
|                     }
 | |
|                     else
 | |
|                     {
 | |
|                         tProgressStr += string.Format("User {0} has cleared {1} levels", tUserMask, tProgressData.UserList[i].Level);
 | |
|                     }
 | |
|                     
 | |
|                     if (i < tTotalCount - 1)
 | |
|                     {
 | |
|                         tProgressStr += "\n";
 | |
|                     }
 | |
|                 }
 | |
|                 mTxtProgress.text = tProgressStr;
 | |
|                 mTxtProgress.rectTransform.sizeDelta = new Vector2(mTxtProgress.rectTransform.sizeDelta.x, 41 * tTotalCount);
 | |
|             }
 | |
| 
 | |
|             mGobEmptyTip.SetActive(!tHasProgress);
 | |
| 
 | |
|             if (tTotalCount > 6)
 | |
|             {
 | |
|                 mScbProgress.value = 1f;
 | |
|                 Sequence tScrollSq = DOTween.Sequence();
 | |
|                 tScrollSq.Append(DOTween.To(() => mScbProgress.value, (pVal) => mScbProgress.value = pVal, 0, (tTotalCount - 6) * 1.5f).SetLoops(-1, LoopType.Restart).SetEase(Ease.Linear));
 | |
|                 tScrollSq.AppendInterval(3);
 | |
|                 tScrollSq.Play().SetLoops(-1, LoopType.Restart);
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 mScbProgress.value = 1f;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void Redeem(int pIndex)
 | |
|         {
 | |
|             MMOTaskRecord tRecord = mList[pIndex];
 | |
| 
 | |
|             if (tRecord.IsFinished)
 | |
|             {
 | |
|                 MMODataTask tTask = MMOTableTask.Instance.GetData(tRecord.TaskID);
 | |
| 
 | |
|                 if (!string.IsNullOrEmpty(tTask.ActionValue))
 | |
|                 {
 | |
|                     MMOInnerSDKManager.Instance.LogRobuxAction(tTask.ActionValue);
 | |
|                 }
 | |
| 
 | |
|                 if (tRecord.TaskType == MMOTaskType.GetDiamond)
 | |
|                 {
 | |
|                     MMOUserData.Instance.Diamond -= tRecord.TargetNum;
 | |
|                 }
 | |
| 
 | |
|                 MMOUserData.Instance.FinishTask(tTask.TaskType);
 | |
| 
 | |
|                 MMODataTask tNextTask = MMOTableTask.Instance.GetData(tTask.NextTaskID);
 | |
|                 if (tNextTask != null)
 | |
|                 {
 | |
|                     MMOUserData.Instance.ModifyTaskRecord(tRecord.RecordID, tTask.NextTaskID);
 | |
| 
 | |
|                     if (tTask.GroupID == -1 || tTask.GroupID != tNextTask.GroupID)
 | |
|                     {
 | |
|                         if (tNextTask.TaskType == MMOTaskType.Final)
 | |
|                         {
 | |
|                             MMOModule.Instance.UIMgr.OpenUI<MMOUIRedeemDone>();
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             MMOUINewTask tUINewTask = MMOModule.Instance.UIMgr.OpenUI<MMOUINewTask>();
 | |
|                             string tContent = tNextTask.TaskDesc;
 | |
|                             if (tNextTask.TaskType == MMOTaskType.RiseRank)
 | |
|                             {
 | |
|                                 tContent = string.Format(tNextTask.TaskDesc, tNextTask.TargetNum - MMOUserData.Instance.GetTaskValue(tRecord.RecordKey));
 | |
|                             }
 | |
|                             tUINewTask.ConfigInfo(tContent, tNextTask.TaskType);
 | |
|                         }
 | |
|                     }
 | |
| 
 | |
|                     if (tNextTask.TaskType == MMOTaskType.Final && !string.IsNullOrEmpty(tNextTask.ActionValue))
 | |
|                     {
 | |
|                         MMOInnerSDKManager.Instance.LogRobuxAction(tNextTask.ActionValue);
 | |
|                     }
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     MMOUserData.Instance.RemoveTaskRecord(tRecord.RecordID);
 | |
|                 }
 | |
| 
 | |
|                 LoadData();
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 MMOModule.Instance.ShowTip("Condition not completed");
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void WatchRV()
 | |
|         {
 | |
|             mDelWatchRV?.Invoke(MMOEventValue.RvGetTask ,null);
 | |
|         }
 | |
|     }
 | |
| } |