Handle potentially missing ship log canvas

This commit is contained in:
Joshua Thome 2022-07-29 14:22:20 -05:00
parent 5d1a16f572
commit e74dbfb863

View File

@ -20,32 +20,40 @@ namespace NewHorizons.Handlers
var shipLogRoot = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas"); var shipLogRoot = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas");
var starChartLog = new GameObject("StarChartMode"); if (shipLogRoot != null)
starChartLog.SetActive(false); {
starChartLog.transform.parent = shipLogRoot.transform; var starChartLog = new GameObject("StarChartMode");
starChartLog.transform.localScale = Vector3.one * 1f; starChartLog.SetActive(false);
starChartLog.transform.localPosition = Vector3.zero; starChartLog.transform.parent = shipLogRoot.transform;
starChartLog.transform.localRotation = Quaternion.Euler(0, 0, 0); starChartLog.transform.localScale = Vector3.one * 1f;
starChartLog.transform.localPosition = Vector3.zero;
starChartLog.transform.localRotation = Quaternion.Euler(0, 0, 0);
ShipLogStarChartMode = starChartLog.AddComponent<ShipLogStarChartMode>(); ShipLogStarChartMode = starChartLog.AddComponent<ShipLogStarChartMode>();
var reticleImage = GameObject.Instantiate(SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ReticleImage (1)/"), starChartLog.transform); var reticleImage = GameObject.Instantiate(SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ReticleImage (1)/"), starChartLog.transform);
var scaleRoot = new GameObject("ScaleRoot"); var scaleRoot = new GameObject("ScaleRoot");
scaleRoot.transform.parent = starChartLog.transform; scaleRoot.transform.parent = starChartLog.transform;
scaleRoot.transform.localScale = Vector3.one; scaleRoot.transform.localScale = Vector3.one;
scaleRoot.transform.localPosition = Vector3.zero; scaleRoot.transform.localPosition = Vector3.zero;
scaleRoot.transform.localRotation = Quaternion.Euler(0, 0, 0); scaleRoot.transform.localRotation = Quaternion.Euler(0, 0, 0);
var panRoot = new GameObject("PanRoot"); var panRoot = new GameObject("PanRoot");
panRoot.transform.parent = scaleRoot.transform; panRoot.transform.parent = scaleRoot.transform;
panRoot.transform.localScale = Vector3.one; panRoot.transform.localScale = Vector3.one;
panRoot.transform.localPosition = Vector3.zero; panRoot.transform.localPosition = Vector3.zero;
panRoot.transform.localRotation = Quaternion.Euler(0, 0, 0); panRoot.transform.localRotation = Quaternion.Euler(0, 0, 0);
var centerPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_Center")?.GetComponent<ScreenPromptList>(); var centerPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_Center")?.GetComponent<ScreenPromptList>();
var upperRightPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_UpperRight")?.GetComponent<ScreenPromptList>(); var upperRightPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_UpperRight")?.GetComponent<ScreenPromptList>();
var oneShotSource = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/OneShotAudio_ShipLog")?.GetComponent<OWAudioSource>(); var oneShotSource = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/OneShotAudio_ShipLog")?.GetComponent<OWAudioSource>();
ShipLogStarChartMode.Initialize(
centerPromptList,
upperRightPromptList,
oneShotSource);
}
_starSystemToFactID = new Dictionary<string, string>(); _starSystemToFactID = new Dictionary<string, string>();
_factIDToStarSystem = new Dictionary<string, string>(); _factIDToStarSystem = new Dictionary<string, string>();
@ -57,11 +65,6 @@ namespace NewHorizons.Handlers
RegisterFactForSystem(system.Config.factRequiredForWarp, system.UniqueID); RegisterFactForSystem(system.Config.factRequiredForWarp, system.UniqueID);
} }
} }
ShipLogStarChartMode.Initialize(
centerPromptList,
upperRightPromptList,
oneShotSource);
} }
public static bool CanWarp() public static bool CanWarp()
@ -98,8 +101,10 @@ namespace NewHorizons.Handlers
if (_factIDToStarSystem.TryGetValue(factID, out var systemUnlocked)) if (_factIDToStarSystem.TryGetValue(factID, out var systemUnlocked))
{ {
Logger.Log($"Just learned [{factID}] and unlocked [{systemUnlocked}]"); Logger.Log($"Just learned [{factID}] and unlocked [{systemUnlocked}]");
if (!Main.HasWarpDrive) Main.Instance.EnableWarpDrive(); if (!Main.HasWarpDrive)
ShipLogStarChartMode.AddSystemCard(systemUnlocked); Main.Instance.EnableWarpDrive();
if (ShipLogStarChartMode != null)
ShipLogStarChartMode.AddSystemCard(systemUnlocked);
} }
} }