Skip to content

Commit

Permalink
Fix for pens
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazzer committed Jul 22, 2021
1 parent 7b9bca2 commit fb7d76c
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 10 deletions.
Binary file modified 1.3/Assemblies/Locks.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
<downloadUrl>https://github.com/pardeike/HarmonyRimWorld/releases/latest</downloadUrl>
</li>
</modDependencies>
<description>Version 2.6.0\nThis addon adds Lock command on every door.\n - Left-click to lock toggle.\n - Right click for more options\n - Alternatively you can use "Lock" inspector tab\n\nNote: Door lock must be flicked by colonist.</description>
<description>Version 2.6.1\nThis addon adds Lock command on every door.\n - Left-click to lock toggle.\n - Right click for more options\n - Alternatively you can use "Lock" inspector tab\n\nNote: Door lock must be flicked by colonist.</description>
</ModMetaData>
4 changes: 4 additions & 0 deletions Languages/English/Keyed/Keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<Locks_ITabVisitorsAllowedDesc>When disabled, allies and traders will not be allowed to pass through this door. This setting do not apply when owners are set.</Locks_ITabVisitorsAllowedDesc>
<Locks_ITabPetDoor>Pet door</Locks_ITabPetDoor>
<Locks_ITabPetDoorDesc>When enabled small animals, like dogs can pass through door. This setting is not required for doors without owners.</Locks_ITabPetDoorDesc>
<Locks_ITabPensDoor>Pens door</Locks_ITabPensDoor>
<Locks_ITabPensDoorDesc>When enabled door will work as pens door. This setting is not required for doors without owners.</Locks_ITabPensDoorDesc>
<Locks_ITabOwners>Owners</Locks_ITabOwners>
<Locks_ITabChangeLocksNotification>Change lock in order to apply settings!</Locks_ITabChangeLocksNotification>

Expand All @@ -23,6 +25,8 @@
<Locks_ForbidVisitors>Forbid visitors from using</Locks_ForbidVisitors>
<Locks_AddPetDoor>Add pet door</Locks_AddPetDoor>
<Locks_RemovePetDoor>Remove pet door</Locks_RemovePetDoor>
<Locks_AddPensDoor>Set as pens door</Locks_AddPensDoor>
<Locks_RemovePensDoor>Remove pens door</Locks_RemovePensDoor>
<Locks_SetOwners>Set owners</Locks_SetOwners>
<Locks_ClearOwners>Clear owners</Locks_ClearOwners>

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>
<p align="center">
<a href="https://github.com/Aviuz/Locks/releases">
<img src="https://img.shields.io/badge/version-2.6.0-blue.svg?style=flat" alt="v2.6.0" />
<img src="https://img.shields.io/badge/version-2.6.1-blue.svg?style=flat" alt="v2.6.1" />
</a>
</p>

Expand Down
15 changes: 10 additions & 5 deletions Source/ITab_Lock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ITab_Lock : ITab
private static readonly Vector2 WinSize = new Vector2(310f + WindowGap, ButtonsHeight + OwnersWindowHeight + OwnersTitleHeight + MainSettingsHeight + WindowGap + 2 * Spacing + WarningHeight);
private const float ButtonsHeight = 25f;
private const float WindowGap = 15f;
private const float MainSettingsHeight = 3 * 32f;
private const float MainSettingsHeight = 4 * 32f;
private const float OwnersTitleHeight = 24f;
private const float OwnersWindowHeight = 200f;
private const float WarningHeight = 24f;
Expand All @@ -27,6 +27,7 @@ public class ITab_Lock : ITab
private bool locked;
private bool vistitorsAllowed;
private bool petDoor;
private bool pensDoor;

private Thing lastSelectedThing;

