72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using Godot;
|
|
|
|
public partial class CraftNodeDisplay : NodeDisplay
|
|
{
|
|
protected override ProgramNode CreateProgramNode()
|
|
{
|
|
return new CraftNode();
|
|
}
|
|
|
|
protected override void LoadContent(NodeDisplay display, string content)
|
|
{
|
|
HBoxContainer valueContainer = GetValueContainer(display);
|
|
string[] parts = content.Split(",");
|
|
string itemString = parts[1].Replace("Item:", "").Trim();
|
|
if (itemString.ToLower() != "empty")
|
|
{
|
|
CraftNode craftNode = display.node as CraftNode;
|
|
if (craftNode != null)
|
|
{
|
|
craftNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
|
}
|
|
}
|
|
string amountString = parts[2].Replace("Amount:", "").Trim();
|
|
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
|
}
|
|
|
|
public override void ReadParameters()
|
|
{
|
|
CraftNode craftNode = node as CraftNode;
|
|
if (craftNode == null) return;
|
|
|
|
HBoxContainer valueContainer = GetValueContainer();
|
|
OptionButton items = valueContainer.GetNode<OptionButton>("./Item");
|
|
string readableItem = items.GetItemText(items.GetSelectedId()).Split(":")[0];
|
|
if (GameData.availableItems.ContainsKey(ItemData.GetIndex(readableItem)))
|
|
{
|
|
craftNode.selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
|
}
|
|
craftNode.amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
|
}
|
|
|
|
public override void SetupDisplay()
|
|
{
|
|
CraftNode craftNode = node as CraftNode;
|
|
if (craftNode == null) return;
|
|
|
|
OptionButton options = GetValueContainer().GetNode<OptionButton>("./Item");
|
|
options.Clear();
|
|
options.AddItem("Select item...");
|
|
foreach (ItemData item in GameData.availableItems.Values)
|
|
{
|
|
if (GameData.availableResearch[item.Research].state != ResearchState.RESEARCHED) continue;
|
|
if (item.Inputs.Count > 0)
|
|
{
|
|
options.AddItem(item.GetCraftingDisplay());
|
|
}
|
|
}
|
|
|
|
if (craftNode.selectedItem != null)
|
|
{
|
|
for (int i = 0; i < options.ItemCount; i++)
|
|
{
|
|
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == craftNode.selectedItem.data.Id)
|
|
{
|
|
options.Select(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|