Skip to content

Commit

Permalink
Title Screen config (#1028)
Browse files Browse the repository at this point in the history
## Major features
- Adds title screen configuration (fixes #1027)

Todo list:
- [x] menuColor
- [x] factRequiredForTitle
- [x] conditionRequiredForTitle
- [x] skyBox
- [x] Music
- [x] rotationSpeed
- [x] menuPlanet
- [x] mergeWithOtherTitles
- [x] title screen handler api method
- [x] Docs
- [x] Multiple title screens for one mod


![image](https://github.com/user-attachments/assets/cdf4658c-eb39-4c5f-a0c4-9f93ed3493c9)
  • Loading branch information
xen-42 authored Feb 18, 2025
2 parents 7cdddf3 + 492c0bf commit 144421c
Show file tree
Hide file tree
Showing 21 changed files with 1,531 additions and 263 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions NewHorizons/Builder/Body/ProxyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ private static bool SharedMake(GameObject planetGO, GameObject proxy, NHProxy pr
{
foreach (var detailInfo in body.Config.Props.proxyDetails)
{
// Thought about switching these to SimplifiedDetailInfo but we use AlignRadial with these so we can't
DetailBuilder.Make(proxy, null, body.Mod, detailInfo);
}
}
Expand Down
6 changes: 3 additions & 3 deletions NewHorizons/Builder/StarSystem/SkyboxBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NewHorizons.External.Configs;
using NewHorizons.External.Modules;
using NewHorizons.Utility;
using NewHorizons.Utility.Files;
using NewHorizons.Utility.OWML;
Expand All @@ -13,13 +13,13 @@ public static class SkyboxBuilder
{
private static readonly Shader _unlitShader = Shader.Find("Unlit/Texture");

public static void Make(StarSystemConfig.SkyboxModule module, IModBehaviour mod)
public static void Make(SkyboxModule module, IModBehaviour mod)
{
NHLogger.Log("Building Skybox");
BuildSkySphere(module, mod);
}

public static GameObject BuildSkySphere(StarSystemConfig.SkyboxModule module, IModBehaviour mod)
public static GameObject BuildSkySphere(SkyboxModule module, IModBehaviour mod)
{
var skybox = SearchUtilities.Find("Skybox");

Expand Down
45 changes: 0 additions & 45 deletions NewHorizons/External/Configs/StarSystemConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,51 +181,6 @@ public class NomaiCoordinates
public int[] z;
}

[JsonObject]
public class SkyboxModule
{

/// <summary>
/// Whether to destroy the star field around the player
/// </summary>
public bool destroyStarField;

/// <summary>
/// Whether to use a cube for the skybox instead of a smooth sphere
/// </summary>
public bool useCube;

/// <summary>
/// Relative filepath to the texture to use for the skybox's positive X direction
/// </summary>
public string rightPath;

/// <summary>
/// Relative filepath to the texture to use for the skybox's negative X direction
/// </summary>
public string leftPath;

/// <summary>
/// Relative filepath to the texture to use for the skybox's positive Y direction
/// </summary>
public string topPath;

/// <summary>
/// Relative filepath to the texture to use for the skybox's negative Y direction
/// </summary>
public string bottomPath;

/// <summary>
/// Relative filepath to the texture to use for the skybox's positive Z direction
/// </summary>
public string frontPath;

/// <summary>
/// Relative filepath to the texture to use for the skybox's negative Z direction
/// </summary>
public string backPath;
}

[JsonObject]
public class GlobalMusicModule
{
Expand Down
119 changes: 119 additions & 0 deletions NewHorizons/External/Configs/TitleScreenConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using NewHorizons.External.Modules;
using NewHorizons.External.Modules.Props;
using NewHorizons.External.SerializableData;
using NewHorizons.Handlers;
using Newtonsoft.Json;

namespace NewHorizons.External.Configs
{
[JsonObject]
public class TitleScreenConfig
{
/// <summary>
/// Create title screens
/// </summary>
public TitleScreenInfo[] titleScreens = new TitleScreenInfo[0];
}

[JsonObject]
public class TitleScreenInfo
{
/// <summary>
/// Colour of the text on the main menu
/// </summary>
public MColor menuTextTint;

/// <summary>
/// Ship log fact required for this title screen to appear.
/// </summary>
public string factRequiredForTitle;

/// <summary>
/// Persistent condition required for this title screen to appear.
/// </summary>
public string persistentConditionRequiredForTitle;

/// <summary>
/// If set to true, NH generated planets will not show on the title screen. If false, this title screen has the same chance as other NH planet title screens to show.
/// </summary>
public bool disableNHPlanets = true;

/// <summary>
/// If set to true, this custom title screen will merge with all other custom title screens with shareTitleScreen set to true. If false, NH will randomly select between this and other valid title screens that are loaded.
/// </summary>
public bool shareTitleScreen = true;

/// <summary>
/// Customize the skybox for this title screen
/// </summary>
public SkyboxModule Skybox;

/// <summary>
/// The music audio that will play on the title screen. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list.
/// </summary>
public string music;

/// <summary>
/// The ambience audio that will play on the title screen. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list.
/// </summary>
public string ambience;

/// <summary>
/// Edit properties of the background
/// </summary>
public BackgroundModule Background;

/// <summary>
/// Edit properties of the main menu planet
/// </summary>
public MenuPlanetModule MenuPlanet;

[JsonObject]
public class BackgroundModule
{
/// <summary>
/// Changes the speed the background rotates (and by extension the main menu planet). This is in degrees per second.
/// </summary>
public float rotationSpeed = 1;

/// <summary>
/// Disables the renderers of objects at the provided paths
/// </summary>
public string[] removeChildren;

/// <summary>
/// A list of DetailInfos to populate the background with.
/// </summary>
public SimplifiedDetailInfo[] details;
}

[JsonObject]
public class MenuPlanetModule
{
/// <summary>
/// Disables the renderers of the main menu planet and all objects on it (this is to improve compatibility with other mods that don't use the NH title screen json).
/// </summary>
public bool destroyMenuPlanet = false;

/// <summary>
/// Disables the renderers of objects at the provided paths
/// </summary>
public string[] removeChildren;

/// <summary>
/// A list of DetailInfos to populate the main menu planet with.
/// </summary>
public SimplifiedDetailInfo[] details;

/// <summary>
/// Changes the speed the main menu planet. This is in degrees per second.
/// </summary>
public float rotationSpeed = 2;
}

/// <summary>
/// Extra data that may be used by extension mods
/// </summary>
public object extras;
}
}
26 changes: 23 additions & 3 deletions NewHorizons/External/Modules/Props/DetailInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

namespace NewHorizons.External.Modules.Props
{
/// <summary>
/// A lesser form of DetailInfo used for the title screen since that supports fewer features
/// </summary>
[JsonObject]
public class DetailInfo : GeneralPropInfo
public class SimplifiedDetailInfo : GeneralPropInfo
{
public DetailInfo() { }
public SimplifiedDetailInfo() { }

public DetailInfo(GeneralPointPropInfo info)
public SimplifiedDetailInfo(GeneralPointPropInfo info)
{
JsonConvert.PopulateObject(JsonConvert.SerializeObject(info), this);
}
Expand Down Expand Up @@ -47,6 +50,23 @@ public DetailInfo(GeneralPointPropInfo info)
/// Scale each axis of the prop. Overrides `scale`.
/// </summary>
public MVector3 stretch;
}

[JsonObject]
public class DetailInfo : SimplifiedDetailInfo
{
public DetailInfo() { }

public DetailInfo(GeneralPointPropInfo info)
{
JsonConvert.PopulateObject(JsonConvert.SerializeObject(info), this);
}

public DetailInfo(SimplifiedDetailInfo info)
{
keepLoaded = true;
JsonConvert.PopulateObject(JsonConvert.SerializeObject(info), this);
}

[Obsolete("Use QuantumDetailInfo")]
public string quantumGroupID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DreamCandleInfo : GeneralPropInfo
/// <summary>
/// The type of dream candle this is.
/// </summary>
[DefaultValue(DreamCandleType.Ground)] public DreamCandleType type = DreamCandleType.Ground;
[DefaultValue("ground")] public DreamCandleType type = DreamCandleType.Ground;

/// <summary>
/// Whether the candle should start lit or extinguished.
Expand Down
48 changes: 48 additions & 0 deletions NewHorizons/External/Modules/SkyboxModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Newtonsoft.Json;

namespace NewHorizons.External.Modules
{
[JsonObject]
public class SkyboxModule
{
/// <summary>
/// Whether to destroy the star field around the player
/// </summary>
public bool destroyStarField;

/// <summary>
/// Whether to use a cube for the skybox instead of a smooth sphere
/// </summary>
public bool useCube;

/// <summary>
/// Relative filepath to the texture to use for the skybox's positive X direction
/// </summary>
public string rightPath;

/// <summary>
/// Relative filepath to the texture to use for the skybox's negative X direction
/// </summary>
public string leftPath;

/// <summary>
/// Relative filepath to the texture to use for the skybox's positive Y direction
/// </summary>
public string topPath;

/// <summary>
/// Relative filepath to the texture to use for the skybox's negative Y direction
/// </summary>
public string bottomPath;

/// <summary>
/// Relative filepath to the texture to use for the skybox's positive Z direction
/// </summary>
public string frontPath;

/// <summary>
/// Relative filepath to the texture to use for the skybox's negative Z direction
/// </summary>
public string backPath;
}
}
12 changes: 10 additions & 2 deletions NewHorizons/Handlers/AudioTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,28 @@ public static class AudioTypeHandler
{
private static Dictionary<string, AudioType> _customAudioTypes;
private static List<AudioLibrary.AudioEntry> _audioEntries;
private static bool _postInitialized = false;

public static void Init()
{
_customAudioTypes = new Dictionary<string, AudioType>();
_audioEntries = new List<AudioLibrary.AudioEntry>();
_postInitialized = false;

Delay.RunWhen(
() => Locator.GetAudioManager()?._libraryAsset != null,
Delay.RunWhen(() => Locator.GetAudioManager()?._libraryAsset != null && Locator.GetAudioManager()?._audioLibraryDict != null,
PostInit
);
}

private static void PostInit()
{
NHLogger.LogVerbose($"Adding all custom AudioTypes to the library");
_postInitialized = true;
ModifyAudioLibrary();
}

private static void ModifyAudioLibrary()
{
var library = Locator.GetAudioManager()._libraryAsset;
var audioEntries = library.audioEntries; // store previous array
library.audioEntries = library.audioEntries.Concat(_audioEntries).ToArray(); // concat custom entries
Expand Down Expand Up @@ -88,6 +94,8 @@ public static AudioType AddCustomAudioType(string id, AudioClip[] audioClips)
_audioEntries.Add(new AudioLibrary.AudioEntry(audioType, audioClips));
_customAudioTypes.Add(id, audioType);

if (_postInitialized) ModifyAudioLibrary();

return audioType;
}
}
Expand Down
Loading

0 comments on commit 144421c

Please sign in to comment.