Merge branch 'kitbash-race-stations': new looks for the Race Menu Ward, Contract Bank and Bone Servant tables
BIN
JotunnModStub/Assets/CookCloth/CookCloth_d.png
Normal file
|
After Width: | Height: | Size: 65 KiB |
BIN
JotunnModStub/Assets/CookCloth/CookCloth_n.png
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
JotunnModStub/Assets/CookCloth/CookCloth_worn_d.png
Normal file
|
After Width: | Height: | Size: 72 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_d.png
Normal file
|
After Width: | Height: | Size: 340 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_m.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_n.png
Normal file
|
After Width: | Height: | Size: 441 KiB |
BIN
JotunnModStub/Assets/SmithMail/SmithMail_worn_d.png
Normal file
|
After Width: | Height: | Size: 339 KiB |
|
|
@ -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,65 @@ namespace RacesOfValheim
|
|||
}));
|
||||
}
|
||||
|
||||
// The look, in the table's own space BEFORE TableScale, so sizes are divided by it to come out
|
||||
// in real metres. The cover lies where the map was: x -2.06 to 0.62, read off the mesh. Its top
|
||||
// is the Dvergar bank's PileHeight, on the same vanilla mesh; the mesh's own height is no use
|
||||
// here, since the writing desk stands taller than the map.
|
||||
private const float CoverTop = 1.05f;
|
||||
private static readonly Vector3 TradeSpot = new Vector3(-0.75f, CoverTop, 0.2f);
|
||||
private static readonly Vector3 SkullSpot = new Vector3(-1.55f, CoverTop, 0.35f);
|
||||
private const float AnvilSize = 0.75f;
|
||||
private const float MealSize = 0.6f;
|
||||
private const float SkullSize = 0.45f;
|
||||
|
||||
/// <summary>
|
||||
/// The map painted over - a sheet of chainmail for the smith, a red and white tablecloth for the
|
||||
/// cook - with the trade's own work on it (an anvil, a meal) and a skeleton's skull beside it.
|
||||
/// </summary>
|
||||
private static void Dress(GameObject prefab, ButlerFamily family)
|
||||
{
|
||||
bool forge = family == ButlerFamily.Forge;
|
||||
LayCover(prefab, forge ? "SmithMail" : "CookCloth", metal: forge);
|
||||
|
||||
float metres = 1f / TableScale;
|
||||
if (forge)
|
||||
{
|
||||
ModelBorrow.Attach(prefab.transform, "TableAnvil", "forge_ext2",
|
||||
TradeSpot, Quaternion.identity, AnvilSize * metres, "Butler", activeOnly: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelBorrow.Attach(prefab.transform, "TableMeal", "MeatPlatter",
|
||||
TradeSpot, Quaternion.identity, MealSize * metres, "Butler", activeOnly: true);
|
||||
}
|
||||
ModelBorrow.Attach(prefab.transform, "TableSkull", "TrophySkeleton",
|
||||
SkullSpot, Quaternion.Euler(0f, -150f, 0f), SkullSize * metres, "Butler", activeOnly: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The cartography table's own textures with the map painted over, offline:
|
||||
/// scripts/paint_cook_cloth.py (CookCloth) and scripts/paint_smith_mail.py (SmithMail). Each set
|
||||
/// has its own worn texture for a damaged table (a stained cloth, rusted mail) and its own normal
|
||||
/// map, so the coastline's relief does not show through. The mail also brings a metallic map,
|
||||
/// which is what makes the rings shine; the cloth keeps vanilla's, which is metal nowhere.
|
||||
/// </summary>
|
||||
private static void LayCover(GameObject prefab, string set, bool metal)
|
||||
{
|
||||
var cover = new System.Collections.Generic.Dictionary<string, Texture>();
|
||||
AddCover(cover, "Cartographer_d", set + "_d.png", false);
|
||||
AddCover(cover, "Cartographer_worn_d", set + "_worn_d.png", false);
|
||||
AddCover(cover, "Cartographer_n", set + "_n.png", true);
|
||||
if (metal) AddCover(cover, "Cartographer_m", set + "_m.png", true);
|
||||
PieceLook.Retexture(prefab.transform, cover);
|
||||
}
|
||||
|
||||
private static void AddCover(System.Collections.Generic.Dictionary<string, Texture> cover,
|
||||
string vanilla, string resource, bool linear)
|
||||
{
|
||||
Texture2D texture = PieceLook.LoadTexture(resource, linear);
|
||||
if (texture != null) cover[vanilla] = texture;
|
||||
}
|
||||
|
||||
public static void EnsureKnown(Player player)
|
||||
{
|
||||
if (player == null) return;
|
||||
|
|
|
|||
|
|
@ -143,7 +143,8 @@ namespace RacesOfValheim
|
|||
string status = servant.Status;
|
||||
if (string.IsNullOrEmpty(status)) status = ModText.Get("rov_hover_butler_waiting");
|
||||
|
||||
return m_title + "\n" + status;
|
||||
// m_title is a $token, and a hover text goes to the HUD as it is: nothing localizes it later.
|
||||
return Localization.instance.Localize(m_title) + "\n" + status;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -76,6 +76,12 @@ 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
|
||||
// tankard stands just clear of it, on the near side.
|
||||
private static readonly Color BankWoodTint = new Color(0.62f, 0.55f, 0.5f, 1f);
|
||||
private static readonly Vector3 TankardSpot = new Vector3(0.45f, PileHeight, -0.25f);
|
||||
private const float TankardSize = 0.38f;
|
||||
|
||||
public class Troop
|
||||
{
|
||||
public string Id;
|
||||
|
|
@ -276,6 +282,12 @@ namespace RacesOfValheim
|
|||
|
||||
prefab.transform.localScale = Vector3.one * TableScale;
|
||||
|
||||
// A counting table, not a map table: darker wood and a dvergr tankard beside the coin.
|
||||
// Tinted BEFORE the tankard goes on, or it would be darkened too.
|
||||
PieceLook.Tint(prefab.transform, BankWoodTint);
|
||||
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);
|
||||
|
|
|
|||
197
JotunnModStub/PieceLook.cs
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Swaps textures by the name of the texture they replace: every material under
|
||||
/// <paramref name="root"/> that uses "Cartographer_d" gets <paramref name="replacements"/>'s
|
||||
/// "Cartographer_d" instead, whichever slot it sits in. Materials are copied as in Tint.
|
||||
/// </summary>
|
||||
public static void Retexture(Transform root, IDictionary<string, Texture> replacements)
|
||||
{
|
||||
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;
|
||||
bool changed = false;
|
||||
for (int i = 0; i < materials.Length; i++)
|
||||
{
|
||||
Material source = materials[i];
|
||||
if (source == null) continue;
|
||||
|
||||
foreach (string property in source.GetTexturePropertyNames())
|
||||
{
|
||||
Texture current = source.GetTexture(property);
|
||||
if (current == null || !replacements.TryGetValue(current.name, out Texture replacement)) continue;
|
||||
|
||||
Material copy = CopyOf(source, copies);
|
||||
copy.SetTexture(property, replacement);
|
||||
materials[i] = copy;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed) renderer.sharedMaterials = materials;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ImageConversion.LoadImage, found at run time. Its module is built against netstandard 2.1 and
|
||||
/// this project targets net48, so referencing it at compile time fails the build (CS1705); the
|
||||
/// game has the module loaded either way.
|
||||
/// </summary>
|
||||
private static readonly System.Reflection.MethodInfo LoadImage =
|
||||
System.Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule")
|
||||
?.GetMethod("LoadImage", new[] { typeof(Texture2D), typeof(byte[]), typeof(bool) });
|
||||
|
||||
/// <summary>
|
||||
/// A PNG embedded in the DLL (see the csproj's EmbeddedResource), or null with a warning.
|
||||
/// <paramref name="linear"/> for anything that is data rather than colour - a normal map read
|
||||
/// as sRGB comes out bent.
|
||||
/// </summary>
|
||||
public static Texture2D LoadTexture(string resource, bool linear = false)
|
||||
{
|
||||
using (System.IO.Stream stream = typeof(PieceLook).Assembly.GetManifestResourceStream(resource))
|
||||
{
|
||||
if (stream == null)
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"No embedded texture '{resource}'.");
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[stream.Length];
|
||||
int read = 0;
|
||||
while (read < bytes.Length) read += stream.Read(bytes, read, bytes.Length - read);
|
||||
|
||||
Texture2D texture = new Texture2D(2, 2, TextureFormat.RGBA32, true, linear)
|
||||
{
|
||||
name = System.IO.Path.GetFileNameWithoutExtension(resource),
|
||||
anisoLevel = 4,
|
||||
};
|
||||
if (LoadImage == null || !(bool)LoadImage.Invoke(null, new object[] { texture, bytes, true }))
|
||||
{
|
||||
Jotunn.Logger.LogWarning($"Embedded texture '{resource}' would not decode.");
|
||||
return null;
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
|
|
|
|||
|
|
@ -53,6 +53,12 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Textures painted offline (scripts/paint_cook_cloth.py), carried inside the DLL so a mod
|
||||
manager has no extra folder to flatten. Loaded by name: PieceLook.LoadTexture("CookCloth_d.png"). -->
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Assets\**\*.png" LogicalName="%(Filename)%(Extension)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
|
|
|
|||