예제 #1
0
        public void Draw(Rect rect)
        {
            curveDrawerStyle.FixedSection        = new Vector2(0, this.scrollPos_curr);
            curveDrawerStyle.MeasureLabelsXCount = (int)this.scrollPos_curr; // number of marks on x axis

            Rect graphRect  = new Rect(rect.x, rect.y, rect.width * .9f, 450f);
            Rect legendRect = new Rect(rect.x, graphRect.yMax, graphRect.width, 40f);
            Rect sliderRect = new Rect(rect.x, legendRect.yMax, graphRect.width, 50f);

            SimpleCurveDrawer.DrawCurves(graphRect, this.curves.Values.ToList(), this.curveDrawerStyle, this.marks, legendRect);
            this.scrollPos_prev = this.scrollPos_curr;
            this.scrollPos_curr = Widgets.HorizontalSlider(sliderRect, this.scrollPos_curr, min_day, max_day);

            this.rect = new Rect(graphRect.x, graphRect.y, graphRect.width, graphRect.height + legendRect.height + sliderRect.height);

            Rect deleteBtn = new Rect(graphRect.xMax + 6, graphRect.yMin, (rect.width - graphRect.width) / 1.5f, 40f);

            if (Widgets.ButtonText(deleteBtn, "Delete".Translate(), true, true, true))
            {
                this.remove = true;
            }
            if (Widgets.ButtonText(new Rect(deleteBtn.x, deleteBtn.yMax, deleteBtn.width, deleteBtn.height), "Setting", true, true, true))
            {
                Find.WindowStack.Add(new Dialog_LineChartConfig(ref this.setting));
            }
            UpdateSetting();
        }
예제 #2
0
        internal static void DrawEntries(Rect rect, Panel_Graph instance, int entries, float aliasing)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            var xIncrement = rect.width / (entries - 1.0f);

            var timeCutoff  = 0.0f;
            var callsCutoff = 0.0f;

            if (aliasing != 0)
            {
                timeCutoff  = instance.calls.max / rect.height / aliasing;
                callsCutoff = instance.times.max / rect.height / aliasing;
            }

            int i = 1, timesIndex = 0, callsIndex = 0;

            visibleMin = instance.times.entries[timesIndex];
            for (; i < entries; i++)
            {
                if (instance.calls.visible)
                {
                    if (Mathf.Abs(instance.calls.entries[callsIndex] - instance.calls.entries[i]) > callsCutoff || i == entries - 1) // We need to draw a line, enough of a difference
                    {
                        DrawLine(instance.calls, callsIndex, i, rect.height, xIncrement, Settings.callsColour);

                        callsIndex = i;
                    }
                }

                if (!instance.times.visible)
                {
                    continue;
                }

                if (Mathf.Abs(instance.times.entries[timesIndex] - instance.times.entries[i]) > timeCutoff || i == entries - 1)
                {
                    var point = DrawLine(instance.times, timesIndex, i, rect.height, xIncrement, Settings.timeColour);

                    if (instance.times.entries[i] < visibleMin)
                    {
                        visibleMin = instance.times.entries[timesIndex];
                    }

                    var cheese = new Rect(point.x - (xIncrement * 0.5f), 0, xIncrement, rect.height);
                    if (Mouse.IsOver(cheese))
                    {
                        SimpleCurveDrawer.DrawPoint(point);
                        hoverValStr = $"{instance.times.entries[timesIndex]}ms {instance.calls.entries[timesIndex]} calls";
                    }

                    timesIndex = i;
                }
            }
        }
