51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using Godot;
|
|
using Newlon;
|
|
using Newlon.Components;
|
|
using Newlon.Components.GUI.Seedpackets;
|
|
using Newlon.Components.Plants;
|
|
|
|
public partial class Previewport : SubViewport
|
|
{
|
|
private Node 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 (GetParent<Control>().IsVisibleInTree() == false) return;
|
|
if (node is Seedpacket packet)
|
|
{
|
|
ChangeDisplay(packet.GetResource());
|
|
}
|
|
}
|
|
|
|
private void ChangeDisplay(DisplayResource 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();
|
|
title.Text = Tr(resource.name_key);
|
|
description.Text = Tr(resource.description_key);
|
|
AddChild(current_display);
|
|
if (current_display is IEntity entity)
|
|
entity.DisableBrain();
|
|
}
|
|
|
|
}
|