예제 #1
0
        private void GatherSingleZoneData(Zone_Growing zone, out SingleZoneGrowingData data)
        {
            data      = new SingleZoneGrowingData();
            data.zone = zone;

            Plant plant;
            int   growthRate;
            float harvestMinGrowth = zone.GetPlantDefToGrow().plant.harvestMinGrowth * 100;

            //analyze growth values
            foreach (Thing t in zone.AllContainedThings)
            {
                if (t.def == zone.GetPlantDefToGrow())
                {
                    plant = t as Plant;
                    if (plant != null)
                    {
                        growthRate = (int)(plant.Growth * 100);
                        data.growRatesAbsolute[growthRate]++;
                        data.totalPlantedCount++;

                        if (growthRate >= 100)
                        {
                            data.fullyGrownPlants.Add(t);
                        }

                        if (growthRate >= harvestMinGrowth)
                        {
                            data.harvestablePlants.Add(t);
                        }
                    }
                }
            }

            //add curve points
            growthValueDrawInfo.curve = new SimpleCurve();
            float maxYValue = 0;

            if (data.totalPlantedCount > 0)
            {
                for (int i = 0; i < data.growRatesAbsolute.Length; i++)
                {
                    growthValueDrawInfo.curve.Add(new CurvePoint((float)i, 100 * data.growRatesAbsolute[i] / data.totalPlantedCount), false);
                }
                maxYValue = 100 * data.growthRateMaxCount / data.totalPlantedCount + 5;
            }
            else
            {
                growthValueDrawInfo.curve.Add(new CurvePoint(0f, 0f), false);
                growthValueDrawInfo.curve.Add(new CurvePoint(100f, 0f), false);
                maxYValue = 5;
            }

            //draw vertical marker
            harvestableMarkerDrawInfo.color = Color.white;
            harvestableMarkerDrawInfo.curve = new SimpleCurve();
            harvestableMarkerDrawInfo.curve.Add(-5, -5f, false);
            harvestableMarkerDrawInfo.curve.Add(harvestMinGrowth, -5f, false);
            harvestableMarkerDrawInfo.curve.Add(harvestMinGrowth, Math.Min(100, maxYValue), false);
            harvestableMarkerDrawInfo.curve.Add(harvestMinGrowth, -5f, false);

            curves.Add(growthValueDrawInfo);
            curves.Add(harvestableMarkerDrawInfo);
        }
예제 #2
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();
            }
        }
예제 #3
0
        private bool DrawZoneInfo(Rect rect, Rect headerRect, ref float singleInfoWidth, SingleZoneGrowingData data)
        {
            bool result = true;

            try
            {
                Rect rect1 = new Rect(rect.x, rect.y, headerRect.xMin, rect.height);
                GUI.color = Color.white;
                //write plant name
                Text.Anchor = TextAnchor.MiddleLeft;
                Text.Font   = GameFont.Small;
                Widgets.Label(rect1, data.zone.GetPlantDefToGrow().label);
                //write numbers
                Text.Anchor = TextAnchor.MiddleCenter;
                Text.Font   = GameFont.Tiny;
                Rect emptyCellRectLabel          = new Rect(headerRect.x, rect1.y, singleInfoWidth, rect.height);
                Rect nonEmptyCellRectLabel       = new Rect(emptyCellRectLabel.xMax, emptyCellRectLabel.y, singleInfoWidth, rect.height);
                Rect nonHarvestableCellRectLabel = new Rect(nonEmptyCellRectLabel.xMax, emptyCellRectLabel.y, singleInfoWidth, rect.height);
                Rect harvestableCellRectLabel    = new Rect(nonHarvestableCellRectLabel.xMax, emptyCellRectLabel.y, singleInfoWidth, rect.height);
                Rect fullyGrownCellRectLabel     = new Rect(harvestableCellRectLabel.xMax, emptyCellRectLabel.y, singleInfoWidth, rect.height);
                Widgets.Label(emptyCellRectLabel, "x" + (data.zone.Cells.Count - data.totalPlantedCount));
                Widgets.Label(nonEmptyCellRectLabel, "x" + data.totalPlantedCount);
                Widgets.Label(nonHarvestableCellRectLabel, "x" + (data.totalPlantedCount - data.harvestablePlants.Count));
                Widgets.Label(harvestableCellRectLabel, "x" + data.harvestablePlants.Count);
                Widgets.Label(fullyGrownCellRectLabel, "x" + data.fullyGrownPlants.Count);
                //additional feature
                Widgets.DrawHighlightIfMouseover(rect);
                if (Widgets.ButtonInvisible(rect))
                {
                    Find.Selector.ClearSelection();
                    Find.Selector.Select(data.zone);
                }
            }
            catch (Exception e)
            {
                result = false;
                Log.Error("EXCEPTION in drawing data row: " + data.zone.GetPlantDefToGrow() + " .. " + e.Message);
            }

            return(result);
        }