public override void DoSettingsWindowContents(Rect inRect)
        {
            int ransomRaidDelay    = Mathf.RoundToInt(this.settings.ransomRaidDelay / (float)GenDate.TicksPerHour);
            int ransomFailCooldown = Mathf.RoundToInt(this.settings.ransomFailCooldown / (float)GenDate.TicksPerHour);

            Rect sliderSection = inRect.TopPart(0.7f);

            this.settings.ransomFactor = (int)Widgets.HorizontalSlider(rect: sliderSection.TopHalf().TopHalf().BottomHalf(), value: this.settings.ransomFactor, leftValue: 1f, rightValue: 5f, middleAlignment: true, label: "SettingsRansomFactor".Translate(this.settings.ransomFactor), leftAlignedLabel: "1", rightAlignedLabel: "5");
            ransomRaidDelay            = (int)Widgets.HorizontalSlider(rect: sliderSection.TopHalf().BottomHalf().TopHalf(), value: ransomRaidDelay, leftValue: 1f, rightValue: 168f, middleAlignment: true, label: "SettingsRansomRaidDelay".Translate(this.settings.ransomRaidDelay.ToStringTicksToPeriod()), leftAlignedLabel: "1", rightAlignedLabel: "168");
            ransomFailCooldown         = (int)Widgets.HorizontalSlider(rect: sliderSection.BottomHalf().TopHalf().TopHalf(), value: ransomFailCooldown, leftValue: ransomRaidDelay, rightValue: 336f, middleAlignment: true, label: "SettingsRansomFailCooldown".Translate(this.settings.ransomFailCooldown.ToStringTicksToPeriod()), leftAlignedLabel: ransomRaidDelay.ToString(), rightAlignedLabel: "336");
            this.settings.adjustment   = (int)Widgets.HorizontalSlider(rect: sliderSection.BottomHalf().BottomHalf().TopHalf(), value: this.settings.adjustment, leftValue: 40f, rightValue: 95f, middleAlignment: true, label: "SettingsRansomAdjustment".Translate(this.settings.adjustment), leftAlignedLabel: "40", rightAlignedLabel: "95");

            this.settings.ransomRaidDelay    = ransomRaidDelay * GenDate.TicksPerHour;
            this.settings.ransomFailCooldown = ransomFailCooldown * GenDate.TicksPerHour;

            SimpleCurve curve = new SimpleCurve();

            for (int i = -50; i <= 50; i++)
            {
                curve.Add(i, RansomSettings.RansomChanceRaw(-75, 10, i) * 100);
            }

            SimpleCurveDrawInfo drawInfo = new SimpleCurveDrawInfo()
            {
                curve  = curve,
                color  = Color.cyan,
                label  = "LABEL",
                labelY = "Prob"
            };

            SimpleCurveDrawer.DrawCurve(inRect.BottomPart(0.3f), drawInfo, new SimpleCurveDrawerStyle
            {
                DrawBackground      = false,
                DrawBackgroundLines = false,
                DrawCurveMousePoint = true,
                DrawLegend          = true,
                DrawMeasures        = true,
                DrawPoints          = false,
                FixedScale          = new Vector2(0, 100),
                FixedSection        = new FloatRange(-50, 50),
                LabelX = "Adj",
                MeasureLabelsXCount      = 10,
                MeasureLabelsYCount      = 10,
                OnlyPositiveValues       = false,
                PointsRemoveOptimization = false,
                UseAntiAliasedLines      = true,
                UseFixedScale            = true,
                UseFixedSection          = true,
                XIntegersOnly            = true,
                YIntegersOnly            = true
            });
        }
            public static void DoCurveEditor(Rect screenRect, SimpleCurve curve, int decimalPlaces = 0, int displayMult = 100, string valueSuffix = "%", Action onChange = null)
            {
                Widgets.DrawMenuSection(screenRect);
                SimpleCurveDrawer.DrawCurve(screenRect, curve, null, null, default(Rect));
                Vector2 mousePosition    = Event.current.mousePosition - screenRect.position;
                Vector2 mouseCurveCoords = SimpleCurveDrawer.ScreenToCurveCoords(screenRect, curve.View.rect, mousePosition);

                if (Mouse.IsOver(screenRect))
                {
                    if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                    {
                        var clampedCoords = mouseCurveCoords;
                        clampedCoords.x = Mathf.Clamp(Mathf.Round(clampedCoords.x), 0, 20);
                        clampedCoords.y = Mathf.Clamp((float)Math.Round(clampedCoords.y, 2), 0, 1);
                        List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                        if (!curve.Any(point => point.x == clampedCoords.x))
                        {
                            list2.Add(new FloatMenuOption($"Add point at [{clampedCoords.x:F0} - {(clampedCoords.y * displayMult).ToString($"F{decimalPlaces}")}{valueSuffix}]", () =>
                            {
                                curve.Add(new CurvePoint(clampedCoords), true);
                                onChange?.Invoke();
                            }, MenuOptionPriority.Default, null, null, 0f, null, null, true, 0));
                        }
                        else
                        {
                            var existingPoint = curve.First(point => point.x == clampedCoords.x);

                            list2.Add(new FloatMenuOption($"Move point at [{existingPoint.x:F0} - {(existingPoint.y * displayMult).ToString($"F{decimalPlaces}")}{valueSuffix}] to [{clampedCoords.x:F0} - {(clampedCoords.y * displayMult).ToString($"F{decimalPlaces}")}{valueSuffix}]", () =>
                            {
                                curve.RemovePointNear(existingPoint);
                                curve.Add(new CurvePoint(clampedCoords), true);
                                onChange?.Invoke();
                            }, MenuOptionPriority.Default, null, null, 0f, null, null, true, 0));

                            if (Mathf.RoundToInt(existingPoint.x) != 0 && Mathf.RoundToInt(existingPoint.x) != 20)
                            {
                                list2.Add(new FloatMenuOption($"Remove point at [{existingPoint.x:F0} - {(existingPoint.y * displayMult).ToString($"F{decimalPlaces}")}{valueSuffix}]", () =>
                                {
                                    curve.RemovePointNear(existingPoint);
                                    onChange?.Invoke();
                                }, MenuOptionPriority.Default, null, null, 0f, null, null, true, 0));
                            }
                        }
                        Find.WindowStack.Add(new FloatMenu(list2));
                        Event.current.Use();
                    }
                }
            }
        protected override void DrawInputs(float x, ref float y, float width)
        {
            if (this.curve != null)
            {
                WindowUtil.PlusMinusLabel(x, ref y, width, this.name,
                                          () =>
                {
                    MinMaxFloatStats p = new MinMaxFloatStats(0, 0);
                    this.points.Add(p);
                    this.pointsInputs.Add(this.CreateFloatInput(p));
                },
                                          () => WindowUtil.DrawFloatingOptions(pointsArgs));
                SimpleCurveDrawer.DrawCurve(new Rect(x + 20, y, width, 100), curve);
                y += 110;

                if (this.innerY > 300)
                {
                    Widgets.BeginScrollView(
                        new Rect(x + 20, y, width - 16, 300),
                        ref this.scroll,
                        new Rect(0, 0, width - 32, this.innerY));
                    this.innerY = 0;

                    foreach (var v in this.pointsInputs)
                    {
                        v.Draw(10, ref this.innerY, width - 60);
                    }

                    Widgets.EndScrollView();
                    y += 332;
                }
                else
                {
                    this.innerY = 0;
                    foreach (var v in this.pointsInputs)
                    {
                        float orig = y;
                        v.Draw(10, ref y, width - 60);
                        this.innerY += y - orig;
                    }
                }
            }
        }
