Ejemplo n.º 1
0
        public override void DoSettingsWindowContents(Rect rect)
        {
            GUI.BeginGroup(new Rect(0, 60, 600, 200));
            {
                Text.Font = GameFont.Medium;
                Widgets.Label(new Rect(0, 0, 300, 40), "ChangeResearchSpeed.Global".Translate());

                Text.Font = GameFont.Small;
                Widgets.Label(new Rect(0, 40, 300, 20), "ChangeResearchSpeed.Factor".Translate() + ":");

                Settings.GlobalFactor.AsString = Widgets.TextField(new Rect(320, 40, 100, 20), Settings.GlobalFactor.AsString);

                if (Widgets.ButtonText(new Rect(320, 65, 100, 20), "ChangeResearchSpeed.Apply".Translate()))
                {
                    if (Settings.GlobalFactor.ValidateInput())
                    {
                        base.GetSettings <Settings>().Write();
                        Messages.Message("ChangeResearchSpeed.Global".Translate() + " " + "ChangeResearchSpeed.ResearchTimesUpdated".Translate(),
                                         MessageTypeDefOf.PositiveEvent);
                    }
                }

                if (Current.Game != null)
                {
                    Text.Font = GameFont.Medium;
                    Widgets.Label(new Rect(0, 90, 300, 40), "ChangeResearchSpeed.CurrentGame".Translate());

                    Text.Font = GameFont.Small;
                    Widgets.Label(new Rect(0, 130, 300, 20), "ChangeResearchSpeed.Factor".Translate() + ":");

                    Settings.GameFactor.AsString = Widgets.TextField(new Rect(320, 130, 100, 20), Settings.GameFactor.AsString);

                    if (Widgets.ButtonText(new Rect(320, 155, 100, 20), "ChangeResearchSpeed.Apply".Translate()))
                    {
                        if (Settings.GameFactor.ValidateInput())
                        {
                            WorldComp.UpdateFactor(Settings.GameFactor.AsFloat);
                            Messages.Message(
                                "ChangeResearchSpeed.CurrentGame".Translate() + " " + "ChangeResearchSpeed.ResearchTimesUpdated".Translate(),
                                MessageTypeDefOf.PositiveEvent);
                        }
                    }
                }
            }
            GUI.EndGroup();

            Listing_Standard l = new Listing_Standard(GameFont.Small);

            l.BeginScrollView(new Rect(0, 300, rect.width, rect.height - 300), ref scroll, ref view);
            //l.Begin(new Rect(0, 300, 400, 300));
            l.ColumnWidth = rect.width - 100;
            l.CheckboxLabeled(
                "ChangeResearchSpeed.AllowTechAdvance".Translate(),
                ref Settings.AllowTechAdvance,
                "ChangeResearchSpeed.AllowTechAdvanceToolTip".Translate());
            if (Settings.AllowTechAdvance)
            {
                l.CheckboxLabeled("ChangeResearchSpeed.StaticNumberResearchPerTier".Translate(), ref Settings.StaticNumberResearchPerTier);
                if (Settings.StaticNumberResearchPerTier)
                {
                    neolithicInput  = l.TextEntryLabeled("ChangeResearchSpeed.NeolithicNeeded".Translate() + ":  ", neolithicInput);
                    medievalInput   = l.TextEntryLabeled("ChangeResearchSpeed.MedievalNeeded".Translate() + ":  ", medievalInput);
                    industrialInput = l.TextEntryLabeled("ChangeResearchSpeed.IndustrialNeeded".Translate() + ":  ", industrialInput);
                    spacerInput     = l.TextEntryLabeled("ChangeResearchSpeed.SpacerNeeded".Translate() + ":  ", spacerInput);
                }

                Rect c = l.GetRect(32f);
                if (Widgets.ButtonText(new Rect(c.xMin, c.yMin, 100, c.height), "Confirm".Translate()))
                {
                    if (!int.TryParse(neolithicInput, out Settings.NeolithicNeeded))
                    {
                        Messages.Message("ChangeResearchSpeed.InvalidNeolithicInput".Translate(), MessageTypeDefOf.RejectInput);
                        return;
                    }

                    if (!int.TryParse(medievalInput, out Settings.MedievalNeeded))
                    {
                        Messages.Message("ChangeResearchSpeed.InvalidMedievalInput".Translate(), MessageTypeDefOf.RejectInput);
                        return;
                    }

                    if (!int.TryParse(industrialInput, out Settings.IndustrialNeeded))
                    {
                        Messages.Message("ChangeResearchSpeed.InvalidIndustrialInput".Translate(), MessageTypeDefOf.RejectInput);
                        return;
                    }

                    if (!int.TryParse(spacerInput, out Settings.SpacerNeeded))
                    {
                        Messages.Message("ChangeResearchSpeed.InvalidSpacerInput".Translate(), MessageTypeDefOf.RejectInput);
                        return;
                    }

                    Messages.Message("ChangeResearchSpeed.ResearchNeededSet".Translate(), MessageTypeDefOf.PositiveEvent);
                }

                if (Widgets.ButtonText(new Rect(c.xMax - 100, c.yMin, 100, c.height), "ChangeResearchSpeed.Default".Translate()))
                {
                    Settings.NeolithicNeeded  = Settings.DEFAULT_NEOLITHIC_NEEDED;
                    Settings.MedievalNeeded   = Settings.DEFAULT_MEDIEVAL_NEEDED;
                    Settings.IndustrialNeeded = Settings.DEFAULT_INDUSTRIAL_NEEDED;
                    Settings.SpacerNeeded     = Settings.DEFAULT_SPACER_NEEDED;

                    neolithicInput  = Settings.NeolithicNeeded.ToString();
                    medievalInput   = Settings.MedievalNeeded.ToString();
                    industrialInput = Settings.IndustrialNeeded.ToString();
                    spacerInput     = Settings.SpacerNeeded.ToString();

                    Messages.Message("ChangeResearchSpeed.ResearchNeededDefaulted".Translate(), MessageTypeDefOf.PositiveEvent);
                }
            }

            l.CheckboxLabeled(
                "ChangeResearchSpeed.ChangeBaseCosts".Translate(),
                ref Settings.ChangeBaseCosts,
                "ChangeResearchSpeed.ChangeBaseCostsToolTip".Translate());
            if (Settings.ChangeBaseCosts)
            {
                if (techValues == null)
                {
                    techValues = new Dictionary <string, string>();
                }
                var techs = ResearchTimeUtil.GetResearchBaseCosts();
                foreach (var tech in techs.Keys)
                {
                    var techDef = ResearchTimeUtil.GetResearchDef(tech);
                    if (techDef != null)
                    {
                        float  cost;
                        string value;
                        if ((value = techValues.TryGetValue(tech, null)) == null)
                        {
                            if (Settings.ResearchBaseCosts.TryGetValue(tech, out cost))
                            {
                                value = ((int)cost).ToString();
                            }
                            else
                            {
                                value = techDef.baseCost.ToString();
                            }
                            techValues.Add(tech, value);
                        }

                        value = l.TextEntryLabeled(techDef.LabelCap + "(default: " + techs[tech] + ")", value);
                        int costInt;
                        if (int.TryParse(value, out costInt) && costInt >= 100)
                        {
                            if (costInt != (int)techDef.baseCost)
                            {
                                ResearchTimeUtil.ChangeBaseCost(techDef, costInt);
                            }
                            if (Settings.ResearchBaseCosts.ContainsKey(tech))
                            {
                                Settings.ResearchBaseCosts[tech] = costInt;
                            }
                            else
                            {
                                Settings.ResearchBaseCosts.Add(tech, costInt);
                            }
                        }

                        techValues[tech] = value;
                    }
                }
            }

            //l.End();
            l.EndScrollView(ref view);
        }
