Beispiel #1
0
 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();
 }
 public History()
 {
     this.autoRecorderGroups = new List <HistoryAutoRecorderGroup>();
     foreach (HistoryAutoRecorderGroupDef allDef in DefDatabase <HistoryAutoRecorderGroupDef> .AllDefs)
     {
         HistoryAutoRecorderGroup historyAutoRecorderGroup = new HistoryAutoRecorderGroup();
         historyAutoRecorderGroup.def = allDef;
         historyAutoRecorderGroup.CreateRecorders();
         this.autoRecorderGroups.Add(historyAutoRecorderGroup);
     }
     this.curveDrawerStyle = new SimpleCurveDrawerStyle();
     this.curveDrawerStyle.DrawMeasures             = true;
     this.curveDrawerStyle.DrawPoints               = false;
     this.curveDrawerStyle.DrawBackground           = true;
     this.curveDrawerStyle.DrawBackgroundLines      = false;
     this.curveDrawerStyle.DrawLegend               = true;
     this.curveDrawerStyle.DrawCurveMousePoint      = true;
     this.curveDrawerStyle.OnlyPositiveValues       = true;
     this.curveDrawerStyle.UseFixedSection          = true;
     this.curveDrawerStyle.UseAntiAliasedLines      = true;
     this.curveDrawerStyle.PointsRemoveOptimization = true;
     this.curveDrawerStyle.MeasureLabelsXCount      = 10;
     this.curveDrawerStyle.MeasureLabelsYCount      = 5;
     this.curveDrawerStyle.XIntegersOnly            = true;
     this.curveDrawerStyle.LabelX = "Day".Translate();
 }
Beispiel #3
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;
        }
Beispiel #4
0
 public History()
 {
     autoRecorderGroups = new List <HistoryAutoRecorderGroup>();
     AddOrRemoveHistoryRecorderGroups();
     curveDrawerStyle = new SimpleCurveDrawerStyle();
     curveDrawerStyle.DrawMeasures             = true;
     curveDrawerStyle.DrawPoints               = false;
     curveDrawerStyle.DrawBackground           = true;
     curveDrawerStyle.DrawBackgroundLines      = false;
     curveDrawerStyle.DrawLegend               = true;
     curveDrawerStyle.DrawCurveMousePoint      = true;
     curveDrawerStyle.OnlyPositiveValues       = true;
     curveDrawerStyle.UseFixedSection          = true;
     curveDrawerStyle.UseAntiAliasedLines      = true;
     curveDrawerStyle.PointsRemoveOptimization = true;
     curveDrawerStyle.MeasureLabelsXCount      = 10;
     curveDrawerStyle.MeasureLabelsYCount      = 5;
     curveDrawerStyle.XIntegersOnly            = true;
     curveDrawerStyle.LabelX = "Day".Translate();
 }
        public static void DrawGraph(Rect graphRect, Rect legendRect, FloatRange section, List <CurveMark> marks, HistoryAutoRecorderGroup recorderGroup)
        {
            if (Find.TickManager.TicksGame != GraphUtility.cachedGraphTick)
            {
                GraphUtility.RecalculateGraph(recorderGroup);
            }
            if (Mathf.Approximately(section.min, section.max))
            {
                section.max += 1.66666669E-05f;
            }
            SimpleCurveDrawerStyle curveDrawerStyle = Find.History.curveDrawerStyle;

            curveDrawerStyle.FixedSection  = section;
            curveDrawerStyle.UseFixedScale = recorderGroup.def.useFixedScale;
            curveDrawerStyle.FixedScale    = recorderGroup.def.fixedScale;
            curveDrawerStyle.YIntegersOnly = recorderGroup.def.integersOnly;
            GraphUtility.DrawCurves(graphRect, curveDrawerStyle, marks);
            GraphUtility.DrawLegends(legendRect, curveDrawerStyle);
            Text.Anchor = TextAnchor.UpperLeft;
        }
        public static void DrawLegends(Rect rect, SimpleCurveDrawerStyle style = null)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            if (style == null)
            {
                style = new SimpleCurveDrawerStyle();
            }
            if (GraphUtility.curves.Count == 0)
            {
                return;
            }

            Text.Anchor = TextAnchor.UpperLeft;
            Text.Font   = GameFont.Small;
            GUI.BeginGroup(rect);
            float num = 0f;

            for (int i = 0; i < curves.Count; i++)
            {
                bool flag = curActiveLegends[i];
                Widgets.Checkbox(0f, num, ref flag, 20f);
                if (curActiveLegends[i] != flag)
                {
                    Log.Message("cghh1");
                    curActiveLegends[i] = flag;
                }
                GUI.color = curves[i].color;
                GUI.DrawTexture(new Rect(28f, num + 2f, 15f, 15f), BaseContent.WhiteTex);
                GUI.color = Color.white;
                if (curves[i].label != null)
                {
                    Widgets.Label(new Rect(46f, num, 140f, 24f), curves[i].label);
                }
                num += 24f;
            }
            GUI.EndGroup();
            GUI.color = Color.white;
        }
        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;
        }
Beispiel #8
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);
            }
        }
        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);
            }
        }