Expand Down Expand Up @@ -56,12 +57,12 @@ public LockData Data
protected override void FillTab()
{
Rect mainRect = new Rect(0f, 0f, ITab_Lock.WinSize.x, ITab_Lock.WinSize.y).ContractedBy(WindowGap);
Rect upperSettingsRect = new Rect(0f, 0f, mainRect.width, MainSettingsHeight);
Rect ownersTitleRect = new Rect(0f, mainRect.height - OwnersWindowHeight - OwnersTitleHeight - WarningHeight - 2* Spacing - ButtonsHeight, mainRect.width, OwnersTitleHeight);
Rect ownersListRect = new Rect(0f, mainRect.height - OwnersWindowHeight - WarningHeight - 2*Spacing- ButtonsHeight, mainRect.width, OwnersWindowHeight);
Rect upperSettingsRect = new Rect(0f, 0f + WindowGap, mainRect.width, MainSettingsHeight);
Rect ownersTitleRect = new Rect(0f, mainRect.height - OwnersWindowHeight - OwnersTitleHeight - WarningHeight - 2 * Spacing - ButtonsHeight, mainRect.width, OwnersTitleHeight);
Rect ownersListRect = new Rect(0f, mainRect.height - OwnersWindowHeight - WarningHeight - 2 * Spacing - ButtonsHeight, mainRect.width, OwnersWindowHeight);
Rect warningRect = new Rect(0f, mainRect.height - WarningHeight - Spacing - ButtonsHeight, mainRect.width, WarningHeight);
Rect cancelButtonRect = new Rect(mainRect.width - ButtonWidth, mainRect.height - WarningHeight, ButtonWidth, WarningHeight);
Rect copyButtonsRect = new Rect(mainRect.width/2 - Spacing - ButtonWidth, mainRect.height - ButtonsHeight, ButtonWidth, ButtonsHeight);
Rect copyButtonsRect = new Rect(mainRect.width / 2 - Spacing - ButtonWidth, mainRect.height - ButtonsHeight, ButtonWidth, ButtonsHeight);
Rect pasteButtonsRect = new Rect(mainRect.width / 2 + Spacing, mainRect.height - ButtonsHeight, ButtonWidth, ButtonsHeight);
Text.Font = GameFont.Small;
float viewRectCalcHeight = (Text.LineHeight + Spacing) * SelDoor.Map.mapPawns.FreeColonists.Count();
Expand All @@ -78,6 +79,8 @@ protected override void FillTab()
listing.CheckboxLabeled("Locks_ITabVisitorsAllowed".Translate(), ref vistitorsAllowed, "Locks_ITabVisitorsAllowedDesc".Translate());
if (Data.WantedState.IsVisible(nameof(LockState.petDoor)))
listing.CheckboxLabeled("Locks_ITabPetDoor".Translate(), ref petDoor, "Locks_ITabPetDoorDesc".Translate());
if (Data.WantedState.IsVisible(nameof(LockState.pensDoor)))
listing.CheckboxLabeled("Locks_ITabPensDoor".Translate(), ref pensDoor, "Locks_ITabPensDoorDesc".Translate());
listing.End();

if (Data.WantedState.IsVisible(nameof(LockState.owners)))
Expand Down Expand Up @@ -141,6 +144,7 @@ private void UpdateSettings()
Data.WantedState.locked = locked;
Data.WantedState.mode = vistitorsAllowed ? LockMode.Allies : LockMode.Colony;
Data.WantedState.petDoor = petDoor;
Data.WantedState.pensDoor = pensDoor;
if (Data.NeedChange)
LockUtility.UpdateLockDesignation(SelDoor);
}
Expand All @@ -156,6 +160,7 @@ public override void OnOpen()
locked = Data.WantedState.locked;
vistitorsAllowed = Data.WantedState.mode == LockMode.Allies ? true : false;
petDoor = Data.WantedState.petDoor;
pensDoor = Data.WantedState.pensDoor;
}

private void OwnerCheckbox(Rect rect, Pawn pawn)
Expand Down
4 changes: 2 additions & 2 deletions Source/LockData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class LockData : IExposable

public LockData()
{
CurrentState = new LockState(LockMode.Allies, true, false, new List<Pawn>());
WantedState = new LockState(LockMode.Allies, true, false, new List<Pawn>());
CurrentState = new LockState(LockMode.Allies, true, false, false, new List<Pawn>());
WantedState = new LockState(LockMode.Allies, true, false, false, new List<Pawn>());
}

// Utilities
Expand Down
23 changes: 23 additions & 0 deletions Source/LockGizmo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ private void InvertPetDoorFloatMenu(Building_Door door, bool value)
LockUtility.UpdateLockDesignation(door);
}

[SyncMethod]
private void InvertPensDoorFloatMenu(Building_Door door, bool value)
{
LockUtility.GetData(door).WantedState.pensDoor = value;
LockUtility.UpdateLockDesignation(door);
}
[SyncMethod]
private void SetOwnersFloatMenu(Building_Door door)
{
Expand Down Expand Up @@ -142,6 +148,23 @@ public List<FloatMenuOption> GetMenuOptions()
})
));
}

