From 6e38fa25575e854a339decec7fec7dc98ffa439f Mon Sep 17 00:00:00 2001 From: James B Date: Wed, 14 Feb 2024 15:07:57 +0100 Subject: [PATCH] Refactor hands visibility logic. --- Source/ThingGenerator/AMSettings/Settings.cs | 2 -- Source/ThingGenerator/AnimRenderer.cs | 32 +++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Source/ThingGenerator/AMSettings/Settings.cs b/Source/ThingGenerator/AMSettings/Settings.cs index bd64fbad..25345feb 100644 --- a/Source/ThingGenerator/AMSettings/Settings.cs +++ b/Source/ThingGenerator/AMSettings/Settings.cs @@ -362,8 +362,6 @@ public class Settings : SimpleSettingsBase "You can opt out of this functionality by disabling this option.\nNote: logging does not occur the first time you run the game with this mod.")] public bool SendStatistics = true; - public bool TrailsAreDisabled => TrailColor.a <= 0 || TrailLengthScale <= 0; - [NonSerialized] public bool IsFirstTimeRunning = true; #endregion diff --git a/Source/ThingGenerator/AnimRenderer.cs b/Source/ThingGenerator/AnimRenderer.cs index 738044ca..5ee3294d 100644 --- a/Source/ThingGenerator/AnimRenderer.cs +++ b/Source/ThingGenerator/AnimRenderer.cs @@ -1321,8 +1321,8 @@ private void ConfigureHandsForPawn(Pawn pawn, int index) var handsMode = tweak?.HandsMode ?? HandsMode.Default; // Hands and skin color... - string mainHandName = $"HandA{(index > 0 ? (index + 1) : "")}"; - string altHandName = $"HandB{(index > 0 ? (index + 1) : "")}"; + string mainHandName = $"HandA{(index > 0 ? index + 1 : "")}"; + string altHandName = $"HandB{(index > 0 ? index + 1 : "")}"; Color skinColor = pawn.story?.SkinColor ?? Color.white; @@ -1330,15 +1330,31 @@ private void ConfigureHandsForPawn(Pawn pawn, int index) // not care about hand visibility, then it is dictated by the weapon. var vis = Def.GetHandsVisibility(index); + /* + * Order of descending priority for deciding what hand(s) to show: + * - Mod settings. + * - Has hands (humanoids only). + * - Animation requirement. + * - Weapon requirement. + */ + + // Settings: + bool settingsShowHands = Core.Settings.ShowHands; + + // Humanoid? + bool isHumanoid = pawn.RaceProps.Humanlike; + + // Animation requirement. bool? animMainHand = vis.showMainHand; - if (animMainHand != null && !pawn.RaceProps.Humanlike) - animMainHand = null; bool? animAltHand = vis.showAltHand; - if (animAltHand != null && !pawn.RaceProps.Humanlike) - animAltHand = null; - bool showMain = Core.Settings.ShowHands && (animMainHand ?? (weapon != null && handsMode != HandsMode.No_Hands)); - bool showAlt = Core.Settings.ShowHands && (animAltHand ?? (weapon != null && handsMode == HandsMode.Default)); + // Weapon requirement: + bool? weaponMainHand = weapon == null ? null : handsMode != HandsMode.No_Hands; + bool? weaponAltHand = weapon == null ? null : handsMode == HandsMode.Default; + + // Final calculation: + bool showMain = settingsShowHands && isHumanoid && (animMainHand ?? weaponMainHand ?? false); + bool showAlt = settingsShowHands && isHumanoid && (animAltHand ?? weaponAltHand ?? false); // Apply main hand. var mainHandPart = GetPart(mainHandName);