Example #4
0
        public override void DoSettingsWindowContents(Rect inRect)
        {
            var viewRect = new Rect(0, 0, inRect.width - 30, ViewRectHeight);
            Widgets.BeginScrollView(inRect, ref scrollPosition, viewRect);

            var viewRect2 = new Rect(0, 0, viewRect.width, 99999);

            var listing_Standard = new Listing_Standard
            {
                ColumnWidth = (float) (viewRect.width - 10.0)
            };
            listing_Standard.Begin(viewRect2);

            listing_Standard.Label("IncidentCountMultiplierDescription".Translate());

            listing_Standard.GapLine(24);

            //listing_Standard.Label("IncidentCountMultiplier".Translate(), -1, "IncidentCountMultiplier_ToolTip".Translate());
            listing_Standard.Label("IncidentCountMultiplier".Translate());
            SimpleCurveEditor(listing_Standard, ref settings.MTBEventOccurs_Multiplier);
            listing_Standard.GapLine();

            //listing_Standard.Label("MinIncidentCountMultiplier".Translate());
            //SimpleCurveEditor(listing_Standard, ref settings.MinIncidentCountMultiplier);
            //listing_Standard.GapLine();

            //listing_Standard.Label("MaxIncidentCountMultiplier".Translate());
            //SimpleCurveEditor(listing_Standard, ref settings.MaxIncidentCountMultiplier);
            //listing_Standard.GapLine();

            //listing_Standard.Label("IncidentCycleAcceleration".Translate());
            //SimpleCurveEditor(listing_Standard, ref settings.IncidentCycleAcceleration);
            //listing_Standard.GapLine();


            style.FixedScale = new Vector2(0, settings.MTBEventOccurs_Multiplier.View.rect.yMax);
            style.FixedSection = new FloatRange(0, settings.MTBEventOccurs_Multiplier.View.rect.xMax);
            listing_Standard.GapLine(24);


            var rect = listing_Standard.GetRect(250);
            SimpleCurveDrawer.DrawCurve(rect, new SimpleCurveDrawInfo
            {
                curve = settings.MTBEventOccurs_Multiplier,
                label = "Multiplier"
            }, style);

            listing_Standard.Label("Sample Preset");
            if (listing_Standard.ButtonText("200%"))
            {
                settings.MTBEventOccurs_Multiplier = new SimpleCurve {{0, 2}};
            }

            if (listing_Standard.ButtonText("50%"))
            {
                settings.MTBEventOccurs_Multiplier = new SimpleCurve {{0, 0.5f}};
            }

            if (listing_Standard.ButtonText("100%(year 0) -> 300%(year 10)"))
            {
                settings.MTBEventOccurs_Multiplier = new SimpleCurve
                {
                    {0, 1},
                    {600, 3}
                };
            }

            if (listing_Standard.ButtonText("150%(year 0) -> 150%(year 1.5) -> 220%(year 4) -> 300%(year 10)"))
            {
                settings.MTBEventOccurs_Multiplier = new SimpleCurve
                {
                    {90, 1.5f},
                    {240, 2.2f},
                    {600, 3}
                };
            }

            if (listing_Standard.ButtonText(
                "50%(year 0) -> 100%(year 1) -> 200%(year 2) -> 350%(year 3) -> 500%(year 4)"))
            {
                settings.MTBEventOccurs_Multiplier = new SimpleCurve
                {
                    {0, 0.5f},
                    {60, 1f},
                    {120, 2f},
                    {180, 3.5f},
                    {240, 5f}
                };
            }

            listing_Standard.End();
            ViewRectHeight = listing_Standard.CurHeight;
            Widgets.EndScrollView();
        }
