Prepicked plants editor

This commit is contained in:
Rendo 2025-07-29 04:08:05 +05:00
commit 56f75a5d06
43 changed files with 532 additions and 50 deletions

View file

@ -15,4 +15,5 @@ public partial class LevelGUIElements : Control
{
Instance = this;
}
}

View file

@ -7,7 +7,7 @@ namespace Newlon.Components.GUI;
public partial class GridLoader : GridContainer
{
private PackedScene _plantCard;
const string SEEDPACKED_UID = "uid://e7vutg71l6f2";
public const string SEEDPACKED_UID = "uid://e7vutg71l6f2";
public override void _Ready()
{
_plantCard = ResourceLoader.Load<PackedScene>(SEEDPACKED_UID);
@ -24,11 +24,21 @@ public partial class GridLoader : GridContainer
slot.SetResource(resource);
slot.SetForbidden(RuntimeLevelData.LevelResource.forbiddenPlants.Contains(resource.internal_id));
slot.SetForbidden(RuntimeLevelData.LevelResource.forbiddenPlants.Contains(resource.GetInternalID()));
slot.SetLocked(PlayerProgress.Instance.PlayerPlants.Contains(resource) == false);
if (GetChildCount() == 1) slot.GrabFocus();
var handler = new ChoosableHandler(slot);
slot.SetHandler(handler);
if (RuntimeLevelData.LevelResource.prepickedPlants.Contains(resource.GetInternalID()))
{
slot.SetHandler(new PrepickedDummyHandler(slot));
slot.disablePacket = true;
}
else
{
slot.SetHandler(new ChoosableHandler(slot));
}
}
}
}

View file

@ -0,0 +1,15 @@
namespace Newlon.Components.GUI.Seedpackets;
public class PrepickedDummyHandler : SeedpacketHandler
{
public PrepickedDummyHandler(Seedpacket owner) : base(owner)
{
if (LevelGUIElements.Instance.SeedpacketsHotbar.GetChildCount() >= PlayerProgress.Instance.MaxSeedpackets) return;
_owner.disablePacket = true;
var hotbarSeedpacket = Seedpacket.Prefab.Instantiate<Seedpacket>();
LevelGUIElements.Instance.SeedpacketsHotbar.AddChild(hotbarSeedpacket);
hotbarSeedpacket.SetResource(_owner.GetResource());
hotbarSeedpacket.SetHandler(new PrepickedHandler(_owner));
}
}

View file

@ -0,0 +1 @@
uid://c7uf1ygofsurs

View file

@ -0,0 +1,23 @@
using Newlon.Components.Level;
namespace Newlon.Components.GUI.Seedpackets;
public class PrepickedHandler : SeedpacketHandler
{
public PrepickedHandler(Seedpacket owner) : base(owner)
{
RuntimeLevelData.Instance.OnLevelStateChanged += OnLevelStateChanged;
}
public void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
{
if (state == RuntimeLevelData.LevelStates.Game)
{
_owner.SetHandler(new HotbarHandler(_owner));
}
else if (state != RuntimeLevelData.LevelStates.ChooseYourSeeds)
{
_owner.disablePacket = true;
}
}
}

View file

@ -0,0 +1 @@
uid://d3da4b6e4qwtm