newlon/scripts/components/gui/choose_your_seeds/Previewport.cs
2025-06-22 23:55:44 +05:00

35 lines
718 B
C#

using Godot;
using Newlon;
using Newlon.Components.GUI.Seedpackets;
using Newlon.Components.Plants;
public partial class Previewport : SubViewport
{
private RuntimePlantData current_display;
public override void _Ready()
{
GetParent().GetViewport().GuiFocusChanged += OnFocusChanged;
}
public void OnFocusChanged(Control node)
{
if (node is Seedpacket packet)
{
ChangeDisplay(packet.GetPlantResource());
}
}
private void ChangeDisplay(PlantResource resource)
{
// Expand with updates
if (current_display != null)
{
current_display.QueueFree();
}
current_display = resource.Scene.Instantiate<RuntimePlantData>();
AddChild(current_display);
current_display.DisableBrain();
}
}