Example #5
0
        public override void DoSettingsWindowContents(Rect rect)
        {
            if (Settings.CustomCurve == null)
            {
                Settings.CustomCurve = CreateDefaultCurve();
            }

            if (skillLossCapBuffers == null)
            {
                ResetCaps();
            }

            if (buffers == null || buffers.Count == 0)
            {
                buffers = this.CreateBuffers();
            }

            Widgets.BeginScrollView(new Rect(20, rect.yMin, 725, 550), ref this.scrollPosition, new Rect(0, 0, 709, this.previousY));

            this.previousY = 0;
            Widgets.CheckboxLabeled(new Rect(0, this.previousY, 250, 30), "Allow Skill Experience Loss", ref Settings.AllowSkillLoss);
            this.previousY += 32;

            if (Settings.AllowSkillLoss)
            {
                Widgets.CheckboxLabeled(new Rect(20, this.previousY, 300, 30), "Allow Skills to Lose Level", ref Settings.CanLoseLevel);
                this.previousY += 32;

                Widgets.CheckboxLabeled(new Rect(20, this.previousY, 300, 30), "Customize Experience Loss Per Tick", ref Settings.AdjustSkillLossCaps);
                if (Settings.AdjustSkillLossCaps)
                {
                    this.previousY += 32;
                    for (int i = 0; i < skillLossCapBuffers.Count; ++i)
                    {
                        skillLossCapBuffers[i] = Widgets.TextEntryLabeled(new Rect(40, this.previousY, 150, 30), $"Level {(i + 10).ToString()}: ", skillLossCapBuffers[i]);
                        this.previousY        += 32;
                    }

                    if (Widgets.ButtonText(new Rect(40, this.previousY, 100, 30), "Apply"))
                    {
                        for (int i = 0; i < skillLossCapBuffers.Count; ++i)
                        {
                            if (float.TryParse(skillLossCapBuffers[i], out float v) && v >= -50f && v <= 0f)
                            {
                                Settings.SkillLossCaps[i] = v;
                                Messages.Message("Skill Loss Per Tick Set", MessageTypeDefOf.PositiveEvent);
                            }
                            else
                            {
                                Log.Error((i + 10).ToString() + "'s Skill Loss Cap must be between -50 and 0");
                                Messages.Message("Error while setting skill loss", MessageTypeDefOf.NegativeEvent);
                            }
                        }
                    }

                    if (Widgets.ButtonText(new Rect(160, this.previousY, 100, 30), "Reset"))
                    {
                        ResetCaps();
                    }
                    this.previousY += 10;
                }
                this.previousY += 32;
            }

            Widgets.CheckboxLabeled(new Rect(0, this.previousY, 250, 30), "Customize Experience Needed", ref Settings.HasCustomCurve);
            this.previousY += 32;
            if (Settings.HasCustomCurve)
            {
                Widgets.Label(new Rect(0, this.previousY, 250, 30), "Experience Curve");
                this.previousY += 32;

                Widgets.CheckboxLabeled(new Rect(425, this.previousY, 200, 30), "Show Graph", ref this.showGraph);
                if (this.showGraph)
                {
                    SimpleCurveDrawer.DrawCurve(new Rect(425, this.previousY + 50, 250, 250), Settings.CustomCurve);
                }

                for (int i = 0; i < this.buffers.Count; ++i)
                {
                    var b = this.buffers[i];
                    Widgets.Label(new Rect(0, this.previousY, 150, 30), "Start Level");
                    if (i == 0)
                    {
                        b.StartLevel = 0;
                        Widgets.Label(new Rect(120, this.previousY, 100, 30), "0");
                    }
                    else
                    {
                        Widgets.TextFieldNumeric(new Rect(120, this.previousY, 100, 30), ref b.StartLevel, ref b.SLBuffer, 0, 20);
                    }
                    if (i > 0 && Widgets.ButtonText(new Rect(255, this.previousY, 30, 30), "-", true, false))
                    {
                        this.buffers.RemoveAt(i);
                        break;
                    }
                    if (Widgets.ButtonText(new Rect(290, this.previousY, 30, 30), "+", true, false))
                    {
                        this.buffers.Insert(i + 1, new CurveValueBuffer(b.StartLevel + 1, 1f));
                        break;
                    }
                    this.previousY += 30;
                    Widgets.Label(new Rect(0, this.previousY, 120, 30), "Exp Needed");
                    Widgets.TextFieldNumeric(new Rect(120, this.previousY, 100, 30), ref b.ExpNeeded, ref b.ENBuffer);
                    this.previousY += 40;
                }

                if (Widgets.ButtonText(new Rect(30, this.previousY, 125, 30), "Apply", true, false, this.buffers.Count > 0))
                {
                    HashSet <int> levels = new HashSet <int>();
                    foreach (var b in this.buffers)
                    {
                        if (b.ExpNeeded == 0)
                        {
                            Messages.Message("Each Exp Need must be greater than 0.", MessageTypeDefOf.RejectInput);
                            return;
                        }
                        if (levels.Contains(b.StartLevel))
                        {
                            Messages.Message("Each Start Level much be unique.", MessageTypeDefOf.RejectInput);
                            return;
                        }
                        levels.Add(b.StartLevel);
                    }
                    levels.Clear();
                    levels = null;

                    Settings.CustomCurve = new SimpleCurve();
                    foreach (var i in buffers)
                    {
                        Settings.CustomCurve.Add(new CurvePoint(i.StartLevel, i.ExpNeeded));
                    }
                    this.buffers.Clear();
                    this.buffers = this.CreateBuffers();
                }

                if (Widgets.ButtonText(new Rect(200, this.previousY, 125, 30), "Reset".Translate()))
                {
                    Settings.CustomCurve = CreateDefaultCurve();
                    this.buffers.Clear();
                    this.buffers = this.CreateBuffers();
                }
                this.previousY += 440;
            }
            Widgets.EndScrollView();
        }