155 lines
5.2 KiB
C#
155 lines
5.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class QuestItem : MonoBehaviour
|
|
{
|
|
public Image progressBarImage;
|
|
|
|
public Text titleText;
|
|
|
|
public Text progressText;
|
|
|
|
public Text pointsText;
|
|
|
|
public Text inProgressText;
|
|
|
|
public Button[] buttonsAction;
|
|
|
|
public int uid;
|
|
|
|
public int indexOfPlayerQuest;
|
|
|
|
public float maxProgress;
|
|
|
|
public float currentProgress;
|
|
|
|
private QuestManager questManager;
|
|
|
|
public static event Action OnQuestCompleteGlobal;
|
|
|
|
private void Start()
|
|
{
|
|
questManager = UnityEngine.Object.FindObjectOfType<QuestManager>();
|
|
buttonsAction[0].gameObject.SetActive(value: true);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
ButtonController();
|
|
SetQuestContent();
|
|
}
|
|
|
|
private void SetQuestContent()
|
|
{
|
|
if (titleText.text == "Title")
|
|
{
|
|
titleText.text = GameManager.Instance.GetQuestDescription(Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest[indexOfPlayerQuest].gameQuest);
|
|
progressText.text = SetProgressTextValue(currentProgress, maxProgress);
|
|
SetProgress(currentProgress, maxProgress);
|
|
}
|
|
}
|
|
|
|
public void SetProgress(float progress, float fullprogress)
|
|
{
|
|
currentProgress = progress;
|
|
maxProgress = fullprogress;
|
|
progressText.text = SetProgressTextValue(progress, maxProgress);
|
|
float fillAmount = SetProgressValue(progress, maxProgress) / maxProgress;
|
|
progressBarImage.fillAmount = fillAmount;
|
|
}
|
|
|
|
private float SetProgressValue(float progress, float fullprogress)
|
|
{
|
|
GameManager.GameQuest.QuestObjectiveType questObjectiveType = GameManager.GameQuest.QuestObjectiveType.Catch_fish;
|
|
for (int i = 0; i < Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest.Count; i++)
|
|
{
|
|
if (Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest[i].uid == uid)
|
|
{
|
|
questObjectiveType = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest[i].gameQuest.questObjectiveType;
|
|
}
|
|
}
|
|
switch (questObjectiveType)
|
|
{
|
|
case GameManager.GameQuest.QuestObjectiveType.Catch_fish_by_weight:
|
|
if (progress >= fullprogress)
|
|
{
|
|
return progress;
|
|
}
|
|
return 0f;
|
|
case GameManager.GameQuest.QuestObjectiveType.Catch_fish:
|
|
case GameManager.GameQuest.QuestObjectiveType.Spend_time:
|
|
case GameManager.GameQuest.QuestObjectiveType.Catch_fish_total_weight:
|
|
case GameManager.GameQuest.QuestObjectiveType.Catch_fish_by_species:
|
|
return progress;
|
|
default:
|
|
return progress;
|
|
}
|
|
}
|
|
|
|
private string SetProgressTextValue(float progress, float fullprogress)
|
|
{
|
|
GameManager.GameQuest.QuestObjectiveType questObjectiveType = GameManager.GameQuest.QuestObjectiveType.Catch_fish;
|
|
for (int i = 0; i < Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest.Count; i++)
|
|
{
|
|
if (Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest[i].uid == uid)
|
|
{
|
|
questObjectiveType = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest[i].gameQuest.questObjectiveType;
|
|
}
|
|
}
|
|
switch (questObjectiveType)
|
|
{
|
|
case GameManager.GameQuest.QuestObjectiveType.Catch_fish_by_weight:
|
|
if (progress >= fullprogress)
|
|
{
|
|
return GameManager.Instance.ConvertWeightWithoutUnit(fullprogress).ToString("F1") + "/" + GameManager.Instance.ConvertWeightWithoutUnit(fullprogress).ToString("F1");
|
|
}
|
|
return GameManager.Instance.ConvertWeightWithoutUnit(0f).ToString("F1") + "/" + GameManager.Instance.ConvertWeightWithoutUnit(fullprogress).ToString("F1");
|
|
case GameManager.GameQuest.QuestObjectiveType.Catch_fish_total_weight:
|
|
case GameManager.GameQuest.QuestObjectiveType.Catch_fish_by_species:
|
|
return GameManager.Instance.ConvertWeightWithoutUnit(progress).ToString("F2") + "/" + GameManager.Instance.ConvertWeightWithoutUnit(fullprogress).ToString("F2");
|
|
case GameManager.GameQuest.QuestObjectiveType.Catch_fish:
|
|
case GameManager.GameQuest.QuestObjectiveType.Spend_time:
|
|
return Mathf.Clamp(progress, 0f, fullprogress).ToString("F0") + "/" + fullprogress;
|
|
default:
|
|
return progress + "/" + fullprogress;
|
|
}
|
|
}
|
|
|
|
public void ChangeMissionButton()
|
|
{
|
|
questManager.ChangeQuest(uid);
|
|
}
|
|
|
|
public void GetRewardButton()
|
|
{
|
|
for (int i = 0; i < Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest.Count; i++)
|
|
{
|
|
if (Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest[i].uid == uid)
|
|
{
|
|
QuestItem.OnQuestCompleteGlobal?.Invoke();
|
|
RewardPopUpItem component = UnityEngine.Object.Instantiate(questManager.RewardPopUpPrefab, questManager.transform).GetComponent<RewardPopUpItem>();
|
|
component.id = uid;
|
|
component.rewardText.text = "$" + Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest[i].gameQuest.reward;
|
|
component.type = Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerQuest[i].gameQuest.type;
|
|
UnityEngine.Object.Destroy(base.gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ButtonController()
|
|
{
|
|
if (buttonsAction[0].gameObject.activeSelf && !GameManager.Instance._playerData.CheckisChangeQuest())
|
|
{
|
|
buttonsAction[0].gameObject.SetActive(value: false);
|
|
inProgressText.gameObject.SetActive(value: true);
|
|
}
|
|
if (currentProgress >= maxProgress && maxProgress > 0f)
|
|
{
|
|
buttonsAction[0].gameObject.SetActive(value: false);
|
|
buttonsAction[1].gameObject.SetActive(value: true);
|
|
inProgressText.gameObject.SetActive(value: false);
|
|
}
|
|
}
|
|
}
|