Skip to content

Commit

Permalink
Merge pull request #212 from crashkonijn/feature/added-target-state-i…
Browse files Browse the repository at this point in the history
…ndicator

Feature: added target state indicator
  • Loading branch information
crashkonijn authored Jul 24, 2024
2 parents ea47a07 + b4763a2 commit c54327c
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions Package/Editor/CrashKonijn.Goap.Editor/GraphViewer/NodeElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,32 @@ public NodeElement(INode graphNode, VisualElement bezierRoot, EditorWindowValues
costWrapper.Add(this.Cost);

this.Content.Add(new HorizontalSplitView(this.Title, costWrapper, 60));

var targetWrapper = new VisualElement
{
style =
{
flexDirection = FlexDirection.Row,
}
};

this.Target = new Label();
this.Content.Add(this.Target);

if (graphNode.Action is IGoapAction)
{
this.TargetCircle = new Circle(Color.white, 10f)
{
style =
{
marginRight = 4,
marginTop = 2
}
};
targetWrapper.Add(this.TargetCircle);
targetWrapper.Add(this.Target);
}

this.Content.Add(targetWrapper);

this.Conditions = new VisualElement();
this.Conditions.AddToClassList("conditions");
Expand Down Expand Up @@ -90,6 +113,7 @@ public NodeElement(INode graphNode, VisualElement bezierRoot, EditorWindowValues
{
if (graphNode.Action is IGoapAction goapAction)
{
this.TargetCircle.SetColor(this.GetCircleColor(goapAction));
this.Target.text = $"Target: {goapAction.Config.Target?.GetType().GetGenericTypeName()}";
this.Cost.text = $"Cost: {goapAction.Config.BaseCost}";
}
Expand Down Expand Up @@ -120,13 +144,28 @@ public NodeElement(INode graphNode, VisualElement bezierRoot, EditorWindowValues
if (graphNode.Action is IGoapAction action)
{
this.TargetCircle.SetColor(this.GetCircleColor(action));
var target = provider.WorldData.GetTarget(action);
var targetText = target != null ? target.Position.ToString() : "null";
this.Target.text = $"Target: {targetText}";
}
}).Every(33);
}

private Color GetCircleColor(IGoapAction goapAction)
{
if (!Application.isPlaying)
return Color.white;

if (!goapAction.Config.RequiresTarget)
return Color.green;

if (goapAction.Config.Target == null)
return Color.red;

return Color.green;
}

private void UpdateClasses(INode graphNode, IMonoGoapActionProvider provider)
{
Expand All @@ -146,7 +185,7 @@ private void UpdateClasses(INode graphNode, IMonoGoapActionProvider provider)
return;
}

if (provider.CurrentPlan != null && provider.CurrentPlan.Plan.Contains(this.GraphNode.Action))
if (provider.CurrentPlan?.Plan != null && provider.CurrentPlan.Plan.Contains(this.GraphNode.Action))
{
this.Node.AddToClassList("path");
return;
Expand All @@ -164,6 +203,8 @@ private void UpdateClasses(INode graphNode, IMonoGoapActionProvider provider)

public Label Target { get; set; }

public Circle TargetCircle { get; set; }

public Label Cost { get; set; }

public Label Title { get; set; }
Expand Down

0 comments on commit c54327c

Please sign in to comment.