Ejemplo n.º 2
0
        static void Postfix()
        {
            if (Settings.AllowTechAdvance == true)
            {
                TechLevel currentTechLevel = Faction.OfPlayer.def.techLevel;
#if DEBUG
                Log.Warning("Tech Level: " + currentTechLevel);
#endif
                int totalCurrentAndPast = 0;
                int finishedResearch    = 0;

                foreach (ResearchProjectDef def in DefDatabase <ResearchProjectDef> .AllDefs)
                {
                    if (def.IsFinished)
                    {
                        ++finishedResearch;
                        //if (def.techLevel <= currentTechLevel)
                        //    ++finishedCurrentAndPast;
                        //else
                        //    ++finishedFuture;
                    }


                    if (def.techLevel <= currentTechLevel)
                    {
                        ++totalCurrentAndPast;
                    }
                }

                int  neededTechsToAdvance = 0;
                bool useStatisPerTier     = Settings.StaticNumberResearchPerTier;
                if (useStatisPerTier)
                {
                    switch (Faction.OfPlayer.def.techLevel)
                    {
                    case TechLevel.Neolithic:
                        neededTechsToAdvance = Settings.NeolithicNeeded;
                        break;

                    case TechLevel.Medieval:
                        neededTechsToAdvance = Settings.MedievalNeeded;
                        break;

                    case TechLevel.Industrial:
                        neededTechsToAdvance = Settings.IndustrialNeeded;
                        break;

                    case TechLevel.Spacer:
                        neededTechsToAdvance = Settings.SpacerNeeded;
                        break;
                    }
                }

#if DEBUG
                Log.Warning("Current Tech Level: " + Faction.OfPlayer.def.techLevel);
                Log.Warning("neededTechsToAdvance: " + neededTechsToAdvance);
                Log.Warning("totalCurrentAndPast: " + totalCurrentAndPast);
                Log.Warning("finishedResearch: " + finishedResearch);
#endif

                if ((useStatisPerTier && neededTechsToAdvance < finishedResearch) ||
                    (!useStatisPerTier && totalCurrentAndPast + 1 < finishedResearch))
                {
                    if (Faction.OfPlayer.def.techLevel < TechLevel.Spacer)
                    {
                        if (Scribe.mode == LoadSaveMode.Inactive)
                        {
                            // Only display this message is not loading
                            Messages.Message(
                                "Advancing Tech Level from [" + currentTechLevel.ToString() + "] to [" + (currentTechLevel + 1).ToString() + "].",
                                MessageTypeDefOf.PositiveEvent);
                        }

                        Faction.OfPlayer.def.techLevel = currentTechLevel + 1;
                    }
                }
                else
                {
                    int needed = (useStatisPerTier) ? neededTechsToAdvance - finishedResearch : totalCurrentAndPast + 1 - finishedResearch;
                    Log.Message("Tech Advance: Need to research [" + needed + "] more technologies");
                }
            }
            if (Settings.ChangeBaseCosts)
            {
                foreach (var cost in Settings.ResearchBaseCosts)
                {
                    var techDef = ResearchTimeUtil.GetResearchDef(cost.Key);
                    if (techDef != null)
                    {
                        techDef.baseCost = cost.Value;
                    }
                }
            }
        }