feat: new looks for the Race Menu Ward, Contract Bank and Bone Servant tables
Recolour and kitbash from vanilla parts, no new assets. PieceLook copies materials before tinting so vanilla pieces keep their colours. ModelBorrow gains activeOnly, which drops hidden snow, fire and broken meshes before a borrowed piece is measured.
This commit is contained in:
parent
cb29f54a28
commit
f3d3c0ebb5
5 changed files with 222 additions and 3 deletions
|
|
@ -218,6 +218,7 @@ namespace RacesOfValheim
|
|||
}
|
||||
|
||||
prefab.transform.localScale = Vector3.one * TableScale;
|
||||
Dress(prefab, family);
|
||||
|
||||
ServantTableBehaviour table = prefab.AddComponent<ServantTableBehaviour>();
|
||||
table.m_switch = prefab.AddComponent<Switch>();
|
||||
|
|
@ -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);
|
||||
|
||||
/// <summary>
|
||||
/// "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.
|
||||
/// </summary>
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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<DvergarBancoBehaviour>();
|
||||
|
||||
foreach (Switch existing in prefab.GetComponentsInChildren<Switch>(true))
|
||||
|
|
|
|||
|
|
@ -36,10 +36,13 @@ namespace RacesOfValheim
|
|||
/// <paramref name="localPosition"/> is where the model's BOTTOM CENTRE goes.
|
||||
/// <paramref name="targetSize"/> is how big its largest dimension should end up, in metres,
|
||||
/// measured AFTER <paramref name="localRotation"/> has been applied.
|
||||
/// <paramref name="activeOnly"/> 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.
|
||||
/// </summary>
|
||||
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<GameObject>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -66,7 +69,7 @@ namespace RacesOfValheim
|
|||
/// </summary>
|
||||
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<Transform>(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);
|
||||
|
|
|
|||
119
JotunnModStub/PieceLook.cs
Normal file
119
JotunnModStub/PieceLook.cs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public static class PieceLook
|
||||
{
|
||||
/// <summary>
|
||||
/// Multiplies the base colour of every mesh under <paramref name="root"/>, inactive ones included
|
||||
/// (a piece's worn and broken meshes are switched off until it takes damage). Particles are left
|
||||
/// alone: that is what <see cref="Rehue"/> is for.
|
||||
/// </summary>
|
||||
public static void Tint(Transform root, Color tint)
|
||||
{
|
||||
if (root == null) return;
|
||||
|
||||
var copies = new Dictionary<Material, Material>();
|
||||
foreach (Renderer renderer in root.GetComponentsInChildren<Renderer>(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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Swaps the hue of everything under <paramref name="root"/> that GLOWS - lights, particles and
|
||||
/// any material with emission - for <paramref name="glow"/>, 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.
|
||||
/// </summary>
|
||||
public static void Rehue(Transform root, Color glow)
|
||||
{
|
||||
if (root == null) return;
|
||||
|
||||
foreach (Light light in root.GetComponentsInChildren<Light>(true))
|
||||
{
|
||||
if (light != null) light.color = glow;
|
||||
}
|
||||
|
||||
foreach (ParticleSystem ps in root.GetComponentsInChildren<ParticleSystem>(true))
|
||||
{
|
||||
if (ps == null) continue;
|
||||
ParticleSystem.MainModule main = ps.main;
|
||||
main.startColor = new ParticleSystem.MinMaxGradient(glow);
|
||||
}
|
||||
|
||||
var copies = new Dictionary<Material, Material>();
|
||||
foreach (Renderer renderer in root.GetComponentsInChildren<Renderer>(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<Material, Material> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -44,6 +44,8 @@ namespace RacesOfValheim
|
|||
|
||||
prefab.AddComponent<RaceMenuWardBehavior>();
|
||||
|
||||
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
|
||||
/// <summary>Seidr blue in place of the Ward's hearth orange: every race builds this, so no race's colour.</summary>
|
||||
private static readonly Color Glow = new Color(0.55f, 0.62f, 1f, 1f);
|
||||
/// <summary>A colder stone, so it reads as a different thing from the vanilla Ward across a base.</summary>
|
||||
private static readonly Color StoneTint = new Color(0.78f, 0.82f, 0.92f, 1f);
|
||||
/// <summary>Narrower and taller than the Ward, on a plinth: a statue rather than a waystone.</summary>
|
||||
private static readonly Vector3 StatueShape = new Vector3(0.9f, 1.12f, 0.9f);
|
||||
private const float PlinthWidth = 1.3f;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue