public Dialog_StoryTellerComponentDialog(IsValid isValid)
        {
            this.forcePause = true;
            this.doCloseX   = true;
            this.absorbInputAroundWindow = true;
            this.closeOnAccept           = false;
            this.closeOnClickedOutside   = true;

            this.isValid   = isValid;
            this.compInput = new EnumInputWidget <Dialog_StoryTellerComponentDialog, StoryTellerCompPropertyTypes>(
                this, "Component", 100, d =>
            {
                if (d.comp != null)
                {
                    return(StorytellerCompPropertiesStats.GetType(d.comp.compClass.Name));
                }
                return(StoryTellerCompPropertyTypes.None);
            }, (d, v) =>
            {
                this.comp = StorytellerCompPropertiesStats.CreateStorytellerCompProperties(v);
                if (this.comp != null)
                {
                    this.categoryInput = null;
                    this.incidentInput = null;
                    if (StorytellerCompPropertiesStats.HasCategory(d.comp))
                    {
                        CreateCategoryInput();
                    }
                    if (StorytellerCompPropertiesStats.HasIncident(d.comp))
                    {
                        CreateIncidentInput();
                    }
                }
            });
        }
        public void ApplyStats(object to)
        {
            if (to is StorytellerDef t)
            {
                t.listOrder                   = this.listOrder;
                t.listVisible                 = this.listVisible;
                t.tutorialMode                = this.tutorialMode;
                t.disableAdaptiveTraining     = this.disableAdaptiveTraining;
                t.disableAlerts               = this.disableAlerts;
                t.disablePermadeath           = this.disablePermadeath;
                t.adaptDaysMin                = this.adaptDaysMin;
                t.adaptDaysMax                = this.adaptDaysMax;
                t.adaptDaysGameStartGraceDays = this.adaptDaysGameStartGraceDays;

                this.populationIntentFactorFromPopCurve?.ApplyStats(t.populationIntentFactorFromPopCurve);
                this.populationIntentFactorFromPopAdaptDaysCurve?.ApplyStats(t.populationIntentFactorFromPopAdaptDaysCurve);
                this.pointsFactorFromDaysPassed?.ApplyStats(t.pointsFactorFromDaysPassed);
                this.pointsFactorFromAdaptDays?.ApplyStats(t.pointsFactorFromAdaptDays);
                this.adaptDaysLossFromColonistLostByPostPopulation?.ApplyStats(t.adaptDaysLossFromColonistLostByPostPopulation);
                this.adaptDaysLossFromColonistViolentlyDownedByPopulation?.ApplyStats(t.adaptDaysLossFromColonistViolentlyDownedByPopulation);
                this.adaptDaysGrowthRateCurve?.ApplyStats(t.adaptDaysGrowthRateCurve);

                t.forcedDifficulty = Util.AssignDef(this.forcedDifficulty);

                if (this.comps != null && this.comps.Count > 0)
                {
                    if (t.comps == null)
                    {
                        t.comps = new List <StorytellerCompProperties>();
                    }
                    Dictionary <int, StorytellerCompProperties> lookup = new Dictionary <int, StorytellerCompProperties>();
                    t.comps.ForEach(v => lookup[StorytellerCompPropertiesStats.GetHashCode(v)] = v);
                    t.comps.Clear();

                    foreach (var v in this.comps)
                    {
                        //Log.Warning("Find: " + StorytellerCompPropertiesStats.GetLabel(v));
                        if (lookup.TryGetValue(StorytellerCompPropertiesStats.GetHashCode(v), out StorytellerCompProperties p))
                        {
                            v.ApplyStats(p);
                            t.comps.Add(p);
                        }
                        else
                        {
                            //Log.Warning("Create new " + StorytellerCompPropertiesStats.GetLabel(v));
                            var newProp = v.ToStorytellerCompProperties();
                            if (newProp != null)
                            {
                                t.comps.Add(newProp);
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        private AcceptanceReport IsUnique(StorytellerCompProperties toCheck)
        {
            var checkHashCode = StorytellerCompPropertiesStats.GetHashCode(toCheck);

            foreach (var c in base.Def.comps)
            {
                if (checkHashCode == StorytellerCompPropertiesStats.GetHashCode(c))
                {
                    return("Component already exists [" + StorytellerCompPropertiesStats.GetLabel(toCheck) + "]");
                }
            }
            return(true);
        }
Example #4
0
        public StorytellerCompPropertiesWidget(StorytellerCompProperties p) : base(true, true)
        {
            if (p.allowedTargetTags == null)
            {
                p.allowedTargetTags = new List <IncidentTargetTagDef>();
            }
            if (p.disallowedTargetTags == null)
            {
                p.disallowedTargetTags = new List <IncidentTargetTagDef>();
            }

            this.Props = p;
            this.label = StorytellerCompPropertiesStats.GetLabel(p);

            this.inputWidgets = new List <IInputWidget>()
            {
                new FloatInputWidget <StorytellerCompProperties>(p, "Min Days Passed", c => c.minDaysPassed, (c, v) => c.minDaysPassed = v),
                new FloatInputWidget <StorytellerCompProperties>(p, "Min Inc Chance Pop Intent Factor", c => c.minIncChancePopulationIntentFactor, (c, v) => c.minIncChancePopulationIntentFactor = v),
            };

            this.allowedTargetTags = new PlusMinusArgs <IncidentTargetTagDef>()
            {
                allItems       = DefDatabase <IncidentTargetTagDef> .AllDefs,
                getDisplayName = v => Util.GetLabel(v),
                beingUsed      = () => this.Props.allowedTargetTags,
                onAdd          = v =>
                {
                    Util.AddTo(this.Props.allowedTargetTags, v);
                    Util.RemoveFrom(this.Props.disallowedTargetTags, v);
                },
                onRemove = v => Util.RemoveFrom(this.Props.allowedTargetTags, v)
            };

            this.disallowedTargetTags = new PlusMinusArgs <IncidentTargetTagDef>()
            {
                allItems       = DefDatabase <IncidentTargetTagDef> .AllDefs,
                getDisplayName = v => Util.GetLabel(v),
                beingUsed      = () => this.Props.disallowedTargetTags,
                onAdd          = v =>
                {
                    Util.AddTo(this.Props.disallowedTargetTags, v);
                    Util.RemoveFrom(this.Props.allowedTargetTags, v);
                },
                onRemove = v => Util.RemoveFrom(this.Props.disallowedTargetTags, v)
            };

            switch (p.compClass.FullName)
            {
            case "RimWorld.StorytellerComp_CategoryIndividualMTBByBiome":
                if (p is StorytellerCompProperties_CategoryIndividualMTBByBiome cb)
                {
                    this.inputWidgets.Add(new BoolInputWidget <StorytellerCompProperties_CategoryIndividualMTBByBiome>(
                                              cb, "Apply Caravan Visibility", c => c.applyCaravanVisibility, (c, v) => c.applyCaravanVisibility = v));
                }
                break;

            case "RimWorld.StorytellerComp_CategoryMTB":
                if (p is StorytellerCompProperties_CategoryMTB cm)
                {
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_CategoryMTB>(
                                              cm, "Mean Time Between (Days)", c => c.mtbDays, (c, v) => c.mtbDays = v));
                }
                break;

            case "RimWorld.StorytellerComp_DeepDrillInfestation":
                if (p is StorytellerCompProperties_DeepDrillInfestation cd)
                {
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_DeepDrillInfestation>(
                                              cd, "Drill Base Mean Time Between (Days)", c => c.baseMtbDaysPerDrill, (c, v) => c.baseMtbDaysPerDrill = v));
                }
                break;

            case "RimWorld.StorytellerComp_FactionInteraction":
                if (p is StorytellerCompProperties_FactionInteraction fi)
                {
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_FactionInteraction>(
                                              fi, "Base Incidents Per Year", c => c.baseIncidentsPerYear, (c, v) => c.baseIncidentsPerYear = v));
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_FactionInteraction>(
                                              fi, "Min Spacing Days", c => c.minSpacingDays, (c, v) => c.minSpacingDays = v));
                    this.inputWidgets.Add(new EnumInputWidget <StorytellerCompProperties_FactionInteraction, StoryDanger>(
                                              fi, "Min Danger", 200, c => c.minDanger, (c, v) => c.minDanger = v));
                    this.inputWidgets.Add(new BoolInputWidget <StorytellerCompProperties_FactionInteraction>(
                                              fi, "Full Allies Only", c => c.fullAlliesOnly, (c, v) => c.fullAlliesOnly = v));
                }
                break;

            case "RimWorld.StorytellerComp_OnOffCycle":
                if (p is StorytellerCompProperties_OnOffCycle ooc)
                {
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_OnOffCycle>(
                                              ooc, "On Days", c => c.onDays, (c, v) => c.onDays = v));
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_OnOffCycle>(
                                              ooc, "Off Days", c => c.offDays, (c, v) => c.offDays = v));
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_OnOffCycle>(
                                              ooc, "Min Spacing Days", c => c.minSpacingDays, (c, v) => c.minSpacingDays = v));
                    // TODO this.inputWidgets.Add(new BoolInputWidget<StorytellerCompProperties_OnOffCycle>(
                    //ooc, "Apply Raid Beacon Thread Mean Time Between Factor", c => c.applyRaidBeaconThreatMtbFactor, (c, v) => c.applyRaidBeaconThreatMtbFactor = v));
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_OnOffCycle>(
                                              ooc, "Force Raid Enemy Before Days Passed", c => c.forceRaidEnemyBeforeDaysPassed, (c, v) => c.forceRaidEnemyBeforeDaysPassed = v));
                    this.inputWidgets.Add(new MinMaxInputWidget <StorytellerCompProperties_OnOffCycle, float>(
                                              "Num Incidents range",
                                              new FloatInputWidget <StorytellerCompProperties_OnOffCycle>(
                                                  ooc, "Min", c => c.numIncidentsRange.min, (c, v) => c.numIncidentsRange.min = v),
                                              new FloatInputWidget <StorytellerCompProperties_OnOffCycle>(
                                                  ooc, "Max", c => c.numIncidentsRange.max, (c, v) => c.numIncidentsRange.max = v)));
                }
                break;

            case "RimWorld.StorytellerComp_RandomMain":
                if (p is StorytellerCompProperties_RandomMain rm)
                {
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_RandomMain>(
                                              rm, "Mean Time Between (Days)", c => c.mtbDays, (c, v) => c.mtbDays = v));
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_RandomMain>(
                                              rm, "Max Threat Big Interval Days", c => c.maxThreatBigIntervalDays, (c, v) => c.maxThreatBigIntervalDays = v));
                    this.inputWidgets.Add(new BoolInputWidget <StorytellerCompProperties_RandomMain>(
                                              rm, "Skip Threat Big If Raid Beacon", c => c.skipThreatBigIfRaidBeacon, (c, v) => c.skipThreatBigIfRaidBeacon = v));
                    this.inputWidgets.Add(new MinMaxInputWidget <StorytellerCompProperties_RandomMain, float>(
                                              "Random Points Factor Range",
                                              new FloatInputWidget <StorytellerCompProperties_RandomMain>(
                                                  rm, "Min", c => c.randomPointsFactorRange.min, (c, v) => c.randomPointsFactorRange.min = v),
                                              new FloatInputWidget <StorytellerCompProperties_RandomMain>(
                                                  rm, "Max", c => c.randomPointsFactorRange.max, (c, v) => c.randomPointsFactorRange.max = v)));

                    this.categoryWeightArgs = new PlusMinusArgs <IncidentCategoryDef>()
                    {
                        allItems    = DefDatabase <IncidentCategoryDef> .AllDefs,
                        isBeingUsed = d =>
                        {
                            foreach (var input in this.categoryWeights)
                            {
                                if (input.Parent.category == d)
                                {
                                    return(true);
                                }
                            }
                            return(false);
                        },
                        getDisplayName = d => Util.GetLabel(d),
                        onAdd          = d =>
                        {
                            IncidentCategoryEntry ice = new IncidentCategoryEntry()
                            {
                                category = d,
                                weight   = 0
                            };
                            this.categoryWeights.Add(this.CreateCategoryWeightInput(ice));
                            ((StorytellerCompProperties_RandomMain)this.Props).categoryWeights.Add(ice);
                        },
                        onRemove = d =>
                        {
                            this.categoryWeights.RemoveAll(v => v.Parent.category == d);
                            ((StorytellerCompProperties_RandomMain)this.Props).categoryWeights.RemoveAll(v => v.category == d);
                        }
                    };
                }
                break;

            case "RimWorld.StorytellerComp_SingleMTB":
                if (p is StorytellerCompProperties_SingleMTB smtb)
                {
                    this.inputWidgets.Add(new FloatInputWidget <StorytellerCompProperties_SingleMTB>(
                                              smtb, "Mean Time Between (Days)", c => c.mtbDays, (c, v) => c.mtbDays = v));
                }
                break;

            case "RimWorld.StorytellerComp_Triggered":
                if (p is StorytellerCompProperties_Triggered t)
                {
                    this.inputWidgets.Add(new IntInputWidget <StorytellerCompProperties_Triggered>(
                                              t, "Delay Ticks", c => c.delayTicks, (c, v) => c.delayTicks = v));
                }
                break;
            }
            this.Rebuild();
        }
 private void CreateIncidentInput()
 {
     this.incidentInput = new DefInputWidget <StorytellerCompProperties, IncidentDef>(this.comp, "Incident", 100, c => StorytellerCompPropertiesStats.GetIncident(c), (c, v) => StorytellerCompPropertiesStats.SetIncident(c, v), true);
 }
 private void CreateCategoryInput()
 {
     this.categoryInput = new DefInputWidget <StorytellerCompProperties, IncidentCategoryDef>(this.comp, "Category", 100, c => StorytellerCompPropertiesStats.GetCategory(c), (c, v) => StorytellerCompPropertiesStats.SetCategory(c, v), true);
 }