if (LockUtility.GetData(parent).WantedState.IsVisible(nameof(LockState.pensDoor)))
{
list.Add(new FloatMenuOption(
LockUtility.GetData(parent).WantedState.pensDoor ?
"Locks_RemovePensDoor".Translate() :
"Locks_AddPensDoor".Translate(),
new Action(() =>
{
bool value = !LockUtility.GetData(parent).WantedState.pensDoor;
foreach (Building_Door door in Find.Selector.SelectedObjects.Where(o => o is Building_Door))
{
InvertPensDoorFloatMenu(door, value);
}
})
));
}
if (LockUtility.GetData(parent).WantedState.IsVisible(nameof(LockState.owners)))
{
list.Add(new FloatMenuOption(
Expand Down
10 changes: 9 additions & 1 deletion Source/LockState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ public struct LockState
public LockMode mode;
public bool locked;
public bool petDoor;
public bool pensDoor;
public List<Pawn> owners;

public LockState(LockMode mode, bool locked, bool petDoor, List<Pawn> owners)
public LockState(LockMode mode, bool locked, bool petDoor, bool pensDoor, List<Pawn> owners)
{
this.mode = mode;
this.locked = locked;
this.petDoor = petDoor;
this.pensDoor = pensDoor;
this.owners = owners;
}

Expand All @@ -32,6 +34,7 @@ public void CopyFrom(LockState copy)
mode = copy.mode;
locked = copy.locked;
petDoor = copy.petDoor;
pensDoor = copy.pensDoor;
owners.Clear();
owners.AddRange(copy.owners);
}
Expand All @@ -44,6 +47,8 @@ public void CopyFrom(LockState copy)
return false;
if (a.petDoor != b.petDoor)
return false;
if (a.pensDoor != b.pensDoor)
return false;
foreach (var p in a.owners)
if (!b.owners.Contains(p))
return false;
Expand All @@ -61,6 +66,8 @@ public void CopyFrom(LockState copy)
return true;
if (a.petDoor != b.petDoor)
return true;
if (a.pensDoor != b.pensDoor)
return true;
foreach (var p in a.owners)
if (!b.owners.Contains(p))
return true;
Expand All @@ -83,6 +90,7 @@ public void ExposeData(String postfix)
Scribe_Values.Look(ref mode, $"Locks_LockData_Mode_{postfix}", LockMode.Allies, false);
Scribe_Values.Look(ref locked, $"Locks_LockData_Locked_{postfix}", true, false);
Scribe_Values.Look(ref petDoor, $"Locks_LockData_PetDoor_{postfix}", false, false);
Scribe_Values.Look(ref pensDoor, $"Locks_LockData_PensDoor_{postfix}", false, false);
Scribe_Collections.Look(ref owners, $"Locks_LockData_Owners_{postfix}", LookMode.Reference);
}
}
Expand Down
11 changes: 11 additions & 0 deletions Source/LockUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public static bool PawnCanOpen(Building_Door door, Pawn p)

if (p.Faction == null || p.Faction.HostileTo(door.Faction))
return false;
Log.Message($"State check: {respectedState.pensDoor}, { p.RaceProps.FenceBlocked} {!door.def.building.roamerCanOpen} {!p.roping.IsRopedByPawn}");
if( p.roping.RopedByPawn != null)
{
Log.Message($"{!PawnCanOpen(door, p.roping.RopedByPawn)}");
}
if (respectedState.pensDoor && p.RaceProps.FenceBlocked && !door.def.building.roamerCanOpen && (!p.roping.IsRopedByPawn || !PawnCanOpen(door, p.roping.RopedByPawn)))
{
return false;
}

if (respectedState.Private && respectedState.petDoor && p.RaceProps != null && p.RaceProps.Animal && p.RaceProps.baseBodySize <= MaxPetSize && p.Faction == door.Faction)
return true;
Expand Down Expand Up @@ -125,6 +134,8 @@ public static bool IsVisible(this LockState state, string propertyName)
return state.locked && !state.Private;
case nameof(LockState.petDoor):
return state.locked;
case nameof(LockState.pensDoor):
return state.locked;
case nameof(LockState.owners):
return state.locked;
default:
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Changelog:
2.6.1
- Add option to set door as pens door. Animals should not leave pens now.
2.6.0
- update to Rimworld 1.3
2.5.1
Expand Down

0 comments on commit fb7d76c

Please sign in to comment.