/// <summary> /// Updates pawn area and master in case it was changed via inspector /// window /// </summary> internal static void UpdateState( List <AnimalLink> links, List <Pawn> pawns, Policy policy) { List <AnimalLink> mapLinks = null; List <AnimalLink> zoneLinks = null; int currentMap = Find.CurrentMap.uniqueID; //get all links from the current map mapLinks = links.FindAll(x => x.mapId == currentMap); //get all links from the selected zone zoneLinks = mapLinks.FindAll(x => x.zone == policy.id); foreach (Pawn p in pawns) { foreach (AnimalLink l in zoneLinks) { if (l.animal != null && l.animal.Equals(p)) { l.master = p.playerSettings.Master; l.area = p.playerSettings.AreaRestriction; } } } AnimalManager.SetActivePolicy(policy); }
internal static void CleanDeadMaps() { for (int i = 0; i < AnimalManager.activePolicies.Count; i++) { MapActivePolicy map = AnimalManager.activePolicies[i]; if (!Find.Maps.Any(x => x.uniqueID == map.mapId)) { if (!Find.Maps.Any(x => x.uniqueID == map.mapId)) { if (Find.Maps.Count == 1 && !AnimalManager.ActivePoliciesContainsValidMap()) { //this means the player was on the move without any base //and just re-settled. So, let's move the settings to //the new map int mapid = Find.CurrentMap.uniqueID; AnimalManager.MoveLinksToMap(mapid); map.mapId = mapid; } else { AnimalManager.DeleteLinksInMap(map.mapId); AnimalManager.DeleteMap(map); } } } } }
/// <summary> /// Get and set all links from an AnimalPolicy /// </summary> internal static void LoadState( List <AnimalLink> links, List <Pawn> pawns, Policy policy) { List <AnimalLink> mapLinks = null; List <AnimalLink> zoneLinks = null; int currentMap = Find.CurrentMap.uniqueID; //get all links from the current map mapLinks = links.FindAll(x => x != null && x.mapId == currentMap); //get all links from the selected zone zoneLinks = mapLinks.FindAll(x => x != null && x.zone == policy.id); foreach (Pawn p in pawns) { foreach (AnimalLink l in zoneLinks) { if (l.animal != null && l.animal.Equals(p)) { //found animal in zone. Update master if alive p.playerSettings.Master = (l.master != null && l.master.Dead) ? null : l.master; p.playerSettings.AreaRestriction = l.area; p.playerSettings.followDrafted = l.followDrafted; p.playerSettings.followFieldwork = l.followFieldwork; } } } AnimalManager.SetActivePolicy(policy); }
public override void PreClose() { base.PreClose(); AnimalManager.CleanDeadMaps(); AnimalManager.CleanDeadAnimals(this.Pawns.ToList()); AnimalManager.SaveCurrentState(this.Pawns.ToList()); }
/// <summary> /// Draw base and two new buttons! /// </summary> public override void DoWindowContents(Rect fillRect) { if (AnimalManager.DirtyPolicy) { LoadState( AnimalManager.links, this.Pawns.ToList(), AnimalManager.GetActivePolicy()); AnimalManager.DirtyPolicy = false; } float offsetX = 5f; base.DoWindowContents(fillRect); Rect position = new Rect(0f, 0f, fillRect.width, 65f); GUI.BeginGroup(position); Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.LowerCenter; Rect rect1 = new Rect(offsetX, -8f, 165f, Mathf.Round(position.height / 3f)); Widgets.Label(rect1, "BPC.CurrentAnimalPolicy".Translate()); GUI.EndGroup(); Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperLeft; Rect rect2 = new Rect( offsetX, Mathf.Round(position.height / 4f) - 4f, rect1.width, Mathf.Round(position.height / 4f) + 4f); if (Widgets.ButtonText( rect2, AnimalManager.GetActivePolicy().label, true, false, true)) { SaveCurrentState(this.Pawns.ToList()); OpenAnimalPolicySelectMenu( AnimalManager.links, this.Pawns.ToList()); } offsetX += rect1.width; Rect rect3 = new Rect(offsetX, 0f, 20f, Mathf.Round(position.height / 2f)); if (Widgets.ButtonText(rect3, "", true, false, true)) { Find.WindowStack.Add( new Dialog_ManagePolicies(Find.VisibleMap)); } Rect rect4 = new Rect(offsetX + 3f, rect3.height / 4f, 14f, 14f); GUI.DrawTexture(rect4, Resources.Settings); TooltipHandler.TipRegion(rect4, "BPC.Settings".Translate()); }
private static void CleanDeadMaps() { for (int i = 0; i < AnimalManager.activePolicies.Count; i++) { MapActivePolicy map = AnimalManager.activePolicies[i]; if (!Find.Maps.Any(x => x.uniqueID == map.mapId)) { AnimalManager.DeleteLinksInMap(map.mapId); AnimalManager.DeleteMap(map); } } }
public override void PreOpen() { base.PreOpen(); AnimalManager.CleanDeadMaps(); AnimalManager.UpdateState( AnimalManager.links, this.Pawns.ToList(), AnimalManager.GetActivePolicy()); AnimalManager.LoadState( AnimalManager.links, this.Pawns.ToList(), AnimalManager.GetActivePolicy()); AnimalManager.CleanDeadAnimals(this.Pawns.ToList()); }
private static void DoColumn( Rect rect, Policy policy, Resources.Type type) { GUI.BeginGroup(rect); WidgetRow widgetRow = new WidgetRow(0f, 0f, UIDirection.RightThenUp, 99999f, 4f); widgetRow.Gap(4f); if (policy != null) { widgetRow.Label(policy.label, 138f); if (widgetRow.ButtonText( "BPC.Rename".Translate(), null, true, false)) { Find.WindowStack.Add(new Dialog_RenamePolicy(policy, type)); } if (policy.id > 0 && widgetRow.ButtonIcon( ContentFinder <Texture2D> .Get( "UI/Buttons/Delete", true), null)) { switch (type) { case Resources.Type.assign: AssignManager.DeletePolicy(policy); break; case Resources.Type.animal: AnimalManager.DeletePolicy(policy); break; case Resources.Type.restrict: RestrictManager.DeletePolicy(policy); break; case Resources.Type.work: WorkManager.DeletePolicy(policy); break; } } } GUI.EndGroup(); }
private static void OpenAnimalPolicySelectMenu( List <AnimalLink> links, List <Pawn> pawns) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (Policy animalPolicy in AnimalManager.policies) { list.Add( new FloatMenuOption( animalPolicy.label, delegate { AnimalManager.LoadState( links, pawns, animalPolicy); }, MenuOptionPriority.Default, null, null, 0f, null)); } Find.WindowStack.Add(new FloatMenu(list)); }
internal static void SaveCurrentState(List <Pawn> pawns) { int currentMap = Find.CurrentMap.uniqueID; //Save current state foreach (Pawn p in pawns) { //find animal on the current zone AnimalLink animalLink = AnimalManager.links.Find( x => x != null && p.Equals(x.animal) && x.zone == AnimalManager.GetActivePolicy().id&& x.mapId == currentMap); if (animalLink != null) { //animal found! save master and area animalLink.master = p.playerSettings.Master; animalLink.area = p.playerSettings.AreaRestriction; animalLink.followDrafted = p.playerSettings.followDrafted; animalLink.followFieldwork = p.playerSettings.followFieldwork; } else { //animal not found. So add it to the AnimalLink list AnimalManager.links.Add(new AnimalLink( AnimalManager.GetActivePolicy().id, p, p.playerSettings.Master, p.playerSettings.AreaRestriction, p.playerSettings.followDrafted, p.playerSettings.followFieldwork, currentMap)); } } }
/// <summary> /// Updates pawn area and master in case it was changed via inspector /// window /// </summary> internal static void UpdateState( List <AnimalLink> links, List <Pawn> pawns, Policy policy) { List <AnimalLink> mapLinks = null; List <AnimalLink> zoneLinks = null; int currentMap = Find.CurrentMap.uniqueID; if (links == null) { throw new ArgumentNullException(nameof(links)); } if (policy == null) { throw new ArgumentNullException(nameof(policy)); } //get all links from the current map mapLinks = links.FindAll(l => l != null && l.mapId == currentMap); //get all links from the selected zone zoneLinks = mapLinks.FindAll(ml => ml != null && ml.zone == policy.id); var brokenLinks = links.FindAll(x => x == null).CountAllowNull(); if (brokenLinks > 0) { Log.Warning("[BPC] AnimalManager.UpdateState was given " + brokenLinks + " dead links"); } foreach (Pawn p in pawns) { foreach (AnimalLink l in zoneLinks) { if (l.animal != null && l.animal.Equals(p)) { l.master = p.playerSettings.Master; l.area = p.playerSettings.AreaRestriction; } } } AnimalManager.SetActivePolicy(policy); }
public override void ExposeData() { base.ExposeData(); if (Scribe.mode == LoadSaveMode.LoadingVars || Scribe.mode == LoadSaveMode.Saving) { Scribe_References.Look <Outfit>( ref AssignManager._defaultOutfit, "DefaultOutfit"); Scribe_References.Look <DrugPolicy>( ref AssignManager._defaultDrugPolicy, "DefaultDrugPolicy"); Scribe_References.Look <FoodRestriction>( ref AssignManager._defaultFoodPolicy, "DefaultFoodPolicy"); Scribe_References.Look <FoodRestriction>( ref AssignManager._defaultPrisonerFoodPolicy, "DefaultPrisonerFoodPolicy"); Scribe_Collections.Look <Policy>( ref AssignManager.policies, "AssignPolicies", LookMode.Deep); Scribe_Collections.Look <AssignLink>( ref AssignManager.links, "AssignLinks", LookMode.Deep); if (AssignManager.links == null) { //this is only required if the save file contains //empty links AssignManager.InstantiateLinks(); } Scribe_Collections.Look <string>( ref AssignManager.Prisoners, "Prisoners", LookMode.Value); if (AssignManager.Prisoners == null) { //this is only required if the save file contains //empty prisoners AssignManager.InstantiatePrisoners(); } Scribe_Collections.Look <MapActivePolicy>( ref AssignManager.activePolicies, "AssignActivePolicies", LookMode.Deep); Scribe_Collections.Look <Policy>( ref AnimalManager.policies, "AnimalPolicies", LookMode.Deep); Scribe_Collections.Look <AnimalLink>( ref AnimalManager.links, "AnimalLinks", LookMode.Deep); if (AnimalManager.links == null) { //this is only required if the save file contains //empty links. Not sure how this can happen though :( AnimalManager.InstantiateLinks(); } Scribe_Collections.Look <MapActivePolicy>( ref AnimalManager.activePolicies, "AnimalActivePolicies", LookMode.Deep); Scribe_Collections.Look <Policy>( ref RestrictManager.policies, "RestrictPolicies", LookMode.Deep); Scribe_Collections.Look <RestrictLink>( ref RestrictManager.links, "RestrictLinks", LookMode.Deep); if (RestrictManager.links == null) { //this is only required if the save file contains //empty links. Not sure how this can happen though :( RestrictManager.InstantiateLinks(); } Scribe_Collections.Look <Policy>( ref WorkManager.policies, "WorkPolicies", LookMode.Deep); Scribe_Collections.Look <WorkLink>( ref WorkManager.links, "WorkLinks", LookMode.Deep); Scribe_Collections.Look <MapActivePolicy>( ref WorkManager.activePolicies, "WorkActivePolicies", LookMode.Deep); if (WorkManager.links == null) { //this is only required if the save file contains //empty links. Not sure how this can happen though :( WorkManager.InstantiateLinks(); } if (Scribe.mode == LoadSaveMode.LoadingVars && WorkManager.activePolicies == null) { //this only happens with existing saves prior. Existing saves //have no WorkPolicy data so let's initialize! WorkManager.ForceInit(); } } if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs) { Scribe_References.Look <Outfit>( ref AssignManager._defaultOutfit, "DefaultOutfit"); Scribe_References.Look <DrugPolicy>( ref AssignManager._defaultDrugPolicy, "DefaultDrugPolicy"); Scribe_References.Look <FoodRestriction>( ref AssignManager._defaultFoodPolicy, "DefaultFoodPolicy"); Scribe_References.Look <FoodRestriction>( ref AssignManager._defaultPrisonerFoodPolicy, "DefaultPrisonerFoodPolicy"); } }