113 lines
3.0 KiB
C#
113 lines
3.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class QuestFisheryProgressItem : MonoBehaviour
|
|
{
|
|
public enum Tab
|
|
{
|
|
Daily = 0,
|
|
Weekly = 1,
|
|
Monthly = 2
|
|
}
|
|
|
|
public int index;
|
|
|
|
public Text QuestTitleText;
|
|
|
|
public Text QuestDescText;
|
|
|
|
public Text QuestPercentText;
|
|
|
|
public Image TickImage;
|
|
|
|
public float maxProgress;
|
|
|
|
public float currentProgress;
|
|
|
|
public bool ifcompletesound;
|
|
|
|
public Tab tab_category;
|
|
|
|
private string lastLanguage = "";
|
|
|
|
private GameManager.PlayerData.CQuest currentQuest = new GameManager.PlayerData.CQuest();
|
|
|
|
public static event Action<Transform> OnQuestCompleteOnMapGlobal;
|
|
|
|
private void Start()
|
|
{
|
|
switch (tab_category)
|
|
{
|
|
case Tab.Daily:
|
|
currentQuest = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest[index];
|
|
QuestTitleText.text = LanguageManager.Instance.GetText("DAILY_TASK");
|
|
break;
|
|
case Tab.Weekly:
|
|
currentQuest = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerWeeklyQuest[index];
|
|
QuestTitleText.text = LanguageManager.Instance.GetText("WEEKLY_TASK");
|
|
break;
|
|
case Tab.Monthly:
|
|
currentQuest = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerMonthlyQuest[index];
|
|
QuestTitleText.text = LanguageManager.Instance.GetText("MONTHLY_TASK");
|
|
break;
|
|
}
|
|
QuestDescText.text = GameManager.Instance.GetQuestDescription(currentQuest.gameQuest);
|
|
maxProgress = currentQuest.gameQuest.objectiveValue;
|
|
lastLanguage = LanguageManager.Instance.currentLanguage;
|
|
}
|
|
|
|
private void UpdateQuest()
|
|
{
|
|
switch (tab_category)
|
|
{
|
|
case Tab.Daily:
|
|
if (!Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest.Contains(currentQuest))
|
|
{
|
|
UnityEngine.Object.Destroy(base.gameObject);
|
|
return;
|
|
}
|
|
break;
|
|
case Tab.Weekly:
|
|
if (!Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerWeeklyQuest.Contains(currentQuest))
|
|
{
|
|
UnityEngine.Object.Destroy(base.gameObject);
|
|
return;
|
|
}
|
|
break;
|
|
case Tab.Monthly:
|
|
if (!Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerMonthlyQuest.Contains(currentQuest))
|
|
{
|
|
UnityEngine.Object.Destroy(base.gameObject);
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
if (lastLanguage != LanguageManager.Instance.currentLanguage)
|
|
{
|
|
QuestTitleText.text = GameManager.Instance.GetQuestDescription(currentQuest.gameQuest);
|
|
lastLanguage = LanguageManager.Instance.currentLanguage;
|
|
}
|
|
currentProgress = currentQuest.curentObjectiveProgress;
|
|
float value = currentProgress / maxProgress * 100f;
|
|
value = Mathf.Clamp(value, 0f, 100f);
|
|
QuestPercentText.text = value.ToString("F0") + "%";
|
|
_ = currentProgress / maxProgress;
|
|
if (currentProgress >= maxProgress)
|
|
{
|
|
TickImage.gameObject.SetActive(value: true);
|
|
if (!ifcompletesound)
|
|
{
|
|
QuestFisheryProgressItem.OnQuestCompleteOnMapGlobal?.Invoke(FScriptsHandler.Instance.transform);
|
|
GetComponentInParent<Animator>().SetTrigger("IsComplete");
|
|
ifcompletesound = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
UpdateQuest();
|
|
}
|
|
}
|