Update dialogue + nomai text to give the text asset a name

This commit is contained in:
Nick 2022-06-30 17:53:46 -04:00
parent 339ddfa35e
commit 351694bb8c
2 changed files with 181 additions and 174 deletions

View File

@ -1,6 +1,7 @@
using NewHorizons.External.Modules; using NewHorizons.External.Modules;
using NewHorizons.Handlers; using NewHorizons.Handlers;
using OWML.Common; using OWML.Common;
using System.IO;
using System.Xml; using System.Xml;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Builder.Props namespace NewHorizons.Builder.Props
@ -76,8 +77,9 @@ namespace NewHorizons.Builder.Props
var dialogueTree = conversationZone.AddComponent<CharacterDialogueTree>(); var dialogueTree = conversationZone.AddComponent<CharacterDialogueTree>();
var xml = System.IO.File.ReadAllText(mod.Manifest.ModFolderPath + info.xmlFile); var xml = File.ReadAllText(mod.Manifest.ModFolderPath + info.xmlFile);
var text = new TextAsset(xml); var text = new TextAsset(xml);
text.name = Path.GetFileNameWithoutExtension(info.xmlFile);
dialogueTree.SetTextXml(text); dialogueTree.SetTextXml(text);
AddTranslation(xml); AddTranslation(xml);

View File

