From 8e7e85d9a129bddfe4e624139db25cde8c47b3d3 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Thu, 15 Aug 2024 14:16:03 -0500 Subject: [PATCH] Add support for dialogue attention points --- NewHorizons/Builder/Props/DialogueBuilder.cs | 35 +++++++++++++++++-- .../Props/Dialogue/AttentionPointInfo.cs | 32 +++++++++++++++++ .../Modules/Props/Dialogue/DialogueInfo.cs | 10 ++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 NewHorizons/External/Modules/Props/Dialogue/AttentionPointInfo.cs diff --git a/NewHorizons/Builder/Props/DialogueBuilder.cs b/NewHorizons/Builder/Props/DialogueBuilder.cs index 27b2654c..1459230f 100644 --- a/NewHorizons/Builder/Props/DialogueBuilder.cs +++ b/NewHorizons/Builder/Props/DialogueBuilder.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Data.SqlTypes; using System.IO; +using System.Linq; using System.Xml; using System.Xml.Linq; using UnityEngine; @@ -35,7 +36,7 @@ namespace NewHorizons.Builder.Props } else { - return (AddToExistingDialogue(go, info, xml, dialogueName), null); + return (AddToExistingDialogue(go, sector, info, xml, dialogueName), null); } } @@ -52,6 +53,8 @@ namespace NewHorizons.Builder.Props } var dialogue = MakeConversationZone(go, sector, info, xml, dialogueName); + + MakeAttentionPoints(go, sector, dialogue, info); RemoteDialogueTrigger remoteTrigger = null; if (info.remoteTrigger != null) @@ -70,7 +73,7 @@ namespace NewHorizons.Builder.Props return (dialogue, remoteTrigger); } - private static CharacterDialogueTree AddToExistingDialogue(GameObject go, DialogueInfo info, string xml, string dialogueName) + private static CharacterDialogueTree AddToExistingDialogue(GameObject go, Sector sector, DialogueInfo info, string xml, string dialogueName) { var dialogueObject = go.FindChild(info.pathToExistingDialogue); if (dialogueObject == null) dialogueObject = SearchUtilities.Find(info.pathToExistingDialogue); @@ -163,6 +166,8 @@ namespace NewHorizons.Builder.Props FixDialogueNextFrame(existingDialogue); + MakeAttentionPoints(go, sector, existingDialogue, info); + return existingDialogue; } @@ -332,6 +337,32 @@ namespace NewHorizons.Builder.Props return dialogueTree; } + private static void MakeAttentionPoints(GameObject go, Sector sector, CharacterDialogueTree dialogue, DialogueInfo info) + { + if (info.attentionPoint != null) + { + var ptGo = GeneralPropBuilder.MakeNew("AttentionPoint", go, sector, info.attentionPoint, defaultParent: dialogue.transform); + dialogue._attentionPoint = ptGo.transform; + dialogue._attentionPointOffset = info.attentionPoint.offset; + ptGo.SetActive(true); + } + if (info.swappedAttentionPoints != null && info.swappedAttentionPoints.Length > 0) + { + foreach (var pointInfo in info.swappedAttentionPoints) + { + var ptGo = GeneralPropBuilder.MakeNew($"AttentionPoint_{pointInfo.dialogueNode}_{pointInfo.dialoguePage}", go, sector, pointInfo, defaultParent: dialogue.transform); + var swapper = ptGo.AddComponent(); + swapper._dialogueTree = dialogue; + swapper._attentionPoint = ptGo.transform; + swapper._attentionPointOffset = pointInfo.offset; + swapper._nodeName = pointInfo.dialogueNode; + swapper._dialoguePage = pointInfo.dialoguePage; + swapper._lookEasing = pointInfo.lookEasing; + ptGo.SetActive(true); + } + } + } + private static void MakePlayerTrackingZone(GameObject go, CharacterDialogueTree dialogue, DialogueInfo info) { var character = go.transform.Find(info.pathToAnimController); diff --git a/NewHorizons/External/Modules/Props/Dialogue/AttentionPointInfo.cs b/NewHorizons/External/Modules/Props/Dialogue/AttentionPointInfo.cs new file mode 100644 index 00000000..5dc9a9d8 --- /dev/null +++ b/NewHorizons/External/Modules/Props/Dialogue/AttentionPointInfo.cs @@ -0,0 +1,32 @@ +using NewHorizons.External.SerializableData; +using Newtonsoft.Json; +using System.ComponentModel; + +namespace NewHorizons.External.Modules.Props.Dialogue +{ + [JsonObject] + public class AttentionPointInfo : GeneralPointPropInfo + { + /// + /// An additional offset to apply to apply when the camera looks at this attention point. + /// + public MVector3 offset; + } + + [JsonObject] + public class SwappedAttentionPointInfo : AttentionPointInfo + { + /// + /// The name of the dialogue node to activate this attention point for. If null or blank, activates for every node. + /// + public string dialogueNode; + /// + /// The index of the page in the current dialogue node to activate this attention point for, if the node has multiple pages. + /// + public int dialoguePage; + /// + /// The easing factor which determines how 'snappy' the camera is when looking at the attention point. + /// + [DefaultValue(1)] public float lookEasing = 1f; + } +} diff --git a/NewHorizons/External/Modules/Props/Dialogue/DialogueInfo.cs b/NewHorizons/External/Modules/Props/Dialogue/DialogueInfo.cs index b2687c3c..d3395938 100644 --- a/NewHorizons/External/Modules/Props/Dialogue/DialogueInfo.cs +++ b/NewHorizons/External/Modules/Props/Dialogue/DialogueInfo.cs @@ -47,6 +47,16 @@ namespace NewHorizons.External.Modules.Props.Dialogue /// [DefaultValue(2f)] public float range = 2f; + /// + /// The point that the camera looks at when dialogue advances. + /// + public AttentionPointInfo attentionPoint; + + /// + /// Additional points that the camera looks at when dialogue advances through specific dialogue nodes and pages. + /// + public SwappedAttentionPointInfo[] swappedAttentionPoints; + /// /// Allows you to trigger dialogue from a distance when you walk into an area. ///