newlon/scripts/gui/choose_your_seeds/GridLoader.cs
2025-07-29 04:08:05 +05:00

44 lines
1.3 KiB
C#

using Godot;
using Newlon.Components.GUI.Seedpackets;
using Newlon.Components.Level;
namespace Newlon.Components.GUI;
public partial class GridLoader : GridContainer
{
private PackedScene _plantCard;
public const string SEEDPACKED_UID = "uid://e7vutg71l6f2";
public override void _Ready()
{
_plantCard = ResourceLoader.Load<PackedScene>(SEEDPACKED_UID);
var list = GameRegistry.GetPlants();
list.Sort((a, b) =>
{
return a.Order - b.Order;
});
foreach (var resource in list)
{
Seedpacket slot = _plantCard.Instantiate<Seedpacket>();
AddChild(slot);
slot.SetResource(resource);
slot.SetForbidden(RuntimeLevelData.LevelResource.forbiddenPlants.Contains(resource.GetInternalID()));
slot.SetLocked(PlayerProgress.Instance.PlayerPlants.Contains(resource) == false);
if (GetChildCount() == 1) slot.GrabFocus();
if (RuntimeLevelData.LevelResource.prepickedPlants.Contains(resource.GetInternalID()))
{
slot.SetHandler(new PrepickedDummyHandler(slot));
slot.disablePacket = true;
}
else
{
slot.SetHandler(new ChoosableHandler(slot));
}
}
}
}