@ -3,6 +3,7 @@ using NewHorizons.Handlers;
using NewHorizons.Utility; using NewHorizons.Utility;
using OWML.Common; using OWML.Common;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Xml; using System.Xml;
using UnityEngine; using UnityEngine;
@ -100,191 +101,194 @@ namespace NewHorizons.Builder.Props
switch (info.type) switch (info.type)
{ {
case PropModule.NomaiTextInfo.NomaiTextType.Wall: case PropModule.NomaiTextInfo.NomaiTextType.Wall:
{
var nomaiWallTextObj = MakeWallText(planetGO, sector, info, xmlPath).gameObject;
nomaiWallTextObj.transform.parent = sector?.transform ?? planetGO.transform;
nomaiWallTextObj.transform.position = planetGO.transform.TransformPoint(info.position);
if (info.normal != null)
{ {
// In global coordinates (normal was in local coordinates) var nomaiWallTextObj = MakeWallText(planetGO, sector, info, xmlPath).gameObject;
var up = (nomaiWallTextObj.transform.position - planetGO.transform.position).normalized;
var forward = planetGO.transform.TransformDirection(info.normal).normalized;
nomaiWallTextObj.transform.up = up; nomaiWallTextObj.transform.parent = sector?.transform ?? planetGO.transform;
nomaiWallTextObj.transform.forward = forward; nomaiWallTextObj.transform.position = planetGO.transform.TransformPoint(info.position);
} if (info.normal != null)
if (info.rotation != null)
{
nomaiWallTextObj.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation));
}
nomaiWallTextObj.SetActive(true);
conversationInfoToCorrespondingSpawnedGameObject[info] = nomaiWallTextObj;
break;
}
case PropModule.NomaiTextInfo.NomaiTextType.Scroll:
{
var customScroll = _scrollPrefab.InstantiateInactive();
var nomaiWallText = MakeWallText(planetGO, sector, info, xmlPath);
nomaiWallText.transform.parent = customScroll.transform;
nomaiWallText.transform.localPosition = Vector3.zero;
nomaiWallText.transform.localRotation = Quaternion.identity;
nomaiWallText._showTextOnStart = false;
// Don't want to be able to translate until its in a socket
nomaiWallText.GetComponent<Collider>().enabled = false;
nomaiWallText.gameObject.SetActive(true);
var scrollItem = customScroll.GetComponent<ScrollItem>();
// Idk why this thing is always around
GameObject.Destroy(customScroll.transform.Find("Arc_BH_City_Forum_2").gameObject);
// This variable is the bane of my existence i dont get it
scrollItem._nomaiWallText = nomaiWallText;
// Because the scroll was already awake it does weird shit in Awake and makes some of the entries in this array be null
scrollItem._colliders = new OWCollider[] { scrollItem.GetComponent<OWCollider>() };
// Else when you put them down you can't pick them back up
customScroll.GetComponent<OWCollider>()._physicsRemoved = false;
// Place scroll
customScroll.transform.parent = sector?.transform ?? planetGO.transform;
customScroll.transform.position = planetGO.transform.TransformPoint(info.position ?? Vector3.zero);
var up = planetGO.transform.InverseTransformPoint(customScroll.transform.position).normalized;
customScroll.transform.rotation = Quaternion.FromToRotation(customScroll.transform.up, up) * customScroll.transform.rotation;
customScroll.SetActive(true);
// Enable the collider and renderer
Main.Instance.ModHelper.Events.Unity.RunWhen(
() => Main.IsSystemReady,
() =>
{ {
Logger.Log("Fixing scroll!"); // In global coordinates (normal was in local coordinates)
scrollItem._nomaiWallText = nomaiWallText; var up = (nomaiWallTextObj.transform.position - planetGO.transform.position).normalized;
scrollItem.SetSector(sector); var forward = planetGO.transform.TransformDirection(info.normal).normalized;
customScroll.transform.Find("Props_NOM_Scroll/Props_NOM_Scroll_Geo").GetComponent<MeshRenderer>().enabled = true;
customScroll.transform.Find("Props_NOM_Scroll/Props_NOM_Scroll_Collider").gameObject.SetActive(true); nomaiWallTextObj.transform.up = up;
nomaiWallText.gameObject.GetComponent<Collider>().enabled = false; nomaiWallTextObj.transform.forward = forward;
customScroll.GetComponent<CapsuleCollider>().enabled = true;
} }
); if (info.rotation != null)
conversationInfoToCorrespondingSpawnedGameObject[info] = customScroll; {
break; nomaiWallTextObj.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation));
} }
nomaiWallTextObj.SetActive(true);
conversationInfoToCorrespondingSpawnedGameObject[info] = nomaiWallTextObj;
break;
}
case PropModule.NomaiTextInfo.NomaiTextType.Scroll:
{
var customScroll = _scrollPrefab.InstantiateInactive();
var nomaiWallText = MakeWallText(planetGO, sector, info, xmlPath);
nomaiWallText.transform.parent = customScroll.transform;
nomaiWallText.transform.localPosition = Vector3.zero;
nomaiWallText.transform.localRotation = Quaternion.identity;
nomaiWallText._showTextOnStart = false;
// Don't want to be able to translate until its in a socket
nomaiWallText.GetComponent<Collider>().enabled = false;
nomaiWallText.gameObject.SetActive(true);
var scrollItem = customScroll.GetComponent<ScrollItem>();
// Idk why this thing is always around
GameObject.Destroy(customScroll.transform.Find("Arc_BH_City_Forum_2").gameObject);
// This variable is the bane of my existence i dont get it
scrollItem._nomaiWallText = nomaiWallText;
// Because the scroll was already awake it does weird shit in Awake and makes some of the entries in this array be null
scrollItem._colliders = new OWCollider[] { scrollItem.GetComponent<OWCollider>() };
// Else when you put them down you can't pick them back up
customScroll.GetComponent<OWCollider>()._physicsRemoved = false;
// Place scroll
customScroll.transform.parent = sector?.transform ?? planetGO.transform;
customScroll.transform.position = planetGO.transform.TransformPoint(info.position ?? Vector3.zero);
var up = planetGO.transform.InverseTransformPoint(customScroll.transform.position).normalized;
customScroll.transform.rotation = Quaternion.FromToRotation(customScroll.transform.up, up) * customScroll.transform.rotation;
customScroll.SetActive(true);
// Enable the collider and renderer
Main.Instance.ModHelper.Events.Unity.RunWhen(
() => Main.IsSystemReady,
() =>
{
Logger.Log("Fixing scroll!");
scrollItem._nomaiWallText = nomaiWallText;
scrollItem.SetSector(sector);
customScroll.transform.Find("Props_NOM_Scroll/Props_NOM_Scroll_Geo").GetComponent<MeshRenderer>().enabled = true;
customScroll.transform.Find("Props_NOM_Scroll/Props_NOM_Scroll_Collider").gameObject.SetActive(true);
nomaiWallText.gameObject.GetComponent<Collider>().enabled = false;
customScroll.GetComponent<CapsuleCollider>().enabled = true;
}
);
conversationInfoToCorrespondingSpawnedGameObject[info] = customScroll;
break;
}
case PropModule.NomaiTextInfo.NomaiTextType.Computer: case PropModule.NomaiTextInfo.NomaiTextType.Computer:
{ {
var computerObject = _computerPrefab.InstantiateInactive(); var computerObject = _computerPrefab.InstantiateInactive();
computerObject.transform.parent = sector?.transform ?? planetGO.transform; computerObject.transform.parent = sector?.transform ?? planetGO.transform;
computerObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero); computerObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero);
var up = computerObject.transform.position - planetGO.transform.position; var up = computerObject.transform.position - planetGO.transform.position;
if (info.normal != null) up = planetGO.transform.TransformDirection(info.normal); if (info.normal != null) up = planetGO.transform.TransformDirection(info.normal);
computerObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, up) * computerObject.transform.rotation; computerObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, up) * computerObject.transform.rotation;
var computer = computerObject.GetComponent<NomaiComputer>(); var computer = computerObject.GetComponent<NomaiComputer>();
computer.SetSector(sector); computer.SetSector(sector);
computer._dictNomaiTextData = MakeNomaiTextDict(xmlPath); computer._dictNomaiTextData = MakeNomaiTextDict(xmlPath);
computer._nomaiTextAsset = new TextAsset(xmlPath); computer._nomaiTextAsset = new TextAsset(xmlPath);
AddTranslation(xmlPath); computer._nomaiTextAsset.name = Path.GetFileNameWithoutExtension(info.xmlFile);
AddTranslation(xmlPath);
// Make sure the computer model is loaded // Make sure the computer model is loaded
OWAssetHandler.LoadObject(computerObject); OWAssetHandler.LoadObject(computerObject);
sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(computerObject)); sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(computerObject));
computerObject.SetActive(true); computerObject.SetActive(true);
conversationInfoToCorrespondingSpawnedGameObject[info] = computerObject; conversationInfoToCorrespondingSpawnedGameObject[info] = computerObject;
break; break;
} }
case PropModule.NomaiTextInfo.NomaiTextType.Cairn: case PropModule.NomaiTextInfo.NomaiTextType.Cairn:
{
var cairnObject = _cairnPrefab.InstantiateInactive();
cairnObject.transform.parent = sector?.transform ?? planetGO.transform;
cairnObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero);
if (info.rotation != null)
{ {
cairnObject.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation)); var cairnObject = _cairnPrefab.InstantiateInactive();
cairnObject.transform.parent = sector?.transform ?? planetGO.transform;
cairnObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero);
if (info.rotation != null)
{
cairnObject.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation));
}
else
{
// By default align it to normal
var up = (cairnObject.transform.position - planetGO.transform.position).normalized;
cairnObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, up) * cairnObject.transform.rotation;
}
// Idk do we have to set it active before finding things?
cairnObject.SetActive(true);
// Make it do the thing when it finishes being knocked over
foreach (var rock in cairnObject.GetComponent<NomaiCairn>()._rocks)
{
rock._returning = false;
rock._owCollider.SetActivation(true);
rock.enabled = false;
}
// So we can actually knock it over
cairnObject.GetComponent<CapsuleCollider>().enabled = true;
var nomaiWallText = cairnObject.transform.Find("Props_TH_ClutterSmall/Arc_Short").GetComponent<NomaiWallText>();
nomaiWallText.SetSector(sector);
nomaiWallText._dictNomaiTextData = MakeNomaiTextDict(xmlPath);
nomaiWallText._nomaiTextAsset = new TextAsset(xmlPath);
nomaiWallText._nomaiTextAsset.name = Path.GetFileNameWithoutExtension(info.xmlFile);
AddTranslation(xmlPath);
// Make sure the computer model is loaded
OWAssetHandler.LoadObject(cairnObject);
sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(cairnObject));
conversationInfoToCorrespondingSpawnedGameObject[info] = cairnObject;
break;
} }
else
{
// By default align it to normal
var up = (cairnObject.transform.position - planetGO.transform.position).normalized;
cairnObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, up) * cairnObject.transform.rotation;
}
// Idk do we have to set it active before finding things?
cairnObject.SetActive(true);
// Make it do the thing when it finishes being knocked over
foreach (var rock in cairnObject.GetComponent<NomaiCairn>()._rocks)
{
rock._returning = false;
rock._owCollider.SetActivation(true);
rock.enabled = false;
}
// So we can actually knock it over
cairnObject.GetComponent<CapsuleCollider>().enabled = true;
var nomaiWallText = cairnObject.transform.Find("Props_TH_ClutterSmall/Arc_Short").GetComponent<NomaiWallText>();
nomaiWallText.SetSector(sector);
nomaiWallText._dictNomaiTextData = MakeNomaiTextDict(xmlPath);
nomaiWallText._nomaiTextAsset = new TextAsset(xmlPath);
AddTranslation(xmlPath);
// Make sure the computer model is loaded
OWAssetHandler.LoadObject(cairnObject);
sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(cairnObject));
conversationInfoToCorrespondingSpawnedGameObject[info] = cairnObject;
break;
}
case PropModule.NomaiTextInfo.NomaiTextType.PreCrashRecorder: case PropModule.NomaiTextInfo.NomaiTextType.PreCrashRecorder:
case PropModule.NomaiTextInfo.NomaiTextType.Recorder: case PropModule.NomaiTextInfo.NomaiTextType.Recorder:
{
var recorderObject = (info.type == PropModule.NomaiTextInfo.NomaiTextType.PreCrashRecorder? _preCrashRecorderPrefab : _recorderPrefab).InstantiateInactive();
recorderObject.transform.parent = sector?.transform ?? planetGO.transform;
recorderObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero);
if (info.rotation != null)
{ {
recorderObject.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation)); var recorderObject = (info.type == PropModule.NomaiTextInfo.NomaiTextType.PreCrashRecorder ? _preCrashRecorderPrefab : _recorderPrefab).InstantiateInactive();
recorderObject.transform.parent = sector?.transform ?? planetGO.transform;
recorderObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero);
if (info.rotation != null)
{
recorderObject.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation));
}
else
{
var up = recorderObject.transform.position - planetGO.transform.position;
recorderObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, up) * recorderObject.transform.rotation;
}
var nomaiText = recorderObject.GetComponentInChildren<NomaiText>();
nomaiText.SetSector(sector);
nomaiText._dictNomaiTextData = MakeNomaiTextDict(xmlPath);
nomaiText._nomaiTextAsset = new TextAsset(xmlPath);
nomaiText._nomaiTextAsset.name = Path.GetFileNameWithoutExtension(info.xmlFile);
AddTranslation(xmlPath);
// Make sure the recorder model is loaded
OWAssetHandler.LoadObject(recorderObject);
sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(recorderObject));
recorderObject.SetActive(true);
recorderObject.transform.Find("InteractSphere").gameObject.GetComponent<SphereShape>().enabled = true;
conversationInfoToCorrespondingSpawnedGameObject[info] = recorderObject;
break;
} }
else
{
var up = recorderObject.transform.position - planetGO.transform.position;
recorderObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, up) * recorderObject.transform.rotation;
}
var nomaiText = recorderObject.GetComponentInChildren<NomaiText>();
nomaiText.SetSector(sector);
nomaiText._dictNomaiTextData = MakeNomaiTextDict(xmlPath);
nomaiText._nomaiTextAsset = new TextAsset(xmlPath);
AddTranslation(xmlPath);
// Make sure the recorder model is loaded
OWAssetHandler.LoadObject(recorderObject);
sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(recorderObject));
recorderObject.SetActive(true);
recorderObject.transform.Find("InteractSphere").gameObject.GetComponent<SphereShape>().enabled = true;
conversationInfoToCorrespondingSpawnedGameObject[info] = recorderObject;
break;
}
default: default:
Logger.LogError($"Unsupported NomaiText type {info.type}"); Logger.LogError($"Unsupported NomaiText type {info.type}");
break; break;
@ -306,6 +310,7 @@ namespace NewHorizons.Builder.Props
var nomaiWallText = nomaiWallTextObj.AddComponent<NomaiWallText>(); var nomaiWallText = nomaiWallTextObj.AddComponent<NomaiWallText>();
var text = new TextAsset(xmlPath); var text = new TextAsset(xmlPath);
text.name = Path.GetFileNameWithoutExtension(info.xmlFile);
BuildArcs(xmlPath, nomaiWallText, nomaiWallTextObj, info); BuildArcs(xmlPath, nomaiWallText, nomaiWallTextObj, info);
AddTranslation(xmlPath); AddTranslation(xmlPath);