Skip to content

Commit

Permalink
adds animal markers for all animals
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Jun 21, 2020
1 parent 26728be commit 37f3d21
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 25 deletions.
1 change: 1 addition & 0 deletions Languages/English/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<IncludeAnimals>Animals have the same marker</IncludeAnimals>
<AnimalsDifferent>Animals have a different marker</AnimalsDifferent>
<HideAnimals>Animals have no marker</HideAnimals>
<IncludeNotTamedAnimals>Include untamed animals</IncludeNotTamedAnimals>
<ZoomToMouse>Zoom to mouse</ZoomToMouse>
<MouseRevealsLabels>Mouse reveals labels</MouseRevealsLabels>
<KeyLeftShift>Left Shift</KeyLeftShift>
Expand Down
1 change: 1 addition & 0 deletions Languages/German/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<IncludeAnimals>Tiere haben den gleichen Marker</IncludeAnimals>
<AnimalsDifferent>Tiere haben einen anderen Marker</AnimalsDifferent>
<HideAnimals>Tiere haben keinen Marker</HideAnimals>
<IncludeNotTamedAnimals>Auch ungezähmte Tiere</IncludeNotTamedAnimals>
<ZoomToMouse>Zoom an die Maus</ZoomToMouse>
<MouseRevealsLabels>Maus zeigt Labels</MouseRevealsLabels>
<KeyLeftShift>Left Shift</KeyLeftShift>
Expand Down
1 change: 1 addition & 0 deletions Languages/Japanese/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<IncludeAnimals>動物は同じマーカーを持っています</IncludeAnimals>
<AnimalsDifferent>動物は別のマーカーを持っています</AnimalsDifferent>
<HideAnimals>動物にはマーカーがありません</HideAnimals>
<IncludeNotTamedAnimals>飼いならされていない動物を含める</IncludeNotTamedAnimals>
<ZoomToMouse>マウスポインタにズーム</ZoomToMouse>
<KeyLeftShift>左Shift</KeyLeftShift>
<KeyLeftAlt>左Alt</KeyLeftAlt>
Expand Down
1 change: 1 addition & 0 deletions Languages/Spanish/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<IncludeAnimals>Los animales tienen el mismo marcador</IncludeAnimals>
<AnimalsDifferent>Los animales tienen un marcador diferente</AnimalsDifferent>
<HideAnimals>Los animales no tienen marcador</HideAnimals>
<IncludeNotTamedAnimals>Incluir animales indómitos</IncludeNotTamedAnimals>
<ZoomToMouse>Acercar al mouse</ZoomToMouse>
<MouseRevealsLabels>El mouse revela etiquetas</MouseRevealsLabels>
<KeyLeftShift>Left Shift</KeyLeftShift>
Expand Down
1 change: 1 addition & 0 deletions Languages/SpanishLatin/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<IncludeAnimals>Los animales tienen el mismo marcador</IncludeAnimals>
<AnimalsDifferent>Los animales tienen un marcador diferente</AnimalsDifferent>
<HideAnimals>Los animales no tienen marcador</HideAnimals>
<IncludeNotTamedAnimals>Incluir animales indómitos</IncludeNotTamedAnimals>
<ZoomToMouse>Acercar al mouse</ZoomToMouse>
<MouseRevealsLabels>El mouse revela etiquetas</MouseRevealsLabels>
<KeyLeftShift>Left Shift</KeyLeftShift>
Expand Down
4 changes: 2 additions & 2 deletions Source/CameraPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<Compile Include="Tools.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.0.8, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Lib.Harmony.2.0.0.8\lib\net472\0Harmony.dll</HintPath>
<Reference Include="0Harmony, Version=2.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Lib.Harmony.2.0.1\lib\net472\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
Expand Down
71 changes: 50 additions & 21 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CameraPlusMain : Mod
public static float orthographicSize = -1f;

// for other mods: set temporarily to true to skip any hiding
public static bool renderEverything = false;
public static bool skipCustomRendering = false;

public CameraPlusMain(ModContentPack content) : base(content)
{
Expand All @@ -38,7 +38,7 @@ public override string SettingsCategory()
}

