PJ/Assets/scripts/dotfs_scripts/UI_QuestItem.cs

83 lines
No EOL
2.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class UI_QuestItem : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI titleText;
[SerializeField] private TextMeshProUGUI descText;
[SerializeField] private TextMeshProUGUI progressText;
[SerializeField] private Button claimButton;
private QuestData _data;
public void Setup(QuestData data)
{
if (data == null)
{
Debug.LogError($"[UI_QuestItem] {gameObject.name}: Setup called with NULL data!");
return;
}
_data = data;
// Логируем, что данные получены
Debug.Log($"[UI_QuestItem] Setting up quest: ID={_data.id}, Title={_data.title}");
if (titleText != null) titleText.text = _data.title;
else Debug.LogWarning($"[UI_QuestItem] {gameObject.name}: titleText reference is missing!");
if (descText != null) descText.text = _data.description;
UpdateUI();
if (claimButton != null)
{
claimButton.onClick.RemoveAllListeners();
claimButton.onClick.AddListener(() => {
Debug.Log($"[UI_QuestItem] Claim button clicked for quest: {_data.id}");
MANAGER_QuestProgress.Instance.ClaimReward(_data);
});
}
}
public void UpdateUI()
{
if (_data == null) return;
if (MANAGER_QuestProgress.Instance == null)
{
Debug.LogError("[UI_QuestItem] MANAGER_QuestProgress Instance is missing!");
return;
}
int current = MANAGER_QuestProgress.Instance.GetProgress(_data.id);
bool isDone = MANAGER_QuestProgress.Instance.IsQuestReady(_data);
bool isClaimed = MANAGER_QuestProgress.Instance.IsQuestCompleted(_data.id);
Debug.Log($"[UI_QuestItem] Updating UI for {_data.id}: Progress={current}/{_data.requiredAmount}, Ready={isDone}, Claimed={isClaimed}");
if (progressText != null)
{
progressText.text = isClaimed ? "Завершено!" : $"{current} / {_data.requiredAmount}";
}
if (claimButton != null)
{
claimButton.interactable = isDone && !isClaimed;
}
// КРИТИЧЕСКАЯ ПРОВЕРКА: Если квест выполнен, ты его скрываешь.
// Если данные загрузились как "уже выполненные", объект исчезнет сразу после спавна.
if (isClaimed)
{
Debug.Log($"[UI_QuestItem] Quest {_data.id} is already claimed. Hiding object.");
gameObject.SetActive(false);
}
else
{
// На всякий случай включаем, если он был выключен в префабе
gameObject.SetActive(true);
}
}
}