131 lines
3.3 KiB
C#
131 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Godot;
|
|
|
|
public partial class NodeDisplay : PanelContainer
|
|
{
|
|
[Export] PanelContainer editorDisplay;
|
|
[Export] public Button listDisplay;
|
|
public ProgramNode node;
|
|
|
|
[Signal]
|
|
public delegate void OnDeleteNodeEventHandler();
|
|
|
|
public void SetNode(ProgramNode node)
|
|
{
|
|
this.node = node;
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
node.Setup(this);
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
|
|
}
|
|
|
|
public void ShowListDisplay()
|
|
{
|
|
editorDisplay.Visible = false;
|
|
listDisplay.Visible = true;
|
|
}
|
|
|
|
public void ShowEditorDisplay()
|
|
{
|
|
editorDisplay.Visible = true;
|
|
listDisplay.Visible = false;
|
|
}
|
|
|
|
public void DeleteNodePressed()
|
|
{
|
|
EmitSignal(SignalName.OnDeleteNode);
|
|
}
|
|
|
|
public static NodeDisplay Load(string content, Dictionary<ProgramNode, PackedScene> DSLNodes)
|
|
{
|
|
NodeDisplay result = null;
|
|
ProgramNode program;
|
|
string nodeName;
|
|
string nodeSanitized;
|
|
PackedScene prefab = null;
|
|
nodeSanitized = content.Replace("\r\n", "");
|
|
nodeName = nodeSanitized.Split(",")[0].Replace("Name: ", "").ToLower();
|
|
foreach (ProgramNode programNode in DSLNodes.Keys)
|
|
{
|
|
if (programNode.DisplayText.ToLower() == nodeName)
|
|
{
|
|
prefab = DSLNodes[programNode];
|
|
break;
|
|
}
|
|
}
|
|
switch (nodeName)
|
|
{
|
|
case "move":
|
|
program = new MoveNode();
|
|
result = prefab.Instantiate<NodeDisplay>();
|
|
result.node = program;
|
|
result.LoadMove(nodeSanitized);
|
|
break;
|
|
case "harvest":
|
|
program = new HarvestNode();
|
|
result = prefab.Instantiate<NodeDisplay>();
|
|
result.node = program;
|
|
result.LoadHarvest(nodeSanitized);
|
|
break;
|
|
case "explore":
|
|
program = new ExploreNode();
|
|
result = prefab.Instantiate<NodeDisplay>();
|
|
result.node = program;
|
|
result.LoadExplore(nodeSanitized);
|
|
break;
|
|
case "craft":
|
|
program = new CraftNode();
|
|
result = prefab.Instantiate<NodeDisplay>();
|
|
result.node = program;
|
|
result.LoadCraft(nodeSanitized);
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public void LoadHarvest(string content)
|
|
{
|
|
//Currently does nothing
|
|
}
|
|
|
|
public void LoadMove(string content)
|
|
{
|
|
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
|
|
string[] parts = content.Split(",");
|
|
string positionValues = parts[1].Replace("Position: ", "").Replace("(", "").Replace(")", "");
|
|
int posX = int.Parse(positionValues.Split("|")[0]);
|
|
int posY = int.Parse(positionValues.Split("|")[1]);
|
|
int posZ = int.Parse(positionValues.Split("|")[2]);
|
|
valueContainer.GetNode<SpinBox>("./CoordinateX").Value = posX;
|
|
valueContainer.GetNode<SpinBox>("./CoordinateY").Value = posY;
|
|
valueContainer.GetNode<SpinBox>("./CoordinateZ").Value = posZ;
|
|
|
|
(node as MoveNode).targetPosition = new Vector3I(posX, posY, posZ);
|
|
}
|
|
|
|
public void LoadExplore(string content)
|
|
{
|
|
//Currently does nothing
|
|
}
|
|
|
|
public void LoadCraft(string content)
|
|
{
|
|
HBoxContainer valueContainer = GetNode<HBoxContainer>("./EditorDisplay/HBoxContainer/");
|
|
string[] parts = content.Split(",");
|
|
string itemString = parts[1].Replace("Item: ", "").Replace(" ", "");
|
|
if (itemString.ToLower() != "empty")
|
|
{
|
|
(node as CraftNode).selectedItem = new Item { data = GameData.availableItems[itemString] };
|
|
}
|
|
string amountString = parts[2].Replace("Amount: ", "");
|
|
valueContainer.GetNode<SpinBox>("./Amount").Value = int.Parse(amountString);
|
|
}
|
|
}
|