newlon/scripts/components/gui/choose_your_seeds/Previewport.cs
2025-06-26 20:18:19 +05:00

40 lines
876 B
C#

using Godot;
using Newlon;
using Newlon.Components.GUI.Seedpackets;
using Newlon.Components.Plants;
public partial class Previewport : SubViewport
{
private RuntimePlantData current_display;
[Export] private Label title;
[Export] private Label description;
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>();
title.Text = resource.display_name;
description.Text = resource.display_description;
AddChild(current_display);
current_display.DisableBrain();
}
}