Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicguru committed Apr 27, 2024
2 parents 9d758a0 + fd3a9e9 commit c228f9e
Show file tree
Hide file tree
Showing 11 changed files with 424 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Source/1.5/AnimationMod/AM_DefOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ static AM_DefOf()
public static HediffDef AM_KnockedOut;

public static RenderSkipFlagDef Body;

public static BodyPartGroupDef Hands;
}
55 changes: 46 additions & 9 deletions Source/1.5/AnimationMod/AnimRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AM.Events;
using AM.Hands;
using AM.Idle;
using AM.Patches;
using AM.Processing;
Expand Down Expand Up @@ -706,7 +707,7 @@ public Pawn GetFirstInvalidPawn(bool ignoreNotSpawned = false)
/// Is this pawn valid to be used in this animator?
/// Checks simple conditions such as not dead, destroyed, downed, or held by another Thing...
/// </summary>
public virtual bool IsPawnValid(Pawn p, bool ignoreNotSpawned = false)
protected virtual bool IsPawnValid(Pawn p, bool ignoreNotSpawned = false)
{
// Summary:
// Not dead or downed.
Expand Down Expand Up @@ -1006,7 +1007,7 @@ protected void DrawPawns(Action<Pawn, Vector2> labelDraw = null)
}

[Pure]
private bool IsPawnBeheaded(Pawn pawn, in AnimPartSnapshot bodySS, in AnimPartSnapshot headSS)
private static bool IsPawnBeheaded(Pawn pawn, in AnimPartSnapshot bodySS, in AnimPartSnapshot headSS)
{
// Not sure if this is okay: are there any pawns that are not humanoid
// but can have their heads removed by rendering separately?
Expand Down Expand Up @@ -1383,7 +1384,7 @@ public bool AddPawn(Pawn pawn, int index, bool register)
return true;
}

private void ConfigureHandsForPawn(Pawn pawn, int index)
public void ConfigureHandsForPawn(Pawn pawn, int index)
{
var weapon = pawn.GetFirstMeleeWeapon();
var tweak = weapon?.TryGetTweakData();
Expand All @@ -1394,6 +1395,10 @@ private void ConfigureHandsForPawn(Pawn pawn, int index)
string altHandName = $"HandB{(index > 0 ? index + 1 : "")}";

Color skinColor = pawn.story?.SkinColor ?? Color.white;
Color mainHandColor = skinColor;
Color altHandColor = skinColor;
var mainHandTex = Content.Hand;
var altHandTex = Content.Hand;

// Hand visibility uses the animation data first and foremost, and if the animation does
// not care about hand visibility, then it is dictated by the weapon.
Expand All @@ -1403,6 +1408,7 @@ private void ConfigureHandsForPawn(Pawn pawn, int index)
* Order of descending priority for deciding what hand(s) to show:
* - Mod settings.
* - Has hands (humanoids only).
* - Pawn health, prosthetics, etc.
* - Animation requirement.
* - Weapon requirement.
*/
Expand All @@ -1413,6 +1419,37 @@ private void ConfigureHandsForPawn(Pawn pawn, int index)
// Humanoid?
bool isHumanoid = pawn.RaceProps.Humanlike;

// Health, prosthetics:
bool healthDrawMain = true;
bool healthDrawAlt = true;

if (settingsShowHands && isHumanoid)
{
Span<HandInfo> handInfo = stackalloc HandInfo[2];
int handCount = HandUtility.GetHandData(pawn, handInfo);

if (handCount > 1)
{
var mainHand = handInfo[1];
mainHandColor = mainHand.Color;

if (mainHand.Flags.HasFlag(HandFlags.Clothed))
mainHandTex = Content.HandClothed;
}
if (handCount > 0)
{
var altHand = handInfo[0];
altHandColor = altHand.Color;

if (altHand.Flags.HasFlag(HandFlags.Clothed))
altHandTex = Content.HandClothed;

if (handCount == 1)
healthDrawMain = false;

}
}

// Animation requirement.
bool? animMainHand = vis.showMainHand;
bool? animAltHand = vis.showAltHand;
Expand All @@ -1422,17 +1459,17 @@ private void ConfigureHandsForPawn(Pawn pawn, int index)
bool? weaponAltHand = weapon == null ? null : handsMode == HandsMode.Default;

// Final calculation:
bool showMain = settingsShowHands && isHumanoid && (animMainHand ?? weaponMainHand ?? false);
bool showAlt = settingsShowHands && isHumanoid && (animAltHand ?? weaponAltHand ?? false);
bool showMain = settingsShowHands && isHumanoid && healthDrawMain && (animMainHand ?? weaponMainHand ?? false);
bool showAlt = settingsShowHands && isHumanoid && healthDrawAlt && (animAltHand ?? weaponAltHand ?? false);

// Apply main hand.
var mainHandPart = GetPart(mainHandName);
if (mainHandPart != null)
{
var ov = GetOverride(mainHandPart);
ov.PreventDraw = !showMain;
ov.Texture = AnimationManager.HandTexture;
ov.ColorOverride = skinColor;
ov.Texture = mainHandTex;
ov.ColorOverride = mainHandColor;
}

// Apply alt hand.
Expand All @@ -1441,8 +1478,8 @@ private void ConfigureHandsForPawn(Pawn pawn, int index)
{
var ov = GetOverride(altHandPart);
ov.PreventDraw = !showAlt;
ov.Texture = AnimationManager.HandTexture;
ov.ColorOverride = skinColor;
ov.Texture = altHandTex;
ov.ColorOverride = altHandColor;
}
}

