104 lines
3.2 KiB
C#
104 lines
3.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
|
|
namespace MMO
|
|
{
|
|
public class MMOTaskCell : MonoBehaviour
|
|
{
|
|
public Action<int> DelRedeem;
|
|
public Action DelWatchAd;
|
|
|
|
[SerializeField] Text mTxtReward;
|
|
[SerializeField] Text mTxtTaskDesc;
|
|
[SerializeField] Image mImgTaskIcon;
|
|
[SerializeField] Text mTxtProgress;
|
|
[SerializeField] Image mImgProgress;
|
|
|
|
[SerializeField] Text mTxtTaskFinal;
|
|
|
|
[SerializeField] GameObject mGobNormal;
|
|
[SerializeField] GameObject mGobFinal;
|
|
|
|
[SerializeField] Button mBtnWatchAd;
|
|
[SerializeField] Button mBtnRedeem;
|
|
|
|
private int mIndex;
|
|
private MMODataTask mData;
|
|
|
|
private bool mIsAdTask => mData.TaskType == MMOTaskType.WatchAds || mData.TaskType == MMOTaskType.DailyAds || mData.TaskType == MMOTaskType.RiseRank;
|
|
|
|
private void Awake()
|
|
{
|
|
mBtnRedeem.onClick.AddListener(OnClickRedeem);
|
|
mBtnWatchAd.onClick.AddListener(OnClickWatchAd);
|
|
}
|
|
|
|
public void ConfigTask(int pIndex, MMOTaskRecord pRecord)
|
|
{
|
|
mIndex = pIndex;
|
|
|
|
mData = MMOTableTask.Instance.GetData(pRecord.TaskID);
|
|
|
|
mTxtReward.text = pRecord.RewardNum.ToString();
|
|
|
|
mBtnRedeem.transform.DOKill();
|
|
mBtnRedeem.transform.localScale = Vector3.one;
|
|
|
|
if (pRecord.TaskType != MMOTaskType.Final)
|
|
{
|
|
mGobNormal.SetActive(true);
|
|
mGobFinal.SetActive(false);
|
|
|
|
int tCurrentValue = MMOUserData.Instance.GetTaskValue(pRecord.RecordKey);
|
|
mTxtTaskDesc.text = mData.TaskName;
|
|
mImgTaskIcon.sprite = MMOUtils.LoadTaskIcon(pRecord.TaskType);
|
|
mImgTaskIcon.SetNativeSize();
|
|
|
|
if (pRecord.TaskType == MMOTaskType.RiseRank)
|
|
{
|
|
mTxtProgress.text = string.Format("{0:f1}%", Mathf.Min(((float)tCurrentValue / mData.TargetNum) * 100, 100));
|
|
}
|
|
else
|
|
{
|
|
mTxtProgress.text = string.Format("{0}/{1}", tCurrentValue, mData.TargetNum);
|
|
}
|
|
|
|
mImgProgress.fillAmount = (float)tCurrentValue / mData.TargetNum;
|
|
|
|
if (pRecord.IsFinished)
|
|
{
|
|
mBtnRedeem.gameObject.SetActive(true);
|
|
mBtnWatchAd.gameObject.SetActive(false);
|
|
|
|
mBtnRedeem.transform.DOScale(1.1f, 0.3f).SetLoops(-1, LoopType.Yoyo).SetEase(Ease.Linear);
|
|
}
|
|
else
|
|
{
|
|
mBtnRedeem.gameObject.SetActive(!mIsAdTask);
|
|
mBtnWatchAd.gameObject.SetActive(mIsAdTask);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
mGobNormal.SetActive(false);
|
|
mGobFinal.SetActive(true);
|
|
|
|
mTxtTaskFinal.text = mData.TaskDesc;
|
|
}
|
|
}
|
|
|
|
private void OnClickRedeem()
|
|
{
|
|
DelRedeem?.Invoke(mIndex);
|
|
}
|
|
|
|
private void OnClickWatchAd()
|
|
{
|
|
DelWatchAd?.Invoke();
|
|
}
|
|
}
|
|
} |