示例#1
0
        /// <summary>
        /// Creates a hediff light modifier setting corresponding to sight affecting hediffs
        /// - has special behaviour for hediffs that effect the eye directly
        /// - takes lists to ensure data is copied
        /// </summary>
        /// <param name="sightAffectingHediffs"></param>
        /// <param name="eyeHediffs"></param>
        private void InitialiseHediffLightMods(List <HediffDef> sightAffectingHediffs, List <HediffDef> eyeHediffs)
        {
            var hediffLightMods = Settings.Store.HediffLightMods ?? new Dictionary <HediffDef, Hediff_LightModifiers>();

            var sightNotEyeHediffs = sightAffectingHediffs.Except(eyeHediffs);

            //Check to see if any non eye hediffs have the right comp
            foreach (HediffDef hediffDef in sightNotEyeHediffs)
            {
                if (!hediffLightMods.TryGetValue(key: hediffDef, value: out Hediff_LightModifiers value) ||
                    value == null)
                {
                    if (hediffDef.HasComp(compClass: typeof(HediffComp_NightVision)))
                    {
                        hediffLightMods[key : hediffDef] = new Hediff_LightModifiers(hediffDef : hediffDef);
                    }
                }

                if (value != null && AutoQualifier.HediffCheck(hediffDef: hediffDef) != null)
                {
                    value.AutoAssigned = true;
                }
            }

            //Do the same thing as above but for eye hediffs;
            foreach (HediffDef hediffDef in eyeHediffs)
            {
                if (!hediffLightMods.TryGetValue(key: hediffDef, value: out Hediff_LightModifiers value) ||
                    value == null)
                {
                    if (hediffDef.CompPropsFor(compClass: typeof(HediffComp_NightVision)) is HediffCompProperties_NightVision)
                    {
                        hediffLightMods[key : hediffDef] = new Hediff_LightModifiers(hediffDef : hediffDef)
                        {
                            AffectsEye = true
                        };
                    }
                    //bionic eyes and such are automatically assigned night vision, this can be individually overridden in the mod settings
                    else if (AutoQualifier.HediffCheck(hediffDef: hediffDef) is VisionType autoOptions)
                    {
                        hediffLightMods[key : hediffDef] =
                            new Hediff_LightModifiers(hediffDef : hediffDef)
                        {
                            AffectsEye = true, AutoAssigned = true, Setting = autoOptions
                        };
                    }
                }
        public static void HediffTab(
            Rect inRect
            )
        {
            int hediffcount = SettingsCache.GetAllHediffs.Count;

            if (DrawSettings._numberOfCustomHediffs == null)
            {
                DrawSettings._numberOfCustomHediffs =
                    Storage.HediffLightMods.Count(hlm => hlm.Value.IntSetting == VisionType.NVCustom);
            }

            inRect = inRect.AtZero();

            SettingsHelpers.DrawLightModifiersHeader(
                ref inRect,
                "NVHediffs".Translate(),
                "NVHediffNote".Translate() + "NVHediffNoteCont".Translate()
                );

            float num = inRect.y + 3f;

            var viewRect = new Rect(
                inRect.x,
                inRect.y,
                inRect.width * 0.9f,
                hediffcount
                * (Constants.RowHeight + Constants.RowGap)
                + (float)DrawSettings._numberOfCustomHediffs * 100f
                );

            var rowRect = new Rect(inRect.x + 6f, num, inRect.width - 12f, Constants.RowHeight);

            Widgets.BeginScrollView(inRect, ref DrawSettings._hediffScrollPosition, viewRect);

            for (var i = 0; i < hediffcount; i++)
            {
                HediffDef hediffdef = SettingsCache.GetAllHediffs[i];
                rowRect.y = num;

                if (Storage.HediffLightMods.TryGetValue(hediffdef, out Hediff_LightModifiers hediffmods))
                {
                    DrawSettings._numberOfCustomHediffs +=
                        SettingsHelpers.DrawLightModifiersRow(
                            hediffdef,
                            hediffmods,
                            rowRect,
                            ref num,
                            false
                            );
                }
                else
                {
                    Hediff_LightModifiers temp = Storage.AllEyeHediffs.Contains(hediffdef)
                                ? new Hediff_LightModifiers {
                        AffectsEye = true
                    }
                                : new Hediff_LightModifiers();

                    DrawSettings._numberOfCustomHediffs +=
                        SettingsHelpers.DrawLightModifiersRow(
                            hediffdef,
                            temp,
                            rowRect,
                            ref num,
                            false
                            );

                    if (temp.IntSetting != VisionType.NVNone)
                    {
                        temp.InitialiseNewFromSettings(hediffdef);
                        Storage.HediffLightMods[hediffdef] = temp;
                    }
                }

                num += Constants.RowHeight + Constants.RowGap;

                if (i < hediffcount)
                {
                    Widgets.DrawLineHorizontal(
                        rowRect.x + 6f,
                        num - (Constants.RowGap / 2 - 0.5f),
                        rowRect.width - 12f
                        );
                }
            }

            Widgets.EndScrollView();
        }