[HarmonyPatch(typeof(Game))]
[HarmonyPatch("FinalizeInit")]
[HarmonyPatch(nameof(Game.FinalizeInit))]
static class Game_FinalizeInit_Patch
{
static void Postfix()
Expand All @@ -48,7 +48,7 @@ static void Postfix()
}

[HarmonyPatch(typeof(CameraDriver))]
[HarmonyPatch("Update")]
[HarmonyPatch(nameof(CameraDriver.Update))]
static class CameraDriver_Update_Patch
{
static readonly MethodInfo m_SetRootSize = SymbolExtensions.GetMethodInfo(() => SetRootSize(null, 0f));
Expand Down Expand Up @@ -98,7 +98,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
}

[HarmonyPatch(typeof(TimeControls))]
[HarmonyPatch("DoTimeControlsGUI")]
[HarmonyPatch(nameof(TimeControls.DoTimeControlsGUI))]
static class TimeControls_DoTimeControlsGUI_Patch
{
static void Prefix()
Expand All @@ -119,13 +119,13 @@ static void Postfix(ref Vector2 __result)
}

[HarmonyPatch(typeof(MoteMaker))]
[HarmonyPatch("ThrowText")]
[HarmonyPatch(nameof(MoteMaker.ThrowText))]
[HarmonyPatch(new Type[] { typeof(Vector3), typeof(Map), typeof(string), typeof(Color), typeof(float) })]
static class MoteMaker_ThrowText_Patch
{
static bool Prefix(Vector3 loc)
{
if (CameraPlusMain.renderEverything)
if (CameraPlusMain.skipCustomRendering)
return true;

if (CameraPlusMain.Settings.hideNamesWhenZoomedOut == false)
Expand All @@ -143,14 +143,14 @@ static bool Prefix(Vector3 loc)
}

[HarmonyPatch(typeof(PawnRenderer))]
[HarmonyPatch("RenderPawnAt")]
[HarmonyPatch(nameof(PawnRenderer.RenderPawnAt))]
[HarmonyPatch(new Type[] { typeof(Vector3), typeof(RotDrawMode), typeof(bool), typeof(bool) })]
static class PawnRenderer_RenderPawnAt_Patch
{
[HarmonyPriority(10000)]
static bool Prefix(Pawn ___pawn)
{
if (CameraPlusMain.renderEverything)
if (CameraPlusMain.skipCustomRendering)
return true;

var cameraDelegate = Tools.GetCachedCameraDelegate(___pawn);
Expand All @@ -173,8 +173,32 @@ static void Postfix(Pawn ___pawn)
}
}

[HarmonyPatch(typeof(PawnUIOverlay))]
[HarmonyPatch(nameof(PawnUIOverlay.DrawPawnGUIOverlay))]
static class PawnUIOverlay_DrawPawnGUIOverlay_Patch
{
[HarmonyPriority(10000)]
public static bool Prefix(Pawn ___pawn)
{
if (CameraPlusMain.skipCustomRendering)
return true;

if (Tools.IncludeNonTamedAnimals() == false)
return true;

if (!___pawn.Spawned || ___pawn.Map.fogGrid.IsFogged(___pawn.Position))
return true;
if (___pawn.RaceProps.Humanlike)
return true;
if (___pawn.Name != null)
return true;

return GenMapUI_DrawPawnLabel_Patch.HandlePawn(___pawn);
}
}

[HarmonyPatch(typeof(GenMapUI))]
[HarmonyPatch("DrawPawnLabel")]
[HarmonyPatch(nameof(GenMapUI.DrawPawnLabel))]
[HarmonyPatch(new Type[] { typeof(Pawn), typeof(Vector2), typeof(float), typeof(float), typeof(Dictionary<string, string>), typeof(GameFont), typeof(bool), typeof(bool) })]
[StaticConstructorOnStartup]
static class GenMapUI_DrawPawnLabel_Patch
Expand All @@ -184,15 +208,8 @@ static class GenMapUI_DrawPawnLabel_Patch
static readonly Color downedColor = new Color(0.9f, 0f, 0f);
static readonly Color draftedColor = new Color(0f, 0.5f, 0f);

[HarmonyPriority(10000)]
public static bool Prefix(Pawn pawn, float truncateToWidth)
public static bool HandlePawn(Pawn pawn)
{
if (CameraPlusMain.renderEverything)
return true;

if (truncateToWidth != 9999f)
return true; // use label

Tools.ShouldShowLabel(pawn.DrawPos, true, out var showLabel, out var showDot);
if (showLabel)
return true;
Expand Down Expand Up @@ -233,13 +250,25 @@ public static bool Prefix(Pawn pawn, float truncateToWidth)
// skip label
return false;
}

[HarmonyPriority(10000)]
public static bool Prefix(Pawn pawn, float truncateToWidth)
{
if (CameraPlusMain.skipCustomRendering)
return true;

if (truncateToWidth != 9999f)
return true; // use label

return HandlePawn(pawn);
}
}

