From 8c3649bb40dcb56547b09bce1b608e7b897a0576 Mon Sep 17 00:00:00 2001 From: xen-42 Date: Thu, 13 Feb 2025 17:21:00 -0500 Subject: [PATCH] Can set which slides to display, make empty slide reels transparent (#888) --- NewHorizons/Builder/Props/ProjectionBuilder.cs | 10 ++++++++-- .../Components/EOTE/NHSlideCollection.cs | 14 +++++++++++++- .../Props/EchoesOfTheEye/ProjectionInfo.cs | 8 +++++++- NewHorizons/Utility/Files/ImageUtilities.cs | 17 +++++++++++++++-- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index 1532fbe1..32c658b8 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -209,8 +209,14 @@ namespace NewHorizons.Builder.Props var slidesBack = slideReelObj.GetComponentInChildren(true).transform.Find("Slides_Back").GetComponent(); var slidesFront = slideReelObj.GetComponentInChildren(true).transform.Find("Slides_Front").GetComponent(); - // Now put together the textures into a 4x4 thing for the materials - var reelTexture = ImageUtilities.MakeReelTexture(mod, textures, key); + // Now put together the textures into a 4x4 thing for the materials #888 + var displayTextures = textures; + if (info.displaySlides != null && info.displaySlides.Length > 0) + { + displayTextures = info.displaySlides.Select(x => textures[x]).ToArray(); + } + + var reelTexture = ImageUtilities.MakeReelTexture(mod, displayTextures, key); slidesBack.material.mainTexture = reelTexture; slidesBack.material.SetTexture(EmissionMap, reelTexture); slidesBack.material.name = reelTexture.name; diff --git a/NewHorizons/Components/EOTE/NHSlideCollection.cs b/NewHorizons/Components/EOTE/NHSlideCollection.cs index 0eed0393..7aeccb30 100644 --- a/NewHorizons/Components/EOTE/NHSlideCollection.cs +++ b/NewHorizons/Components/EOTE/NHSlideCollection.cs @@ -24,7 +24,19 @@ public class NHSlideCollection : SlideCollection static NHSlideCollection() { - SceneManager.sceneUnloaded += (_) => _slidesRequiringPath.Clear(); + SceneManager.sceneUnloaded += (_) => + { + foreach (var (slide, collections) in _slidesRequiringPath) + { + // If it has null, that means some other permanent thing loaded this texture and it will get cleared elsewhere + // Otherwise it was loaded by an NHSlideCollection and should be deleted + if (collections.Any() && !collections.Contains(null)) + { + ImageUtilities.DeleteTexture(slide); + } + } + _slidesRequiringPath.Clear(); + }; } public NHSlideCollection(int startArrSize, IModBehaviour mod, string[] slidePaths) : base(startArrSize) diff --git a/NewHorizons/External/Modules/Props/EchoesOfTheEye/ProjectionInfo.cs b/NewHorizons/External/Modules/Props/EchoesOfTheEye/ProjectionInfo.cs index c61ef06b..e059c310 100644 --- a/NewHorizons/External/Modules/Props/EchoesOfTheEye/ProjectionInfo.cs +++ b/NewHorizons/External/Modules/Props/EchoesOfTheEye/ProjectionInfo.cs @@ -85,6 +85,12 @@ namespace NewHorizons.External.Modules.Props.EchoesOfTheEye /// Exclusive to the slide reel type. Condition/material of the reel. Antique is the Stranger, Pristine is the Dreamworld, Rusted is a burned reel. /// [DefaultValue("antique")] public SlideReelCondition reelCondition = SlideReelCondition.Antique; - } + /// + /// Set which slides appear on the slide reel model. Leave empty to default to the first few slides. + /// Takes a list of indices, i.e., to show the first 5 slides in reverse you would put [4, 3, 2, 1, 0]. + /// Index starts at 0. + /// + public int[] displaySlides; + } } diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index a0f02204..09ff831f 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -71,6 +71,19 @@ namespace NewHorizons.Utility.Files } } + /// + /// Not sure why the other method takes in the texture as well + /// + /// + public static void DeleteTexture(string key) + { + if (_textureCache.ContainsKey(key)) + { + UnityEngine.Object.Destroy(_textureCache[key]); + _textureCache.Remove(key); + } + } + public static void DeleteTexture(IModBehaviour mod, string filename, Texture2D texture) { var path = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, filename); @@ -194,9 +207,9 @@ namespace NewHorizons.Utility.Files { for (int j = 0; j < size; j++) { - var colour = Color.black; + var colour = Color.clear; - if (srcTexture) + if (srcTexture != null) { var srcX = i * srcTexture.width / (float)size; var srcY = j * srcTexture.height / (float)size;