Пример #1
0
        public override void ExposeData()
        {
            base.ExposeData();

            OnOffIncident gameOT = Settings.GameOrbitalTrade;

            Scribe_Deep.Look(ref gameOT, "AdjustableTradeShips.OrbitalTrader");
            Scribe_Values.Look(ref Settings.GameWeight, "AdjustableTradeShips.Weight", 1.0f);
            Settings.GameWeightBuffer = Settings.GameWeight.ToString();
            Settings.GameOrbitalTrade = gameOT;

            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                Initialize();
            }
        }
        public static bool TryGetStoryTellerDefault(IncidentDef incidentDef, out OnOffIncident incident)
        {
            foreach (StorytellerDef def in DefDatabase <StorytellerDef> .AllDefs)
            {
                if (def == Current.Game.storyteller.def)
                {
                    foreach (StorytellerCompProperties comp in def.comps)
                    {
                        if (comp is StorytellerCompProperties_OnOffCycle)
                        {
                            StorytellerCompProperties_OnOffCycle ooc = (StorytellerCompProperties_OnOffCycle)comp;
                            if (ooc.incident == incidentDef)
                            {
                                incident = new OnOffIncident
                                {
                                    Incident  = ooc.incident,
                                    Days      = ooc.onDays + ooc.offDays,
                                    Instances = ooc.numIncidentsRange.TrueMin,
                                };
                                return(true);
                            }
                        }

                        /*else if (comp is StorytellerCompProperties_FactionInteraction)
                         * {
                         *  StorytellerCompProperties_FactionInteraction fi = (StorytellerCompProperties_FactionInteraction)comp;
                         *  interactions.Add(new FactionInteraction
                         *  {
                         *      Incident = fi.incident,
                         *      IncidenctsPerYear = fi.baseIncidentsPerYear,
                         *      MinSpacingDays = fi.minSpacingDays,
                         *      FullAlliesOnly = fi.fullAlliesOnly,
                         *      MinDanger = fi.minDanger,
                         *      MinDaysPassed = fi.minDaysPassed
                         *  });
                         * }*/
                    }
                    break;
                }
            }
            incident = null;
            return(false);
        }
        public override void ExposeData()
        {
            base.ExposeData();

            OnOffIncident gameOT = Settings.GameOrbitalTrade;

            Scribe_Deep.Look(ref gameOT, "AdjustableTradeShips.OrbitalTrader");

            Settings.GameOrbitalTrade = gameOT;

            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                if (Settings.GameOrbitalTrade == null)
                {
                    Initialize();
                }
                else
                {
                    StoryTellerUtil.ApplyOrbitalTrade(
                        Settings.GameOrbitalTrade.Days, Settings.GameOrbitalTrade.Instances);
                }
            }
        }
 public OrbitalTradeBuffers(OnOffIncident ooi)
 {
     this.Days      = ooi.Days.ToString();
     this.Instances = ooi.Instances.ToString();
 }
        public override void DoSettingsWindowContents(Rect inRect)
        {
            this.Init();

            // Draw Contents
            // Global
            Text.Font = GameFont.Small;
            float y = 60;

            Widgets.Label(new Rect(0, y, 600, 40), "AdjustableTradeShips.Global".Translate());
            y += 40;

            Widgets.Label(new Rect(20, y, 600, 40), "AdjustableTradeShips.TradeShips".Translate());
            y += 40;


            NumberInput(40, y, ref Settings.GlobalOrbitalTrade.Instances, ref globalOtBuffers.Instances, MIN_ONOFF_VALUE, MAX_VALUE);

            Widgets.Label(new Rect(100, y, inRect.width - 200, 32), "AdjustableTradeShips.OTS".Translate());
            y += 40;

            NumberInput(40, y, ref Settings.GlobalOrbitalTrade.Days, ref globalOtBuffers.Days, MIN_ONOFF_VALUE, MAX_VALUE);

            Widgets.Label(new Rect(100, y, inRect.width - 200, 32), "AdjustableTradeShips.Days".Translate());
            y += 40;

            if (Widgets.ButtonText(new Rect(0, y, 100, 32), "AdjustableTradeShips.Default".Translate()))
            {
                OnOffIncident ooi = StoryTellerDefaultsUtil.GetGlobalDefault(IncidentDefOf.OrbitalTraderArrival);
                Settings.GlobalOrbitalTrade.Days      = ooi.Days;
                globalOtBuffers.Days                  = ooi.Days.ToString();
                Settings.GlobalOrbitalTrade.Instances = ooi.Instances;
                globalOtBuffers.Instances             = ooi.Instances.ToString();
            }

            if (Widgets.ButtonText(new Rect(200, y, 100, 32), "AdjustableTradeShips.Apply".Translate()))
            {
                StoryTellerUtil.ApplyOrbitalTrade(Settings.GlobalOrbitalTrade.Days, Settings.GlobalOrbitalTrade.Instances);
                Messages.Message("AdjustableTradeShips.GlobalSettingsApplied".Translate(), MessageTypeDefOf.PositiveEvent);
                this.globalOtBuffers = null;
            }
            y += 40;

            // Current Game
            if (Current.Game != null)
            {
                Widgets.DrawLineHorizontal(20, y, inRect.width - 40);
                y += 40;

                Widgets.Label(new Rect(0, y, 600, 40), "AdjustableTradeShips.CurrentGame".Translate());
                y += 40;

                if (StoryTellerUtil.HasOrbitalTraders() && Settings.GameOrbitalTrade != null)
                {
                    Widgets.Label(new Rect(20, y, 600, 40), "AdjustableTradeShips.TradeShips".Translate());
                    y += 40;

                    // Game Orbital Trade
                    NumberInput(40, y, ref Settings.GameOrbitalTrade.Instances, ref gameOtBuffers.Instances, MIN_ONOFF_VALUE, MAX_VALUE);

                    Widgets.Label(new Rect(100, y, inRect.width - 200, 32), "AdjustableTradeShips.OTS".Translate());
                    y += 40;

                    NumberInput(40, y, ref Settings.GameOrbitalTrade.Days, ref gameOtBuffers.Days, MIN_ONOFF_VALUE, MAX_VALUE);

                    Widgets.Label(new Rect(100, y, inRect.width - 200, 32), "AdjustableTradeShips.Days".Translate());
                    y += 40;

                    if (Widgets.ButtonText(new Rect(0, y, 100, 32), "AdjustableTradeShips.Default".Translate()))
                    {
                        if (StoryTellerDefaultsUtil.TryGetStoryTellerDefault(IncidentDefOf.OrbitalTraderArrival, out OnOffIncident ooi))
                        {
                            Settings.GameOrbitalTrade.Days      = ooi.Days;
                            gameOtBuffers.Days                  = ooi.Days.ToString();
                            Settings.GameOrbitalTrade.Instances = ooi.Instances;
                            gameOtBuffers.Instances             = ooi.Instances.ToString();
                        }
                        else
                        {
                            ooi = StoryTellerDefaultsUtil.GetGlobalDefault(IncidentDefOf.OrbitalTraderArrival);
                            Settings.GameOrbitalTrade.Days      = ooi.Days;
                            gameOtBuffers.Days                  = ooi.Days.ToString();
                            Settings.GameOrbitalTrade.Instances = ooi.Instances;
                            gameOtBuffers.Instances             = ooi.Instances.ToString();
                        }
                    }

                    if (Widgets.ButtonText(new Rect(200, y, 100, 32), "AdjustableTradeShips.Apply".Translate()))
                    {
                        StoryTellerUtil.ApplyOrbitalTrade(Settings.GameOrbitalTrade.Days, Settings.GameOrbitalTrade.Instances);
                        Messages.Message("AdjustableTradeShips.GameSettingsApplied".Translate(), MessageTypeDefOf.PositiveEvent);
                        this.gameOtBuffers = null;
                    }
                }
                else if (StoryTellerUtil.HasRandom())
                {
                    if (this.weightBuffer == null)
                    {
                        if (StoryTellerUtil.TryGetRandomWeight(IncidentCategoryDefOf.OrbitalVisitor, out float weight))
                        {
                            this.weight       = weight;
                            this.weightBuffer = weight.ToString();
                        }
                    }

                    NumberInput(20, y, "Orbital Visitor Weight", ref this.weight, ref this.weightBuffer, MIN_VALUE, MAX_VALUE);
                    y += 40;

                    if (Widgets.ButtonText(new Rect(0, y, 100, 32), "AdjustableTradeShips.Default".Translate()))
                    {
                        this.weight       = 1.0f;
                        this.weightBuffer = "1.0";
                    }

                    if (Widgets.ButtonText(new Rect(200, y, 100, 32), "AdjustableTradeShips.Apply".Translate()))
                    {
                        StoryTellerUtil.ApplyRandom(IncidentCategoryDefOf.OrbitalVisitor, this.weight);
                        Messages.Message("AdjustableTradeShips.GameSettingsApplied".Translate(), MessageTypeDefOf.PositiveEvent);
                        this.weightBuffer = this.weight.ToString();
                    }
                }
                else
                {
                    Widgets.Label(new Rect(20, y, 300, 32), Current.Game.storyteller.def.label + ": " + "AdjustableTradeShips.CannotModifyOrbitalTraderTimes".Translate());
                }
                y += 25;
            }
        }