예제 #3
0
        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();
                    }
                }
            }
        private static List <SimpleCurveDrawInfo> GetFocusedCurves(List <SimpleCurveDrawInfo> curves, Rect screenRect, Rect viewRect)
        {
            if (curves.Count == 0)
            {
                return(null);
            }
            if (!Mouse.IsOver(screenRect))
            {
                return(null);
            }
            GUI.BeginGroup(screenRect);
            Vector2 mousePosition = Event.current.mousePosition;
            Vector2 vector        = default(Vector2);
            Vector2 vector2       = default(Vector2);
            bool    flag          = false;
            List <SimpleCurveDrawInfo> simpleCurveDrawInfos = new List <SimpleCurveDrawInfo>();

            foreach (SimpleCurveDrawInfo simpleCurveDrawInfo2 in curves)
            {
                if (simpleCurveDrawInfo2.curve.PointsCount != 0)
                {
                    Vector2 vector3 = SimpleCurveDrawer.ScreenToCurveCoords(screenRect, viewRect, mousePosition);
                    vector3.y = simpleCurveDrawInfo2.curve.Evaluate(vector3.x);
                    Vector2 vector4 = SimpleCurveDrawer.CurveToScreenCoordsInsideScreenRect(screenRect, viewRect, vector3);
                    if (!flag || Mathf.Approximately(Vector2.Distance(vector4, mousePosition), Vector2.Distance(vector2, mousePosition)))
                    {
                        flag    = true;
                        vector  = vector3;
                        vector2 = vector4;
                        simpleCurveDrawInfos.Add(simpleCurveDrawInfo2);
                    }
                    else if (!flag || Vector2.Distance(vector4, mousePosition) < Vector2.Distance(vector2, mousePosition))
                    {
                        flag    = true;
                        vector  = vector3;
                        vector2 = vector4;
                        simpleCurveDrawInfos.Clear();
                        simpleCurveDrawInfos.Add(simpleCurveDrawInfo2);
                    }
                }
            }
            GUI.EndGroup();
            return(simpleCurveDrawInfos);
        }
        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;
                    }
                }
            }
        }
예제 #7
0
        public void DrawGraph(Rect graphRect, Rect legendRect, FloatRange section, List <CurveMark> marks)
        {
            int ticksGame = Find.TickManager.TicksGame;

            if (ticksGame != cachedGraphTickCount)
            {
                cachedGraphTickCount = ticksGame;
                curves.Clear();
                for (int i = 0; i < recorders.Count; i++)
                {
                    HistoryAutoRecorder historyAutoRecorder = recorders[i];
                    SimpleCurveDrawInfo simpleCurveDrawInfo = new SimpleCurveDrawInfo();
                    simpleCurveDrawInfo.color  = historyAutoRecorder.def.graphColor;
                    simpleCurveDrawInfo.label  = historyAutoRecorder.def.LabelCap;
                    simpleCurveDrawInfo.labelY = historyAutoRecorder.def.GraphLabelY;
                    simpleCurveDrawInfo.curve  = new SimpleCurve();
                    for (int j = 0; j < historyAutoRecorder.records.Count; j++)
                    {
                        simpleCurveDrawInfo.curve.Add(new CurvePoint((float)j * (float)historyAutoRecorder.def.recordTicksFrequency / 60000f, historyAutoRecorder.records[j]), sort: false);
                    }
                    simpleCurveDrawInfo.curve.SortPoints();
                    if (historyAutoRecorder.records.Count == 1)
                    {
                        simpleCurveDrawInfo.curve.Add(new CurvePoint(1.66666669E-05f, historyAutoRecorder.records[0]));
                    }
                    curves.Add(simpleCurveDrawInfo);
                }
            }
            if (Mathf.Approximately(section.min, section.max))
            {
                section.max += 1.66666669E-05f;
            }
            SimpleCurveDrawerStyle curveDrawerStyle = Find.History.curveDrawerStyle;

            curveDrawerStyle.FixedSection       = section;
            curveDrawerStyle.UseFixedScale      = def.useFixedScale;
            curveDrawerStyle.FixedScale         = def.fixedScale;
            curveDrawerStyle.YIntegersOnly      = def.integersOnly;
            curveDrawerStyle.OnlyPositiveValues = def.onlyPositiveValues;
            SimpleCurveDrawer.DrawCurves(graphRect, curves, curveDrawerStyle, marks, legendRect);
            Text.Anchor = TextAnchor.UpperLeft;
        }
 // Token: 0x06001E03 RID: 7683 RVA: 0x000BCB34 File Offset: 0x000BAD34
 private static IEnumerable <int> PointsNearMouse(Rect screenRect, SimpleCurve curve, Vector2 mousePosition)
 {
     GUI.BeginGroup(screenRect);
     try
     {
         int num;
         for (int i = 0; i < curve.PointsCount; i = num + 1)
         {
             if ((SimpleCurveDrawer.CurveToScreenCoordsInsideScreenRect(screenRect, curve.View.rect, curve[i].Loc) - mousePosition).sqrMagnitude < 49f)
             {
                 yield return(i);
             }
             num = i;
         }
     }
     finally
     {
         GUI.EndGroup();
     }
     yield break;
 }
