Add map marker display distance overrides and make a map marker module

This commit is contained in:
Noah Pilarski 2024-06-01 22:58:43 -04:00
parent fb9e10fee7
commit 6951a40e58
8 changed files with 78 additions and 11 deletions

View File

@ -36,7 +36,6 @@ namespace NewHorizons.Builder.Body
config.Base = new BaseModule() config.Base = new BaseModule()
{ {
hasMapMarker = false,
surfaceGravity = 1, surfaceGravity = 1,
surfaceSize = size, surfaceSize = size,
gravityFallOff = GravityFallOff.InverseSquared gravityFallOff = GravityFallOff.InverseSquared
@ -58,6 +57,11 @@ namespace NewHorizons.Builder.Body
enabled = false enabled = false
}; };
config.MapMarker = new MapMarkerModule()
{
enabled = false
};
config.ProcGen = belt.procGen; config.ProcGen = belt.procGen;
if (config.ProcGen == null) if (config.ProcGen == null)
{ {

View File

@ -16,7 +16,7 @@ namespace NewHorizons.Builder.General
var config = nhBody.Config; var config = nhBody.Config;
astroObject.isVanilla = isVanilla; astroObject.isVanilla = isVanilla;
astroObject.HideDisplayName = !config.Base.hasMapMarker; astroObject.HideDisplayName = !config.MapMarker.enabled;
astroObject.invulnerableToSun = config.Base.invulnerableToSun; astroObject.invulnerableToSun = config.Base.invulnerableToSun;
if (config.Orbit != null) astroObject.SetOrbitalParametersFromConfig(config.Orbit); if (config.Orbit != null) astroObject.SetOrbitalParametersFromConfig(config.Orbit);

View File

@ -1,5 +1,6 @@
#region #region
using NewHorizons.Components;
using NewHorizons.External.Configs; using NewHorizons.External.Configs;
using NewHorizons.Handlers; using NewHorizons.Handlers;
using UnityEngine; using UnityEngine;
@ -12,7 +13,8 @@ namespace NewHorizons.Builder.General
{ {
public static void Make(GameObject body, string name, PlanetConfig config) public static void Make(GameObject body, string name, PlanetConfig config)
{ {
MapMarker mapMarker = body.AddComponent<MapMarker>(); var module = config.MapMarker;
NHMapMarker mapMarker = body.AddComponent<NHMapMarker>();
mapMarker._labelID = (UITextType)TranslationHandler.AddUI(config.name); mapMarker._labelID = (UITextType)TranslationHandler.AddUI(config.name);
var markerType = MapMarker.MarkerType.Planet; var markerType = MapMarker.MarkerType.Planet;
@ -37,6 +39,9 @@ namespace NewHorizons.Builder.General
*/ */
mapMarker._markerType = markerType; mapMarker._markerType = markerType;
mapMarker.minDisplayDistanceOverride = module.minDisplayDistanceOverride;
mapMarker.maxDisplayDistanceOverride = module.maxDisplayDistanceOverride;
} }
} }
} }

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.Components
{
public class NHMapMarker : MapMarker
{
public float minDisplayDistanceOverride = -1;
public float maxDisplayDistanceOverride = -1;
public new void Awake()
{
base.Awake();
if (minDisplayDistanceOverride >= 0)
{
_minDisplayDistance = minDisplayDistanceOverride;
}
if (maxDisplayDistanceOverride >= 0)
{
_maxDisplayDistance = maxDisplayDistanceOverride;
}
}
}
}

View File

