Esempio n. 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();
        }
Esempio n. 2
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;
        }
        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;
        }
Esempio n. 4
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();
            }
        }
Esempio n. 5
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);
            }
        }