Beispiel #1
0
        internal static void Initialize()
        {
            int defCount = 0;

            if (!isInitialized)
            {
                if (ToSave == null)
                {
                    ToSave = new ToSave();
                }

                foreach (ThingDef d in DefDatabase <ThingDef> .AllDefs)
                {
                    ++defCount;

                    if (d.apparel == null ||
                        !IsHeadwear(d.apparel) ||
                        (String.IsNullOrEmpty(d.apparel.wornGraphicPath) &&
                         d.apparel.wornGraphicPaths?.Count == 0))
                    {
                        continue;
                    }

                    HatHideEnum e = HatHideEnum.ShowsHair;
                    if (ToSave.hatsThatHideHair?.Contains(d.defName) == true)
                    {
                        e = HatHideEnum.HidesAllHair;
                    }
                    else if (ToSave.hatsToHideShowBeards?.Contains(d.defName) == true)
                    {
                        e = HatHideEnum.HidesHairShowBeard;
                    }
                    else if (ToSave.hatsToHide?.Contains(d.defName) == true)
                    {
                        e = HatHideEnum.HideHat;
                    }
                    else if (ToSave.hatsToHideUnlessDraftedSH?.Contains(d.defName) == true)
                    {
                        e = HatHideEnum.OnlyDraftSH;
                    }
                    else if (ToSave.hatsToHideUnlessDraftedHH?.Contains(d.defName) == true)
                    {
                        e = HatHideEnum.OnlyDraftHH;
                    }
                    else if (ToSave.hatsToHideUnlessDraftedHHSB?.Contains(d.defName) == true)
                    {
                        e = HatHideEnum.OnlyDraftHHSB;
                    }
                    HatsThatHide[d] = e;
                }

                foreach (HairDef d in DefDatabase <HairDef> .AllDefs)
                {
                    ++defCount;
                    bool selected = false;
                    if (ToSave.hairToHide != null)
                    {
                        foreach (string s in ToSave.hairToHide)
                        {
                            if (s.Equals(d.defName))
                            {
                                selected = true;
                                break;
                            }
                        }
                    }
                    HairToHide[d] = selected;
                }

                if (defCount > 0)
                {
                    isInitialized = true;
                }

                if (isInitialized)
                {
                    ToSave?.Clear();
                    ToSave = null;
                }
            }
        }
Beispiel #2
0
        public override void ExposeData()
        {
            base.ExposeData();

            if (ToSave == null)
            {
                ToSave = new ToSave();
            }

            if (Scribe.mode == LoadSaveMode.Saving)
            {
                ToSave.Clear();

                if (Current.Game != null)
                {
                    foreach (var p in PawnsFinder.AllMaps)
                    {
                        if (p.IsColonist && !p.Dead && p.def.race.Humanlike)
                        {
                            PortraitsCache.SetDirty(p);
                            GlobalTextureAtlasManager.TryMarkPawnFrameSetDirty(p);
                        }
                    }
                }

                foreach (KeyValuePair <ThingDef, HatHideEnum> kv in HatsThatHide)
                {
                    switch (kv.Value)
                    {
                    case HatHideEnum.HidesAllHair:
                        ToSave.hatsThatHideHair.Add(kv.Key.defName);
                        break;

                    case HatHideEnum.HidesHairShowBeard:
                        ToSave.hatsToHideShowBeards.Add(kv.Key.defName);
                        break;

                    case HatHideEnum.HideHat:
                        ToSave.hatsToHide.Add(kv.Key.defName);
                        break;

                    case HatHideEnum.OnlyDraftSH:
                        ToSave.hatsToHideUnlessDraftedSH.Add(kv.Key.defName);
                        break;

                    case HatHideEnum.OnlyDraftHH:
                        ToSave.hatsToHideUnlessDraftedHH.Add(kv.Key.defName);
                        break;

                    case HatHideEnum.OnlyDraftHHSB:
                        ToSave.hatsToHideUnlessDraftedHHSB.Add(kv.Key.defName);
                        break;

                    default:     // ShowHair, do nothing
                        break;
                    }
                }

                ToSave.hairToHide = new List <string>();
                foreach (KeyValuePair <HairDef, bool> kv in HairToHide)
                {
                    if (kv.Value)
                    {
                        ToSave.hairToHide.Add(kv.Key.defName);
                    }
                }
            }

            Scribe_Collections.Look(ref ToSave.hatsThatHideHair, "HatsThatHide", LookMode.Value);
            Scribe_Collections.Look(ref ToSave.hatsToHideShowBeards, "HatsToHideShowBeards", LookMode.Value);
            Scribe_Collections.Look(ref ToSave.hatsToHideUnlessDraftedSH, "HatsToHideUnlessDraftedSH", LookMode.Value);
            Scribe_Collections.Look(ref ToSave.hatsToHideUnlessDraftedHH, "HatsToHideUnlessDraftedHH", LookMode.Value);
            Scribe_Collections.Look(ref ToSave.hatsToHideUnlessDraftedHHSB, "hatsToHideUnlessDraftedHHSB", LookMode.Value);
            Scribe_Collections.Look(ref ToSave.hatsToHide, "HatsToHide", LookMode.Value);
            Scribe_Collections.Look(ref ToSave.hairToHide, "HairToHide", LookMode.Value);
            Scribe_Values.Look <bool>(ref HideAllHats, "HideAllHats", false, false);
            Scribe_Values.Look <bool>(ref OnlyApplyToColonists, "OnlyApplyToColonists", false, false);
            Scribe_Values.Look <bool>(ref ShowHatsOnlyWhenDrafted, "ShowHatsOnlyWhenDrafted", false, false);
            Scribe_Values.Look <bool>(ref ShowHatsWhenDraftedIndoors, "ShowHatsWhenDraftedIndoors", false, false);
            Scribe_Values.Look <Indoors>(ref Indoors, "Indoors", Indoors.ShowHats, false);
            if (Scribe.mode != LoadSaveMode.Saving)
            {
                bool b = false;
                Scribe_Values.Look <bool>(ref b, "HideHatsIndoors", false, false);
                if (b)
                {
                    Indoors = Indoors.HideHats;
                }
            }
            Scribe_Values.Look <bool>(ref UpdatePortrait, "UpdatePortrait", false, false);
            Scribe_Values.Look <bool>(ref UseDontShaveHead, "UseDontShaveHead", true, false);

            if (Scribe.mode == LoadSaveMode.Saving)
            {
                ToSave?.Clear();
                ToSave = null;
            }

            OptionsOpen = false;
        }