// if we zoom in a lot, tiny font labels look very out of place
// so we make them bigger with the available fonts
//
[HarmonyPatch(typeof(GenMapUI))]
[HarmonyPatch("DrawThingLabel")]
[HarmonyPatch(nameof(GenMapUI.DrawThingLabel))]
[HarmonyPatch(new Type[] { typeof(Vector2), typeof(string), typeof(Color) })]
static class GenMapUI_DrawThingLabel_Patch
{
Expand All @@ -255,7 +284,7 @@ static GameFont GetAdaptedGameFont(float rootSize)
[HarmonyPriority(10000)]
public static bool Prefix(Vector2 screenPos)
{
if (CameraPlusMain.renderEverything)
if (CameraPlusMain.skipCustomRendering)
return true;

Tools.ShouldShowLabel(screenPos, false, out var showLabel, out _);
Expand Down Expand Up @@ -285,7 +314,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
// map our new camera settings to meaningful enum values
//
[HarmonyPatch(typeof(CameraDriver))]
[HarmonyPatch("CurrentZoom", MethodType.Getter)]
[HarmonyPatch(nameof(CameraDriver.CurrentZoom), MethodType.Getter)]
static class CameraDriver_CurrentZoom_Patch
{
static bool Prefix(ref CameraZoomRange __result, float ___rootSize)
Expand Down Expand Up @@ -350,7 +379,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
// the beginning of this method and replace every "this.rootSize" witn "lerpedRootSize"
//
[HarmonyPatch(typeof(CameraDriver))]
[HarmonyPatch("CurrentViewRect", MethodType.Getter)]
[HarmonyPatch(nameof(CameraDriver.CurrentViewRect), MethodType.Getter)]
static class CameraDriver_CurrentViewRect_Patch
{
static readonly MethodInfo m_Main_LerpRootSize = SymbolExtensions.GetMethodInfo(() => Tools.LerpRootSize(0f));
Expand Down
16 changes: 16 additions & 0 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class CameraPlusSettings : ModSettings
public int hideThingLabelBelow = 32;
public bool mouseOverShowsLabels = true;
public LabelStyle customNameStyle = LabelStyle.AnimalsDifferent;
public bool includeNotTamedAnimals = true;

public KeyCode[] cameraSettingsMod = new[] { KeyCode.LeftShift, KeyCode.None };
public KeyCode cameraSettingsKey = KeyCode.Tab;
Expand Down Expand Up @@ -82,6 +83,7 @@ public override void ExposeData()
Scribe_Values.Look(ref hideThingLabelBelow, "hideThingLabelBelow", 32);
Scribe_Values.Look(ref mouseOverShowsLabels, "mouseOverShowsLabels", true);
Scribe_Values.Look(ref customNameStyle, "customNameStyle", LabelStyle.AnimalsDifferent);
Scribe_Values.Look(ref includeNotTamedAnimals, "includeNotTamedAnimals", true);
Scribe_Values.Look(ref cameraSettingsMod[0], "cameraSettingsMod1", KeyCode.LeftShift);
Scribe_Values.Look(ref cameraSettingsMod[1], "cameraSettingsMod2", KeyCode.None);
Scribe_Values.Look(ref cameraSettingsKey, "cameraSettingsKey", KeyCode.Tab);
Expand All @@ -94,6 +96,12 @@ public override void ExposeData()
{
minRootResult = zoomedInPercent * 2;
maxRootResult = zoomedOutPercent * 2;

if (includeNotTamedAnimals && Prefs.AnimalNameMode != AnimalNameDisplayMode.TameAll)
{
Prefs.AnimalNameMode = AnimalNameDisplayMode.TameAll;
Prefs.Save();
}
}
}

Expand Down Expand Up @@ -229,6 +237,13 @@ public void DoWindowContents(Rect inRect)
var val = (LabelStyle)Enum.Parse(typeof(LabelStyle), label);
if (list.RadioButton(label.Translate(), customNameStyle == val, 8f)) customNameStyle = val;
}
var oldIncludeNotTamedAnimals = includeNotTamedAnimals;
list.CheckboxLabeled("IncludeNotTamedAnimals".Translate(), ref includeNotTamedAnimals);
if (oldIncludeNotTamedAnimals == false || includeNotTamedAnimals == true)
{
Prefs.AnimalNameMode = AnimalNameDisplayMode.TameAll;
Prefs.Save();
}
}

list.Gap(28f);
Expand All @@ -250,6 +265,7 @@ public void DoWindowContents(Rect inRect)
hideThingLabelBelow = 32;
mouseOverShowsLabels = true;
customNameStyle = LabelStyle.AnimalsDifferent;
includeNotTamedAnimals = true;
cameraSettingsMod[0] = KeyCode.LeftShift;
cameraSettingsMod[1] = KeyCode.None;
cameraSettingsKey = KeyCode.Tab;
Expand Down
15 changes: 14 additions & 1 deletion Source/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,21 @@ class Tools : CameraPlusSettings
return color;
}