예제 #9
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();
        }
        public void DrawGraph(Rect graphRect, Rect legendRect, FloatRange section, List <CurveMark> marks)
        {
            int ticksGame = Find.TickManager.TicksGame;

            if (ticksGame != this.cachedGraphTickCount || RecordGroup.forceRedraw)
            {
                this.cachedGraphTickCount = ticksGame;
                this.curves.Clear();
                int i = 0;
                Func <Pawn, bool> pred = delegate(Pawn p) {
                    return(ColonistHistoryMod.Settings.showOtherFactionPawn || !p.ExistExtraNoPlayerFactions());
                };
                int numOfColonist = this.comp.Colonists.Where(pred).Count();
                foreach (Pawn pawn in this.comp.Colonists.Where(pred))
                {
                    List <Vector2> vectors = this.cachedGraph[pawn];

                    SimpleCurveDrawInfo simpleCurveDrawInfo = new SimpleCurveDrawInfo();
                    simpleCurveDrawInfo.color       = Color.HSVToRGB((float)i / numOfColonist, 1f, 1f);
                    simpleCurveDrawInfo.label       = pawn.Name.ToStringShort;
                    simpleCurveDrawInfo.valueFormat = recordID.colonistHistoryDef.GraphLabelY;
                    simpleCurveDrawInfo.curve       = new SimpleCurve();
                    for (int j = 0; j < vectors.Count; j++)
                    {
                        float x = vectors[j].x / 60000f;
                        float y = vectors[j].y;
                        simpleCurveDrawInfo.curve.Add(new CurvePoint(x, y), false);
                    }
                    simpleCurveDrawInfo.curve.SortPoints();

                    /*
                     *                  if (ticksGame % 100 == 0) {
                     *                          Log.Message(pawn.Label + "\n" + string.Join("\n",simpleCurveDrawInfo.curve.Points.ConvertAll(p => p.ToString())));
                     *                  }
                     */
                    this.curves.Add(simpleCurveDrawInfo);
                    i++;
                }

                RecordGroup.forceRedraw = false;
            }
            if (Mathf.Approximately(section.min, section.max))
            {
                section.max += 1.66666669E-05f;
            }
            SimpleCurveDrawerStyle curveDrawerStyle = Find.History.curveDrawerStyle;

            curveDrawerStyle.FixedSection       = section;
            curveDrawerStyle.UseFixedScale      = this.recordID.colonistHistoryDef.useFixedScale;
            curveDrawerStyle.FixedScale         = this.recordID.colonistHistoryDef.fixedScale;
            curveDrawerStyle.YIntegersOnly      = this.recordID.colonistHistoryDef.integersOnly;
            curveDrawerStyle.OnlyPositiveValues = this.recordID.colonistHistoryDef.onlyPositiveValues;
            curveDrawerStyle.DrawLegend         = false;
            List <SimpleCurveDrawInfo> renderableCurves = new List <SimpleCurveDrawInfo>();

            for (int i = 0; i < this.curves.Count; i++)
            {
                if (!hidePawnIndexes.Contains(i))
                {
                    renderableCurves.Add(this.curves[i]);
                }
            }
            if (SimpleCurveDrawer_DrawCurveLines_Patch.highLightCurve != null)
            {
                renderableCurves.SortBy(c => SimpleCurveDrawer_DrawCurveLines_Patch.IsHighlightedCurve(c));
            }
            SimpleCurveDrawer.DrawCurves(graphRect, renderableCurves, curveDrawerStyle, marks, legendRect);
            DrawCurvesLegend(legendRect, this.curves);
            Text.Anchor = TextAnchor.UpperLeft;
        }
