Skip to content

Commit

Permalink
Add map marker display distance overrides and make a map marker module (
Browse files Browse the repository at this point in the history
#878)

## Minor features

- Added a map marker module with display distance overrides (#847)
  • Loading branch information
MegaPiggy committed Jun 4, 2024
2 parents 7a44824 + 2e7f1b7 commit eebcdc1
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 15 deletions.
6 changes: 5 additions & 1 deletion NewHorizons/Builder/Body/AsteroidBeltBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public static void Make(string bodyName, PlanetConfig parentConfig, IModBehaviou

config.Base = new BaseModule()
{
hasMapMarker = false,
surfaceGravity = 1,
surfaceSize = size,
gravityFallOff = GravityFallOff.InverseSquared
Expand All @@ -58,6 +57,11 @@ public static void Make(string bodyName, PlanetConfig parentConfig, IModBehaviou
enabled = false
};

config.MapMarker = new MapMarkerModule()
{
enabled = false
};

config.ProcGen = belt.procGen;
if (config.ProcGen == null)
{
Expand Down
2 changes: 1 addition & 1 deletion NewHorizons/Builder/General/AstroObjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static NHAstroObject Make(GameObject body, AstroObject primaryBody, NewHo
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);
Expand Down
9 changes: 7 additions & 2 deletions NewHorizons/Builder/General/MarkerBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#region
#region

using NewHorizons.Components;
using NewHorizons.External.Configs;
using NewHorizons.Handlers;
using UnityEngine;
Expand All @@ -12,7 +13,8 @@ static class MarkerBuilder
{
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;
Expand All @@ -37,6 +39,9 @@ public static void Make(GameObject body, string name, PlanetConfig config)
*/

mapMarker._markerType = markerType;

mapMarker.minDisplayDistanceOverride = module.minDisplayDistanceOverride;
mapMarker.maxDisplayDistanceOverride = module.maxDisplayDistanceOverride;
}
}
}
27 changes: 27 additions & 0 deletions NewHorizons/Components/NHMapMarker.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
8 changes: 8 additions & 0 deletions NewHorizons/External/Configs/PlanetConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public class PlanetConfig
/// </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>
Expand Down Expand Up @@ -214,6 +219,7 @@ public PlanetConfig()
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()
Expand Down Expand Up @@ -307,6 +313,8 @@ public void Migrate()

if (!Base.hasReferenceFrame) ReferenceFrame.enabled = false;

if (Base.hasMapMarker) MapMarker.enabled = true;

if (childrenToDestroy != null) removeChildren = childrenToDestroy;

if (Base.cloakRadius != 0)
Expand Down
8 changes: 3 additions & 5 deletions NewHorizons/External/Modules/BaseModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ public class BaseModule
/// </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>
Expand Down Expand Up @@ -108,6 +103,9 @@ public class BaseModule
[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;

Expand Down
25 changes: 25 additions & 0 deletions NewHorizons/External/Modules/MapMarkerModule.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 2 additions & 2 deletions NewHorizons/Handlers/PlanetCreationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public static GameObject GenerateBrambleDimensionBody(NewHorizonsBody body)
go.SetActive(false);

body.Config.Base.showMinimap = false;
body.Config.Base.hasMapMarker = false;
body.Config.MapMarker.enabled = false;

const float sphereOfInfluence = 2000f;

Expand Down Expand Up @@ -459,7 +459,7 @@ public static GameObject GenerateStandardBody(NewHorizonsBody body, bool default

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);
}
Expand Down
28 changes: 24 additions & 4 deletions NewHorizons/Schemas/body_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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?"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit eebcdc1

Please sign in to comment.