Expand Down
6 changes: 0 additions & 6 deletions Source/1.5/AnimationMod/AnimationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ public class AnimationManager : MapComponent
public static int CullingPadding = 5;
public static bool IsDoingMultithreadedSeek { get; private set; }
public static double MultithreadedSeekTimeMS;
public static Texture2D HandTexture;

private static ulong frameLastSeeked;

public static void Init()
{
HandTexture = ContentFinder<Texture2D>.Get("AM/Hand");
}

public readonly MapPawnProcessor PawnProcessor;

private readonly List<Action> toDraw = new List<Action>();
Expand Down
4 changes: 4 additions & 0 deletions Source/1.5/AnimationMod/Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public static class Content
public static Texture2D BoundMaleRope;
[Content("AM/Shadow")]
public static Texture2D Shadow;
[Content("AM/Hand")]
public static Texture2D Hand;
[Content("AM/HandClothed")]
public static Texture2D HandClothed;

// UI
[Content("AM/UI/IconExecute")]
Expand Down
5 changes: 4 additions & 1 deletion Source/1.5/AnimationMod/Core.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AM.AMSettings;
using AM.Hands;
using AM.Patches;
using AM.Retexture;
using AM.Tweaks;
Expand Down Expand Up @@ -199,6 +200,7 @@ public Core(ModContentPack content) : base(content)
// Initialize settings.
Settings = GetSettings<Settings>();

// Sync:
AddLateLoadAction(true, "Loading default shaders", () =>
{
AnimRenderer.DefaultCutout ??= new Material(ThingDefOf.AIPersonaCore.graphic.Shader);
Expand All @@ -209,15 +211,16 @@ public Core(ModContentPack content) : base(content)
AddLateLoadAction(false, "Checking for patch conflicts...", () => LogPotentialConflicts(Harmony));
AddLateLoadAction(false, "Finding all lassos...", AM.Content.FindAllLassos);

// Async:
AddLateLoadAction(true, "Loading main content...", AM.Content.Load);
AddLateLoadAction(true, "Loading misc textures...", AnimationManager.Init);
AddLateLoadAction(true, "Initializing anim defs...", AnimDef.Init);
AddLateLoadAction(true, "Registering def overrides...", RegisterWeaponDefOverrides);
AddLateLoadAction(true, "Applying settings...", Settings.PostLoadDefs);
AddLateLoadAction(true, "Matching textures with mods...", PreCacheAllRetextures);
AddLateLoadAction(true, "Loading weapon tweak data...", LoadAllTweakData);
AddLateLoadAction(true, "Patch VBE", PatchVBE);
AddLateLoadAction(true, "Apply final patches", Patch_Verb_MeleeAttack_ApplyMeleeDamageToTarget.PatchAll);
AddLateLoadAction(true, "Cache gloves", HandUtility.DoInitialLoading);

AddLateLoadEvents();
}
Expand Down
11 changes: 11 additions & 0 deletions Source/1.5/AnimationMod/Hands/HandFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace AM.Hands;

[Flags]
public enum HandFlags
{
Natural = 1 << 0,
Artificial = 1 << 2,
Clothed = 1 << 1
}
9 changes: 9 additions & 0 deletions Source/1.5/AnimationMod/Hands/HandInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using UnityEngine;

namespace AM.Hands;

public readonly struct HandInfo
{
public required Color Color { get; init; }
public required HandFlags Flags { get; init; }
}
Loading

0 comments on commit c228f9e

Please sign in to comment.