588879951d
Readded node deletion.
90 lines
2.6 KiB
C#
90 lines
2.6 KiB
C#
using Godot;
|
|
|
|
public partial class IfNodeDisplay : NodeDisplay
|
|
{
|
|
protected override ProgramNode CreateProgramNode()
|
|
{
|
|
return new IfNode();
|
|
}
|
|
|
|
protected override void LoadContent(NodeDisplay display, string content)
|
|
{
|
|
HBoxContainer valueContainer = GetValueContainer(display);
|
|
string[] parts = content.Split(",");
|
|
string itemString = parts[1].Replace("Item:", "").Trim();
|
|
string comparatorString = parts[2].Replace("Comparator:", "").Trim();
|
|
if (itemString.ToLower() != "empty")
|
|
{
|
|
IfNode ifNode = display.node as IfNode;
|
|
if (ifNode != null)
|
|
{
|
|
ifNode.selectedItem = new Item { data = GameData.availableItems[itemString] };
|
|
ifNode.comparator = comparatorString;
|
|
}
|
|
}
|
|
string amountString = parts[3].Replace("Amount:", "").Trim();
|
|
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
|
}
|
|
|
|
public override void ReadParameters()
|
|
{
|
|
IfNode ifNode = node as IfNode;
|
|
if (ifNode == 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)))
|
|
{
|
|
ifNode.selectedItem = new Item { data = GameData.availableItems[ItemData.GetIndex(readableItem)] };
|
|
}
|
|
ifNode.amount = (int)valueContainer.GetNode<SpinBox>("./Amount").Value;
|
|
|
|
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
|
if(comparators.GetSelectedId() == -1) return;
|
|
ifNode.comparator = comparators.GetItemText(comparators.GetSelectedId());
|
|
}
|
|
|
|
public override void SetupDisplay()
|
|
{
|
|
IfNode ifNode = node as IfNode;
|
|
if (ifNode == null) return;
|
|
|
|
HBoxContainer valueContainer = GetValueContainer();
|
|
OptionButton options = valueContainer.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;
|
|
options.AddItem(item.GetReadableName());
|
|
}
|
|
|
|
if (ifNode.selectedItem != null)
|
|
{
|
|
for (int i = 0; i < options.ItemCount; i++)
|
|
{
|
|
if (ItemData.GetIndex(options.GetItemText(i).Split(":")[0]) == ifNode.selectedItem.data.Id)
|
|
{
|
|
options.Select(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
OptionButton comparators = valueContainer.GetNode<OptionButton>("./Comparator");
|
|
|
|
if (ifNode.comparator != null)
|
|
{
|
|
for (int i = 0; i < comparators.ItemCount; i++)
|
|
{
|
|
if (comparators.GetItemText(i) == ifNode.comparator)
|
|
{
|
|
comparators.Select(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|