diff --git a/JotunnModStub/Butler/BoneServant.cs b/JotunnModStub/Butler/BoneServant.cs index 714016f..cd633b1 100644 --- a/JotunnModStub/Butler/BoneServant.cs +++ b/JotunnModStub/Butler/BoneServant.cs @@ -218,6 +218,7 @@ namespace RacesOfValheim } prefab.transform.localScale = Vector3.one * TableScale; + Dress(prefab, family); ServantTableBehaviour table = prefab.AddComponent(); table.m_switch = prefab.AddComponent(); @@ -255,6 +256,36 @@ namespace RacesOfValheim })); } + // The look, in the table's own space BEFORE TableScale, like the Dvergar bank's coin pile. + // TableTop is that pile's height: the same vanilla mesh, so the same surface. + private static readonly Color BoneSlateTint = new Color(0.72f, 0.74f, 0.78f, 1f); + private const float TableTop = 1.05f; + private static readonly Vector3 SkullSpot = new Vector3(1.6f, TableTop, -0.5f); + private static readonly Vector3 TradeSpot = new Vector3(-1.55f, TableTop, 0.3f); + + /// + /// "A slab of bone and slate": the cartography table greyed down, a skeleton's skull on one end + /// and the trade's own tool on the other - an anvil for the smith, a mortar for the cook. + /// + private static void Dress(GameObject prefab, ButlerFamily family) + { + PieceLook.Tint(prefab.transform, BoneSlateTint); + + ModelBorrow.Attach(prefab.transform, "TableSkull", "TrophySkeleton", + SkullSpot, Quaternion.Euler(0f, -120f, 0f), 0.3f, "Butler", activeOnly: true); + + if (family == ButlerFamily.Forge) + { + ModelBorrow.Attach(prefab.transform, "TableAnvil", "forge_ext2", + TradeSpot, Quaternion.identity, 0.55f, "Butler", activeOnly: true); + } + else + { + ModelBorrow.Attach(prefab.transform, "TableMortar", "cauldron_ext5_mortarandpestle", + TradeSpot, Quaternion.identity, 0.6f, "Butler", activeOnly: true); + } + } + public static void EnsureKnown(Player player) { if (player == null) return; diff --git a/JotunnModStub/Dvergar/DvergarBanco.cs b/JotunnModStub/Dvergar/DvergarBanco.cs index a912a2d..36d945a 100644 --- a/JotunnModStub/Dvergar/DvergarBanco.cs +++ b/JotunnModStub/Dvergar/DvergarBanco.cs @@ -76,6 +76,14 @@ namespace RacesOfValheim private const float PileHeight = 1.05f; private const float PileSize = 0.45f; + // The dressing, in the same unscaled table space as the pile. The pile owns the centre, so the + // lantern takes the far end of the map half and the tankard the near edge of the writing half. + private static readonly Color BankWoodTint = new Color(0.62f, 0.55f, 0.5f, 1f); + private static readonly Vector3 LanternSpot = new Vector3(-1.75f, PileHeight, 0.55f); + private const float LanternSize = 0.55f; + private static readonly Vector3 TankardSpot = new Vector3(0.35f, PileHeight, -0.65f); + private const float TankardSize = 0.2f; + public class Troop { public string Id; @@ -276,6 +284,14 @@ namespace RacesOfValheim prefab.transform.localScale = Vector3.one * TableScale; + // A counting table, not a map table: darker wood, a dvergr lantern at the far end and a + // tankard by the ledger. Tinted BEFORE the props go on, or they would be darkened too. + PieceLook.Tint(prefab.transform, BankWoodTint); + ModelBorrow.Attach(prefab.transform, "BankLantern", "piece_dvergr_lantern", + LanternSpot, Quaternion.identity, LanternSize, "Dvergar", activeOnly: true); + ModelBorrow.Attach(prefab.transform, "BankTankard", "Tankard_dvergr", + TankardSpot, Quaternion.identity, TankardSize, "Dvergar", activeOnly: true); + DvergarBancoBehaviour bank = prefab.AddComponent(); foreach (Switch existing in prefab.GetComponentsInChildren(true)) diff --git a/JotunnModStub/ModelBorrow.cs b/JotunnModStub/ModelBorrow.cs index 08a777b..19a6ced 100644 --- a/JotunnModStub/ModelBorrow.cs +++ b/JotunnModStub/ModelBorrow.cs @@ -36,10 +36,13 @@ namespace RacesOfValheim /// is where the model's BOTTOM CENTRE goes. /// is how big its largest dimension should end up, in metres, /// measured AFTER has been applied. + /// drops every child the source keeps switched off before measuring. + /// A build piece carries its snow cover, its fire, its worn and broken meshes that way, and they + /// count towards the size: the cauldron's hidden tripod legs are two metres long. /// public static GameObject Attach(Transform parent, string holderName, string sourcePrefab, Vector3 localPosition, Quaternion localRotation, float targetSize, - string label) + string label, bool activeOnly = false) { GameObject source = Jotunn.Managers.PrefabManager.Cache.GetPrefab(sourcePrefab); if (source == null) @@ -52,7 +55,7 @@ namespace RacesOfValheim return empty; } - return Attach(parent, holderName, source, localPosition, localRotation, targetSize, label); + return Attach(parent, holderName, source, localPosition, localRotation, targetSize, label, activeOnly); } /// @@ -66,7 +69,7 @@ namespace RacesOfValheim /// public static GameObject Attach(Transform parent, string holderName, GameObject source, Vector3 localPosition, Quaternion localRotation, float targetSize, - string label) + string label, bool activeOnly = false) { GameObject holder = new GameObject(holderName); holder.transform.SetParent(parent, false); @@ -110,6 +113,16 @@ namespace RacesOfValheim if (nview != null) Object.DestroyImmediate(nview); } + if (activeOnly) + { + foreach (Transform child in copy.GetComponentsInChildren(true)) + { + // Null once an inactive parent above it has already gone. + if (child == null || child == copy.transform || child.gameObject.activeSelf) continue; + Object.DestroyImmediate(child.gameObject); + } + } + FitAndGround(copy.transform, holder.transform, targetSize, sourcePrefab, label); holder.SetActive(true); diff --git a/JotunnModStub/PieceLook.cs b/JotunnModStub/PieceLook.cs new file mode 100644 index 0000000..402d96d --- /dev/null +++ b/JotunnModStub/PieceLook.cs @@ -0,0 +1,119 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace RacesOfValheim +{ + /// + /// Recolouring a cloned vanilla piece without touching the original. + /// + /// A clone made by CreateClonedPrefab shares its MATERIALS with the vanilla prefab, so writing a + /// colour onto renderer.sharedMaterial would repaint every Ward or cartography table in the world. + /// Each material is copied once and the copy is written; renderers that shared one material before + /// share the one copy after, so the LOD, worn and broken meshes stay matched. + /// + public static class PieceLook + { + /// + /// Multiplies the base colour of every mesh under , inactive ones included + /// (a piece's worn and broken meshes are switched off until it takes damage). Particles are left + /// alone: that is what is for. + /// + public static void Tint(Transform root, Color tint) + { + if (root == null) return; + + var copies = new Dictionary(); + foreach (Renderer renderer in root.GetComponentsInChildren(true)) + { + if (renderer == null || renderer is ParticleSystemRenderer) continue; + + Material[] materials = renderer.sharedMaterials; + for (int i = 0; i < materials.Length; i++) + { + Material copy = CopyOf(materials[i], copies); + if (copy == null) continue; + if (copy.HasProperty("_Color")) copy.SetColor("_Color", copy.GetColor("_Color") * tint); + materials[i] = copy; + } + renderer.sharedMaterials = materials; + } + } + + /// + /// Swaps the hue of everything under that GLOWS - lights, particles and + /// any material with emission - for , keeping each one's brightness. + /// + /// Brightness is kept rather than overwritten because these values are not 0 to 1: the Ward's + /// sparks are authored at a colour of 2.0, and painting them a flat 1.0 blue would dim them by + /// half. A material whose emission is black does not glow and is skipped, so the Ward's stone + /// stays stone. + /// + public static void Rehue(Transform root, Color glow) + { + if (root == null) return; + + foreach (Light light in root.GetComponentsInChildren(true)) + { + if (light != null) light.color = glow; + } + + foreach (ParticleSystem ps in root.GetComponentsInChildren(true)) + { + if (ps == null) continue; + ParticleSystem.MainModule main = ps.main; + main.startColor = new ParticleSystem.MinMaxGradient(glow); + } + + var copies = new Dictionary(); + foreach (Renderer renderer in root.GetComponentsInChildren(true)) + { + if (renderer == null) continue; + bool particles = renderer is ParticleSystemRenderer; + + Material[] materials = renderer.sharedMaterials; + bool changed = false; + for (int i = 0; i < materials.Length; i++) + { + Material source = materials[i]; + if (source == null) continue; + + bool emits = source.HasProperty("_EmissionColor") && Brightness(source.GetColor("_EmissionColor")) > 0.01f; + if (!emits && !particles) continue; + + Material copy = CopyOf(source, copies); + if (emits) Recolour(copy, "_EmissionColor", glow); + if (particles) + { + Recolour(copy, "_Color", glow); + Recolour(copy, "_TintColor", glow); + } + materials[i] = copy; + changed = true; + } + if (changed) renderer.sharedMaterials = materials; + } + } + + private static void Recolour(Material material, string property, Color glow) + { + if (!material.HasProperty(property)) return; + Color old = material.GetColor(property); + Color hue = glow * Brightness(old); + hue.a = old.a; + material.SetColor(property, hue); + } + + private static float Brightness(Color colour) => Mathf.Max(colour.r, Mathf.Max(colour.g, colour.b)); + + private static Material CopyOf(Material source, Dictionary copies) + { + if (source == null) return null; + if (!copies.TryGetValue(source, out Material copy)) + { + copy = new Material(source) { name = source.name + "_rov" }; + copies[source] = copy; + } + return copy; + } + } +} diff --git a/JotunnModStub/RaceMenuWard.cs b/JotunnModStub/RaceMenuWard.cs index e59b237..4ed4c37 100644 --- a/JotunnModStub/RaceMenuWard.cs +++ b/JotunnModStub/RaceMenuWard.cs @@ -44,6 +44,8 @@ namespace RacesOfValheim prefab.AddComponent(); + Restyle(prefab); + PieceConfig config = new PieceConfig { Name = "$rov_piece_racemenuward_name", @@ -60,6 +62,44 @@ namespace RacesOfValheim PieceManager.Instance.AddPiece(new CustomPiece(prefab, fixReference: false, config)); } + // ---------------------------------------------------------------- the look + /// Seidr blue in place of the Ward's hearth orange: every race builds this, so no race's colour. + private static readonly Color Glow = new Color(0.55f, 0.62f, 1f, 1f); + /// A colder stone, so it reads as a different thing from the vanilla Ward across a base. + private static readonly Color StoneTint = new Color(0.78f, 0.82f, 0.92f, 1f); + /// Narrower and taller than the Ward, on a plinth: a statue rather than a waystone. + private static readonly Vector3 StatueShape = new Vector3(0.9f, 1.12f, 0.9f); + private const float PlinthWidth = 1.3f; + + /// + /// Odin's stone on a plinth, glowing blue. The statue, its light and its sparks are lifted by the + /// plinth's MEASURED height, so a different plinth model needs no new offset. + /// + private static void Restyle(GameObject prefab) + { + Transform statue = prefab.transform.Find("new"); + if (statue == null) + { + Jotunn.Logger.LogWarning("guard_stone has no 'new' model; the Race Menu Ward keeps the vanilla look."); + return; + } + + PieceLook.Tint(statue, StoneTint); + PieceLook.Rehue(prefab.transform, Glow); + statue.localScale = Vector3.Scale(statue.localScale, StatueShape); + + GameObject plinth = ModelBorrow.Attach(prefab.transform, "WardPlinth", "stone_floor_2x2", + Vector3.zero, Quaternion.identity, PlinthWidth, + "RaceMenuWard", activeOnly: true); + float lift = ModelBorrow.HeightOf(plinth); + + foreach (string child in new[] { "new", "WayEffect", "GuidePoint" }) + { + Transform part = prefab.transform.Find(child); + if (part != null) part.localPosition += Vector3.up * lift; + } + } + // Marks a world as already having its starter ward, so it is placed exactly once rather // than every time someone loads in. private const string PlacedKey = "RacesOfValheim_StarterWardPlaced";