diff --git a/NewHorizons/Builder/Body/RingBuilder.cs b/NewHorizons/Builder/Body/RingBuilder.cs index a0918a56..40d5953f 100644 --- a/NewHorizons/Builder/Body/RingBuilder.cs +++ b/NewHorizons/Builder/Body/RingBuilder.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using NewHorizons.External.Modules; using UnityEngine; using Logger = NewHorizons.Utility.Logger; +using NewHorizons.Components.Volumes; namespace NewHorizons.Builder.Body { diff --git a/NewHorizons/Builder/Body/SingularityBuilder.cs b/NewHorizons/Builder/Body/SingularityBuilder.cs index 263eae4f..fe135a1f 100644 --- a/NewHorizons/Builder/Body/SingularityBuilder.cs +++ b/NewHorizons/Builder/Body/SingularityBuilder.cs @@ -1,4 +1,3 @@ -using NewHorizons.Components; using NewHorizons.External.Configs; using NewHorizons.Utility; using System; @@ -10,6 +9,7 @@ using System.Linq; using NewHorizons.Components.SizeControllers; using System.Drawing; using Color = UnityEngine.Color; +using NewHorizons.Components.Volumes; namespace NewHorizons.Builder.Body { diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index af2cf59f..761d2397 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -1,4 +1,3 @@ -using NewHorizons.Components; using NewHorizons.Components.SizeControllers; using NewHorizons.Utility; using OWML.Utils; @@ -9,6 +8,7 @@ using OWML.ModHelper; using OWML.Common; using UnityEngine.InputSystem.XR; using System.Linq; +using NewHorizons.Components.Stars; namespace NewHorizons.Builder.Body { @@ -157,7 +157,6 @@ namespace NewHorizons.Builder.Body light.CopyPropertiesFrom(_sunLight.GetComponent()); light.intensity *= starModule.solarLuminosity; light.range = starModule.lightRadius; - light.range *= Mathf.Sqrt(starModule.solarLuminosity); Color lightColour = light.color; if (starModule.lightTint != null) lightColour = starModule.lightTint.ToColor(); diff --git a/NewHorizons/Builder/Body/WaterBuilder.cs b/NewHorizons/Builder/Body/WaterBuilder.cs index ef55887a..a004b763 100644 --- a/NewHorizons/Builder/Body/WaterBuilder.cs +++ b/NewHorizons/Builder/Body/WaterBuilder.cs @@ -1,9 +1,9 @@ -using NewHorizons.Components; using NewHorizons.Components.SizeControllers; using NewHorizons.Utility; using UnityEngine; using NewHorizons.External.Modules.VariableSize; using Tessellation; +using NewHorizons.Components.Volumes; namespace NewHorizons.Builder.Body { diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 25e22eb2..660956b6 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -1,4 +1,3 @@ -using NewHorizons.Builder.General; using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Handlers; @@ -80,7 +79,7 @@ namespace NewHorizons.Builder.Props } else FixSectoredComponent(component, sector, isTorch); - FixComponent(component, go, prefab.name); + FixComponent(component, go); } prop.transform.position = detail.position == null ? go.transform.position : go.transform.TransformPoint(detail.position); @@ -101,7 +100,6 @@ namespace NewHorizons.Builder.Props prop.transform.localScale = detail.scale != 0 ? Vector3.one * detail.scale : prefab.transform.localScale; - if (!detail.keepLoaded) GroupsBuilder.Make(prop, sector); prop.SetActive(true); if (prop == null) return null; @@ -224,11 +222,11 @@ namespace NewHorizons.Builder.Props return false; } - private static void FixComponent(Component component, GameObject planetGO, string prefab) + private static void FixComponent(Component component, GameObject planetGO) { // Fix other components // I forget why this is here - if (component is GhostIK || component is GhostEffects) + if (component is GhostIK or GhostEffects) { Component.DestroyImmediate(component); return; @@ -280,43 +278,52 @@ namespace NewHorizons.Builder.Props torchItem.mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); } - // Fix a bunch of stuff when done loading - Delay.RunWhen(() => Main.IsSystemReady, () => + if (component is Animator animator) animator.enabled = true; + if (component is Collider collider) collider.enabled = true; + if (component is Renderer renderer) renderer.enabled = true; + if (component is Shape shape) shape.enabled = true; + + // fixes sector cull group deactivating renderers on map view enter and fast foward + // TODO: does this actually work? what? how? + if (component is SectorCullGroup sectorCullGroup) { - try + sectorCullGroup._inMapView = false; + sectorCullGroup._isFastForwarding = false; + sectorCullGroup.SetVisible(sectorCullGroup.ShouldBeVisible(), true, false); + } + + // If it's not a moving anglerfish make sure the anim controller is regular + if (component is AnglerfishAnimController && component.GetComponentInParent() == null) + component.gameObject.AddComponent(); + } + + /// + /// Has to happen after AnglerfishAnimController awake to remove the events it has set up. + /// Otherwise results in the anglerfish 1) having its animations controlled by an actual fish 2) randomly having different animations on solarsystem load + /// Can't do delay because it needs to work with scatter (copies a prefab made using MakeDetail). + /// + [RequireComponent(typeof(AnglerfishAnimController))] + private class AnglerAnimFixer : MonoBehaviour + { + private void Start() + { + var angler = GetComponent(); + + Logger.LogVerbose("Fixing anglerfish animation"); + + // Remove any event reference to its angler + if (angler._anglerfishController) { - if (component == null) return; - if (component is Animator animator) animator.enabled = true; - else if (component is Collider collider) collider.enabled = true; - else if (component is Renderer renderer) renderer.enabled = true; - else if (component is Shape shape) shape.enabled = true; - else if (component is SectorCullGroup sectorCullGroup) - { - sectorCullGroup._inMapView = false; - sectorCullGroup._isFastForwarding = false; - sectorCullGroup.SetVisible(sectorCullGroup.ShouldBeVisible(), true, false); - } - // If it's not a moving anglerfish make sure the anim controller is regular - else if (component is AnglerfishAnimController angler && angler.GetComponentInParent() == null) - { - Logger.LogVerbose("Enabling anglerfish animation"); - // Remove any reference to its angler - if (angler._anglerfishController) - { - angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; - angler._anglerfishController.OnAnglerTurn -= angler.OnAnglerTurn; - angler._anglerfishController.OnAnglerSuspended -= angler.OnAnglerSuspended; - angler._anglerfishController.OnAnglerUnsuspended -= angler.OnAnglerUnsuspended; - } - angler.enabled = true; - angler.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); - } + angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; + angler._anglerfishController.OnAnglerTurn -= angler.OnAnglerTurn; + angler._anglerfishController.OnAnglerSuspended -= angler.OnAnglerSuspended; + angler._anglerfishController.OnAnglerUnsuspended -= angler.OnAnglerUnsuspended; } - catch (Exception e) - { - Logger.LogWarning($"Exception when modifying component [{component.GetType().Name}] on [{planetGO.name}] for prop [{prefab}]:\n{e}"); - } - }); + angler.enabled = true; + angler.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); + + Destroy(this); + } } } } \ No newline at end of file diff --git a/NewHorizons/Builder/Props/QuantumBuilder.cs b/NewHorizons/Builder/Props/QuantumBuilder.cs index 16484b8f..3dd81c3b 100644 --- a/NewHorizons/Builder/Props/QuantumBuilder.cs +++ b/NewHorizons/Builder/Props/QuantumBuilder.cs @@ -1,5 +1,5 @@ using HarmonyLib; -using NewHorizons.Components; +using NewHorizons.Components.Quantum; using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Utility; diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index c2f36e42..742f1b65 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -1,4 +1,5 @@ using NewHorizons.Components; +using NewHorizons.Components.Volumes; using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index 3ce71605..a92ebd9b 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -3,6 +3,8 @@ using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; using System; +using System.Collections.Generic; +using System.Linq; using UnityEngine; using Object = UnityEngine.Object; using Random = UnityEngine.Random; @@ -19,13 +21,20 @@ namespace NewHorizons.Builder.Props { var heightMap = config.HeightMap; - var area = 4f * Mathf.PI * radius * radius; + var makeFibonacciSphere = scatterInfo.Any(x => x.preventOverlap); - // To not use more than 0.5GB of RAM while doing this - // Works up to planets with 575 radius before capping - var numPoints = Math.Min((int)(area * 10), 41666666); + List points = new(); - var points = RandomUtility.FibonacciSphere(numPoints); + if (makeFibonacciSphere) + { + var area = 4f * Mathf.PI * radius * radius; + + // To not use more than 0.5GB of RAM while doing this + // Works up to planets with 575 radius before capping + var numPoints = Math.Min((int)(area * 10), 41666666); + + points = RandomUtility.FibonacciSphere(numPoints); + } Texture2D heightMapTexture = null; if (heightMap != null) @@ -55,13 +64,29 @@ namespace NewHorizons.Builder.Props GameObject prefab; if (propInfo.assetBundle != null) prefab = AssetBundleUtilities.LoadPrefab(propInfo.assetBundle, propInfo.path, mod); else prefab = SearchUtilities.Find(propInfo.path); + + // Run all the make detail stuff on it early and just copy it over and over instead + var detailInfo = new PropModule.DetailInfo() + { + scale = propInfo.scale, + keepLoaded = propInfo.keepLoaded + }; + var scatterPrefab = DetailBuilder.Make(go, sector, prefab, detailInfo); + for (int i = 0; i < propInfo.count; i++) { - // Failsafe - if (points.Count == 0) break; - - var randomInd = (int)Random.Range(0, points.Count - 1); - var point = points[randomInd]; + Vector3 point; + if (propInfo.preventOverlap) + { + if (points.Count == 0) break; + var randomInd = Random.Range(0, points.Count - 1); + point = points[randomInd]; + points.QuickRemoveAt(randomInd); + } + else + { + point = Random.onUnitSphere; + } var height = radius; if (heightMapTexture != null) @@ -92,14 +117,11 @@ namespace NewHorizons.Builder.Props point = Quaternion.Euler(90, 0, 0) * point; } - var detailInfo = new PropModule.DetailInfo() - { - position = point.normalized * height, - scale = propInfo.scale, - keepLoaded = propInfo.keepLoaded, - alignToNormal = true - }; - var prop = DetailBuilder.Make(go, sector, prefab, detailInfo); + var prop = scatterPrefab.InstantiateInactive(); + prop.transform.SetParent(sector?.transform ?? go.transform); + prop.transform.localPosition = go.transform.TransformPoint(point * height); + var up = go.transform.InverseTransformPoint(prop.transform.position).normalized; + prop.transform.rotation = Quaternion.FromToRotation(Vector3.up, up); if (propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset); if (propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation); @@ -107,9 +129,10 @@ namespace NewHorizons.Builder.Props // Rotate around normal prop.transform.localRotation *= Quaternion.AngleAxis(Random.Range(0, 360), Vector3.up); - points.QuickRemoveAt(randomInd); - if (points.Count == 0) return; + prop.SetActive(true); } + + GameObject.Destroy(scatterPrefab); } } } diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 12e55581..0eaf91aa 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -1,4 +1,3 @@ -using NewHorizons.Components; using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; @@ -9,6 +8,8 @@ using NewHorizons.External.Modules.VariableSize; using UnityEngine; using UnityEngine.UI; using Logger = NewHorizons.Utility.Logger; +using NewHorizons.Components.ShipLog; + namespace NewHorizons.Builder.ShipLog { public static class MapModeBuilder diff --git a/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs b/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs index 13386e79..dab95143 100644 --- a/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs @@ -1,4 +1,3 @@ -using NewHorizons.Components; using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; @@ -9,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using UnityEngine; using Logger = NewHorizons.Utility.Logger; -using NHNotificationVolume = NewHorizons.Components.NotificationVolume; +using NHNotificationVolume = NewHorizons.Components.Volumes.NotificationVolume; namespace NewHorizons.Builder.Volumes { diff --git a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs index 9e9a9c36..9b13db4f 100644 --- a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs +++ b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs @@ -1,7 +1,7 @@ using NewHorizons.Builder.Body; using NewHorizons.Builder.ShipLog; using NewHorizons.Builder.Volumes; -using NewHorizons.Components; +using NewHorizons.Components.Volumes; using NewHorizons.External.Configs; using OWML.Common; using System; @@ -61,7 +61,7 @@ namespace NewHorizons.Builder.Volumes { foreach (var interferenceVolume in config.Volumes.interferenceVolumes) { - VolumeBuilder.Make(go, sector, interferenceVolume); + VolumeBuilder.Make(go, sector, interferenceVolume); } } if (config.Volumes.reverbVolumes != null) diff --git a/NewHorizons/Components/MapSatelliteOrbitFix.cs b/NewHorizons/Components/Fixers/MapSatelliteOrbitFix.cs similarity index 94% rename from NewHorizons/Components/MapSatelliteOrbitFix.cs rename to NewHorizons/Components/Fixers/MapSatelliteOrbitFix.cs index 1e8e0778..4b1a9b30 100644 --- a/NewHorizons/Components/MapSatelliteOrbitFix.cs +++ b/NewHorizons/Components/Fixers/MapSatelliteOrbitFix.cs @@ -1,7 +1,7 @@ using NewHorizons.Builder.General; using NewHorizons.External.Configs; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Fixers { public class MapSatelliteOrbitFix : MonoBehaviour { diff --git a/NewHorizons/Components/NHMultiStateQuantumObject.cs b/NewHorizons/Components/Quantum/NHMultiStateQuantumObject.cs similarity index 54% rename from NewHorizons/Components/NHMultiStateQuantumObject.cs rename to NewHorizons/Components/Quantum/NHMultiStateQuantumObject.cs index 6c73cef5..4abd57b1 100644 --- a/NewHorizons/Components/NHMultiStateQuantumObject.cs +++ b/NewHorizons/Components/Quantum/NHMultiStateQuantumObject.cs @@ -7,60 +7,60 @@ using UnityEngine; using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Components +namespace NewHorizons.Components.Quantum { public class NHMultiStateQuantumObject : MultiStateQuantumObject { - - public override bool ChangeQuantumState(bool skipInstantVisibilityCheck) - { - for (int i = 0; i < _prerequisiteObjects.Length; i++) - { - if (!_prerequisiteObjects[i].HasCollapsed()) - { - return false; - } - } - int stateIndex = _stateIndex; - if (_stateIndex == -1 && _initialState != -1) - { - _stateIndex = _initialState; - } - else if (_sequential) - { - _stateIndex = (_reverse ? (_stateIndex - 1) : (_stateIndex + 1)); - if (_loop) - { - if (_stateIndex < 0) - { - _stateIndex = _states.Length - 1; - } - else if (_stateIndex > _states.Length - 1) - { - _stateIndex = 0; - } - } - else - { - _stateIndex = Mathf.Clamp(_stateIndex, 0, _states.Length - 1); - } - } - else - { + + public override bool ChangeQuantumState(bool skipInstantVisibilityCheck) + { + for (int i = 0; i < _prerequisiteObjects.Length; i++) + { + if (!_prerequisiteObjects[i].HasCollapsed()) + { + return false; + } + } + int stateIndex = _stateIndex; + if (_stateIndex == -1 && _initialState != -1) + { + _stateIndex = _initialState; + } + else if (_sequential) + { + _stateIndex = _reverse ? _stateIndex - 1 : _stateIndex + 1; + if (_loop) + { + if (_stateIndex < 0) + { + _stateIndex = _states.Length - 1; + } + else if (_stateIndex > _states.Length - 1) + { + _stateIndex = 0; + } + } + else + { + _stateIndex = Mathf.Clamp(_stateIndex, 0, _states.Length - 1); + } + } + else + { // TODO: perform this roll for number of states, each time adding the selected state to the end of a list and removing it from the source list // this gets us a randomly ordered list that respects states' probability // then we can sequentially attempt collapsing to them, checking at each state whether the new state is invalid due to the player being able to see it, according to this: // // if (!((!IsPlayerEntangled()) ? (CheckIllumination() ? CheckVisibilityInstantly() : CheckPointInside(Locator.GetPlayerCamera().transform.position)) : CheckIllumination())) - // { - // return true; // this is a valid state - // } + // { + // return true; // this is a valid state + // } // List indices = new List(); for (var i = 0; i < _states.Length; i++) if (i != stateIndex) indices.Add(i); - + var previousIndex = stateIndex; do @@ -69,31 +69,31 @@ namespace NewHorizons.Components _stateIndex = RollState(stateIndex, indices); if (previousIndex >= 0 && previousIndex < _states.Length) _states[previousIndex].SetVisible(visible: false); _states[_stateIndex].SetVisible(visible: true); - + Logger.LogVerbose($"MultiStateQuantumObject - Trying to change state {_stateIndex}"); indices.Remove(_stateIndex); } while (!CurrentStateIsValid() && indices.Count > 0); - } + } var stateIndexIsValid = stateIndex >= 0 && stateIndex < _states.Length; - if (stateIndexIsValid) _states[stateIndex].SetVisible(visible: false); + if (stateIndexIsValid) _states[stateIndex].SetVisible(visible: false); - _states[_stateIndex].SetVisible(visible: true); + _states[_stateIndex].SetVisible(visible: true); if (!CurrentStateIsValid() && stateIndexIsValid) { - _states[_stateIndex].SetVisible(visible: false); - _states[stateIndex] .SetVisible(visible: true); - _stateIndex = stateIndex; + _states[_stateIndex].SetVisible(visible: false); + _states[stateIndex].SetVisible(visible: true); + _stateIndex = stateIndex; return false; } - if (_sequential && !_loop && _stateIndex == _states.Length - 1) - { - SetActivation(active: false); - } - return true; - } + if (_sequential && !_loop && _stateIndex == _states.Length - 1) + { + SetActivation(active: false); + } + return true; + } public bool CurrentStateIsValid() { @@ -102,20 +102,20 @@ namespace NewHorizons.Components var visibility = CheckVisibilityInstantly(); var playerInside = CheckPointInside(Locator.GetPlayerCamera().transform.position); - var isVisible = + var isVisible = isPlayerEntangled ? illumination - : ( - illumination + : + illumination ? visibility : playerInside - ); + ; return !isVisible; } public int RollState(int excludeIndex, List indices) - { + { var stateIndex = excludeIndex; // this function constructs a sort of segmented range: @@ -132,32 +132,32 @@ namespace NewHorizons.Components // // the second for looop uses num3 and num4 to figure out which segment num2 landed in - int num = 0; - foreach (int j in indices) - { - if (j != stateIndex) - { - _probabilities[j] = _states[j].GetProbability(); - num += _probabilities[j]; - } - } - int num2 = UnityEngine.Random.Range(0, num); - int num3 = 0; - int num4 = 0; - foreach (int k in indices) - { - if (k != stateIndex) - { - num3 = num4; - num4 += _probabilities[k]; - if (_probabilities[k] > 0 && num2 >= num3 && num2 < num4) - { - return k; - } - } - } + int num = 0; + foreach (int j in indices) + { + if (j != stateIndex) + { + _probabilities[j] = _states[j].GetProbability(); + num += _probabilities[j]; + } + } + int num2 = UnityEngine.Random.Range(0, num); + int num3 = 0; + int num4 = 0; + foreach (int k in indices) + { + if (k != stateIndex) + { + num3 = num4; + num4 += _probabilities[k]; + if (_probabilities[k] > 0 && num2 >= num3 && num2 < num4) + { + return k; + } + } + } - return indices[indices.Count-1]; + return indices[indices.Count - 1]; } } } diff --git a/NewHorizons/Components/QuantumPlanet.cs b/NewHorizons/Components/Quantum/QuantumPlanet.cs similarity index 98% rename from NewHorizons/Components/QuantumPlanet.cs rename to NewHorizons/Components/Quantum/QuantumPlanet.cs index 2b853b76..568a364b 100644 --- a/NewHorizons/Components/QuantumPlanet.cs +++ b/NewHorizons/Components/Quantum/QuantumPlanet.cs @@ -9,7 +9,7 @@ using System.Linq; using UnityEngine; using Logger = NewHorizons.Utility.Logger; using Random = UnityEngine.Random; -namespace NewHorizons.Components +namespace NewHorizons.Components.Quantum { public class QuantumPlanet : QuantumObject { @@ -162,9 +162,9 @@ namespace NewHorizons.Components private void OnPlayerBlink() { - if (base.IsVisible()) + if (IsVisible()) { - base.Collapse(true); + Collapse(true); } } diff --git a/NewHorizons/Components/RingOpacityController.cs b/NewHorizons/Components/RingOpacityController.cs index fde75452..df707a33 100644 --- a/NewHorizons/Components/RingOpacityController.cs +++ b/NewHorizons/Components/RingOpacityController.cs @@ -1,3 +1,4 @@ +using NewHorizons.Components.Volumes; using NewHorizons.External.Modules.VariableSize; using NewHorizons.Utility; using UnityEngine; diff --git a/NewHorizons/Components/ShipLogDetail.cs b/NewHorizons/Components/ShipLog/ShipLogDetail.cs similarity index 92% rename from NewHorizons/Components/ShipLogDetail.cs rename to NewHorizons/Components/ShipLog/ShipLogDetail.cs index a2ce809d..3852ff88 100644 --- a/NewHorizons/Components/ShipLogDetail.cs +++ b/NewHorizons/Components/ShipLog/ShipLogDetail.cs @@ -1,8 +1,8 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; using UnityEngine; using UnityEngine.UI; using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Components +namespace NewHorizons.Components.ShipLog { public class ShipLogDetail : MonoBehaviour { @@ -51,7 +51,7 @@ namespace NewHorizons.Components private void SetGreyScale(bool greyScale) { - _revealedImage.material = (greyScale ? _greyScaleMaterial : null); + _revealedImage.material = greyScale ? _greyScaleMaterial : null; } } } \ No newline at end of file diff --git a/NewHorizons/Components/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs similarity index 95% rename from NewHorizons/Components/ShipLogStarChartMode.cs rename to NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs index b36f8cac..f20769ec 100644 --- a/NewHorizons/Components/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs @@ -6,7 +6,7 @@ using System.Linq; using UnityEngine; using UnityEngine.UI; using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Components +namespace NewHorizons.Components.ShipLog { public class ShipLogStarChartMode : ShipLogMode { @@ -41,7 +41,7 @@ namespace NewHorizons.Components public override void Initialize(ScreenPromptList centerPromptList, ScreenPromptList upperRightPromptList, OWAudioSource oneShotSource) { - root = base.transform.Find("ScaleRoot/PanRoot"); + root = transform.Find("ScaleRoot/PanRoot"); _oneShotSource = oneShotSource; _centerPromptList = centerPromptList; @@ -100,11 +100,11 @@ namespace NewHorizons.Components if (_cardTemplate == null) { var panRoot = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ScaleRoot/PanRoot"); - _cardTemplate = GameObject.Instantiate(panRoot.GetComponentInChildren().gameObject); + _cardTemplate = Instantiate(panRoot.GetComponentInChildren().gameObject); _cardTemplate.SetActive(false); } - var newCard = GameObject.Instantiate(_cardTemplate, parent); + var newCard = Instantiate(_cardTemplate, parent); var textComponent = newCard.transform.Find("EntryCardRoot/NameBackground/Name").GetComponent(); var name = UniqueIDToName(uniqueID); @@ -167,7 +167,7 @@ namespace NewHorizons.Components public override void EnterMode(string entryID = "", List revealQueue = null) { - base.gameObject.SetActive(true); + gameObject.SetActive(true); Locator.GetPromptManager().AddScreenPrompt(_detectiveModePrompt, _upperRightPromptList, TextAnchor.MiddleRight, -1, true); Locator.GetPromptManager().AddScreenPrompt(_targetSystemPrompt, _centerPromptList, TextAnchor.MiddleCenter, -1, true); @@ -175,7 +175,7 @@ namespace NewHorizons.Components public override void ExitMode() { - base.gameObject.SetActive(false); + gameObject.SetActive(false); Locator.GetPromptManager().RemoveScreenPrompt(_detectiveModePrompt); Locator.GetPromptManager().RemoveScreenPrompt(_targetSystemPrompt); @@ -226,7 +226,7 @@ namespace NewHorizons.Components if (oldIndex != _cardIndex) { - _oneShotSource.PlayOneShot(global::AudioType.ShipLogMoveBetweenPlanets, 1f); + _oneShotSource.PlayOneShot(AudioType.ShipLogMoveBetweenPlanets, 1f); _startPanTime = Time.unscaledTime; _startPanPos = _panRootPos; _panDuration = 0.25f; @@ -300,7 +300,7 @@ namespace NewHorizons.Components { if (_warpNotificationData != null) NotificationManager.SharedInstance.UnpinNotification(_warpNotificationData); if (_target == null) return; - if (playSound) _oneShotSource.PlayOneShot(global::AudioType.ShipLogMarkLocation, 1f); + if (playSound) _oneShotSource.PlayOneShot(AudioType.ShipLogMarkLocation, 1f); _target.SetMarkedOnHUD(false); _target = null; } diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index f84cf676..77289286 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -1,5 +1,6 @@ using NewHorizons.Builder.Body; using NewHorizons.Components.Orbital; +using NewHorizons.Components.Stars; using NewHorizons.External.Modules.VariableSize; using NewHorizons.Handlers; using NewHorizons.Utility; @@ -286,7 +287,9 @@ namespace NewHorizons.Components.SizeControllers { _stellarRemnant.SetActive(true); var remnantStarController = _stellarRemnant.GetComponentInChildren(); - if (remnantStarController != null) StarLightController.AddStar(remnantStarController); + if (remnantStarController != null) SunLightEffectsController.AddStar(remnantStarController); + var remnantStarLight = _stellarRemnant.FindChild("SunLight"); + if (remnantStarLight != null) SunLightEffectsController.AddStarLight(remnantStarLight.GetComponent()); } if (Time.time > _supernovaStartTime + supernovaTime) @@ -299,7 +302,8 @@ namespace NewHorizons.Components.SizeControllers private void DisableStar(bool start = false) { - if (controller != null) StarLightController.RemoveStar(controller); + if (controller != null) SunLightEffectsController.RemoveStar(controller); + if (!isProxy) SunLightEffectsController.RemoveStarLight(gameObject.FindChild("SunLight").GetComponent()); if (_stellarRemnant != null) { diff --git a/NewHorizons/Components/StarLightController.cs b/NewHorizons/Components/StarLightController.cs deleted file mode 100644 index 55a79074..00000000 --- a/NewHorizons/Components/StarLightController.cs +++ /dev/null @@ -1,129 +0,0 @@ -using NewHorizons.Builder.Atmosphere; -using System.Collections.Generic; -using UnityEngine; -using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Components -{ - [RequireComponent(typeof(SunLightController))] - [RequireComponent(typeof(SunLightParamUpdater))] - public class StarLightController : MonoBehaviour - { - private static readonly int SunIntensity = Shader.PropertyToID("_SunIntensity"); - private static readonly float hearthSunDistanceSqr = 8593 * 8593; - - public static StarLightController Instance { get; private set; } - - private List _stars = new List(); - private StarController _activeStar; - - private SunLightController _sunLightController; - private SunLightParamUpdater _sunLightParamUpdater; - - public void Awake() - { - Instance = this; - _sunLightController = GetComponent(); - _sunLightController.enabled = true; - _sunLightParamUpdater = GetComponent(); - _sunLightParamUpdater._sunLightController = _sunLightController; - } - - public static void AddStar(StarController star) - { - if (star == null) return; - - Logger.LogVerbose($"Adding new star to list: {star.gameObject.name}"); - Instance._stars.Add(star); - } - - public static void RemoveStar(StarController star) - { - Logger.LogVerbose($"Removing star from list: {star?.gameObject?.name}"); - if (Instance._stars.Contains(star)) - { - if (Instance._activeStar != null && Instance._activeStar.Equals(star)) - { - Instance._stars.Remove(star); - if (Instance._stars.Count > 0) Instance.ChangeActiveStar(Instance._stars[0]); - } - else - { - Instance._stars.Remove(star); - } - } - } - - public void Update() - { - if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy) - { - if (_stars.Contains(_activeStar)) _stars.Remove(_activeStar); - if (_stars.Count > 0) ChangeActiveStar(_stars[0]); - else gameObject.SetActive(false); - - foreach (var (_, material) in AtmosphereBuilder.Skys) - { - material.SetFloat(SunIntensity, 0); - } - - return; - } - - // Update atmo shaders - foreach (var (planet, material) in AtmosphereBuilder.Skys) - { - var sqrDist = (planet.transform.position - _activeStar.transform.position).sqrMagnitude; - var intensity = Mathf.Min(_activeStar.Intensity / (sqrDist / hearthSunDistanceSqr), 1f); - - material.SetFloat(SunIntensity, intensity); - } - - foreach (var star in _stars) - { - if (star == null) continue; - if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue; - - // Player is always at 0,0,0 more or less so if they arent using the map camera then wtv - var origin = Vector3.zero; - if (PlayerState.InMapView()) - { - origin = Locator.GetActiveCamera().transform.position; - } - - if (star.Intensity * (star.transform.position - origin).sqrMagnitude < _activeStar.Intensity * (_activeStar.transform.position - origin).sqrMagnitude) - { - ChangeActiveStar(star); - break; - } - } - } - - private void ChangeActiveStar(StarController star) - { - if (_sunLightController == null || _sunLightParamUpdater == null) return; - - if (_activeStar != null) _activeStar.Disable(); - - Logger.LogVerbose($"Switching active star: {star.gameObject.name}"); - - _activeStar = star; - - star.Enable(); - - _sunLightController._sunBaseColor = star.SunColor; - _sunLightController._sunBaseIntensity = star.Intensity; - _sunLightController._sunLight = star.Light; - _sunLightController._ambientLight = star.AmbientLight; - - _sunLightParamUpdater.sunLight = star.Light; - _sunLightParamUpdater._sunController = star.transform.GetComponent(); - _sunLightParamUpdater._propID_SunPosition = Shader.PropertyToID("_SunPosition"); - _sunLightParamUpdater._propID_OWSunPositionRange = Shader.PropertyToID("_OWSunPositionRange"); - _sunLightParamUpdater._propID_OWSunColorIntensity = Shader.PropertyToID("_OWSunColorIntensity"); - - // For the param thing to work it wants this to be on the star idk - this.transform.parent = star.transform; - this.transform.localPosition = Vector3.zero; - } - } -} diff --git a/NewHorizons/Components/StarController.cs b/NewHorizons/Components/Stars/StarController.cs similarity index 94% rename from NewHorizons/Components/StarController.cs rename to NewHorizons/Components/Stars/StarController.cs index 8f69f085..374d4437 100644 --- a/NewHorizons/Components/StarController.cs +++ b/NewHorizons/Components/Stars/StarController.cs @@ -1,5 +1,5 @@ -using UnityEngine; -namespace NewHorizons.Components +using UnityEngine; +namespace NewHorizons.Components.Stars { public class StarController : MonoBehaviour { diff --git a/NewHorizons/Components/StarDestructionVolume.cs b/NewHorizons/Components/Stars/StarDestructionVolume.cs similarity index 98% rename from NewHorizons/Components/StarDestructionVolume.cs rename to NewHorizons/Components/Stars/StarDestructionVolume.cs index e0068d24..5354821a 100644 --- a/NewHorizons/Components/StarDestructionVolume.cs +++ b/NewHorizons/Components/Stars/StarDestructionVolume.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Stars { public class StarDestructionVolume : DestructionVolume { diff --git a/NewHorizons/Components/StarFluidVolume.cs b/NewHorizons/Components/Stars/StarFluidVolume.cs similarity index 96% rename from NewHorizons/Components/StarFluidVolume.cs rename to NewHorizons/Components/Stars/StarFluidVolume.cs index 150d39f4..bd91f025 100644 --- a/NewHorizons/Components/StarFluidVolume.cs +++ b/NewHorizons/Components/Stars/StarFluidVolume.cs @@ -1,6 +1,6 @@ using NewHorizons.Components.SizeControllers; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Stars { public class StarFluidVolume : SimpleFluidVolume { diff --git a/NewHorizons/Components/StarSurfaceAudioController.cs b/NewHorizons/Components/Stars/StarSurfaceAudioController.cs similarity index 88% rename from NewHorizons/Components/StarSurfaceAudioController.cs rename to NewHorizons/Components/Stars/StarSurfaceAudioController.cs index aab8d3ce..71bdf525 100644 --- a/NewHorizons/Components/StarSurfaceAudioController.cs +++ b/NewHorizons/Components/Stars/StarSurfaceAudioController.cs @@ -1,7 +1,7 @@ using UnityEngine; using NewHorizons.Components.SizeControllers; -namespace NewHorizons.Components +namespace NewHorizons.Components.Stars { [RequireComponent(typeof(OWAudioSource))] public class StarSurfaceAudioController : SectoredMonoBehaviour @@ -34,7 +34,7 @@ namespace NewHorizons.Components public void Update() { _fade = Mathf.MoveTowards(_fade, 1, Time.deltaTime * 0.2f); - float value = Mathf.Max(0.0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, this.transform.position) - (_starEvolutionController != null ? _starEvolutionController.CurrentScale : _size)); + float value = Mathf.Max(0.0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, transform.position) - (_starEvolutionController != null ? _starEvolutionController.CurrentScale : _size)); float num = Mathf.InverseLerp(1600f, 100f, value); _audioSource.SetLocalVolume(num * num * _fade); } diff --git a/NewHorizons/Components/StellarDeathController.cs b/NewHorizons/Components/Stars/StellarDeathController.cs similarity index 88% rename from NewHorizons/Components/StellarDeathController.cs rename to NewHorizons/Components/Stars/StellarDeathController.cs index fe5dadb3..400297b3 100644 --- a/NewHorizons/Components/StellarDeathController.cs +++ b/NewHorizons/Components/Stars/StellarDeathController.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Stars { public class StellarDeathController : MonoBehaviour { @@ -22,6 +22,7 @@ namespace NewHorizons.Components private float _currentSupernovaScale; private Material _localSupernovaMat; private bool _isProxy; + private bool _renderingEnabled = true; private ParticleSystemRenderer[] _cachedParticleRenderers; public void Awake() @@ -34,8 +35,12 @@ namespace NewHorizons.Components public void Activate() { enabled = true; - shockwave.enabled = true; - foreach (var particle in explosionParticles) particle.Play(); + shockwave.enabled = _renderingEnabled; + for (int i = 0; i < explosionParticles.Length; i++) + { + explosionParticles[i].Play(); + _cachedParticleRenderers[i].enabled = _renderingEnabled; + } _time = 0.0f; _currentSupernovaScale = supernovaScale.Evaluate(0.0f); _localSupernovaMat = new Material(supernovaMaterial); @@ -71,7 +76,7 @@ namespace NewHorizons.Components surface.transform.localScale = Vector3.one * _currentSupernovaScale; _localSupernovaMat.color = Color.Lerp(Color.black, supernovaMaterial.color, supernovaAlpha.Evaluate(_time)); - float distanceToPlayer = PlayerState.InDreamWorld() ? 20000f : (Vector3.Distance(transform.position, Locator.GetPlayerCamera().transform.position) - GetSupernovaRadius()); + float distanceToPlayer = PlayerState.InDreamWorld() ? 20000f : Vector3.Distance(transform.position, Locator.GetPlayerCamera().transform.position) - GetSupernovaRadius(); if (_isProxy) return; @@ -97,6 +102,7 @@ namespace NewHorizons.Components public void SetRenderingEnabled(bool renderingEnabled) { + _renderingEnabled = renderingEnabled; if (!enabled) return; shockwave.enabled = renderingEnabled; SetParticlesVisibility(renderingEnabled); diff --git a/NewHorizons/Components/Stars/SunLightEffectsController.cs b/NewHorizons/Components/Stars/SunLightEffectsController.cs new file mode 100644 index 00000000..c5260e54 --- /dev/null +++ b/NewHorizons/Components/Stars/SunLightEffectsController.cs @@ -0,0 +1,191 @@ +using NewHorizons.Builder.Atmosphere; +using NewHorizons.Utility; +using System.Collections.Generic; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; +namespace NewHorizons.Components.Stars +{ + [RequireComponent(typeof(SunLightController))] + [RequireComponent(typeof(SunLightParamUpdater))] + public class SunLightEffectsController : MonoBehaviour + { + private static readonly int SunIntensity = Shader.PropertyToID("_SunIntensity"); + private static readonly float hearthSunDistanceSqr = 8593 * 8593; + + public static SunLightEffectsController Instance { get; private set; } + + private readonly List _stars = new(); + private readonly List _lights = new(); + + private StarController _activeStar; + private SunLightController _sunLightController; + private SunLightParamUpdater _sunLightParamUpdater; + + public void Awake() + { + Instance = this; + + _sunLightController = GetComponent(); + _sunLightController.enabled = true; + + _sunLightParamUpdater = GetComponent(); + _sunLightParamUpdater._sunLightController = _sunLightController; + } + + public void Start() + { + // Using GameObject.Find here so that if its null we just dont find it + var sunlight = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + if (sunlight != null) AddStarLight(sunlight); + } + + public static void AddStar(StarController star) + { + if (star == null) return; + + Logger.LogVerbose($"Adding new star to list: {star.gameObject.name}"); + Instance._stars.Add(star); + } + + public static void RemoveStar(StarController star) + { + Logger.LogVerbose($"Removing star from list: {star?.gameObject?.name}"); + if (Instance._stars.Contains(star)) + { + if (Instance._activeStar != null && Instance._activeStar.Equals(star)) + { + Instance._stars.Remove(star); + if (Instance._stars.Count > 0) Instance.ChangeActiveStar(Instance._stars[0]); + } + else + { + Instance._stars.Remove(star); + } + } + } + + public static void AddStarLight(Light light) + { + if (light != null) + { + Instance._lights.SafeAdd(light); + } + } + + public static void RemoveStarLight(Light light) + { + if (light != null && Instance._lights.Contains(light)) + { + Instance._lights.Remove(light); + } + } + + public void Update() + { + // Player is always at 0,0,0 more or less so if they arent using the map camera then wtv + var origin = Vector3.zero; + + if (PlayerState.InMapView()) + { + origin = Locator.GetActiveCamera().transform.position; + + // Keep all star lights on in map + foreach (var light in _lights) + { + light.enabled = true; + } + } + else + { + // Outside map, only show lights within 50km range or light.range + // For some reason outside of the actual range of the lights they still show reflection effects on water and glass + foreach (var light in _lights) + { + // Minimum 50km range so it's not badly noticeable for dim stars + if ((light.transform.position - origin).sqrMagnitude <= Mathf.Max(light.range * light.range, 2500000000)) + { + light.enabled = true; + } + else + { + light.enabled = false; + } + } + } + + if (_stars.Count > 0) + { + if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy) + { + if (_stars.Contains(_activeStar)) + { + _stars.Remove(_activeStar); + } + + if (_stars.Count > 0) + { + ChangeActiveStar(_stars[0]); + } + else + { + foreach (var (_, material) in AtmosphereBuilder.Skys) + { + material.SetFloat(SunIntensity, 0); + } + } + } + else + { + // Update atmo shaders + foreach (var (planet, material) in AtmosphereBuilder.Skys) + { + var sqrDist = (planet.transform.position - _activeStar.transform.position).sqrMagnitude; + var intensity = Mathf.Min(_activeStar.Intensity / (sqrDist / hearthSunDistanceSqr), 1f); + + material.SetFloat(SunIntensity, intensity); + } + + foreach (var star in _stars) + { + if (star == null) continue; + if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue; + + if (star.Intensity * (star.transform.position - origin).sqrMagnitude < _activeStar.Intensity * (_activeStar.transform.position - origin).sqrMagnitude) + { + ChangeActiveStar(star); + break; + } + } + } + } + } + + private void ChangeActiveStar(StarController star) + { + if (_sunLightController == null || _sunLightParamUpdater == null) return; + + if (_activeStar != null) _activeStar.Disable(); + + Logger.LogVerbose($"Switching active star: {star.gameObject.name}"); + + _activeStar = star; + + star.Enable(); + + _sunLightController._sunBaseColor = star.SunColor; + _sunLightController._sunBaseIntensity = star.Intensity; + _sunLightController._sunLight = star.Light; + _sunLightController._ambientLight = star.AmbientLight; + + _sunLightParamUpdater.sunLight = star.Light; + _sunLightParamUpdater._sunController = star.transform.GetComponent(); + _sunLightParamUpdater._propID_SunPosition = Shader.PropertyToID("_SunPosition"); + _sunLightParamUpdater._propID_OWSunPositionRange = Shader.PropertyToID("_OWSunPositionRange"); + _sunLightParamUpdater._propID_OWSunColorIntensity = Shader.PropertyToID("_OWSunColorIntensity"); + + // For the param thing to work it wants this to be on the star idk + transform.parent = star.transform; + transform.localPosition = Vector3.zero; + } + } +} diff --git a/NewHorizons/Components/BaseVolume.cs b/NewHorizons/Components/Volumes/BaseVolume.cs similarity index 95% rename from NewHorizons/Components/BaseVolume.cs rename to NewHorizons/Components/Volumes/BaseVolume.cs index 6ddccada..f313310c 100644 --- a/NewHorizons/Components/BaseVolume.cs +++ b/NewHorizons/Components/Volumes/BaseVolume.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { [RequireComponent(typeof(OWTriggerVolume))] public abstract class BaseVolume : MonoBehaviour diff --git a/NewHorizons/Components/BlackHoleDestructionVolume.cs b/NewHorizons/Components/Volumes/BlackHoleDestructionVolume.cs similarity index 84% rename from NewHorizons/Components/BlackHoleDestructionVolume.cs rename to NewHorizons/Components/Volumes/BlackHoleDestructionVolume.cs index 145a0c5c..e5489760 100644 --- a/NewHorizons/Components/BlackHoleDestructionVolume.cs +++ b/NewHorizons/Components/Volumes/BlackHoleDestructionVolume.cs @@ -1,6 +1,6 @@ using NewHorizons.OtherMods.AchievementsPlus.NH; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class BlackHoleDestructionVolume : DestructionVolume { @@ -15,7 +15,7 @@ namespace NewHorizons.Components SurveyorProbe requiredComponent = probeBody.GetRequiredComponent(); if (requiredComponent.IsLaunched()) { - UnityEngine.Object.Destroy(requiredComponent.gameObject); + Destroy(requiredComponent.gameObject); ProbeLostAchievement.Earn(); } } diff --git a/NewHorizons/Components/ChangeStarSystemVolume.cs b/NewHorizons/Components/Volumes/ChangeStarSystemVolume.cs similarity index 94% rename from NewHorizons/Components/ChangeStarSystemVolume.cs rename to NewHorizons/Components/Volumes/ChangeStarSystemVolume.cs index ea57c53f..bdf43aae 100644 --- a/NewHorizons/Components/ChangeStarSystemVolume.cs +++ b/NewHorizons/Components/Volumes/ChangeStarSystemVolume.cs @@ -1,4 +1,4 @@ -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class ChangeStarSystemVolume : BlackHoleDestructionVolume { diff --git a/NewHorizons/Components/InterferenceVolume.cs b/NewHorizons/Components/Volumes/InterferenceVolume.cs similarity index 97% rename from NewHorizons/Components/InterferenceVolume.cs rename to NewHorizons/Components/Volumes/InterferenceVolume.cs index 43cf34ac..acb3582f 100644 --- a/NewHorizons/Components/InterferenceVolume.cs +++ b/NewHorizons/Components/Volumes/InterferenceVolume.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class InterferenceVolume : BaseVolume { diff --git a/NewHorizons/Components/MapRestrictionVolume.cs b/NewHorizons/Components/Volumes/MapRestrictionVolume.cs similarity index 94% rename from NewHorizons/Components/MapRestrictionVolume.cs rename to NewHorizons/Components/Volumes/MapRestrictionVolume.cs index 04442840..ee31a2a2 100644 --- a/NewHorizons/Components/MapRestrictionVolume.cs +++ b/NewHorizons/Components/Volumes/MapRestrictionVolume.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class MapRestrictionVolume : BaseVolume { diff --git a/NewHorizons/Components/NHFluidVolume.cs b/NewHorizons/Components/Volumes/NHFluidVolume.cs similarity index 86% rename from NewHorizons/Components/NHFluidVolume.cs rename to NewHorizons/Components/Volumes/NHFluidVolume.cs index 3b19f04d..3b5a4a00 100644 --- a/NewHorizons/Components/NHFluidVolume.cs +++ b/NewHorizons/Components/Volumes/NHFluidVolume.cs @@ -1,5 +1,5 @@ -using UnityEngine; -namespace NewHorizons.Components +using UnityEngine; +namespace NewHorizons.Components.Volumes { public class NHFluidVolume : RadialFluidVolume { diff --git a/NewHorizons/Components/NHInnerFogWarpVolume.cs b/NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs similarity index 83% rename from NewHorizons/Components/NHInnerFogWarpVolume.cs rename to NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs index 61c5e3ea..70d74979 100644 --- a/NewHorizons/Components/NHInnerFogWarpVolume.cs +++ b/NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs @@ -1,4 +1,4 @@ -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class NHInnerFogWarpVolume : InnerFogWarpVolume { diff --git a/NewHorizons/Components/NotificationVolume.cs b/NewHorizons/Components/Volumes/NotificationVolume.cs similarity index 97% rename from NewHorizons/Components/NotificationVolume.cs rename to NewHorizons/Components/Volumes/NotificationVolume.cs index 6fe7b746..70543449 100644 --- a/NewHorizons/Components/NotificationVolume.cs +++ b/NewHorizons/Components/Volumes/NotificationVolume.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class NotificationVolume : BaseVolume { @@ -16,7 +16,7 @@ namespace NewHorizons.Components public void SetPinned(bool pin) => _pin = pin; - public void SetTarget(External.Modules.VolumesModule.NotificationVolumeInfo.NotificationTarget target) => SetTarget(EnumUtils.Parse(target.ToString(), NotificationTarget.All)); + public void SetTarget(External.Modules.VolumesModule.NotificationVolumeInfo.NotificationTarget target) => SetTarget(EnumUtils.Parse(target.ToString(), NotificationTarget.All)); public void SetTarget(NotificationTarget target) => _target = target; diff --git a/NewHorizons/Components/RingFluidVolume.cs b/NewHorizons/Components/Volumes/RingFluidVolume.cs similarity index 95% rename from NewHorizons/Components/RingFluidVolume.cs rename to NewHorizons/Components/Volumes/RingFluidVolume.cs index 83b377a7..66982bdc 100644 --- a/NewHorizons/Components/RingFluidVolume.cs +++ b/NewHorizons/Components/Volumes/RingFluidVolume.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class RingFluidVolume : SimpleFluidVolume { @@ -14,7 +14,7 @@ namespace NewHorizons.Components ForceDetector forceDetector = hitObj.GetComponent(); if (forceDetector != null && forceDetector._activeVolumes != null && forceDetector._activeVolumes.Count > 0 && forceDetector._activeVolumes.Where(activeVolume => activeVolume is ForceVolume).Select(activeVolume => activeVolume as ForceVolume).Any(activeVolume => activeVolume.GetAffectsAlignment(forceDetector._attachedBody))) return; - + fluidDetector.AddVolume(this); } diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index b02f762d..1644192d 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -139,6 +139,11 @@ namespace NewHorizons.External.Modules /// The highest height that these objects will be placed at (only relevant if there's a heightmap) /// public float? maxHeight; + + /// + /// Should we try to prevent overlap between the scattered details? True by default. If it's affecting load times turn it off. + /// + [DefaultValue(true)] public bool preventOverlap = true; /// /// Should this detail stay loaded even if you're outside the sector (good for very large props) diff --git a/NewHorizons/Handlers/InterferenceHandler.cs b/NewHorizons/Handlers/InterferenceHandler.cs index 3b9f374c..23495653 100644 --- a/NewHorizons/Handlers/InterferenceHandler.cs +++ b/NewHorizons/Handlers/InterferenceHandler.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace NewHorizons.Handlers { - using InterferenceVolume = NewHorizons.Components.InterferenceVolume; + using InterferenceVolume = Components.Volumes.InterferenceVolume; public static class InterferenceHandler { diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index f5df748a..65771442 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -4,8 +4,9 @@ using NewHorizons.Builder.General; using NewHorizons.Builder.Orbital; using NewHorizons.Builder.Props; using NewHorizons.Builder.Volumes; -using NewHorizons.Components; using NewHorizons.Components.Orbital; +using NewHorizons.Components.Quantum; +using NewHorizons.Components.Stars; using NewHorizons.OtherMods.OWRichPresence; using NewHorizons.Utility; using System; @@ -59,8 +60,9 @@ namespace NewHorizons.Handlers GameObject.Destroy(starLightGO.GetComponent()); starLightGO.name = "StarLightController"; - starLightGO.AddComponent(); - StarLightController.AddStar(starController); + starLightGO.AddComponent(); + SunLightEffectsController.AddStar(starController); + SunLightEffectsController.AddStarLight(starController.Light); starLightGO.SetActive(true); } @@ -514,7 +516,10 @@ namespace NewHorizons.Handlers { var (star, starController, starEvolutionController) = StarBuilder.Make(go, sector, body.Config.Star, body.Mod, body.Config.isStellarRemnant); - if (starController != null) StarLightController.AddStar(starController); + if (starController != null) SunLightEffectsController.AddStar(starController); + + var starLight = star.FindChild("SunLight"); + if (starLight != null) SunLightEffectsController.AddStarLight(starLight.GetComponent()); // If it has an evolution controller that means it will die -> we make a remnant (unless its a remnant) if (starEvolutionController != null && !body.Config.isStellarRemnant) diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 7649194a..05ad3455 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components.Stars; using NewHorizons.Utility; using OWML.Utils; using System; @@ -141,7 +141,8 @@ namespace NewHorizons.Handlers break; case AstroObject.Name.Sun: var starController = ao.gameObject.GetComponent(); - StarLightController.RemoveStar(starController); + SunLightEffectsController.RemoveStar(starController); + SunLightEffectsController.RemoveStarLight(ao.transform.Find("Sector_SUN/Effects_SUN/SunLight").GetComponent()); GameObject.Destroy(starController); var audio = ao.GetComponentInChildren(); diff --git a/NewHorizons/Handlers/StarChartHandler.cs b/NewHorizons/Handlers/StarChartHandler.cs index f18e82b7..8083e20e 100644 --- a/NewHorizons/Handlers/StarChartHandler.cs +++ b/NewHorizons/Handlers/StarChartHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components.ShipLog; using NewHorizons.Utility; using System.Collections.Generic; using UnityEngine; diff --git a/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs b/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs index 81e01dd4..c5871604 100644 --- a/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs +++ b/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components.ShipLog; using NewHorizons.Utility; using System; using System.Collections.Generic; diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 5aced0de..e0c2ec5e 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -5,6 +5,7 @@ using NewHorizons.Builder.General; using NewHorizons.Builder.Props; using NewHorizons.Components; using NewHorizons.Components.Orbital; +using NewHorizons.Components.Fixers; using NewHorizons.Components.SizeControllers; using NewHorizons.External; using NewHorizons.External.Configs; @@ -124,7 +125,7 @@ namespace NewHorizons _wasConfigured = true; } - public static void ResetConfigs(bool resetTranslation = true) + public void ResetConfigs(bool resetTranslation = true) { BodyDict.Clear(); SystemDict.Clear(); @@ -165,9 +166,13 @@ namespace NewHorizons } }; - if (!resetTranslation) return; - TranslationHandler.ClearTables(); - TextTranslation.Get().SetLanguage(TextTranslation.Get().GetLanguage()); + if (resetTranslation) + { + TranslationHandler.ClearTables(); + TextTranslation.Get().SetLanguage(TextTranslation.Get().GetLanguage()); + } + + LoadTranslations(Instance.ModHelper.Manifest.ModFolderPath + "Assets/", this); } public void Awake() @@ -217,7 +222,6 @@ namespace NewHorizons OnStarSystemLoaded.AddListener(RichPresenceHandler.OnStarSystemLoaded); OnChangeStarSystem.AddListener(RichPresenceHandler.OnChangeStarSystem); - LoadTranslations(ModHelper.Manifest.ModFolderPath + "Assets/", this); LoadAddonManifest("Assets/addon-manifest.json", this); } @@ -537,6 +541,7 @@ namespace NewHorizons var map = GameObject.FindObjectOfType(); if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; + // Fix the map satellite SearchUtilities.Find("HearthianMapSatellite_Body", false).AddComponent(); diff --git a/NewHorizons/NewHorizons.csproj b/NewHorizons/NewHorizons.csproj index bb43cdbf..a4e7f6e4 100644 --- a/NewHorizons/NewHorizons.csproj +++ b/NewHorizons/NewHorizons.csproj @@ -17,7 +17,7 @@ - + diff --git a/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs new file mode 100644 index 00000000..e344a57f --- /dev/null +++ b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs @@ -0,0 +1,27 @@ +using NewHorizons.OtherMods.MenuFramework; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.OtherMods.CommonCameraUtility +{ + public static class CommonCameraHandler + { + private static ICommonCameraAPI _cameraAPI; + + static CommonCameraHandler() + { + _cameraAPI = Main.Instance.ModHelper.Interaction.TryGetModApi("xen.CommonCameraUtility"); + } + + public static void RegisterCustomCamera(OWCamera camera) + { + if (_cameraAPI != null) + { + _cameraAPI.RegisterCustomCamera(camera); + } + else + { + Logger.LogError("Tried to register custom camera but Common Camera Utility was missing."); + } + } + } +} diff --git a/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs b/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs new file mode 100644 index 00000000..bd49375b --- /dev/null +++ b/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs @@ -0,0 +1,13 @@ +using UnityEngine; +using UnityEngine.Events; + +namespace NewHorizons.OtherMods.CommonCameraUtility +{ + public interface ICommonCameraAPI + { + void RegisterCustomCamera(OWCamera OWCamera); + (OWCamera, Camera) CreateCustomCamera(string name); + UnityEvent EquipTool(); + UnityEvent UnequipTool(); + } +} diff --git a/NewHorizons/OtherMods/MenuFramework/MenuHandler.cs b/NewHorizons/OtherMods/MenuFramework/MenuHandler.cs index 45682279..bb88e7b4 100644 --- a/NewHorizons/OtherMods/MenuFramework/MenuHandler.cs +++ b/NewHorizons/OtherMods/MenuFramework/MenuHandler.cs @@ -4,9 +4,7 @@ using NewHorizons.Utility; using OWML.Common; using System.Collections.Generic; using System.Linq; -using System.Net.Mail; using UnityEngine; -using static UnityEngine.InputSystem.InputRemoting; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.OtherMods.MenuFramework diff --git a/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs b/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs index 7b94ca6c..727bc082 100644 --- a/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs +++ b/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components.ShipLog; using NewHorizons.Handlers; using NewHorizons.Utility; using System; diff --git a/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs new file mode 100644 index 00000000..29719c0e --- /dev/null +++ b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using NewHorizons.OtherMods.CommonCameraUtility; +using UnityEngine; + +namespace NewHorizons.Patches.CameraPatches +{ + [HarmonyPatch] + public static class NomaiRemoteCameraPatches + { + [HarmonyPostfix] + [HarmonyPatch(typeof(NomaiRemoteCamera), nameof(NomaiRemoteCamera.Awake))] + public static void NomaiRemoteCamera_Awake(NomaiRemoteCamera __instance) + { + // Ensures that if the player is visible from the remote camera they look normal + CommonCameraHandler.RegisterCustomCamera(__instance._camera); + + // These layers were left on because it doesnt come up in base game (Dreamworld is inactive, player is far away) + __instance._camera.mainCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("DreamSimulation")); + __instance._camera.mainCamera.cullingMask &= ~(1 < - +