Example #1
0
        public void FindAllValidApparel()
        {
            var headgearCategoryDef = ThingCategoryDef.Named(defName: "Headgear");
            var fullHead            = Defs_Rimworld.Head;
            var eyes = Defs_Rimworld.Eyes;

            var allEyeCoveringHeadgearDefs = new HashSet <ThingDef>(
                collection: DefDatabase <ThingDef> .AllDefsListForReading.FindAll(
                    match: def => def.IsApparel &&
                    ((def.thingCategories?.Contains(item: headgearCategoryDef) ?? false) ||
                     def.apparel.bodyPartGroups.Any(predicate: bpg => bpg == eyes || bpg == fullHead) ||
                     def.HasComp(compType: typeof(Comp_NightVisionApparel)))
                    )
                );
            var nvApparel = Settings.Store.NVApparel ?? new Dictionary <ThingDef, ApparelVisionSetting>();

            //Add defs that have NV comp
            foreach (ThingDef apparel in allEyeCoveringHeadgearDefs)
            {
                if (apparel.comps.Find(match: comp => comp is CompProperties_NightVisionApparel) is CompProperties_NightVisionApparel)
                {
                    if (!nvApparel.TryGetValue(key: apparel, value: out ApparelVisionSetting setting))
                    {
                        nvApparel[key : apparel] = new ApparelVisionSetting(apparel : apparel);
                    }
                    else
                    {
                        setting.InitExistingSetting(apparel: apparel);
                    }
                }
Example #2
0
 public ApparelSaveLoadClass(
     ThingDef key,
     ApparelVisionSetting value
     )
 {
     Key   = key;
     Value = value;
 }
Example #3
0
        public static ApparelVisionSetting CreateNewApparelVisionSetting(
            ThingDef apparel
            )
        {
            var newAppSetting = new ApparelVisionSetting {
                ParentDef = apparel
            };

            newAppSetting.AttachComp();

            if (newAppSetting.ParentDef != apparel)
            {
                Log.Message(
                    "NightVision.ApparelVisionSetting.CreateNewApparelVisionSetting: Failed to attach Comp, parentdef != given appareldef"
                    );
            }

            return(newAppSetting);
        }
Example #4
0
        public void DrawTab(Rect inRect)
        {
            var nvApparel      = Settings.Store.NVApparel;
            var cachedHeadgear = Settings.Cache.GetAllHeadgear;

            Text.Anchor = TextAnchor.LowerCenter;
            var apparelCount = cachedHeadgear.Count;
            var headerRect   = new Rect(24f, 0f, inRect.width - 64f, 36f);
            var leftRect     = headerRect.LeftPart(0.4f);
            var midRect      = headerRect.RightPart(0.6f).LeftHalf().RightPart(0.8f);
            var rightRect    = headerRect.RightPart(0.6f).RightHalf().LeftPart(0.8f);

            Widgets.Label(leftRect, "NVApparel".Translate());
            Widgets.Label(midRect, "NVNullPS".Translate());
            Widgets.Label(rightRect, "NVGiveNV".Translate());

            Widgets.DrawLineHorizontal(headerRect.x + 12f, headerRect.yMax + 4f, headerRect.xMax - 64f);

            Text.Anchor = TextAnchor.MiddleCenter;
            var viewRect   = new Rect(32f, 48f, inRect.width - 64f, apparelCount * 48f);
            var scrollRect = new Rect(12f, 48f, inRect.width - 12f, inRect.height - 48f);


            var leftBoxX  = midRect.center.x + CheckboxSize;
            var rightBoxX = rightRect.center.x + CheckboxSize;
            var leftBox   = new Rect(leftBoxX, 0f, CheckboxSize, CheckboxSize);
            var rightBox  = new Rect(rightBoxX, 0f, CheckboxSize, CheckboxSize);

            var num = 48f;

            Widgets.BeginScrollView(scrollRect, ref _apparelScrollPosition, viewRect);

            foreach (var apparelDef in cachedHeadgear)
            {
                var rowRect = new Rect(scrollRect.x + 12f, num, scrollRect.width - 24f, 40);
                Widgets.DrawAltRect(rowRect);

                var locGUIContent = new GUIContent(apparelDef.LabelCap, apparelDef.uiIcon);
                var apparelRect   = rowRect.LeftPart(0.4f);
                Widgets.Label(apparelRect, locGUIContent);

                TooltipHandler.TipRegion(
                    apparelRect,
                    new TipSignal(apparelDef.DescriptionDetailed /*, apparelRect.GetHashCode()*/)
                    );

                var leftBoxPos  = new Vector2(leftBoxX, rowRect.center.y - CheckboxSize / 2);
                var rightBoxPos = new Vector2(rightBoxX, rowRect.center.y - CheckboxSize / 2);
                leftBox.y  = leftBoxPos.y;
                rightBox.y = leftBoxPos.y;
                TooltipHandler.TipRegion(leftBox, new TipSignal("PSApparelExplained".Translate()));
                TooltipHandler.TipRegion(rightBox, new TipSignal("NVApparelExplained".Translate()));

                if (nvApparel.TryGetValue(apparelDef, out var apparelSetting))
                {
                    Widgets.Checkbox(leftBoxPos, ref apparelSetting.NullifiesPS, CheckboxSize);
                    Widgets.Checkbox(rightBoxPos, ref apparelSetting.GrantsNV, CheckboxSize);

                    if (!apparelSetting.Equals(nvApparel[apparelDef]))
                    {
                        if (apparelSetting.IsRedundant())
                        {
                            nvApparel.Remove(apparelDef);
                        }
                        else
                        {
                            nvApparel[apparelDef] = apparelSetting;
                        }
                    }
                }
                else
                {
                    var nullPs = false;
                    var giveNV = false;
                    Widgets.Checkbox(leftBoxPos, ref nullPs, CheckboxSize);
                    Widgets.Checkbox(rightBoxPos, ref giveNV, CheckboxSize);

                    if (nullPs || giveNV)
                    {
                        if (apparelDef.GetCompProperties <CompProperties_NightVisionApparel>() is
                            CompProperties_NightVisionApparel compprops)
                        {
                            apparelSetting = compprops.AppVisionSetting;
                        }
                        else
                        {
                            apparelSetting =
                                ApparelVisionSetting.CreateNewApparelVisionSetting(apparelDef);
                        }

                        apparelSetting.NullifiesPS = nullPs;
                        apparelSetting.GrantsNV    = giveNV;
                        nvApparel[apparelDef]      = apparelSetting;
                    }
                }

                num += 48f;
            }

            Widgets.EndScrollView();
            Text.Anchor = TextAnchor.UpperLeft;
        }
Example #5
0
 public bool Equals(
     ApparelVisionSetting other
     )
 => GrantsNV == other.GrantsNV && NullifiesPS == other.NullifiesPS;