fix(dvergur): tint the skin from UpdateColors, and raise the height
The tint was applied the way the race-selection menu appears to do it, with VisEquipment.SetSkinColor followed by UpdateColors, and had no visible effect. That pair is not what colours a player: UpdateColors rebuilds the body material from Valheim own state each refresh, so a tint only survives if it is written after it runs. Every race here that visibly changes colour already has a postfix on UpdateColors setting _SkinColor on the material, and the SetSkinColor calls in the menu are decorative on their own. The Dvergur now follows the Trol. Reading the race from the ZDO with a m_customData fallback and no local-player check covers the main-menu preview and the first spawn frame, where Player.m_localPlayer is still null. Nothing needs saving or restoring either, since the tint stops being applied the moment the race changes. Beard and hair go pale to match; the hood hides most of the hair but the beard shows. Height goes from 0.70 to 0.78. The spec asked for at least -30% but that read as too small beside a human on screen.
This commit is contained in:
parent
79a54fb533
commit
8df7681cea
4 changed files with 60 additions and 47 deletions
|
|
@ -33,12 +33,18 @@ namespace RacesOfValheim
|
|||
// Tuning knobs are static readonly rather than const throughout: a const folds at compile
|
||||
// time, which turns "is this perk switched off?" guards into dead code the moment a knob
|
||||
// is set to zero, and would bake the old value into any assembly built against this one.
|
||||
public static readonly float VisualScale = 0.70f; // -30% versus a human
|
||||
// Nudged up from the 0.70 the spec asked for: -30% read as too small next to a human once
|
||||
// it was actually on screen.
|
||||
public static readonly float VisualScale = 0.78f; // -22% versus a human
|
||||
|
||||
// ─── Skin ────────────────────────────────────────────────────────────
|
||||
// Tint applied over the human skin texture, the same multiplicative m_skinColor the
|
||||
// Furling and Trol use. Ashen grey with a blue cast, to read as one of the deep folk.
|
||||
public static readonly Vector3 SkinColor = new Vector3(0.72f, 0.74f, 0.82f);
|
||||
// Written straight onto the body material's _SkinColor by the UpdateColors postfix, which
|
||||
// is the only thing that actually tints a player - see the comment on that patch.
|
||||
// Ashen grey with a blue cast, to read as one of the deep folk.
|
||||
public static readonly Color SkinColor = new Color(0.72f, 0.74f, 0.82f, 1f);
|
||||
|
||||
// Dvergr are white-haired. The hood hides most of it, but the beard shows.
|
||||
public static readonly Color HairColor = new Color(0.88f, 0.88f, 0.90f, 1f);
|
||||
|
||||
// ─── Cosmetic hood ───────────────────────────────────────────────────
|
||||
// The helmet slot itself stays free — whatever the player equips keeps all of its stats,
|
||||
|
|
|
|||
|
|
@ -300,6 +300,52 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
// ─── Skin ────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Tints the Dvergur ashen grey.
|
||||
///
|
||||
/// The first attempt did this the way the race-selection menu appears to - VisEquipment's
|
||||
/// SetSkinColor followed by UpdateColors - and nothing happened, because that pair is not
|
||||
/// what actually colours a player. UpdateColors rebuilds the body material from Valheim's
|
||||
/// own state on every refresh, so any tint has to be written *after* it runs. That is why
|
||||
/// every race in this mod that visibly changes colour has a postfix here writing
|
||||
/// _SkinColor onto the material directly, and why the SetSkinColor calls in the selection
|
||||
/// menu are, on their own, decorative.
|
||||
///
|
||||
/// No local-player check and no saved original: the race is read from the ZDO with a
|
||||
/// m_customData fallback so the main-menu preview and the first spawn frame are covered
|
||||
/// too, and the tint simply stops being applied once the player is no longer a Dvergur.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(VisEquipment), "UpdateColors")]
|
||||
public static class Dvergur_VisEquipment_UpdateColors_Patch
|
||||
{
|
||||
public static void Postfix(VisEquipment __instance)
|
||||
{
|
||||
if (__instance == null || !__instance.m_isPlayer) return;
|
||||
|
||||
Player player = __instance.GetComponent<Player>();
|
||||
if (player == null || !DvergurVisuals.IsDvergurPlayer(player)) return;
|
||||
|
||||
if (__instance.m_bodyModel != null && __instance.m_bodyModel.material != null)
|
||||
{
|
||||
__instance.m_bodyModel.material.SetColor("_SkinColor", DvergurConfig.SkinColor);
|
||||
}
|
||||
|
||||
TintRenderers(Traverse.Create(__instance).Field("m_hairItemInstance").GetValue<GameObject>());
|
||||
TintRenderers(Traverse.Create(__instance).Field("m_beardItemInstance").GetValue<GameObject>());
|
||||
}
|
||||
|
||||
private static void TintRenderers(GameObject instance)
|
||||
{
|
||||
if (instance == null) return;
|
||||
foreach (Renderer renderer in instance.GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
if (renderer.material != null) renderer.material.SetColor("_SkinColor", DvergurConfig.HairColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Cosmetic hood ───────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -78,40 +78,6 @@ namespace RacesOfValheim
|
|||
}
|
||||
}
|
||||
|
||||
// ─── Skin ────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Tints the local player's skin, saving the original first so ResetRace can put it back.
|
||||
/// Same save-then-tint dance the Furling, Trol and Draugh selections do.
|
||||
/// </summary>
|
||||
public static void ApplySkinColor(Player player)
|
||||
{
|
||||
if (player == null) return;
|
||||
|
||||
VisEquipment visEq = player.GetComponent<VisEquipment>();
|
||||
if (visEq == null) return;
|
||||
|
||||
if (!player.m_customData.ContainsKey("OriginalSkinColor_X"))
|
||||
{
|
||||
Vector3 current = Traverse.Create(visEq).Field("m_skinColor").GetValue<Vector3>();
|
||||
player.m_customData["OriginalSkinColor_X"] = current.x.ToString();
|
||||
player.m_customData["OriginalSkinColor_Y"] = current.y.ToString();
|
||||
player.m_customData["OriginalSkinColor_Z"] = current.z.ToString();
|
||||
}
|
||||
|
||||
Traverse.Create(visEq).Method("SetSkinColor", DvergurConfig.SkinColor).GetValue();
|
||||
RefreshColors(visEq);
|
||||
}
|
||||
|
||||
public static void RefreshColors(VisEquipment visEq)
|
||||
{
|
||||
if (visEq == null) return;
|
||||
visEq.GetType().GetMethod("UpdateColors",
|
||||
System.Reflection.BindingFlags.Instance |
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
|
||||
// ─── Hood ────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -593,9 +593,8 @@ namespace RacesOfValheim
|
|||
|
||||
Player.m_localPlayer.GetSEMan().AddStatusEffect(DvergurConfig.StatsSE.GetStableHashCode(), true);
|
||||
|
||||
// Saves the original skin first, so ResetRace can hand it back.
|
||||
DvergurVisuals.ApplySkinColor(Player.m_localPlayer);
|
||||
|
||||
// No SetSkinColor here: the tint is written onto the material by the UpdateColors
|
||||
// postfix in DvergurPatches, which keys off the race and so needs nothing saved.
|
||||
VisEquipment visEq = Player.m_localPlayer.GetComponent<VisEquipment>();
|
||||
if (visEq != null)
|
||||
{
|
||||
|
|
@ -692,12 +691,8 @@ namespace RacesOfValheim
|
|||
if (visEq != null) visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null);
|
||||
}
|
||||
|
||||
// Re-tinted rather than merely refreshed: the skin colour is the one piece of the
|
||||
// Dvergur that is not rebuilt from the race id on its own.
|
||||
if (__instance.m_customData.ContainsKey("Race") && __instance.m_customData["Race"] == DvergurConfig.RaceId)
|
||||
{
|
||||
DvergurVisuals.ApplySkinColor(__instance);
|
||||
}
|
||||
// The Dvergur needs no entry here: its tint is applied by the UpdateColors postfix
|
||||
// every time Valheim refreshes the body, rather than being stored on the player.
|
||||
|
||||
// Check for Race Selection
|
||||
if (!__instance.m_customData.ContainsKey("Race"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue