private static void SaveCurrentState(List <Pawn> pawns) { int currentMap = Find.CurrentMap.uniqueID; //Save current state foreach (Pawn p in pawns) { //find colonist on the current zone in the current map RestrictLink link = RestrictManager.links.Find( x => x.colonist.Equals(p) && x.zone == RestrictManager.GetActivePolicy().id&& x.mapId == currentMap); if (link != null) { //colonist found! save link.area = p.playerSettings.AreaRestriction; } else { //colonist not found. So add it to the RestrictLink list RestrictManager.links.Add( new RestrictLink( RestrictManager.GetActivePolicy().id, p, p.playerSettings.AreaRestriction, currentMap)); } } }
internal static void PasteToActivePolicy() { Policy policy = GetActivePolicy(); if (!RestrictManager.clipboard.NullOrEmpty() && RestrictManager.clipboard[0].zone != policy.id) { //RestrictManager.links.RemoveAll(x => x.zone == policy.id); foreach (RestrictLink copiedLink in RestrictManager.clipboard) { foreach (RestrictLink link in RestrictManager.links) { if (link.colonist == copiedLink.colonist && link.zone == policy.id) { RestrictManager.CopySchedule(copiedLink.schedule, link.schedule); Log.Message("Copied Schedule"); } } } RestrictManager.LoadState( links, Find.CurrentMap.mapPawns.FreeColonists.ToList(), policy); } }
private static void UpdateState( List <RestrictLink> links, List <Pawn> pawns, Policy policy) { List <RestrictLink> mapLinks = null; List <RestrictLink> zoneLinks = null; int currentMap = Find.VisibleMap.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 (RestrictLink l in zoneLinks) { if (l.colonist != null && l.colonist.Equals(p)) { l.area = p.playerSettings.AreaRestriction; } } } RestrictManager.SetActivePolicy(policy); }
internal static void SaveCurrentState(List <Pawn> pawns) { int currentMap = Find.CurrentMap.uniqueID; int activePolicyId = RestrictManager.GetActivePolicy().id; //Save current state foreach (Pawn p in pawns) { //find colonist in the current zone in the current map RestrictLink link = RestrictManager.links.Find( x => p.Equals(x.colonist) && x.zone == activePolicyId && x.mapId == currentMap); if (link != null) { //colonist found! save link.area = p.playerSettings.AreaRestriction; RestrictManager.CopySchedule(p.timetable.times, link.schedule); } else { //colonist not found. So add it to the RestrictLink list RestrictManager.links.Add( new RestrictLink( activePolicyId, p, p.playerSettings.AreaRestriction, p.timetable.times, currentMap)); } } }
internal static void LoadState( List <RestrictLink> links, List <Pawn> pawns, Policy policy) { List <RestrictLink> mapLinks = null; List <RestrictLink> 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 (RestrictLink l in zoneLinks) { if (l.colonist != null && l.colonist.Equals(p)) { p.playerSettings.AreaRestriction = l.area; RestrictManager.CopySchedule(l.schedule, p.timetable.times); } } } RestrictManager.SetActivePolicy(policy); }
public override void PreClose() { base.PreClose(); RestrictManager.CleanDeadMaps(); RestrictManager.CleanDeadColonists(this.Pawns.ToList()); RestrictManager.SaveCurrentState(this.Pawns.ToList()); }
public override void DoWindowContents(Rect fillRect) { if (RestrictManager.DirtyPolicy) { LoadState( RestrictManager.links, this.Pawns.ToList(), RestrictManager.GetActivePolicy()); RestrictManager.DirtyPolicy = false; } float offsetX = 200f; if (Widget_CSL.CLSAvailable) { offsetX = offsetX + 87f; } 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.CurrentRestrictPolicy".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, RestrictManager.GetActivePolicy().label, true, false, true)) { //CleanDeadColonists(this.pawns); SaveCurrentState(this.Pawns.ToList()); OpenRestrictPolicySelectMenu( RestrictManager.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.CurrentMap)); } 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 < RestrictManager.activePolicies.Count; i++) { MapActivePolicy map = RestrictManager.activePolicies[i]; if (!Find.Maps.Any(x => x.uniqueID == map.mapId)) { RestrictManager.DeleteLinksInMap(map.mapId); RestrictManager.DeleteMap(map); } } }
internal static void PasteToActivePolicy() { Policy policy = GetActivePolicy(); if (!RestrictManager.clipboard.NullOrEmpty() && RestrictManager.clipboard[0].zone != policy.id) { RestrictManager.links.RemoveAll(x => x.zone == policy.id); foreach (RestrictLink copiedLink in RestrictManager.clipboard) { copiedLink.zone = policy.id; RestrictManager.links.Add(copiedLink); } RestrictManager.LoadState(links, Find.CurrentMap.mapPawns.FreeColonists.ToList(), policy); } }
public override void PreOpen() { base.PreOpen(); RestrictManager.CleanDeadMaps(); RestrictManager.UpdateState( RestrictManager.links, this.Pawns.ToList(), RestrictManager.GetActivePolicy()); RestrictManager.LoadState( RestrictManager.links, this.Pawns.ToList(), RestrictManager.GetActivePolicy()); RestrictManager.CleanDeadColonists(this.Pawns.ToList()); }
public override void PreOpen() { base.PreOpen(); //PrintAllAssignPolicies(); UpdateState( RestrictManager.links, this.Pawns.ToList(), RestrictManager.GetActivePolicy()); LoadState( RestrictManager.links, this.Pawns.ToList(), RestrictManager.GetActivePolicy()); CleanDeadMaps(); CleanDeadColonists(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 OpenRestrictPolicySelectMenu( List <RestrictLink> links, List <Pawn> pawns) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (Policy restrictPolicy in RestrictManager.policies) { list.Add( new FloatMenuOption( restrictPolicy.label, delegate { RestrictManager.LoadState( links, pawns, restrictPolicy); }, MenuOptionPriority.Default, null, null, 0f, null)); } Find.WindowStack.Add(new FloatMenu(list)); }
internal static void CleanDeadMaps() { for (int i = 0; i < RestrictManager.activePolicies.Count; i++) { MapActivePolicy map = RestrictManager.activePolicies[i]; if (!Find.Maps.Any(x => x.uniqueID == map.mapId)) { if (Find.Maps.Count == 1 && !RestrictManager.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; RestrictManager.MoveLinksToMap(mapid); map.mapId = mapid; } else { RestrictManager.DeleteLinksInMap(map.mapId); RestrictManager.DeleteMap(map); } } } }
//public class DataStorage : WorldComponent //{ // public DataStorage(World world) : base(world) // { // } public override void ExposeData() { base.ExposeData(); if (Scribe.mode == LoadSaveMode.LoadingVars) { //Let's make sure all static variables are cleaned. //This shows there's a fundamental problem with this code //A code refractor is require to remove the Static Managers //and replace it with GameComponents AssignManager.Prisoners = null; AssignManager.links = null; AssignManager.policies = null; AssignManager.activePolicies = null; AssignManager.DefaultDrugPolicy = null; AssignManager.DefaultFoodPolicy = null; AssignManager.DefaultOutfit = null; AssignManager.DefaultPrisonerFoodPolicy = null; AnimalManager.links = null; AnimalManager.policies = null; AnimalManager.activePolicies = null; WorkManager.links = null; WorkManager.policies = null; WorkManager.activePolicies = null; RestrictManager.links = null; RestrictManager.policies = null; RestrictManager.activePolicies = null; AlertManager.alertLevelsList = null; System.GC.Collect(); } 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); 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); 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); Scribe_Collections.Look <MapActivePolicy>( ref RestrictManager.activePolicies, "RestrictActivePolicies", LookMode.Deep); 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); Scribe_Values.Look <int>( ref AlertManager._alertLevel, "ActiveLevel", 0, true); Scribe_Values.Look <bool>( ref AlertManager._automaticPawnsInterrupt, "AutomaticPawnsInterrupt", true, true); Scribe_Collections.Look <AlertLevel>( ref AlertManager.alertLevelsList, "AlertLevelsList", LookMode.Deep); if (Scribe.mode == LoadSaveMode.LoadingVars && WorkManager.activePolicies == null) { //this only happens with existing saves. Existing saves //have no WorkPolicy data so let's initialize! WorkManager.ForceInit(); } if (Scribe.mode == LoadSaveMode.LoadingVars && RestrictManager.activePolicies == null) { //temporary code to be removed on the next version. To fix saves games without activePolicies RestrictManager.FixActivePolicies(); } } 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"); } }
public override void DoWindowContents(Rect fillRect) { if (RestrictManager.DirtyPolicy) { RestrictManager.LoadState( RestrictManager.links, this.Pawns.ToList(), RestrictManager.GetActivePolicy()); RestrictManager.DirtyPolicy = false; } float offsetX = 200f; if (Widget_CSL.CLSAvailable) { offsetX = offsetX + 87f; } 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.CurrentRestrictPolicy".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, RestrictManager.GetActivePolicy().label, true, false, true)) { RestrictManager.SaveCurrentState(this.Pawns.ToList()); OpenRestrictPolicySelectMenu( RestrictManager.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.CurrentMap)); } Rect rect4 = new Rect(offsetX + 3f, rect3.height / 4f, 14f, 14f); GUI.DrawTexture(rect4, Resources.Settings); TooltipHandler.TipRegion(rect4, "BPC.Settings".Translate()); offsetX += rect3.width; Rect rect5 = new Rect(offsetX + 3f, rect3.height / 4f - 6f, 21f, 28f); if (Widgets.ButtonImage(rect5, ContentFinder <Texture2D> .Get("UI/Buttons/Copy", true))) { RestrictManager.CopyToClipboard(); SoundDefOf.Tick_High.PlayOneShotOnCamera(null); showPaste = true; } TooltipHandler.TipRegion(rect5, "BPC.CopySchedule".Translate()); if (showPaste) { offsetX += rect3.width; Rect rect6 = new Rect(offsetX + 3f, rect3.height / 4f - 6f, 21f, 28f); if (Widgets.ButtonImage(rect6, ContentFinder <Texture2D> .Get("UI/Buttons/Paste", true))) { RestrictManager.PasteToActivePolicy(); SoundDefOf.Tick_Low.PlayOneShotOnCamera(null); } TooltipHandler.TipRegion(rect6, "BPC.PasteSchedule".Translate()); } }
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"); } }