From b59a03d15ee7385e33a639f0dce1b9a100294829 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 2 May 2022 20:58:22 -0400 Subject: [PATCH] Finish slide reel --- NewHorizons/Builder/Props/DetailBuilder.cs | 5 ++ NewHorizons/Builder/Props/SlideReelBuilder.cs | 80 ++++++++++++++++++- NewHorizons/External/PropModule.cs | 30 ++++++- NewHorizons/Utility/ImageUtilities.cs | 66 +++++++++++++-- 4 files changed, 172 insertions(+), 9 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 2922d480..bd7123f6 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -141,6 +141,11 @@ namespace NewHorizons.Builder.Props { sector.OnOccupantEnterSector.AddListener((_) => (component as SlideCollectionContainer).LoadStreamingTextures()); } + + if(component is OWItemSocket) + { + (component as OWItemSocket)._sector = sector; + } } prop.transform.position = position == null ? go.transform.position : go.transform.TransformPoint((Vector3)position); diff --git a/NewHorizons/Builder/Props/SlideReelBuilder.cs b/NewHorizons/Builder/Props/SlideReelBuilder.cs index d84188ea..ffebda8a 100644 --- a/NewHorizons/Builder/Props/SlideReelBuilder.cs +++ b/NewHorizons/Builder/Props/SlideReelBuilder.cs @@ -19,7 +19,7 @@ namespace NewHorizons.Builder.Props { if (_prefab == null) { - _prefab = GameObject.FindObjectOfType().gameObject.InstantiateInactive(); + _prefab = GameObject.Find("RingWorld_Body/Sector_RingInterior/Sector_Zone1/Sector_SlideBurningRoom_Zone1/Interactables_SlideBurningRoom_Zone1/Prefab_IP_SecretAlcove/RotationPivot/SlideReelSocket/Prefab_IP_Reel_1_LibraryPath").gameObject.InstantiateInactive(); _prefab.name = "Prefab_IP_Reel"; } @@ -42,22 +42,96 @@ namespace NewHorizons.Builder.Props slideReelObj.transform.rotation = Quaternion.Euler((Vector3)(info.position ?? Vector3.zero)); // Now we replace the slides - int slidesCount = info.slideImagePaths.Length; + int slidesCount = info.slides.Length; var slideCollection = new SlideCollection(slidesCount); + // The base game ones only have 15 slides max + var textures = new Texture2D[slidesCount >= 15 ? 15 : slidesCount]; + for(int i = 0; i < slidesCount; i++) { var slide = new Slide(); - slide.textureOverride = ImageUtilities.GetTextureForSlide(mod, info.slideImagePaths[i]); + var slideInfo = info.slides[i]; + + var texture = ImageUtilities.GetTexture(mod, slideInfo.imagePath); + slide.textureOverride = ImageUtilities.Invert(texture); + + // Track the first 15 to put on the slide reel object + if(i < 15) textures[i] = texture; + + AddModules(slideInfo, ref slide); + slideCollection.slides[i] = slide; } + // Else when you put them down you can't pick them back up + slideReelObj.GetComponent()._physicsRemoved = false; + + // Idk why but it wants reveals to be comma delimited not a list slideCollectionContainer.slideCollection = slideCollection; if (info.reveals != null) slideCollectionContainer._shipLogOnComplete = string.Join(",", info.reveals); OWAssetHandler.LoadObject(slideReelObj); + var slidesBack = slideReelObj.transform.Find("Props_IP_SlideReel_7/Slides_Back").GetComponent(); + var slidesFront = slideReelObj.transform.Find("Props_IP_SlideReel_7/Slides_Front").GetComponent(); + + // Now put together the textures into a 4x4 thing for the materials + var reelTexture = ImageUtilities.MakeReelTexture(textures); + slidesBack.material.mainTexture = reelTexture; + slidesBack.material.SetTexture("_EmissionMap", reelTexture); + slidesFront.material.mainTexture = reelTexture; + slidesFront.material.SetTexture("_EmissionMap", reelTexture); + slideReelObj.SetActive(true); } + + private static void AddModules(PropModule.SlideInfo slideInfo, ref Slide slide) + { + var modules = new List(); + if (!String.IsNullOrEmpty(slideInfo.beatAudio)) + { + var audioBeat = new SlideBeatAudioModule(); + audioBeat._audioType = (AudioType)Enum.Parse(typeof(AudioType), slideInfo.beatAudio); + audioBeat._delay = slideInfo.beatDelay; + modules.Add(audioBeat); + } + if (!String.IsNullOrEmpty(slideInfo.backdropAudio)) + { + var audioBackdrop = new SlideBackdropAudioModule(); + audioBackdrop._audioType = (AudioType)Enum.Parse(typeof(AudioType), slideInfo.backdropAudio); + audioBackdrop._fadeTime = slideInfo.backdropFadeTime; + modules.Add(audioBackdrop); + } + if (slideInfo.ambientLightIntensity > 0) + { + var ambientLight = new SlideAmbientLightModule(); + ambientLight._intensity = slideInfo.ambientLightIntensity; + ambientLight._range = slideInfo.ambientLightRange; + ambientLight._color = slideInfo.ambientLightColor.ToColor(); + ambientLight._spotIntensityMod = slideInfo.spotIntensityMod; + modules.Add(ambientLight); + } + if (slideInfo.playTimeDuration != 0) + { + var playTime = new SlidePlayTimeModule(); + playTime._duration = slideInfo.playTimeDuration; + modules.Add(playTime); + } + if (slideInfo.blackFrameDuration != 0) + { + var blackFrame = new SlideBlackFrameModule(); + blackFrame._duration = slideInfo.blackFrameDuration; + modules.Add(blackFrame); + } + if (!String.IsNullOrEmpty(slideInfo.reveal)) + { + var shipLogEntry = new SlideShipLogEntryModule(); + shipLogEntry._entryKey = slideInfo.reveal; + modules.Add(shipLogEntry); + } + + Slide.WriteModules(modules, ref slide._modulesList, ref slide._modulesData, ref slide.lengths); + } } } diff --git a/NewHorizons/External/PropModule.cs b/NewHorizons/External/PropModule.cs index 6c55b050..3f39f1c6 100644 --- a/NewHorizons/External/PropModule.cs +++ b/NewHorizons/External/PropModule.cs @@ -107,7 +107,35 @@ namespace NewHorizons.External public MVector3 position; public MVector3 rotation; public string[] reveals; - public string[] slideImagePaths; + public SlideInfo[] slides; + } + + public class SlideInfo + { + public string imagePath; + + // SlideBeatAudioModule + public string beatAudio; + public float beatDelay; + + // SlideBackdropAudioModule + public string backdropAudio; + public float backdropFadeTime; + + // SlideAmbientLightModule + public float ambientLightIntensity; + public float ambientLightRange; + public MColor ambientLightColor; + public float spotIntensityMod; + + // SlidePlayTimeModule + public float playTimeDuration; + + // SlideBlackFrameModule + public float blackFrameDuration; + + // SlideShipLogEntryModule + public string reveal; } } } diff --git a/NewHorizons/Utility/ImageUtilities.cs b/NewHorizons/Utility/ImageUtilities.cs index f4959850..01f6f1ab 100644 --- a/NewHorizons/Utility/ImageUtilities.cs +++ b/NewHorizons/Utility/ImageUtilities.cs @@ -48,10 +48,8 @@ namespace NewHorizons.Utility _generatedTextures.Clear(); } - public static Texture2D GetTextureForSlide(IModBehaviour mod, string filename) + public static Texture2D Invert(Texture2D texture) { - var texture = GetTexture(mod, filename); - var pixels = texture.GetPixels(); for (int i = 0; i < pixels.Length; i++) { @@ -75,7 +73,7 @@ namespace NewHorizons.Utility } var newTexture = new Texture2D(texture.width, texture.height); - newTexture.name = texture.name + "SlideReel"; + newTexture.name = texture.name + "Inverted"; newTexture.SetPixels(pixels); newTexture.Apply(); @@ -86,6 +84,58 @@ namespace NewHorizons.Utility return newTexture; } + public static Texture2D MakeReelTexture(Texture2D[] textures) + { + var size = 256; + + var texture = (new Texture2D(size * 4, size * 4, TextureFormat.ARGB32, false)); + texture.name = "SlideReelAtlas"; + + Color[] fillPixels = new Color[size * size * 4 * 4]; + for(int xIndex = 0; xIndex < 4; xIndex++) + { + for(int yIndex = 0; yIndex < 4; yIndex++) + { + int index = yIndex * 4 + xIndex; + var srcTexture = index < textures.Length ? textures[index] : null; + + for(int i = 0; i < size; i++) + { + for(int j = 0; j < size; j++) + { + var colour = Color.black; + + if(srcTexture) + { + var srcX = i * srcTexture.width / (float)size; + var srcY = j * srcTexture.height / (float)size; + if (srcX >= 0 && srcX < srcTexture.width && srcY >= 0 && srcY < srcTexture.height) + { + colour = srcTexture.GetPixel((int)srcX, (int)srcY); + } + } + + var x = xIndex * size + i; + // Want it to start from the first row from the bottom then go down then modulo around idk + // 5 because no pos mod idk + var y = ((5 - yIndex)%4) * size + j; + + var pixelIndex = x + y * (size * 4); + + if(pixelIndex < fillPixels.Length && pixelIndex >= 0) fillPixels[pixelIndex] = colour; + } + } + } + } + + texture.SetPixels(fillPixels); + texture.Apply(); + + _generatedTextures.Add(texture); + + return texture; + } + public static Texture2D MakeOutline(Texture2D texture, Color color, int thickness) { var outline = new Texture2D(texture.width, texture.height, TextureFormat.ARGB32, false); @@ -200,7 +250,13 @@ namespace NewHorizons.Utility { for(int j = 0; j < tex.height; j++) { - fillPixels[i + j * tex.width] = src.GetPixel(i, j); + var x = i + (src.width - width) / 2; + var y = j + (src.height - height) / 2; + + var colour = Color.black; + if (x < src.width && y < src.height) colour = src.GetPixel(i, j); + + fillPixels[i + j * tex.width] = colour; } } tex.SetPixels(fillPixels);