예제 #11
0
        private void DrawSingleSelectionInfo(Rect rect)
        {
            //Draw Graph
            try
            {
                SingleZoneGrowingData singleZoneData = singleZoneDataList[0];
                GUI.BeginGroup(rect);
                //-20f for x due to adjustments when displaying measures
                Rect graphRect      = new Rect(-20f, 90f, rect.width - 24f, GROWINGZONE_SINGLE_SELECT_GRAPHHEIGHT);
                Rect yAxisLabelRect = new Rect(12f, 78f, graphRect.yMin - 12, 20);
                Rect xAxisLabelRect = new Rect(12f, graphRect.yMax - 6, rect.width - 36, 20);
                Rect infoRect       = new Rect(40f, xAxisLabelRect.yMax, graphRect.width - 80f, GROWINGZONE_SINGLE_SELECT_INFOHEIGHT - 12f);

                //draw graph and labels
                Text.Anchor = TextAnchor.MiddleLeft;
                Text.Font   = GameFont.Tiny;
                GUI.color   = AXIS_LABEL_COLOR;
                Widgets.Label(yAxisLabelRect, "Value".Translate() + " (%)");
                Text.Anchor = TextAnchor.UpperRight;
                Widgets.Label(xAxisLabelRect, "PercentGrowth".Translate(new object[] { "%" }));
                SimpleCurveDrawer.DrawCurves(graphRect, this.curves, curveDrawerStyle, null);

                //draw infos
                Text.Anchor = TextAnchor.MiddleCenter;
                Text.Font   = GameFont.Tiny;
                GUI.color   = AXIS_LABEL_COLOR;
                float singleInfoWidth = infoRect.width / 5f;

                //Draw total empty cells
                Rect iconRect1 = new Rect(infoRect.x + (singleInfoWidth / 2) - 10f, infoRect.y + 5f, 20f, 20f);
                GUI.DrawTexture(iconRect1, emptyCellCountIcon);
                Rect emptyCellRectLabel = new Rect(infoRect.x, iconRect1.yMax + 10f, singleInfoWidth, 20f);
                Widgets.Label(emptyCellRectLabel, "x" + (singleZoneData.zone.Cells.Count - singleZoneData.totalPlantedCount));

                //Draw total cells with plants
                Rect iconRect2 = new Rect(iconRect1.x + singleInfoWidth, iconRect1.y, 20f, 20f);
                GUI.DrawTexture(iconRect2, nonEmptyCellCountIcon);
                Rect nonEmptyCellRectLabel = new Rect(emptyCellRectLabel.xMax, emptyCellRectLabel.y, singleInfoWidth, 20f);
                Widgets.Label(nonEmptyCellRectLabel, "x" + singleZoneData.totalPlantedCount);

                //Draw non harvestable cells (growth value limit not reached)
                Rect iconRect3 = new Rect(iconRect2.x + singleInfoWidth - 1, iconRect1.y, 10f, 20f);
                Rect iconRect4 = new Rect(iconRect3.xMax + 2f, iconRect1.y, 10f, 20f);
                GUI.DrawTexture(iconRect3, nonHarvestableIcon);
                GUI.DrawTexture(iconRect4, nonHarvestableIcon);
                Rect nonHarvestableCellRectLabel = new Rect(nonEmptyCellRectLabel.xMax, emptyCellRectLabel.y, singleInfoWidth, 20f);
                Widgets.Label(nonHarvestableCellRectLabel, "x" + (singleZoneData.totalPlantedCount - singleZoneData.harvestablePlants.Count));

                //Draw harvestable cells (growth value limit reached)
                Rect iconRect5 = new Rect(iconRect3.x + singleInfoWidth, iconRect1.y, 20f, 20f);
                GUI.DrawTexture(iconRect5, harvestableIcon);
                if (Mouse.IsOver(iconRect5))
                {
                    Widgets.DrawBox(iconRect5);
                }
                Rect harvestableCellRectLabel = new Rect(nonHarvestableCellRectLabel.xMax, emptyCellRectLabel.y, singleInfoWidth, 20f);
                Widgets.Label(harvestableCellRectLabel, "x" + singleZoneData.harvestablePlants.Count);
                if (Widgets.ButtonInvisible(iconRect5))
                {
                    Find.Selector.ClearSelection();
                    foreach (Thing t in singleZoneData.harvestablePlants)
                    {
                        if (!t.Destroyed)
                        {
                            Find.Selector.Select(t, false);
                        }
                    }
                }

                //Draw fully grown cells (growth value >= 100%)
                Rect iconRect6 = new Rect(iconRect5.x + singleInfoWidth, iconRect1.y, 20f, 20f);
                GUI.DrawTexture(iconRect6, fullyGrown);
                if (Mouse.IsOver(iconRect6))
                {
                    Widgets.DrawBox(iconRect6);
                }
                Rect fullyGrownCellRectLabel = new Rect(harvestableCellRectLabel.xMax, emptyCellRectLabel.y, singleInfoWidth, 20f);
                Widgets.Label(fullyGrownCellRectLabel, "x" + singleZoneData.fullyGrownPlants.Count);
                if (Widgets.ButtonInvisible(iconRect6))
                {
                    Find.Selector.ClearSelection();
                    foreach (Thing t in singleZoneData.fullyGrownPlants)
                    {
                        if (!t.Destroyed)
                        {
                            Find.Selector.Select(t, false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.ErrorOnce(string.Concat(new object[]
                {
                    "Error in Mod ZoneInspectData: ZoneGrowingInspectPaneFiller#DrawGraph ",
                    Find.Selector.FirstSelectedObject,
                    ": ", ex.StackTrace
                }), this.GetHashCode());
            }
            finally
            {
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.EndGroup();
            }
        }
예제 #12
0
        public static void DoGraph(Rect position)
        {
            ResetRange++;
            if (ResetRange >= 500)
            {
                ResetRange = 0;
                WindowMax  = 0;
            }

            Text.Font = GameFont.Small;

            var settings = position.TopPartPixels(30f);

            position = position.BottomPartPixels(position.height - 30f);



            Widgets.DrawBoxSolid(position, Analyzer.Settings.GraphCol);


            GUI.color = Color.grey;
            Widgets.DrawBox(position, 2);
            GUI.color = Color.white;

            if (!Analyzer.Profiles.ContainsKey(key))
            {
                return;
            }

            var prof = Analyzer.Profiles[key];

            if (prof.History.times.Length <= 0)
            {
                return;
            }


            var mescou = prof.History.times.Length;

            if (mescou > entryCount)
            {
                mescou = entryCount;
            }

            var gap = position.width / mescou;

            var car = settings.RightPartPixels(200f);

            car.x     -= 15;
            entryCount = (int)Widgets.HorizontalSlider(car, entryCount, 10, 2000, true,
                                                       string.Intern($"{entryCount} Entries"));

            car = new Rect(car.xMax + 5, car.y + 2, 10, 10);
            Widgets.DrawBoxSolid(car, Analyzer.Settings.LineCol);
            if (Widgets.ButtonInvisible(car, true))
            {
                if (Find.WindowStack.WindowOfType <colourPicker>() != null)
                {
                    Find.WindowStack.RemoveWindowsOfType(typeof(colourPicker));
                }
                else
                {
                    var cp = new colourPicker
                    {
                        Setcol = () => Analyzer.Settings.LineCol = colourPicker.CurrentCol
                    };
                    cp.SetColor(Analyzer.Settings.LineCol);
                    Find.WindowStack.Add(cp);
                }
            }
            car.y += 12;
            Widgets.DrawBoxSolid(car, Analyzer.Settings.GraphCol);
            if (Widgets.ButtonInvisible(car, true))
            {
                if (Find.WindowStack.WindowOfType <colourPicker>() != null)
                {
                    Find.WindowStack.RemoveWindowsOfType(typeof(colourPicker));
                }
                else
                {
                    var cp = new colourPicker
                    {
                        Setcol = () => Analyzer.Settings.GraphCol = colourPicker.CurrentCol
                    };
                    cp.SetColor(Analyzer.Settings.GraphCol);
                    Find.WindowStack.Add(cp);
                }
            }

            if (Analyzer.Settings.AdvancedMode)
            {
                var memr = settings.LeftPartPixels(20f);
                if (Widgets.ButtonImageFitted(memr, mem, ShowMem ? Color.white : Color.grey))
                {
                    ShowMem = !ShowMem;
                }
                GUI.color = Color.white;
                TooltipHandler.TipRegion(memr, "Toggle garbage tracking, approximation of total garbage produced by the selected log");

                memr.x     = memr.xMax;
                memr.width = 300f;
                if (ShowMem)
                {
                    Text.Anchor = TextAnchor.MiddleLeft;
                    Widgets.Label(memr, totalBytesStr);
                }
            }


            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(settings, hoverValStr);
            Text.Anchor = TextAnchor.UpperLeft;

            maxBytes = 0;
            minBytes = 0;

            var LastMax = max;

            max = 0;

            GUI.BeginGroup(position);
            position = position.AtZero();

            for (var i = 0; i < mescou; i++)
            {
                var bytes = prof.History.mem[i];
                var TM    = prof.History.times[i];

                if (i == 0)
                {
                    minBytes = bytes;
                    maxBytes = bytes;
                    max      = TM;
                }

                if (bytes < minBytes)
                {
                    minBytes = bytes;
                }

                if (bytes > maxBytes)
                {
                    maxBytes = bytes;
                }

                if (TM > max)
                {
                    max = TM;
                }
            }

            if (max > WindowMax)
            {
                WindowMax = (float)max;
            }

            var DoHover = false;

            for (var i = 0; i < mescou; i++)
            {
                var bytes = prof.History.mem[i];
                var TM    = prof.History.times[i];

                var y    = GenMath.LerpDoubleClamped(0, WindowMax, position.height, position.y, (float)TM);
                var MEMy = GenMath.LerpDoubleClamped(minBytes, maxBytes, position.height, position.y, bytes);

                var screenPoint    = new Vector2(position.xMax - gap * i, y);
                var MEMscreenPoint = new Vector2(position.xMax - gap * i, MEMy);

                if (i != 0)
                {
                    Widgets.DrawLine(last, screenPoint, Analyzer.Settings.LineCol, 1f);
                    if (ShowMem)
                    {
                        Widgets.DrawLine(lastMEM, MEMscreenPoint, Color.grey, 2f);
                    }

                    var vag = new Rect(screenPoint.x - gap / 2f, position.y, gap, position.height);

                    //if (Widgets.ButtonInvisible(vag))
                    //{
                    //    Log.Warning(prof.History.stack[i]);
                    //    Find.WindowStack.Windows.Add(new StackWindow { stkRef = prof.History.stack[i] });
                    //}

                    if (Mouse.IsOver(vag))
                    {
                        DoHover = true;
                        if (i != hoverVal)
                        {
                            hoverVal    = i;
                            hoverValStr = $"{TM} {prof.History.hits[i]} calls";
                        }

                        SimpleCurveDrawer.DrawPoint(screenPoint);
                    }
                }

                last    = screenPoint;
                lastMEM = MEMscreenPoint;
            }

            if (LastMax != max)
            {
                MaxStr = $"Max {max}ms";
            }

            if (LASTtotalBytesStr < prof.BytesUsed)
            {
                LASTtotalBytesStr = prof.BytesUsed;
                totalBytesStr     = $"Mem {(long)(prof.BytesUsed / (long)1024)} Kb";
            }


            var LogMaxY = GenMath.LerpDoubleClamped(0, WindowMax, position.height, position.y, (float)max);
            var crunt   = position;

            crunt.y = LogMaxY;
            Widgets.Label(crunt, MaxStr);
            Widgets.DrawLine(new Vector2(position.x, LogMaxY), new Vector2(position.xMax, LogMaxY), Color.red, 1f);

            last = Vector2.zero;
            GUI.EndGroup();
        }
예제 #13
0
        void DrawUI(Rect rect)
        {
            const float PADDING = 5f;

            draggableIndex = 0;
            float topHeight    = rect.height * VerticalSplit;
            Rect  topArea      = new Rect(rect.x, rect.y, rect.width, topHeight);
            float bottomHeight = rect.height - topHeight;
            Rect  bottomArea   = new Rect(rect.x, rect.y + topHeight, rect.width, bottomHeight);

            // Net power.
            float  netWatts    = 123.5f;
            string netPowerTxt = PowerConvert.GetPrettyPower(netWatts);

            Text.Font = GameFont.Medium;
            var txtSize = Text.CalcSize(netPowerTxt);

            Widgets.Label(new Rect(rect.xMax - txtSize.x - PADDING, rect.y + PADDING, txtSize.x, txtSize.y), netPowerTxt);

            // Vertical slide.
            float vertSize = Mathf.Clamp(Draggable(new Vector2(rect.x, rect.y + topHeight), rect.width, 0) - rect.y, MinVerticalSize, rect.height - MinVerticalSize);

            VerticalSplit = vertSize / rect.height;

            // First section slide.
            float maxSecAWidth = rect.width - SectionCWidth() - MinSectionWidth;

            SectionAWidth = Mathf.Clamp(Draggable(new Vector2(rect.x + SectionAWidth, rect.y + topHeight), 0f, bottomHeight, () =>
            {
                sectionBStart = SectionBWidth;
                sectionAStart = SectionAWidth;
            }) - rect.x, MinSectionWidth, maxSecAWidth);
            if (IsDragging())
            {
                float deltaA    = SectionAWidth - sectionAStart;
                float adjustedB = sectionBStart - deltaA;
                SectionBWidth = adjustedB;
            }

            // Second section slide.
            float cWidth = rect.xMax - Draggable(new Vector2(rect.x + SectionAWidth + SectionBWidth, rect.y + topHeight), 0f, bottomHeight);
            float bWidth = rect.width - cWidth - SectionAWidth;

            SectionBWidth = Mathf.Clamp(bWidth, MinSectionWidth, rect.width - SectionAWidth - MinSectionWidth);

            Rect sectionA = new Rect(rect.x, rect.y + topHeight, SectionAWidth, bottomHeight);
            Rect sectionB = new Rect(rect.x + SectionAWidth, rect.y + topHeight, SectionBWidth, bottomHeight);
            Rect sectionC = new Rect(rect.x + SectionAWidth + SectionBWidth, rect.y + topHeight, SectionCWidth(), bottomHeight);

            List <SimpleCurveDrawInfo> curves = new List <SimpleCurveDrawInfo>();
            var curve  = new SimpleCurve();
            var curve2 = new SimpleCurve();

            for (int i = 0; i < 100; i++)
            {
                float x  = i;
                float y  = x * x;
                float y2 = x * 80;

                curve.Add(new CurvePoint(x, y));
                curve2.Add(new CurvePoint(x, y2));
            }

            var drawInfo = new SimpleCurveDrawInfo();

            drawInfo.curve = curve;
            drawInfo.color = Color.cyan;
            drawInfo.label = "Power Production";
            curves.Add(drawInfo);

            var drawInfo2 = new SimpleCurveDrawInfo();

            drawInfo2.curve = curve2;
            drawInfo2.color = Color.red;
            drawInfo2.label = "Power Consumption";
            curves.Add(drawInfo2);

            var style = new SimpleCurveDrawerStyle();

            //style.UseFixedScale = true;
            style.DrawBackground      = true;
            style.DrawLegend          = true;
            style.DrawMeasures        = true;
            style.DrawPoints          = false;
            style.DrawCurveMousePoint = true;
            style.UseAntiAliasedLines = true;

            SimpleCurveDrawer.DrawCurves(topArea, curves, style);

            //GUI.Box(rect, "");
            GUI.Box(topArea, "");
            GUI.Box(sectionA, "");
            GUI.Box(sectionB, "");
            GUI.Box(sectionC, "");

            float SectionCWidth()
            {
                return(rect.width - SectionAWidth - SectionBWidth);
            }
        }
예제 #14
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();
        }
        private static void DrawCurves(Rect rect, SimpleCurveDrawerStyle style = null, List <CurveMark> marks = null)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            if (style == null)
            {
                style = new SimpleCurveDrawerStyle();
            }
            bool flag     = true;
            Rect viewRect = default(Rect);

            for (int i = 0; i < activeCurves.Count; i++)
            {
                SimpleCurveDrawInfo simpleCurveDrawInfo = activeCurves[i];
                if (simpleCurveDrawInfo.curve != null)
                {
                    if (flag)
                    {
                        flag     = false;
                        viewRect = simpleCurveDrawInfo.curve.View.rect;
                    }
                    else
                    {
                        viewRect.xMin = Mathf.Min(viewRect.xMin, simpleCurveDrawInfo.curve.View.rect.xMin);
                        viewRect.xMax = Mathf.Max(viewRect.xMax, simpleCurveDrawInfo.curve.View.rect.xMax);
                        viewRect.yMin = Mathf.Min(viewRect.yMin, simpleCurveDrawInfo.curve.View.rect.yMin);
                        viewRect.yMax = Mathf.Max(viewRect.yMax, simpleCurveDrawInfo.curve.View.rect.yMax);
                    }
                }
            }
            if (style.UseFixedScale)
            {
                viewRect.yMin = style.FixedScale.x;
                viewRect.yMax = style.FixedScale.y;
            }
            if (style.OnlyPositiveValues)
            {
                if (viewRect.xMin < 0f)
                {
                    viewRect.xMin = 0f;
                }
                if (viewRect.yMin < 0f)
                {
                    viewRect.yMin = 0f;
                }
            }
            if (style.UseFixedSection)
            {
                viewRect.xMin = style.FixedSection.min;
                viewRect.xMax = style.FixedSection.max;
            }
            if (Mathf.Approximately(viewRect.width, 0f) || Mathf.Approximately(viewRect.height, 0f))
            {
                return;
            }
            Rect rect2 = rect;

            if (style.DrawMeasures)
            {
                rect2.xMin += 60f;
                rect2.yMax -= 30f;
            }
            if (marks != null)
            {
                Rect rect3 = rect2;
                rect3.height = 15f;
                SimpleCurveDrawer.DrawCurveMarks(rect3, viewRect, marks);
                rect2.yMin = rect3.yMax;
            }
            if (style.DrawBackground)
            {
                GUI.color = new Color(0.302f, 0.318f, 0.365f);
                GUI.DrawTexture(rect2, BaseContent.WhiteTex);
            }
            if (style.DrawBackgroundLines)
            {
                SimpleCurveDrawer.DrawGraphBackgroundLines(rect2, viewRect);
            }
            if (style.DrawMeasures)
            {
                SimpleCurveDrawer.DrawCurveMeasures(rect, viewRect, rect2, style.MeasureLabelsXCount, style.MeasureLabelsYCount, style.XIntegersOnly, style.YIntegersOnly);
            }
            foreach (SimpleCurveDrawInfo current in activeCurves)
            {
                SimpleCurveDrawer.DrawCurveLines(rect2, current, style.DrawPoints, viewRect, style.UseAntiAliasedLines, style.PointsRemoveOptimization);
            }
            if (style.DrawCurveMousePoint)
            {
                SimpleCurveDrawer.DrawCurveMousePoint(activeCurves, rect2, viewRect, style.LabelX);
            }
        }