public ZoneGrowingInspectPaneFiller() { curves = new List <SimpleCurveDrawInfo>(); graphSection = new Vector2(0f, 101f); singleZoneDataList = new List <SingleZoneGrowingData>() { new SingleZoneGrowingData() }; scrollPosition = Vector2.zero; sortHarvestableDesc = false; sortFullyGrownDesc = false; growthValueDrawInfo = new SimpleCurveDrawInfo(); growthValueDrawInfo.color = Color.yellow; curveDrawerStyle = new SimpleCurveDrawerStyle(); curveDrawerStyle.DrawPoints = false; curveDrawerStyle.DrawBackground = false; curveDrawerStyle.DrawBackgroundLines = false; curveDrawerStyle.UseAntiAliasedLines = true; curveDrawerStyle.OnlyPositiveValues = true; curveDrawerStyle.DrawMeasures = true; curveDrawerStyle.MeasureLabelsXCount = 10; curveDrawerStyle.MeasureLabelsYCount = 5; curveDrawerStyle.PointsRemoveOptimization = true; curveDrawerStyle.UseFixedSection = true; curveDrawerStyle.FixedSection = graphSection; harvestableMarkerDrawInfo = new SimpleCurveDrawInfo(); }
static void Prefix(SimpleCurveDrawInfo curve) { if (IsHighlightedCurve(curve)) { Widgets_DrawLine_Patch.fixWidth = ColonistHistoryMod.Settings.highlightedCurveWidth; } }
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 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; }
public static void RecalculateGraph(HistoryAutoRecorderGroup recorderGroup) { GraphUtility.cachedGraphTick = Find.TickManager.TicksGame; GraphUtility.curves.Clear(); GraphUtility.activeCurves.Clear(); if (!activeLegends.TryGetValue(recorderGroup, out curActiveLegends)) { curActiveLegends = new List <bool>(); for (int i = 0; i < recorderGroup.recorders.Count; i++) { curActiveLegends.Add(true); } activeLegends.Add(recorderGroup, curActiveLegends); } for (int i = 0; i < recorderGroup.recorders.Count; i++) { HistoryAutoRecorder historyAutoRecorder = recorderGroup.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]), false); } simpleCurveDrawInfo.curve.SortPoints(); if (historyAutoRecorder.records.Count == 1) { simpleCurveDrawInfo.curve.Add(new CurvePoint(1.66666669E-05f, historyAutoRecorder.records[0]), true); } if (curActiveLegends[i]) { GraphUtility.activeCurves.Add(simpleCurveDrawInfo); } GraphUtility.curves.Add(simpleCurveDrawInfo); } }
public static bool IsHighlightedCurve(SimpleCurveDrawInfo curve) { return(highLightCurve != null && highLightCurve.label == curve.label && highLightCurve.color == curve.color); }
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; }
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); } }
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); } }