Add map marker display distance overrides and make a map marker module (#878)

## Minor features

- Added a map marker module with display distance overrides (#847)
This commit is contained in:
Noah Pilarski 2024-06-04 11:44:00 -04:00 committed by GitHub
commit eebcdc1ccd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 102 additions and 15 deletions

View File

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

View File

@ -16,7 +16,7 @@ namespace NewHorizons.Builder.General
var config = nhBody.Config;
astroObject.isVanilla = isVanilla;
astroObject.HideDisplayName = !config.Base.hasMapMarker;
astroObject.HideDisplayName = !config.MapMarker.enabled;
astroObject.invulnerableToSun = config.Base.invulnerableToSun;
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.Handlers;
using UnityEngine;
@ -12,7 +13,8 @@ namespace NewHorizons.Builder.General
{
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);
var markerType = MapMarker.MarkerType.Planet;
@ -37,6 +39,9 @@ namespace NewHorizons.Builder.General
*/
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>
public LavaModule Lava;
/// <summary>
/// Map marker properties of this body
/// </summary>
public MapMarkerModule MapMarker;
/// <summary>
/// Describes this Body's orbit (or lack there of)
/// </summary>
@ -214,6 +219,7 @@ namespace NewHorizons.External.Configs
if (Base == null) Base = new BaseModule();
if (Orbit == null) Orbit = new OrbitModule();
if (ReferenceFrame == null) ReferenceFrame = new ReferenceFrameModule();
if (MapMarker == null) MapMarker = new MapMarkerModule();
}
public void Validate()
@ -307,6 +313,8 @@ namespace NewHorizons.External.Configs
if (!Base.hasReferenceFrame) ReferenceFrame.enabled = false;
if (Base.hasMapMarker) MapMarker.enabled = true;
if (childrenToDestroy != null) removeChildren = childrenToDestroy;
if (Base.cloakRadius != 0)

View File

@ -36,11 +36,6 @@ namespace NewHorizons.External.Modules
/// </summary>
public float groundSize;
/// <summary>
/// If the body should have a marker on the map screen.
/// </summary>
public bool hasMapMarker;
/// <summary>
/// Can this planet survive entering a star?
/// </summary>
@ -108,6 +103,9 @@ namespace NewHorizons.External.Modules
[Obsolete("AmbientLight is deprecated, please use AmbientLightModule instead")]
public float ambientLight;
[Obsolete("HasMapMarker is deprecated, please use MapMarkerModule instead")]
public bool hasMapMarker;
[Obsolete("HasReferenceFrame is deprecated, please use ReferenceModule instead")]
[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);
body.Config.Base.showMinimap = false;
body.Config.Base.hasMapMarker = false;
body.Config.MapMarker.enabled = false;
const float sphereOfInfluence = 2000f;
@ -459,7 +459,7 @@ namespace NewHorizons.Handlers
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);
}

View File

@ -85,6 +85,10 @@
"description": "Add lava to this planet",
"$ref": "#/definitions/LavaModule"
},
"MapMarker": {
"description": "Map marker properties of this body",
"$ref": "#/definitions/MapMarkerModule"
},
"Orbit": {
"description": "Describes this Body's orbit (or lack there of)",
"$ref": "#/definitions/OrbitModule"
@ -543,10 +547,6 @@
"description": "Radius of a simple sphere used as the ground for the planet. If you want to use more complex terrain, leave this as\n0.",
"format": "float"
},
"hasMapMarker": {
"type": "boolean",
"description": "If the body should have a marker on the map screen."
},
"invulnerableToSun": {
"type": "boolean",
"description": "Can this planet survive entering a star?"
@ -1022,6 +1022,26 @@
}
}
},
"MapMarkerModule": {
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"description": "If the body should have a marker on the map screen."
},
"minDisplayDistanceOverride": {
"type": "number",
"description": "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.",
"format": "float"
},
"maxDisplayDistanceOverride": {
"type": "number",
"description": "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).",
"format": "float"
}
}
},
"OrbitModule": {
"type": "object",
"additionalProperties": false,