64 lines
1.4 KiB
C#
64 lines
1.4 KiB
C#
using Godot;
|
|
|
|
public partial class ResearchList : PanelContainer
|
|
{
|
|
[Export] GraphEdit researchGraph;
|
|
|
|
public override void _Ready()
|
|
{
|
|
foreach (ResearchData research in GameData.availableResearch.Values)
|
|
{
|
|
researchGraph.AddChild(CreateItemNode(research.Id, research.Texture));
|
|
}
|
|
foreach (ResearchData research in GameData.availableResearch.Values)
|
|
{
|
|
researchGraph.ConnectNode(
|
|
research.Research,
|
|
0,
|
|
research.Id,
|
|
0
|
|
);
|
|
}
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
|
|
}
|
|
|
|
private GraphNode CreateItemNode(string id, string texturePath)
|
|
{
|
|
Vector2 viewportSize = GetViewport().GetVisibleRect().Size;
|
|
TextureRect icon = new TextureRect
|
|
{
|
|
Texture = GD.Load<Texture2D>(texturePath),
|
|
StretchMode = TextureRect.StretchModeEnum.KeepAspectCentered
|
|
};
|
|
//Step 1: Place the node in the visible field for the player
|
|
Vector2 nodePosition = new Vector2(viewportSize.X / 32, viewportSize.Y / 4);
|
|
//Step 2: Modify position by nodeIndex
|
|
nodePosition = nodePosition + new Vector2(GameData.availableResearch.Count * -icon.Texture.GetWidth() + researchGraph.GetChildCount() * icon.Texture.GetWidth() * 10, 0);
|
|
|
|
GraphNode node = new GraphNode
|
|
{
|
|
Name = id,
|
|
Title = id,
|
|
PositionOffset = nodePosition
|
|
};
|
|
|
|
node.SetSlot(
|
|
0,
|
|
true,
|
|
0,
|
|
Colors.White,
|
|
true,
|
|
0,
|
|
Colors.White
|
|
);
|
|
|
|
node.AddChild(icon);
|
|
|
|
return node;
|
|
}
|
|
}
|