public static bool IncludeNonTamedAnimals()
{
return CameraPlusMain.Settings.includeNotTamedAnimals && Prefs.AnimalNameMode == AnimalNameDisplayMode.TameAll;
}

// shameless copy of vanilla
public static bool PawnHasNoLabel(Pawn pawn)
{
if (!pawn.Spawned || pawn.Map.fogGrid.IsFogged(pawn.Position))
return true;
if (!pawn.RaceProps.Humanlike)
{
if (IncludeNonTamedAnimals())
return false;

var animalNameMode = Prefs.AnimalNameMode;
if (animalNameMode == AnimalNameDisplayMode.None)
return true;
Expand Down Expand Up @@ -241,6 +249,7 @@ public static CameraDelegates GetCachedCameraDelegate(Pawn pawn)
}

// returning true will prefer markers over labels
static readonly Color dangerousAnimalColor = new Color(0.62f, 0f, 0.05f);
public static bool GetMarkerColors(Pawn pawn, out Color innerColor, out Color outerColor)
{
var cameraDelegate = GetCachedCameraDelegate(pawn);
Expand Down Expand Up @@ -269,7 +278,11 @@ public static bool GetMarkerColors(Pawn pawn, out Color innerColor, out Color ou

innerColor = PawnNameColorUtility.PawnNameColorOf(pawn);
if (pawn.RaceProps.Animal)
innerColor = GetMainColor(pawn) ?? innerColor;
{
var stateDef = pawn.mindState.mentalStateHandler.CurStateDef;
var isDangerous = stateDef == MentalStateDefOf.ManhunterPermanent || stateDef == MentalStateDefOf.Manhunter;
innerColor = isDangerous ? dangerousAnimalColor : (GetMainColor(pawn) ?? innerColor);
}
outerColor = Find.Selector.IsSelected(pawn) ? Color.black : Color.white;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Lib.Harmony" version="2.0.0.8" targetFramework="net472" />
<package id="Lib.Harmony" version="2.0.1" targetFramework="net472" />
</packages>
Binary file modified v1.1/Assemblies/CameraPlus.dll
Binary file not shown.

0 comments on commit 37f3d21

Please sign in to comment.