Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rules button to Health Overview, closes #5 #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Source/Interface/Dialog_Rules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void UpdateSelected()
UpdateTemplate();
}

private IEnumerable<Pawn> GetOtherPawnsOfType(bool byKind) => _type == null ? Find.CurrentMap.mapPawns.AllPawns.Where(pawn => (pawn != _pawn) && (pawn.GetTargetType() == _preset.Type) && (!byKind || (pawn.kindDef == _pawn.kindDef))) : Find.CurrentMap.mapPawns.AllPawns.Where(pawn => pawn.GetTargetType() == _type);
private IEnumerable<Pawn> GetOtherPawnsOfType(bool byKind) => _type == null ? Find.CurrentMap?.mapPawns.AllPawns.Where(pawn => (pawn != _pawn) && (pawn.GetTargetType() == _preset.Type) && (!byKind || (pawn.kindDef == _pawn.kindDef))) : Find.CurrentMap?.mapPawns.AllPawns.Where(pawn => pawn.GetTargetType() == _type);

private string GetPresetNameDefinite()
{
Expand All @@ -149,9 +149,10 @@ private List<FloatMenuOption> GetAssignmentOptions()
var options = new List<FloatMenuOption>();

var otherPawnsOfType = GetOtherPawnsOfType(false);
if (GetOtherPawnsOfType(false).Any()) { options.Add(new FloatMenuOption(Lang.Get("Dialog_Rules.AssignAll", _preset.Type.LabelPlural.ToLower()), () => AssignAll(false))); }
if (GetOtherPawnsOfType(false)?.Any() == true) { options.Add(new FloatMenuOption(Lang.Get("Dialog_Rules.AssignAll", _preset.Type.LabelPlural.ToLower()), () => AssignAll(false))); }
if ((_type == null) && _pawn.RaceProps.Animal && otherPawnsOfType.Any(kind => kind.kindDef == _pawn.kindDef)) { options.Add(new FloatMenuOption(Lang.Get("Dialog_Rules.AssignAll", _pawn.kindDef.GetLabelPlural().ToLower()), () => AssignAll(true))); }
options.AddRange(Find.CurrentMap.mapPawns.AllPawns.Where(pawn => ((_type != null) || (pawn != _pawn)) && (pawn.GetTargetType() == _preset.Type)).Select(pawn => new FloatMenuOption(Lang.Get("Dialog_Rules.AssignSpecific", pawn.Name.ToString().Italic()), () => AssignSpecific(pawn))));
var toAdd = Find.CurrentMap?.mapPawns.AllPawns.Where(pawn => ((_type != null) || (pawn != _pawn)) && (pawn.GetTargetType() == _preset.Type)).Select(pawn => new FloatMenuOption(Lang.Get("Dialog_Rules.AssignSpecific", pawn.Name.ToString().Italic()), () => AssignSpecific(pawn)));
if (toAdd != null) { options.AddRange(toAdd); }
if ((_type == null) && _preset.Selected.IsPreset) { options.Add(new FloatMenuOption(Lang.Get("Dialog_Rules.AssignDefault", _preset.Type.LabelPlural.ToLower()), () => Dialog_Alert.Open(Lang.Get("Dialog_Rules.AssignDefaultConfirm", _preset.Type.LabelPlural.ToLower(), _preset.Selected.Name.Bold()), Dialog_Alert.Buttons.YesNo, () => Registry.SetDefaultRules(_preset.Selected)))); }

return options;
Expand Down
31 changes: 31 additions & 0 deletions Source/Patch/RimWorld_HealthCardUtility_DrawOverviewTab.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using HarmonyLib;
using PawnRules.Data;
using PawnRules.Interface;
using RimWorld;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Verse;

namespace PawnRules.Patch
{
[HarmonyPatch(typeof(HealthCardUtility), "DrawOverviewTab")]
internal static class RimWorld_HealthCardUtility_DrawOverviewTab
{
private static void Postfix(ref float __result, UnityEngine.Rect leftRect, Pawn pawn, float curY)
{
if (!Registry.IsActive) { return; }

FloatMenu overviewWindowStack = Find.WindowStack.FloatMenu;

if (overviewWindowStack == null) { return; }

List<FloatMenuOption> overviewWindowStackOptions = (List<FloatMenuOption>) typeof(FloatMenu).GetField("options", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(overviewWindowStack);
if (overviewWindowStackOptions?.Count > 0 && overviewWindowStackOptions.Last().Label.Equals("ManageFoodRestrictions".Translate()))
{
overviewWindowStack.Close(false);
Dialog_Rules.Open(pawn);
}
}
}
}
18 changes: 0 additions & 18 deletions Source/Patch/RimWorld_Pawn_FoodRestrictionTracker_Configurable.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private static bool Prefix(ref FoodRestriction __result)
{
if (!Registry.IsActive) { return true; }

__result = new FoodRestriction(-1, Lang.Get("FoodRestrictionsOverridden"));
__result = new FoodRestriction(-1, Lang.Get("Gizmo.EditRulesLabel"));
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/PawnRules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Patch\RimWorld_HealthCardUtility_DrawOverviewTab.cs" />
<Compile Include="Patch\RimWorld_PawnColumnWorker_FoodRestriction_Compare.cs" />
<Compile Include="Patch\RimWorld_PawnColumnWorker_FoodRestriction_DoAssignFoodRestrictionButtons.cs" />
<Compile Include="Patch\RimWorld_PawnColumnWorker_FoodRestriction_DoHeader.cs" />
Expand Down Expand Up @@ -94,7 +95,6 @@
<Compile Include="Patch\RimWorld_GenConstruct_CanConstruct.cs" />
<Compile Include="Patch\RimWorld_InteractionWorker_RomanceAttempt_RandomSelectionWeight.cs" />
<Compile Include="Patch\RimWorld_InteractionWorker_RomanceAttempt_SuccessChance.cs" />
<Compile Include="Patch\RimWorld_Pawn_FoodRestrictionTracker_Configurable.cs" />
<Compile Include="Patch\RimWorld_Pawn_FoodRestrictionTracker_CurrentFoodRestriction.cs" />
<Compile Include="Patch\RimWorld_Pawn_GuestTracker_SetGuestStatus.cs" />
<Compile Include="Patch\RimWorld_PawnUtility_TrySpawnHatchedOrBornPawn.cs" />
Expand Down