67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Events;
|
|
|
|
public class taskPrefabController : MonoBehaviour
|
|
{
|
|
[Header("basic infos")]
|
|
public TextMeshProUGUI taskNumber;
|
|
public Text taskText;
|
|
public Image taskProgress_fillAmount_img;
|
|
|
|
[Header("the rewards")]
|
|
public Button rewardButton;
|
|
public Image rewardImg;
|
|
public Text rewardAmmount;
|
|
|
|
public void Setup(DailyTaskViewData taskView, int displayIndex, Sprite rewardSprite, UnityAction onRewardClicked)
|
|
{
|
|
if (taskView == null || taskView.definition == null || taskView.runtimeEntry == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (taskNumber != null)
|
|
{
|
|
taskNumber.text = displayIndex.ToString("00");
|
|
}
|
|
|
|
if (taskText != null)
|
|
{
|
|
taskText.text = taskView.definition.description;
|
|
}
|
|
|
|
if (taskProgress_fillAmount_img != null)
|
|
{
|
|
float targetValue = Mathf.Max(0.0001f, taskView.definition.targetValue);
|
|
float clampedProgress = Mathf.Clamp(taskView.runtimeEntry.progress, 0f, targetValue);
|
|
taskProgress_fillAmount_img.fillAmount = clampedProgress / targetValue;
|
|
}
|
|
|
|
if (rewardImg != null)
|
|
{
|
|
rewardImg.sprite = rewardSprite;
|
|
rewardImg.enabled = rewardSprite != null;
|
|
}
|
|
|
|
if (rewardAmmount != null)
|
|
{
|
|
rewardAmmount.text = taskView.definition.rewardAmount.ToString();
|
|
}
|
|
|
|
if (rewardButton == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
rewardButton.onClick.RemoveAllListeners();
|
|
if (onRewardClicked != null)
|
|
{
|
|
rewardButton.onClick.AddListener(onRewardClicked);
|
|
}
|
|
|
|
rewardButton.interactable = taskView.runtimeEntry.isCompleted && !taskView.runtimeEntry.isClaimed;
|
|
}
|
|
}
|