Skip to content

Commit

Permalink
fix for the FS bench
Browse files Browse the repository at this point in the history
  • Loading branch information
Killface1980 committed Nov 14, 2016
1 parent 04ff09b commit c68b341
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 58 deletions.
Binary file modified Assemblies/RW_FacialStuff.dll
Binary file not shown.
62 changes: 33 additions & 29 deletions Source/RW_FacialStuff/FaceStyler/Dialog_FaceStyling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void DrawIcon(Rect rect)

private Vector2 _scrollPosition = Vector2.zero;

public HairDef newHair
public HairDef NewHair
{
get
{
Expand All @@ -151,11 +151,11 @@ public HairDef newHair
set
{
_newHair = value;
SetGraphicSlot(GraphicSlotGroup.Hair, pawn, HairGraphic(value), pawn.def.uiIcon, newColour);
SetGraphicSlot(GraphicSlotGroup.Hair, pawn, HairGraphic(value), pawn.def.uiIcon, NewColour);
}
}

public BeardDef newBeard
public BeardDef NewBeard
{
get
{
Expand All @@ -164,7 +164,7 @@ public BeardDef newBeard
set
{
_newBeard = value;
SetGraphicSlot(GraphicSlotGroup.Beard, pawn, BeardGraphic(value), pawn.def.uiIcon, newColour);
SetGraphicSlot(GraphicSlotGroup.Beard, pawn, BeardGraphic(value), pawn.def.uiIcon, NewColour);
}
}

Expand All @@ -177,11 +177,11 @@ public MouthDef NewMouth
set
{
_newMouth = value;
SetGraphicSlot(GraphicSlotGroup.Mouth, pawn, MouthGraphic(value), pawn.def.uiIcon, newColour);
SetGraphicSlot(GraphicSlotGroup.Mouth, pawn, MouthGraphic(value), pawn.def.uiIcon, NewColour);
}
}

public EyeDef newEye
public EyeDef NewEye
{
get
{
Expand All @@ -190,11 +190,11 @@ public EyeDef newEye
set
{
_newEye = value;
SetGraphicSlot(GraphicSlotGroup.Eyes, pawn, EyeGraphic(value), pawn.def.uiIcon, newColour);
SetGraphicSlot(GraphicSlotGroup.Eyes, pawn, EyeGraphic(value), pawn.def.uiIcon, NewColour);
}
}

public BrowDef newBrow
public BrowDef NewBrow
{
get
{
Expand All @@ -203,11 +203,11 @@ public BrowDef newBrow
set
{
_newBrow = value;
SetGraphicSlot(GraphicSlotGroup.Brows, pawn, BrowGraphic(value), pawn.def.uiIcon, newColour * new Color(0.3f, 0.3f, 0.3f));
SetGraphicSlot(GraphicSlotGroup.Brows, pawn, BrowGraphic(value), pawn.def.uiIcon, NewColour * new Color(0.3f, 0.3f, 0.3f));
}
}

public Color newColour
public Color NewColour
{
get
{
Expand Down Expand Up @@ -262,7 +262,7 @@ public Dialog_FaceStyling(Pawn p)
pawn = p;
originalColour = (_newColour = pawnSave.HairColorOrg);

colourWrapper = new ColorWrapper(newColour);
colourWrapper = new ColorWrapper(NewColour);

_newHair = (originalHair = pawn.story.hairDef);
_newBeard = (originalBeard = pawnSave.BeardDef);
Expand Down Expand Up @@ -464,7 +464,7 @@ private void DrawUI(Rect parentRect)
{
if (pawn.gender == Gender.Male)
{
if (!newBeard.drawMouth || !pawnSave.drawMouth)
if (!NewBeard.drawMouth || !pawnSave.drawMouth)
{
// layer 1-5 = body
if (i <= 5)
Expand Down Expand Up @@ -585,7 +585,7 @@ private void DrawUI(Rect parentRect)
set.y += 36f;
set.x = selectionRect.x;

if (newBeard.drawMouth || pawn.gender == Gender.Female)
if (NewBeard.drawMouth || pawn.gender == Gender.Female)
{
if (Widgets.ButtonText(set, "Mouth"))
Page = "mouth";
Expand Down Expand Up @@ -907,7 +907,7 @@ private void DrawHairPickerCell(HairDef hair, Rect rect)
GUI.DrawTexture(rect, HairGraphic(hair).MatFront.mainTexture);
string text = hair.LabelCap;
Widgets.DrawHighlightIfMouseover(rect);
if (hair == newHair)
if (hair == NewHair)
{
Widgets.DrawHighlightSelected(rect);
text += "\n(selected)";
Expand All @@ -924,13 +924,13 @@ private void DrawHairPickerCell(HairDef hair, Rect rect)
TooltipHandler.TipRegion(rect, text);
if (Widgets.ButtonInvisible(rect))
{
newHair = hair;
NewHair = hair;
while (Find.WindowStack.TryRemove(typeof(Dialog_ColorPicker)))
{
}
Find.WindowStack.Add(new Dialog_ColorPicker(colourWrapper, delegate
{
newColour = colourWrapper.Color;
NewColour = colourWrapper.Color;
}, false, true)
{
initialPosition = new Vector2(windowRect.xMax + _margin, windowRect.yMin),
Expand All @@ -943,7 +943,7 @@ private void DrawBeardPickerCell(BeardDef beard, Rect rect)
GUI.DrawTexture(rect, BeardGraphic(beard).MatFront.mainTexture);
string text = beard.LabelCap;
Widgets.DrawHighlightIfMouseover(rect);
if (beard == newBeard)
if (beard == NewBeard)
{
Widgets.DrawHighlightSelected(rect);
text += "\n(selected)";
Expand All @@ -959,13 +959,13 @@ private void DrawBeardPickerCell(BeardDef beard, Rect rect)
TooltipHandler.TipRegion(rect, text);
if (Widgets.ButtonInvisible(rect))
{
newBeard = beard;
NewBeard = beard;
while (Find.WindowStack.TryRemove(typeof(Dialog_ColorPicker)))
{
}
Find.WindowStack.Add(new Dialog_ColorPicker(colourWrapper, delegate
{
newColour = colourWrapper.Color;
NewColour = colourWrapper.Color;
}, false, true)
{
initialPosition = new Vector2(windowRect.xMax + _margin, windowRect.yMin),
Expand Down Expand Up @@ -1004,7 +1004,7 @@ private void DrawEyePickerCell(EyeDef eye, Rect rect)
GUI.DrawTexture(rect, EyeGraphic(eye).MatFront.mainTexture);
string text = eye.LabelCap;
Widgets.DrawHighlightIfMouseover(rect);
if (eye == newEye)
if (eye == NewEye)
{
Widgets.DrawHighlightSelected(rect);
text += "\n(selected)";
Expand All @@ -1020,7 +1020,7 @@ private void DrawEyePickerCell(EyeDef eye, Rect rect)
TooltipHandler.TipRegion(rect, text);
if (Widgets.ButtonInvisible(rect))
{
newEye = eye;
NewEye = eye;
Find.WindowStack.TryRemove(typeof(Dialog_ColorPicker));
}
}
Expand All @@ -1030,7 +1030,7 @@ private void DrawBrowPickerCell(BrowDef brow, Rect rect)
GUI.DrawTexture(rect, BrowGraphic(brow).MatFront.mainTexture);
string text = brow.LabelCap;
Widgets.DrawHighlightIfMouseover(rect);
if (brow == newBrow)
if (brow == NewBrow)
{
Widgets.DrawHighlightSelected(rect);
text += "\n(selected)";
Expand All @@ -1046,7 +1046,7 @@ private void DrawBrowPickerCell(BrowDef brow, Rect rect)
TooltipHandler.TipRegion(rect, text);
if (Widgets.ButtonInvisible(rect))
{
newBrow = brow;
NewBrow = brow;
Find.WindowStack.TryRemove(typeof(Dialog_ColorPicker));
}
}
Expand All @@ -1056,7 +1056,7 @@ private void DrawColorPickerCell(Color color, Rect rect)
Widgets.DrawBoxSolid(rect, color);
string text = color.ToString();
Widgets.DrawHighlightIfMouseover(rect);
if (color == newColour)
if (color == NewColour)
{
Widgets.DrawHighlightSelected(rect);
text += "\n(selected)";
Expand All @@ -1072,7 +1072,7 @@ private void DrawColorPickerCell(Color color, Rect rect)
TooltipHandler.TipRegion(rect, text);
if (Widgets.ButtonInvisible(rect))
{
newColour = color;
NewColour = color;

Find.WindowStack.TryRemove(typeof(Dialog_ColorPicker));
}
Expand All @@ -1093,16 +1093,20 @@ public override void DoWindowContents(Rect inRect)
DialogUtility.DoNextBackButtons(inRect, "FacialStuffColorChangerButtonAccept".Translate(), delegate
{
// update render for graphics
pawn.Drawer.renderer.graphics.hairGraphic = GraphicDatabase.Get<Graphic_Multi>(newHair.texPath, ShaderDatabase.Cutout, Vector2.one, newColour);
pawn.Drawer.renderer.graphics.hairGraphic = GraphicDatabase.Get<Graphic_Multi>(NewHair.texPath, ShaderDatabase.Cutout, Vector2.one, NewColour);

// update story to persist across save/load
pawn.story.hairColor = newColour;
pawn.story.hairDef = newHair;
pawn.story.hairColor = NewColour;
pawn.story.hairDef = NewHair;

// FS additions
SaveablePawn pawnSave = MapComponent_FacialStuff.GetCache(pawn);
if (pawn.gender == Gender.Male)
{
pawnSave.BeardDef = newBeard;
pawnSave.BeardDef = NewBeard;
}
pawnSave.EyeDef = NewEye;
pawnSave.BrowDef = NewBrow;
pawnSave.MouthDef = NewMouth;
pawnSave.sessionOptimized = false;
pawn.Drawer.renderer.graphics.ResolveAllGraphics();
Expand Down
52 changes: 24 additions & 28 deletions Source/RW_FacialStuff/GraphicDatabaseHeadRecordsModded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class GraphicDatabaseHeadRecordsModded : GraphicDatabaseHeadRecords
private static readonly string SkullPath = "Things/Pawn/Humanlike/Heads/None_Average_Skull";
protected Pawn pawn;



public static int headIndex = 0;

public class HeadGraphicRecordVanillaCustom
Expand Down Expand Up @@ -57,16 +59,16 @@ public HeadGraphicRecordVanillaCustom(string graphicPath)

public Graphic_Multi GetGraphic(Color color)
{
for (int i = 0; i < graphics.Count; i++)
foreach (KeyValuePair<Color, Graphic_Multi> graphic_multi in graphics)
{
if (color.IndistinguishableFrom(graphics[i].Key))
if (color.IndistinguishableFrom(graphic_multi.Key))
{
return graphics[i].Value;
return graphic_multi.Value;
}
}
Graphic_Multi graphic_Multi_Head = (Graphic_Multi)GraphicDatabase.Get<Graphic_Multi>(graphicPathVanillaCustom, ShaderDatabase.Cutout, Vector2.one, color);
graphics.Add(new KeyValuePair<Color, Graphic_Multi>(color, graphic_Multi_Head));
return graphic_Multi_Head;
Graphic_Multi graphicMultiHead = (Graphic_Multi)GraphicDatabase.Get<Graphic_Multi>(graphicPathVanillaCustom, ShaderDatabase.Cutout, Vector2.one, color);
graphics.Add(new KeyValuePair<Color, Graphic_Multi>(color, graphicMultiHead));
return graphicMultiHead;
}
}

Expand Down Expand Up @@ -134,21 +136,17 @@ public static Graphic_Multi GetModdedHeadNamed(Pawn pawn, bool useVanilla, Color

if (useVanilla)
{
for (int i = 0; i < headsVanillaCustom.Count; i++)
foreach (HeadGraphicRecordVanillaCustom headGraphicRecordVanillaCustom in headsVanillaCustom)
{
HeadGraphicRecordVanillaCustom headGraphicRecordVanillaCustom = headsVanillaCustom[i];

if (headGraphicRecordVanillaCustom.graphicPathVanillaCustom == pawn.story.HeadGraphicPath.Remove(0, 22))
{
return headGraphicRecordVanillaCustom.GetGraphic(color);
}
}
}

for (int i = 0; i < headsModded.Count; i++)
foreach (HeadGraphicRecordModded headGraphicRecordModded in headsModded)
{
HeadGraphicRecordModded headGraphicRecordModded = headsModded[i];

if (headGraphicRecordModded.graphicPathModded == pawnSave.headGraphicIndex)
{
return headGraphicRecordModded.GetGraphicBlank(color);
Expand Down Expand Up @@ -336,8 +334,6 @@ public static Graphic_Multi ModifiedVanillaHead(Pawn pawn, Color color, Graphic
MergeTwoGraphics(ref finalHeadFront, temptexturefront, Color.black);
MergeTwoGraphics(ref finalHeadSide, temptextureside, Color.black);



#region Male
if (pawn.gender == Gender.Male)
{
Expand Down Expand Up @@ -467,16 +463,15 @@ public static Graphic_Multi ModifiedVanillaHead(Pawn pawn, Color color, Graphic
// MergeColor(ref finalHeadBack, pawn.story.SkinColor);
if (pawn.story.crownType == CrownType.Narrow)
{

MergeHeadWithHair(ref finalHeadFront, temptexturefront, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Narrow_front+back"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadSide, temptextureside, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Narrow_side"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadBack, temptextureback, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Narrow_front+back"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadFront, temptexturefront, MaskTextures.MaskTex_Narrow_FrontBack, pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadSide, temptextureside, MaskTextures.MaskTex_Narrow_Side, pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadBack, temptextureback, MaskTextures.MaskTex_Narrow_FrontBack, pawn.story.hairColor);
}
else
{
MergeHeadWithHair(ref finalHeadFront, temptexturefront, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Average_front+back"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadSide, temptextureside, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Average_side"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadBack, temptextureback, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Average_front+back"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadFront, temptexturefront, MaskTextures.MaskTex_Average_FrontBack, pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadSide, temptextureside, MaskTextures.MaskTex_Average_Side, pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadBack, temptextureback, MaskTextures.MaskTex_Average_FrontBack, pawn.story.hairColor);
}

if (false)
Expand Down Expand Up @@ -557,16 +552,15 @@ public static Graphic_Multi ModifiedAlienHead(Pawn pawn, Color color, Graphic ha
// MergeColor(ref finalHeadBack, pawn.story.SkinColor);
if (pawn.story.crownType == CrownType.Narrow)
{

MergeHeadWithHair(ref finalHeadFront, temptexturefront, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Narrow_front+back"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadSide, temptextureside, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Narrow_side"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadBack, temptextureback, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Narrow_front+back"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadFront, temptexturefront, MaskTextures.MaskTex_Narrow_FrontBack, pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadSide, temptextureside, MaskTextures.MaskTex_Narrow_Side, pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadBack, temptextureback, MaskTextures.MaskTex_Narrow_FrontBack, pawn.story.hairColor);
}
else
{
MergeHeadWithHair(ref finalHeadFront, temptexturefront, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Average_front+back"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadSide, temptextureside, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Average_side"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadBack, temptextureback, ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Average_front+back"), pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadFront, temptexturefront, MaskTextures.MaskTex_Average_FrontBack, pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadSide, temptextureside, MaskTextures.MaskTex_Average_Side, pawn.story.hairColor);
MergeHeadWithHair(ref finalHeadBack, temptextureback, MaskTextures.MaskTex_Average_FrontBack, pawn.story.hairColor);
}

finalHeadFront.Compress(true);
Expand Down Expand Up @@ -655,6 +649,7 @@ public static Texture2D MakeReadable(Texture2D texture)

private static void AddFacialHair(Pawn pawn, ref Texture2D finalTexture, Texture2D beard)
{
// offset neede if beards are stretched => narrow
int offset = (finalTexture.width - beard.width) / 2;
int startX = 0;
int startY = finalTexture.height - beard.height;
Expand Down Expand Up @@ -687,6 +682,7 @@ private static void AddFacialHair(Pawn pawn, ref Texture2D finalTexture, Texture

private static void MergeTwoGraphics(ref Texture2D finalTexture, Texture2D topLayer, Color multiplyColor)
{
// offset neede if beards are stretched => narrow
int offset = (finalTexture.width - topLayer.width) / 2;

for (int x = 0; x < 128; x++)
Expand Down
2 changes: 1 addition & 1 deletion Source/RW_FacialStuff/GraphicNamesInFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static IEnumerable<string> GraphicNamesInFolder(string folderPath)
{
while (enumerator.MoveNext())
{
List<string> list2 = enumerator.Current?.name.Split("_".ToCharArray()).ToList();
List<string> list2 = enumerator.Current?.name?.Split("_".ToCharArray()).ToList();
if (list2 == null)
break;
if (list2.Count > 4)
Expand Down
18 changes: 18 additions & 0 deletions Source/RW_FacialStuff/MaskTextures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;

namespace RW_FacialStuff
{
[StaticConstructorOnStartup]
public class MaskTextures
{
public static readonly Texture2D MaskTex_Narrow_FrontBack = ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Narrow_front+back");
public static readonly Texture2D MaskTex_Narrow_Side = ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Narrow_side");
public static readonly Texture2D MaskTex_Average_FrontBack = ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Average_front+back");
public static readonly Texture2D MaskTex_Average_Side = ContentFinder<Texture2D>.Get("MaskTex/MaskTex_Average_side");
}
}
1 change: 1 addition & 0 deletions Source/RW_FacialStuff/RW_FacialStuff.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="GraphicNamesInFolder.cs" />
<Compile Include="Graphic_Multi_HeadParts.cs" />
<Compile Include="Initializer\FS_SpecialInjector.cs" />
<Compile Include="MaskTextures.cs" />
<Compile Include="Utilities\DialogUtility.cs" />
<Compile Include="MapComponent_FacialStuff.cs" />
<Compile Include="ModConfigMenu.cs" />
Expand Down

0 comments on commit c68b341

Please sign in to comment.