@ -113,6 +113,11 @@ namespace NewHorizons.External.Configs
/// </summary> /// </summary>
public LavaModule Lava; public LavaModule Lava;
/// <summary>
/// Map marker properties of this body
/// </summary>
public MapMarkerModule MapMarker;
/// <summary> /// <summary>
/// Describes this Body's orbit (or lack there of) /// Describes this Body's orbit (or lack there of)
/// </summary> /// </summary>
@ -214,6 +219,7 @@ namespace NewHorizons.External.Configs
if (Base == null) Base = new BaseModule(); if (Base == null) Base = new BaseModule();
if (Orbit == null) Orbit = new OrbitModule(); if (Orbit == null) Orbit = new OrbitModule();
if (ReferenceFrame == null) ReferenceFrame = new ReferenceFrameModule(); if (ReferenceFrame == null) ReferenceFrame = new ReferenceFrameModule();
if (MapMarker == null) MapMarker = new MapMarkerModule();
} }
public void Validate() public void Validate()
@ -307,6 +313,8 @@ namespace NewHorizons.External.Configs
if (!Base.hasReferenceFrame) ReferenceFrame.enabled = false; if (!Base.hasReferenceFrame) ReferenceFrame.enabled = false;
if (Base.hasMapMarker) MapMarker.enabled = true;
if (childrenToDestroy != null) removeChildren = childrenToDestroy; if (childrenToDestroy != null) removeChildren = childrenToDestroy;
if (Base.cloakRadius != 0) if (Base.cloakRadius != 0)

View File

@ -36,11 +36,6 @@ namespace NewHorizons.External.Modules
/// </summary> /// </summary>
public float groundSize; public float groundSize;
/// <summary>
/// If the body should have a marker on the map screen.
/// </summary>
public bool hasMapMarker;
/// <summary> /// <summary>
/// Can this planet survive entering a star? /// Can this planet survive entering a star?
/// </summary> /// </summary>
@ -108,6 +103,9 @@ namespace NewHorizons.External.Modules
[Obsolete("AmbientLight is deprecated, please use AmbientLightModule instead")] [Obsolete("AmbientLight is deprecated, please use AmbientLightModule instead")]
public float ambientLight; public float ambientLight;
[Obsolete("HasMapMarker is deprecated, please use MapMarkerModule instead")]
public bool hasMapMarker;
[Obsolete("HasReferenceFrame is deprecated, please use ReferenceModule instead")] [Obsolete("HasReferenceFrame is deprecated, please use ReferenceModule instead")]
[DefaultValue(true)] public bool hasReferenceFrame = true; [DefaultValue(true)] public bool hasReferenceFrame = true;

View File

@ -0,0 +1,25 @@
using System.ComponentModel;
using NewHorizons.External.SerializableData;
using Newtonsoft.Json;
namespace NewHorizons.External.Modules
{
[JsonObject]
public class MapMarkerModule
{
/// <summary>
/// If the body should have a marker on the map screen.
/// </summary>
public bool enabled;
/// <summary>
/// Lowest distance away from the body that the marker can be shown. This is automatically set to 0 for all bodies except focal points where it is 5,000.
/// </summary>
public float minDisplayDistanceOverride = -1;
/// <summary>
/// Highest distance away from the body that the marker can be shown. For planets and focal points the automatic value is 50,000. Moons and planets in focal points are 5,000. Stars are 1E+10 (10,000,000,000).
/// </summary>
public float maxDisplayDistanceOverride = -1;
}
}

View File

@ -366,7 +366,7 @@ namespace NewHorizons.Handlers
go.SetActive(false); go.SetActive(false);
body.Config.Base.showMinimap = false; body.Config.Base.showMinimap = false;
body.Config.Base.hasMapMarker = false; body.Config.MapMarker.enabled = false;
const float sphereOfInfluence = 2000f; const float sphereOfInfluence = 2000f;
@ -459,7 +459,7 @@ namespace NewHorizons.Handlers
RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence, body.Config.ReferenceFrame); RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence, body.Config.ReferenceFrame);
if (body.Config.Base.hasMapMarker) if (body.Config.MapMarker.enabled)
{ {
MarkerBuilder.Make(go, body.Config.name, body.Config); MarkerBuilder.Make(go, body.Config.name, body.Config);
} }