You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
using Godot;
|
|
using System;
|
|
using Babushka.scripts.CSharp.Common.Quest;
|
|
|
|
public partial class QuestListUi : VBoxContainer
|
|
{
|
|
[Export]
|
|
private PackedScene _questListItemPrefab;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
UpdateList();
|
|
QuestManager.Instance!.QuestsChanged += UpdateList;
|
|
}
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
QuestManager.Instance!.QuestsChanged -= UpdateList;
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
UpdateList();
|
|
}
|
|
|
|
public void UpdateList()
|
|
{
|
|
// delete children
|
|
foreach (Node child in GetChildren())
|
|
{
|
|
RemoveChild(child);
|
|
child.QueueFree();
|
|
}
|
|
|
|
// recreate children
|
|
var activeQuests = QuestManager.Instance.GetVisibleQuests();
|
|
|
|
foreach (var questPair in activeQuests)
|
|
{
|
|
var questResource = questPair.Key;
|
|
var questStatus = questPair.Value;
|
|
|
|
var questListItem = _questListItemPrefab.Instantiate<QuestListItemUi>();
|
|
questListItem.UpdateButton(questResource);
|
|
AddChild(questListItem);
|
|
}
|
|
}
|
|
}
|