newlon/scripts/components/gui/choose_your_seeds/Previewport.cs
2025-07-01 17:31:12 +05:00

48 lines
1.2 KiB
C#

using Godot;
using Newlon;
using Newlon.Components.GUI.Seedpackets;
using Newlon.Components.Plants;
public partial class Previewport : SubViewport
{
private RuntimePlantData current_display;
private Texture2D start_Field;
[Export] private Label title;
[Export] private RichTextLabel description;
public override void _Ready()
{
GetParent().GetViewport().GuiFocusChanged += OnFocusChanged;
start_Field = GetNode<Sprite2D>("FrameField").Texture;
}
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();
}
if (resource.customFrame != null && resource.customFrame.almanachField != null)
{
GetNode<Sprite2D>("FrameField").Texture = resource.customFrame.almanachField;
}
else
GetNode<Sprite2D>("FrameField").Texture = start_Field;
current_display = resource.Scene.Instantiate<RuntimePlantData>();
title.Text = resource.display_name;
description.Text = resource.display_description;
AddChild(current_display);
current_display.DisableBrain();
}
}