From 665c3dfc26747c258d6683144d2eef72ef1db65d Mon Sep 17 00:00:00 2001 From: Debug <49997488+DebugOk@users.noreply.github.com> Date: Tue, 17 Oct 2023 22:09:26 +0200 Subject: [PATCH] Moth RGB 2: The electric boogaloo (#184) --- .../UI/HumanoidProfileEditor.xaml.cs | 10 +++++- .../Humanoid/HumanoidCharacterAppearance.cs | 14 ++++++++ Content.Shared/Humanoid/SkinColor.cs | 34 +++++++++++++++++-- Resources/Prototypes/Species/moth.yml | 2 +- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs index c9a64eb0973..369d8aeab94 100644 --- a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs @@ -642,6 +642,8 @@ private void OnSkinColorOnValueChanged() var skin = _prototypeManager.Index(Profile.Species).SkinColoration; + var skinColor = _prototypeManager.Index(Profile.Species).DefaultSkinTone; + switch (skin) { case HumanoidSkinColor.HumanToned: @@ -671,6 +673,7 @@ private void OnSkinColorOnValueChanged() break; } case HumanoidSkinColor.TintedHues: + case HumanoidSkinColor.TintedHuesSkin: // DeltaV - Tone blending { if (!_rgbSkinColorContainer.Visible) { @@ -678,7 +681,12 @@ private void OnSkinColorOnValueChanged() _rgbSkinColorContainer.Visible = true; } - var color = SkinColor.TintedHues(_rgbSkinColorSelector.Color); + var color = skin switch // DeltaV - Tone blending + { + HumanoidSkinColor.TintedHues => SkinColor.TintedHues(_rgbSkinColorSelector.Color), + HumanoidSkinColor.TintedHuesSkin => SkinColor.TintedHuesSkin(_rgbSkinColorSelector.Color, skinColor), + _ => Color.White + }; CMarkings.CurrentSkinColor = color; Profile = Profile.WithCharacterAppearance(Profile.Appearance.WithSkinColor(color)); diff --git a/Content.Shared/Humanoid/HumanoidCharacterAppearance.cs b/Content.Shared/Humanoid/HumanoidCharacterAppearance.cs index 1ffcd1870be..f1f7de5c11a 100644 --- a/Content.Shared/Humanoid/HumanoidCharacterAppearance.cs +++ b/Content.Shared/Humanoid/HumanoidCharacterAppearance.cs @@ -104,6 +104,8 @@ public static HumanoidCharacterAppearance DefaultWithSpecies(string species) HumanoidSkinColor.HumanToned => Humanoid.SkinColor.HumanSkinTone(speciesPrototype.DefaultHumanSkinTone), HumanoidSkinColor.Hues => speciesPrototype.DefaultSkinTone, HumanoidSkinColor.TintedHues => Humanoid.SkinColor.TintedHues(speciesPrototype.DefaultSkinTone), + // DeltaV - Blended tint for moths + HumanoidSkinColor.TintedHuesSkin => Humanoid.SkinColor.TintedHuesSkin(speciesPrototype.DefaultSkinTone, speciesPrototype.DefaultSkinTone), _ => Humanoid.SkinColor.ValidHumanSkinTone }; @@ -153,6 +155,7 @@ public static HumanoidCharacterAppearance Random(string species, Sex sex) var newEyeColor = random.Pick(RealisticEyeColors); var skinType = IoCManager.Resolve().Index(species).SkinColoration; + var skinTone = IoCManager.Resolve().Index(species).DefaultSkinTone; // DeltaV, required for tone blending var newSkinColor = Humanoid.SkinColor.ValidHumanSkinTone; switch (skinType) @@ -168,6 +171,12 @@ public static HumanoidCharacterAppearance Random(string species, Sex sex) var bbyte = random.NextByte(); newSkinColor = new Color(rbyte, gbyte, bbyte); break; + case HumanoidSkinColor.TintedHuesSkin: // DeltaV, tone blending + rbyte = random.NextByte(); + gbyte = random.NextByte(); + bbyte = random.NextByte(); + newSkinColor = new Color(rbyte, gbyte, bbyte); + break; } if (skinType == HumanoidSkinColor.TintedHues) @@ -175,6 +184,11 @@ public static HumanoidCharacterAppearance Random(string species, Sex sex) newSkinColor = Humanoid.SkinColor.ValidTintedHuesSkinTone(newSkinColor); } + if (skinType == HumanoidSkinColor.TintedHuesSkin) // DeltaV, tone blending + { + newSkinColor = Humanoid.SkinColor.ValidTintedHuesSkinTone(skinTone, newSkinColor); + } + return new HumanoidCharacterAppearance(newHairStyle, newHairColor, newFacialHairStyle, newHairColor, newEyeColor, newSkinColor, new ()); float RandomizeColor(float channel) diff --git a/Content.Shared/Humanoid/SkinColor.cs b/Content.Shared/Humanoid/SkinColor.cs index 89c78b7ea00..2899afae873 100644 --- a/Content.Shared/Humanoid/SkinColor.cs +++ b/Content.Shared/Humanoid/SkinColor.cs @@ -12,9 +12,9 @@ public static class SkinColor /// /// The color to validate /// Validated tinted hue skin tone - public static Color ValidTintedHuesSkinTone(Color color) + public static Color ValidTintedHuesSkinTone(Color color, Color? skinTone = null) { - return TintedHues(color); + return skinTone != null ? TintedHuesSkin(color, skinTone.Value) : TintedHues(color); } /// @@ -127,6 +127,33 @@ public static Color TintedHues(Color color) return Color.FromHsv(newColor); } + /// + /// DeltaV - Convert a color to the 'tinted hues' skin tone type, and blend it into skinColor + /// + /// Color to convert + /// Tinted hue color + public static Color TintedHuesSkin(Color color, Color skinColor, float blendFactor = 0.2f) + { + var colorHsv = Color.ToHsv(color); + var skinHsv = Color.ToHsv(skinColor); + + colorHsv = new Vector4( + skinHsv.X + (colorHsv.X - skinHsv.X) * blendFactor, + skinHsv.Y + (colorHsv.Y - skinHsv.Y) * blendFactor, + skinHsv.Z + (colorHsv.Z - skinHsv.Z) * blendFactor, + skinHsv.W + ); + + colorHsv = new Vector4( + Math.Clamp(colorHsv.X, 0f, 360f), + Math.Clamp(colorHsv.Y, 0f, 1f), + Math.Clamp(colorHsv.Z, 0f, 1f), + colorHsv.W + ); + + return Color.FromHsv(colorHsv); + } + /// /// Verify if this color is a valid tinted hue color type, or not. /// @@ -144,6 +171,7 @@ public static bool VerifySkinColor(HumanoidSkinColor type, Color color) { HumanoidSkinColor.HumanToned => VerifyHumanSkinTone(color), HumanoidSkinColor.TintedHues => VerifyTintedHues(color), + HumanoidSkinColor.TintedHuesSkin => VerifyTintedHues(color), // DeltaV - Tone blending HumanoidSkinColor.Hues => true, _ => false, }; @@ -155,6 +183,7 @@ public static Color ValidSkinTone(HumanoidSkinColor type, Color color) { HumanoidSkinColor.HumanToned => ValidHumanSkinTone, HumanoidSkinColor.TintedHues => ValidTintedHuesSkinTone(color), + HumanoidSkinColor.TintedHuesSkin => ValidTintedHuesSkinTone(color), // DeltaV - Tone blending _ => color }; } @@ -165,4 +194,5 @@ public enum HumanoidSkinColor : byte HumanToned, Hues, TintedHues, //This gives a color tint to a humanoid's skin (10% saturation with full hue range). + TintedHuesSkin, // DeltaV - Default TintedHues assumes the texture will have the proper skin color, but moths dont } diff --git a/Resources/Prototypes/Species/moth.yml b/Resources/Prototypes/Species/moth.yml index 4f587eb40e0..724c268a0bb 100644 --- a/Resources/Prototypes/Species/moth.yml +++ b/Resources/Prototypes/Species/moth.yml @@ -7,7 +7,7 @@ defaultSkinTone: "#ffda93" markingLimits: MobMothMarkingLimits dollPrototype: MobMothDummy - skinColoration: Hues + skinColoration: TintedHuesSkin # DeltaV - No rgb moths, literally 1849 maleFirstNames: names_moth_first_male femaleFirstNames: names_moth_first_female lastNames: names_moth_last