Ejemplo n.º 1
0
        protected float DrawEntryHeader(string entryLabel, bool useStartingGap = true,
                                        bool useFollowingGap = false, Color?backgroundColor = null, float colorAlpha = 0.2f)
        {
            if (useStartingGap)
            {
                ListingStandard.Gap();
            }

            var textHeight = Text.CalcHeight(entryLabel, ListingStandard.ColumnWidth);
            var r          = ListingStandard.GetRect(0f);

            r.height = textHeight;

            var bgColor = backgroundColor.GetValueOrDefault(DefaultMenuSectionBgFillColor);

            if (backgroundColor != null)
            {
                bgColor.a = colorAlpha;
            }

            Verse.Widgets.DrawBoxSolid(r, bgColor);

            ListingStandard.Label($"{entryLabel}:", DefaultElementHeight);

            ListingStandard.GapLine(DefaultGapLineHeight);

            if (useFollowingGap)
            {
                ListingStandard.Gap();
            }

            return(ListingStandard.CurHeight);
        }
Ejemplo n.º 2
0
        protected void DrawUsableMinMaxNumericField <T>(UsableMinMaxNumericItem <T> numericItem, string label,
                                                        float min = 0f, float max = 1E+09f) where T : struct, IComparable, IConvertible
        {
            var tmpCheckedOn = numericItem.Use;

            var textMin = "PLINT_UsableMinMaxNumFieldMin".Translate();
            var textMax = "PLINT_UsableMinMaxNumFieldMax".Translate();

            ListingStandard.Gap();
            ListingStandard.CheckboxLabeled(label, ref tmpCheckedOn, $"{"PLINT_UsableMinMaxNumFieldUse".Translate()} {textMin}/{textMax} {label}");
            numericItem.Use = tmpCheckedOn;

            var minValue          = numericItem.Min;
            var minValueString    = numericItem.MinString;
            var minValueLabelRect = ListingStandard.GetRect(DefaultElementHeight);

            Verse.Widgets.TextFieldNumericLabeled(minValueLabelRect, $"{textMin}: ", ref minValue, ref minValueString, min, max);
            numericItem.Min       = minValue;
            numericItem.MinString = minValueString;

            var maxValue          = numericItem.Max;
            var maxValueString    = numericItem.MaxString;
            var maxValueLabelRect = ListingStandard.GetRect(DefaultElementHeight);

            Verse.Widgets.TextFieldNumericLabeled(maxValueLabelRect, $"{textMax}: ", ref maxValue, ref maxValueString, min, max);
            numericItem.Max       = maxValue;
            numericItem.MaxString = maxValueString;
        }
Ejemplo n.º 3
0
        protected virtual void DrawUsableMinMaxNumericField <T>(UsableMinMaxNumericItem <T> numericItem, string label,
                                                                float min = 0f, float max = 1E+09f) where T : struct, IComparable, IConvertible
        {
            var tmpCheckedOn = numericItem.Use;

            ListingStandard.Gap(DefaultGapHeight);
            ListingStandard.CheckboxLabeled(label, ref tmpCheckedOn, $"Use Min/Max {label}");
            numericItem.Use = tmpCheckedOn;

            var minValue          = numericItem.Min;
            var minValueString    = numericItem.MinString;
            var minValueLabelRect = ListingStandard.GetRect(DefaultElementHeight);

            Widgets.TextFieldNumericLabeled(minValueLabelRect, "Min: ", ref minValue, ref minValueString, min, max);
            numericItem.Min       = minValue;
            numericItem.MinString = minValueString;

            var maxValue          = numericItem.Max;
            var maxValueString    = numericItem.MaxString;
            var maxValueLabelRect = ListingStandard.GetRect(DefaultElementHeight);

            Widgets.TextFieldNumericLabeled(maxValueLabelRect, "Max: ", ref maxValue, ref maxValueString, min, max);
            numericItem.Max       = maxValue;
            numericItem.MaxString = maxValueString;
        }
Ejemplo n.º 4
0
        protected void DrawGrowingPeriodSelection()
        {
            const string label = "Growing Period";

            DrawEntryHeader($"{label} (days)", backgroundColor: ColorFromFilterSubjectThingDef("Growing Periods"));

            var boundField = _userData.GrowingPeriod;

            var tmpCheckedOn = boundField.Use;

            ListingStandard.Gap();
            ListingStandard.CheckboxLabeled(label, ref tmpCheckedOn, $"Use Min/Max {label}");
            boundField.Use = tmpCheckedOn;

            // MIN

            if (ListingStandard.ButtonText($"Min {label}"))
            {
                var floatMenuOptions = new List <FloatMenuOption>();
                foreach (var growingTwelfth in boundField.Options)
                {
                    var menuOption = new FloatMenuOption(growingTwelfth.GrowingDaysString(),
                                                         delegate { boundField.Min = growingTwelfth; });
                    floatMenuOptions.Add(menuOption);
                }

                var floatMenu = new FloatMenu(floatMenuOptions, $"Select {label}");
                Find.WindowStack.Add(floatMenu);
            }

            ListingStandard.LabelDouble($"Min. {label}:", boundField.Min.GrowingDaysString());

            // MAX

            if (ListingStandard.ButtonText($"Max {label}"))
            {
                var floatMenuOptions = new List <FloatMenuOption>();
                foreach (var growingTwelfth in boundField.Options)
                {
                    var menuOption = new FloatMenuOption(growingTwelfth.GrowingDaysString(),
                                                         delegate { boundField.Max = growingTwelfth; });
                    floatMenuOptions.Add(menuOption);
                }

                var floatMenu = new FloatMenu(floatMenuOptions, $"Select {label}");
                Find.WindowStack.Add(floatMenu);
            }

            ListingStandard.LabelDouble($"Max. {label}:", boundField.Max.GrowingDaysString());
        }
Ejemplo n.º 5
0
        protected virtual void DrawFilterInfo()
        {
            DrawEntryHeader("Filter Info", backgroundColor: Color.yellow);

            if (ListingStandard.ButtonText("Clear Info"))
            {
                PrepareLanding.Instance.TileFilter.FilterInfoLogger.Clear();
            }

            ListingStandard.Gap();

            var text = PrepareLanding.Instance.TileFilter.FilterInfoLogger.Text;

            if (text.NullOrEmpty())
            {
                return;
            }

            var maxOuterRectHeight = InRect.height - ListingStandard.CurHeight - 30f;

            ListingStandard.ScrollableTextArea(maxOuterRectHeight, text, ref _scrollPosFilterInfo, _styleFilterInfo,
                                               16f);
        }
Ejemplo n.º 6
0
        private void DrawFilterInfo()
        {
            DrawEntryHeader("PLMWINF_FilterInfo".Translate(), backgroundColor: Color.yellow);

            if (ListingStandard.ButtonText("PLMWINF_ClearInfo".Translate()))
            {
                PrepareLanding.Instance.TileFilter.FilterInfoLogger.Clear();
            }

            ListingStandard.Gap();

            var text = PrepareLanding.Instance.TileFilter.FilterInfoLogger.Text;

            if (text.NullOrEmpty())
            {
                return;
            }

            var maxOuterRectHeight = InRect.height - ListingStandard.CurHeight - DefaultElementHeight;

            ListingStandard.ScrollableTextArea(maxOuterRectHeight, text, ref _scrollPosFilterInfo, _styleFilterInfo,
                                               DefaultScrollableViewShrinkWidth);
        }
Ejemplo n.º 7
0
        private void DrawTemperatureForecast()
        {
            DrawEntryHeader("PLMWT2T_TemperatureForecast".Translate(), backgroundColor: Color.magenta);

            var tileId = Find.WorldSelector.selectedTile;

            if (!Find.WorldSelector.AnyObjectOrTileSelected || tileId < 0)
            {
                var labelRect = ListingStandard.GetRect(DefaultElementHeight);
                Widgets.Label(labelRect, "PLMWT2T_TempPickTileOnWorldMap".Translate());
                _selectedTileIdForTemperatureForecast = -1;
                return;
            }

            ListingStandard.LabelDouble($"{"PLMWT2T_TempSelectedTile".Translate()}: ", tileId.ToString());
            _selectedTileIdForTemperatureForecast = tileId;

            ListingStandard.GapLine(DefaultGapLineHeight);

            /*
             * Day / Quadrum / Year selector
             */
            var backupAnchor = Text.Anchor;

            Text.Anchor = TextAnchor.MiddleLeft;

            // day
            var daySelector  = ListingStandard.GetRect(30f);
            var dayLabelRect = daySelector.LeftPart(0.70f);
            var dayFieldRect = daySelector.RightPart(0.30f);

            Widgets.Label(dayLabelRect, $"{"PLMWT2T_QuadrumDay".Translate()} [1, 15]: ");
            Widgets.TextFieldNumeric(dayFieldRect, ref _dayOfQuadrum, ref _dayOfQuadrumString, 1,
                                     GenDate.DaysPerQuadrum);

            ListingStandard.Gap(6f);

            // quadrum
            var quadrumRect       = ListingStandard.GetRect(30f);
            var quadrumButtonRect = quadrumRect.LeftHalf();

            if (Widgets.ButtonText(quadrumButtonRect, "PLMWT2T_SelectQuadrum".Translate()))
            {
                // get all possible enumeration values for hilliness
                var quadrumList = Enum.GetValues(typeof(Quadrum)).Cast <Quadrum>().ToList();

                var floatMenuOptions = new List <FloatMenuOption>();
                foreach (var quadrum in quadrumList)
                {
                    if (quadrum == Quadrum.Undefined)
                    {
                        continue;
                    }

                    var label = quadrum.Label();

                    var menuOption = new FloatMenuOption(label,
                                                         delegate { _quadrum = quadrum; });
                    floatMenuOptions.Add(menuOption);
                }

                var floatMenu = new FloatMenu(floatMenuOptions, "PLMWT2T_SelectQuadrum".Translate());
                Find.WindowStack.Add(floatMenu);
            }
            var quadrumLabelRect = quadrumRect.RightHalf();

            Widgets.Label(quadrumLabelRect, _quadrum.ToString());

            ListingStandard.Gap(6f);

            // year
            var yearSelector  = ListingStandard.GetRect(30f);
            var yearLabelRect = yearSelector.LeftPart(0.7f);
            var yearFieldRect = yearSelector.RightPart(0.3f);

            Widgets.Label(yearLabelRect, $"{"ClockYear".Translate()} [{GenDate.DefaultStartingYear}, {GenDate.DefaultStartingYear + 50}]: ");
            Widgets.TextFieldNumeric(yearFieldRect, ref _year, ref _yearString, GenDate.DefaultStartingYear,
                                     GenDate.DefaultStartingYear + 50);

            // translate day, quadrum and year to ticks
            _dateTicks = WorldData.DateToTicks(_dayOfQuadrum - 1, _quadrum, _year);

            // date display
            var dateNowRect       = ListingStandard.GetRect(30f);
            var labelDateLeftRect = dateNowRect.LeftPart(0.20f);

            Widgets.Label(labelDateLeftRect, $"{"ClockDate".Translate()}: ");
            var labelDateRightRect = dateNowRect.RightPart(0.60f);
            var dateString         = GenDate.DateReadoutStringAt(_dateTicks,
                                                                 Find.WorldGrid.LongLatOf(_selectedTileIdForTemperatureForecast));

            Widgets.Label(labelDateRightRect, dateString);

            Text.Anchor = backupAnchor;

            ListingStandard.GapLine(DefaultGapLineHeight);

            /*
             * Forecast
             */
            if (ListingStandard.ButtonText("PLMWT2T_ViewTemperatureForecast".Translate()))
            {
                ViewTemperatureForecast(_selectedTileIdForTemperatureForecast, _dateTicks);
            }
        }
Ejemplo n.º 8
0
        private void DrawCoastalSelection()
        {
            DrawEntryHeader("PLMWTT_CoastalTiles".Translate(), false,
                            backgroundColor: ColorFromFilterType(typeof(TileFilterCoastalTiles)));

            // coastal tiles (sea)
            var rect          = ListingStandard.GetRect(DefaultElementHeight);
            var tmpCheckState = _gameData.UserData.ChosenCoastalTileState;

            Widgets.CheckBoxLabeledMulti(rect, $"{"PLMWTT_IsCoastalTileOcean".Translate()}:", ref tmpCheckState);

            _gameData.UserData.ChosenCoastalTileState = tmpCheckState;

            ListingStandard.Gap(6f);

            /*
             * Coastal rotation
             */
            var filterCoastalRotation = _gameData.UserData.CoastalRotation.Use;

            ListingStandard.CheckboxLabeled("PLMWTT_UseCoastalRoation".Translate(), ref filterCoastalRotation,
                                            "PLMWTT_UseCoastalRoationTooltip".Translate());
            _gameData.UserData.CoastalRotation.Use = filterCoastalRotation;

            // "Select" button
            if (ListingStandard.ButtonText("PLMWTT_SelectCoastRotation".Translate()))
            {
                var floatMenuOptions = new List <FloatMenuOption>();

                // loop through all meaningful rotations
                foreach (var currentRotation in TileFilterCoastRotation.PossibleRotations)
                {
                    // clicking on the floating menu saves the selected rotation
                    void ActionClick()
                    {
                        _gameData.UserData.CoastalRotation.Selected = currentRotation.AsInt;
                    }

                    // tool-tip when hovering above the rotation name on the floating menu
                    void MouseOverAction()
                    {
                        var mousePos = Event.current.mousePosition;

                        rect = new Rect(mousePos.x, mousePos.y, DefaultElementHeight, DefaultElementHeight);

                        TooltipHandler.TipRegion(rect, ("HasCoast" + currentRotation).Translate());
                    }

                    //create the floating menu
                    var menuOption = new FloatMenuOption(currentRotation.ToStringHuman(), ActionClick, MenuOptionPriority.Default,
                                                         MouseOverAction);
                    // add it to the list of floating menu options
                    floatMenuOptions.Add(menuOption);
                }

                // create the floating menu
                var floatMenu = new FloatMenu(floatMenuOptions, "PLMWTT_SelectCoastRotation".Translate());

                // add it to the window stack to display it
                Find.WindowStack.Add(floatMenu);
            }

            var rightLabel = _gameData.UserData.CoastalRotation.Use /*&& _gameData.UserData.CoastalRotation.Selected != Rot4.Invalid*/
                ? ("HasCoast" + _gameData.UserData.CoastalRotation.Selected).Translate().CapitalizeFirst()
                : "PLMW_None".Translate();

            ListingStandard.LabelDouble($"{"PLMWTT_SelectedCoastRotation".Translate()}:", rightLabel);

            /*
             * coastal tiles (lake)
             */

            ListingStandard.Gap(6f);


            rect = ListingStandard.GetRect(DefaultElementHeight);
            TooltipHandler.TipRegion(rect, "PLMWTT_IsCoastalTileLakeTooltip".Translate());
            tmpCheckState = _gameData.UserData.ChosenCoastalLakeTileState;
            Widgets.CheckBoxLabeledMulti(rect, $"{"PLMWTT_IsCoastalTileLake".Translate()}:", ref tmpCheckState);

            _gameData.UserData.ChosenCoastalLakeTileState = tmpCheckState;
        }
Ejemplo n.º 9
0
        private void DrawSelectedTileInfo()
        {
            DrawEntryHeader("PLMWFTIL_SelectedTileInfo".Translate(), backgroundColor: Color.yellow);

            var matchingTiles = PrepareLanding.Instance.TileFilter.AllMatchingTiles;

            if (_selectedTileIndex < 0 || _selectedTileIndex >= matchingTiles.Count)
            {
                return;
            }

            ListingStandard.verticalSpacing = 0f;

            var selTileId = matchingTiles[_selectedTileIndex];
            var selTile   = Find.World.grid[selTileId];

            ListingStandard.Label(selTile.biome.description);
            ListingStandard.Gap(8f);
            ListingStandard.GapLine();
            if (!selTile.biome.implemented)
            {
                ListingStandard.Label(selTile.biome.LabelCap + " " + "BiomeNotImplemented".Translate());
            }
            ListingStandard.LabelDouble("Terrain".Translate(), selTile.hilliness.GetLabelCap());
            if (selTile.Roads != null)
            {
                ListingStandard.LabelDouble("Road".Translate(), (from roadlink in selTile.Roads
                                                                 select roadlink.road.label).Distinct().ToCommaList(true).CapitalizeFirst());
            }
            if (selTile.Rivers != null)
            {
                ListingStandard.LabelDouble("River".Translate(), selTile.Rivers.MaxBy(riverlink => riverlink.river.degradeThreshold).river.LabelCap);
            }
            if (!Find.World.Impassable(selTileId))
            {
                var        stringBuilder   = new StringBuilder();
                var        tile            = selTileId;
                const bool perceivedStatic = false;
                var        explanation     = stringBuilder;
                var        rightLabel      = (WorldPathGrid.CalculatedMovementDifficultyAt(tile, perceivedStatic, null, explanation) * Find.WorldGrid.GetRoadMovementDifficultyMultiplier(selTileId, -1, stringBuilder)).ToString("0.#");
                if (WorldPathGrid.WillWinterEverAffectMovementDifficulty(selTileId) && WorldPathGrid.GetCurrentWinterMovementDifficultyOffset(selTileId, null) < 2f)
                {
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine();
                    stringBuilder.Append(" (");
                    stringBuilder.Append("MovementDifficultyOffsetInWinter".Translate("+" + 2f.ToString("0.#")));
                    stringBuilder.Append(")");
                }
                ListingStandard.LabelDouble("MovementDifficulty".Translate(), rightLabel, stringBuilder.ToString());
            }
            if (selTile.biome.canBuildBase)
            {
                ListingStandard.LabelDouble("StoneTypesHere".Translate(), (from rt in Find.World.NaturalRockTypesIn(selTileId)
                                                                           select rt.label).ToCommaList(true).CapitalizeFirst());
            }
            ListingStandard.LabelDouble("Elevation".Translate(), selTile.elevation.ToString("F0") + "m");
            ListingStandard.GapLine();
            ListingStandard.LabelDouble("AvgTemp".Translate(), GenTemperature.GetAverageTemperatureLabel(selTileId));
            ListingStandard.LabelDouble("OutdoorGrowingPeriod".Translate(), Zone_Growing.GrowingQuadrumsDescription(selTileId));
            ListingStandard.LabelDouble("Rainfall".Translate(), selTile.rainfall.ToString("F0") + "mm");
            if (selTile.biome.foragedFood != null && selTile.biome.forageability > 0f)
            {
                ListingStandard.LabelDouble("Forageability".Translate(), selTile.biome.forageability.ToStringPercent() + " (" + selTile.biome.foragedFood.label + ")");
            }
            else
            {
                ListingStandard.LabelDouble("Forageability".Translate(), "0%");
            }
            ListingStandard.LabelDouble("AnimalsCanGrazeNow".Translate(), (!VirtualPlantsUtility.EnvironmentAllowsEatingVirtualPlantsNowAt(selTileId)) ? "No".Translate() : "Yes".Translate());
            ListingStandard.GapLine();
            ListingStandard.LabelDouble("AverageDiseaseFrequency".Translate(),
                                        $"{(60f / selTile.biome.diseaseMtbDays):F1} {"PerYear".Translate()}");
            ListingStandard.LabelDouble("TimeZone".Translate(), GenDate.TimeZoneAt(Find.WorldGrid.LongLatOf(selTileId).x).ToStringWithSign());
            var stringBuilder2 = new StringBuilder();
            var rot            = Find.World.CoastDirectionAt(selTileId);

            if (rot.IsValid)
            {
                stringBuilder2.AppendWithComma(("HasCoast" + rot).Translate());
            }
            if (Find.World.HasCaves(selTileId))
            {
                stringBuilder2.AppendWithComma("HasCaves".Translate());
            }
            if (stringBuilder2.Length > 0)
            {
                ListingStandard.LabelDouble("SpecialFeatures".Translate(), stringBuilder2.ToString().CapitalizeFirst());
            }
            if (Prefs.DevMode)
            {
                ListingStandard.LabelDouble("Debug world tile ID", selTileId.ToString());
            }
        }
Ejemplo n.º 10
0
        private void DrawFilteredTiles()
        {
            DrawEntryHeader("PLMWFTIL_FilteredTiles".Translate(), backgroundColor: Color.yellow);

            // default line height
            const float gapLineHeight = 4f;

            //check if we have something to display (tiles)
            var matchingTiles      = PrepareLanding.Instance.TileFilter.AllMatchingTiles;
            var matchingTilesCount = matchingTiles.Count;

            if (matchingTilesCount == 0)
            {
                return;
            }

            /*
             * Buttons
             */

            if (ListingStandard.ButtonText("PLMWFTIL_ClearFilteredTiles".Translate()))
            {
                // clear everything
                PrepareLanding.Instance.TileFilter.ClearMatchingTiles();

                // reset starting display index
                _tileDisplayIndexStart = 0;

                // reset selected index
                _selectedTileIndex = -1;

                // don't go further as there are no tile content to draw
                return;
            }

            var buttonsRectSpace = ListingStandard.GetRect(30f);
            var splittedRect     = buttonsRectSpace.SplitRectWidthEvenly(_minimizedWindowButtonsDescriptorList.Count);

            for (var i = 0; i < _minimizedWindowButtonsDescriptorList.Count; i++)
            {
                // get button descriptor
                var buttonDescriptor = _minimizedWindowButtonsDescriptorList[i];

                // display button; if clicked: call the related action
                if (Widgets.ButtonText(splittedRect[i], buttonDescriptor.Label))
                {
                    buttonDescriptor.Action();
                }

                // display tool-tip (if any)
                if (!string.IsNullOrEmpty(buttonDescriptor.ToolTip))
                {
                    TooltipHandler.TipRegion(splittedRect[i], buttonDescriptor.ToolTip);
                }
            }

            /*
             * Label
             */

            // number of elements (tiles) to display
            var itemsToDisplay = Math.Min(matchingTilesCount - _tileDisplayIndexStart, MaxDisplayedTileWhenMinimized);

            // label to display where we actually are in the tile list
            GenUI.SetLabelAlign(TextAnchor.MiddleCenter);
            var heightBefore = ListingStandard.StartCaptureHeight();

            ListingStandard.Label(
                $"{_tileDisplayIndexStart}: {_tileDisplayIndexStart + itemsToDisplay - 1} / {matchingTilesCount - 1}",
                DefaultElementHeight);
            GenUI.ResetLabelAlign();
            var counterLabelRect = ListingStandard.EndCaptureHeight(heightBefore);

            Core.Gui.Widgets.DrawHighlightColor(counterLabelRect, Color.cyan, 0.50f);

            // add a gap before the scroll view
            ListingStandard.Gap(gapLineHeight);

            /*
             * Calculate heights
             */

            // height of the scrollable outer Rect (visible portion of the scroll view, not the 'virtual' one)
            var maxScrollViewOuterHeight = InRect.height - ListingStandard.CurHeight - 30f;

            // height of the 'virtual' portion of the scroll view
            var scrollableViewHeight = itemsToDisplay * DefaultElementHeight + gapLineHeight * MaxDisplayedTileWhenMinimized;

            /*
             * Scroll view
             */
            var innerLs = ListingStandard.BeginScrollView(maxScrollViewOuterHeight, scrollableViewHeight,
                                                          ref _scrollPosMatchingTiles, 16f);

            var endIndex = _tileDisplayIndexStart + itemsToDisplay;

            for (var i = _tileDisplayIndexStart; i < endIndex; i++)
            {
                var selectedTileId = matchingTiles[i];
                var selectedTile   = Find.World.grid[selectedTileId];

                // get latitude & longitude for the tile
                var vector    = Find.WorldGrid.LongLatOf(selectedTileId);
                var labelText =
                    $"{i}: {vector.y.ToStringLatitude()} {vector.x.ToStringLongitude()} - {selectedTile.biome.LabelCap} ; {selectedTileId}";

                // display the label
                var labelRect = innerLs.GetRect(DefaultElementHeight);
                var selected  = i == _selectedTileIndex;
                if (Core.Gui.Widgets.LabelSelectable(labelRect, labelText, ref selected, TextAnchor.MiddleCenter))
                {
                    // go to the location of the selected tile
                    _selectedTileIndex = i;
                    Find.WorldInterface.SelectedTile = selectedTileId;
                    Find.WorldCameraDriver.JumpTo(Find.WorldGrid.GetTileCenter(Find.WorldInterface.SelectedTile));
                }
                // add a thin line between each label
                innerLs.GapLine(gapLineHeight);
            }

            ListingStandard.EndScrollView(innerLs);
        }
Ejemplo n.º 11
0
        private void DrawWorldRecord()
        {
            DrawEntryHeader("PLMWINF_WorldRecords".Translate(), backgroundColor: Color.yellow);

            if (_gameData.WorldData.WorldCharacteristics == null || _gameData.WorldData.WorldCharacteristics.Count == 0)
            {
                //Log.Error("[PrepareLanding] TabInfo.BuildWorldRecords: No Info");
                return;
            }

            // default line height
            const float gapLineHeight = 4f;

            // add a gap before the scroll view
            ListingStandard.Gap(gapLineHeight);

            /*
             * Calculate heights
             */

            // height of the scrollable outer Rect (visible portion of the scroll view, not the 'virtual' one)
            var maxScrollViewOuterHeight = InRect.height - ListingStandard.CurHeight - DefaultElementHeight;

            // height of the 'virtual' portion of the scroll view
            var numElements          = _gameData.WorldData.WorldCharacteristics.Count * 3; // 1 label + 2 elements  (highest + lowest) = 3
            var scrollableViewHeight = (numElements * DefaultElementHeight) + (_gameData.WorldData.WorldCharacteristics.Count * gapLineHeight);

            /*
             * Scroll view
             */
            var innerLs = ListingStandard.BeginScrollView(maxScrollViewOuterHeight, scrollableViewHeight,
                                                          ref _scrollPosWorldRecords, 16f);

            var selectedTileIndex = 0;

            foreach (var characteristicData in _gameData.WorldData.WorldCharacteristics)
            {
                var characteristicName = characteristicData.CharacteristicName;
                innerLs.Label(RichText.Bold(RichText.Color($"{characteristicName}:", Color.cyan)));

                // there might be no characteristics
                if (characteristicData.WorldTilesCharacteristics.Count == 0)
                {
                    innerLs.Label("No Info [DisableWorldData enabled]");
                    continue;
                }

                /*
                 *   lowest
                 */

                var lowestCharacteristicKvp = characteristicData.WorldTilesCharacteristics.First();

                // we need to follow user preference for temperature.
                var value = characteristicData.Characteristic == MostLeastCharacteristic.Temperature ?
                            GenTemperature.CelsiusTo(lowestCharacteristicKvp.Value, Prefs.TemperatureMode) : lowestCharacteristicKvp.Value;

                var vectorLongLat = Find.WorldGrid.LongLatOf(lowestCharacteristicKvp.Key);
                var textLowest    = $"{"PLMWINF_WorldLowest".Translate()} {characteristicName}: {value:F1} {characteristicData.CharacteristicMeasureUnit} [{lowestCharacteristicKvp.Key}; {vectorLongLat.y.ToStringLatitude()} - {vectorLongLat.x.ToStringLongitude()}]";

                var labelRect = innerLs.GetRect(DefaultElementHeight);
                var selected  = selectedTileIndex == _worldRecordSelectedTileIndex;
                if (Core.Gui.Widgets.LabelSelectable(labelRect, textLowest, ref selected, TextAnchor.MiddleLeft))
                {
                    // go to the location of the selected tile
                    _worldRecordSelectedTileIndex    = selectedTileIndex;
                    Find.WorldInterface.SelectedTile = lowestCharacteristicKvp.Key;
                    Find.WorldCameraDriver.JumpTo(Find.WorldGrid.GetTileCenter(Find.WorldInterface.SelectedTile));
                }

                selectedTileIndex++;

                /*
                 *   highest
                 */

                var highestCharacteristicKvp = characteristicData.WorldTilesCharacteristics.Last();
                // we need to follow user preference for temperature.
                value = characteristicData.Characteristic == MostLeastCharacteristic.Temperature ?
                        GenTemperature.CelsiusTo(highestCharacteristicKvp.Value, Prefs.TemperatureMode) : highestCharacteristicKvp.Value;

                vectorLongLat = Find.WorldGrid.LongLatOf(highestCharacteristicKvp.Key);
                var textHighest = $"{"PLMWINF_WorldHighest".Translate()} {characteristicName}: {value:F1} {characteristicData.CharacteristicMeasureUnit} [{highestCharacteristicKvp.Key}; {vectorLongLat.y.ToStringLatitude()} - {vectorLongLat.x.ToStringLongitude()}]";

                labelRect = innerLs.GetRect(DefaultElementHeight);
                selected  = selectedTileIndex == _worldRecordSelectedTileIndex;
                if (Core.Gui.Widgets.LabelSelectable(labelRect, textHighest, ref selected, TextAnchor.MiddleLeft))
                {
                    // go to the location of the selected tile
                    _worldRecordSelectedTileIndex    = selectedTileIndex;
                    Find.WorldInterface.SelectedTile = highestCharacteristicKvp.Key;
                    Find.WorldCameraDriver.JumpTo(Find.WorldGrid.GetTileCenter(Find.WorldInterface.SelectedTile));
                }

                selectedTileIndex++;

                // add a thin line between each label
                innerLs.GapLine(gapLineHeight);
            }

            ListingStandard.EndScrollView(innerLs);
        }
Ejemplo n.º 12
0
        protected void DrawLoadPresetList(Rect inRect)
        {
            DrawEntryHeader("Preset Files: Load mode", backgroundColor: Color.green);

            var presetFiles = _userData.PresetManager.AllPresetFiles;

            if (presetFiles == null)
            {
                Log.ErrorOnce("[PrepareLanding] PresetManager.AllPresetFiles is null.", 0x1238cafe);
                return;
            }

            var presetFilesCount = presetFiles.Count;

            if (presetFiles.Count == 0)
            {
                ListingStandard.Label("No existing presets.");
                return;
            }

            // add a gap before the scroll view
            ListingStandard.Gap(DefaultGapLineHeight);

            /*
             * Buttons
             */

            var buttonsRectSpace = ListingStandard.GetRect(30f);
            var splittedRect     = buttonsRectSpace.SplitRectWidthEvenly(_buttonList.Count);

            for (var i = 0; i < _buttonList.Count; i++)
            {
                // get button descriptor
                var buttonDescriptor = _buttonList[i];

                // display button; if clicked: call the related action
                if (Widgets.ButtonText(splittedRect[i], buttonDescriptor.Label))
                {
                    buttonDescriptor.Action();
                }

                // display tool-tip (if any)
                if (!string.IsNullOrEmpty(buttonDescriptor.ToolTip))
                {
                    TooltipHandler.TipRegion(splittedRect[i], buttonDescriptor.ToolTip);
                }
            }

            /*
             * Label
             */

            // number of elements (tiles) to display
            var itemsToDisplay = Math.Min(presetFilesCount - _listDisplayStartIndex, MaxItemsToDisplay);

            // label to display where we actually are in the tile list
            GenUI.SetLabelAlign(TextAnchor.MiddleCenter);
            var heightBefore = ListingStandard.StartCaptureHeight();

            ListingStandard.Label(
                $"{_listDisplayStartIndex}: {_listDisplayStartIndex + itemsToDisplay - 1} / {presetFilesCount - 1}",
                DefaultElementHeight);
            GenUI.ResetLabelAlign();
            var counterLabelRect = ListingStandard.EndCaptureHeight(heightBefore);

            Core.Gui.Widgets.DrawHighlightColor(counterLabelRect, Color.cyan, 0.50f);

            // add a gap before the scroll view
            ListingStandard.Gap(DefaultGapLineHeight);

            /*
             * Calculate heights
             */

            // height of the scrollable outer Rect (visible portion of the scroll view, not the 'virtual' one)
            var maxScrollViewOuterHeight = InRect.height - ListingStandard.CurHeight - 30f;

            // height of the 'virtual' portion of the scroll view
            var scrollableViewHeight = itemsToDisplay * DefaultElementHeight + DefaultGapLineHeight * MaxItemsToDisplay;

            /*
             * Scroll view
             */
            var innerLs = ListingStandard.BeginScrollView(maxScrollViewOuterHeight, scrollableViewHeight,
                                                          ref _scrollPosPresetFiles, 16f);

            var endIndex = _listDisplayStartIndex + itemsToDisplay;

            for (var i = _listDisplayStartIndex; i < endIndex; i++)
            {
                var selectedPresetFile = presetFiles[i];
                var labelText          = Path.GetFileNameWithoutExtension(selectedPresetFile.Name);

                // display the label
                var labelRect = innerLs.GetRect(DefaultElementHeight);
                var selected  = i == _selectedItemIndex;
                if (Core.Gui.Widgets.LabelSelectable(labelRect, labelText, ref selected, TextAnchor.MiddleCenter))
                {
                    // save item index
                    _selectedItemIndex = i;
                    _selectedFileName  = labelText;
                }
                // add a thin line between each label
                innerLs.GapLine(DefaultGapLineHeight);
            }

            ListingStandard.EndScrollView(innerLs);
        }
Ejemplo n.º 13
0
        protected void DrawSelectedTileInfo()
        {
            DrawEntryHeader("Selected Tile Info", backgroundColor: Color.yellow);

            var matchingTiles = PrepareLanding.Instance.TileFilter.AllMatchingTiles;

            if (_selectedTileIndex < 0 || _selectedTileIndex >= matchingTiles.Count)
            {
                return;
            }

            ListingStandard.verticalSpacing = 0f;

            var selTileId = matchingTiles[_selectedTileIndex];
            var selTile   = Find.World.grid[selTileId];

            ListingStandard.Label(selTile.biome.LabelCap);
            var y = Find.WorldGrid.LongLatOf(selTileId).y;

            ListingStandard.Label(selTile.biome.description);
            ListingStandard.Gap(8f);
            ListingStandard.GapLine();
            if (!selTile.biome.implemented)
            {
                ListingStandard.Label(selTile.biome.LabelCap + " " + "BiomeNotImplemented".Translate());
            }
            ListingStandard.LabelDouble("Terrain".Translate(), selTile.hilliness.GetLabelCap());
            if (selTile.VisibleRoads != null)
            {
                ListingStandard.LabelDouble("Road".Translate(), GenText.ToCommaList((from roadlink in selTile.VisibleRoads
                                                                                     select roadlink.road.label).Distinct()).CapitalizeFirst());
            }
            if (selTile.VisibleRivers != null)
            {
                ListingStandard.LabelDouble("River".Translate(), selTile.VisibleRivers.MaxBy((riverlink) => riverlink.river.degradeThreshold).river.LabelCap);
            }
            if (!Find.World.Impassable(selTileId))
            {
                const int num      = 2500;
                var       numTicks = Mathf.Min(num + WorldPathGrid.CalculatedCostAt(selTileId, false), 120000);
                ListingStandard.LabelDouble("MovementTimeNow".Translate(), numTicks.ToStringTicksToPeriod());
                var numTicks2 = Mathf.Min(num + WorldPathGrid.CalculatedCostAt(selTileId, false, Season.Summer.GetMiddleYearPct(y)), 120000);
                ListingStandard.LabelDouble("MovementTimeSummer".Translate(), numTicks2.ToStringTicksToPeriod());
                var numTicks3 = Mathf.Min(num + WorldPathGrid.CalculatedCostAt(selTileId, false, Season.Winter.GetMiddleYearPct(y)), 120000);
                ListingStandard.LabelDouble("MovementTimeWinter".Translate(), numTicks3.ToStringTicksToPeriod());
            }
            if (selTile.biome.canBuildBase)
            {
                ListingStandard.LabelDouble("StoneTypesHere".Translate(), GenText.ToCommaList(from rt in Find.World.NaturalRockTypesIn(selTileId)
                                                                                              select rt.label).CapitalizeFirst());
            }
            ListingStandard.LabelDouble("Elevation".Translate(), selTile.elevation.ToString("F0") + "m");
            ListingStandard.GapLine();
            ListingStandard.LabelDouble("AvgTemp".Translate(), selTile.temperature.ToStringTemperature());
            var celsiusTemp = GenTemperature.AverageTemperatureAtTileForTwelfth(selTileId, Season.Winter.GetMiddleTwelfth(y));

            ListingStandard.LabelDouble("AvgWinterTemp".Translate(), celsiusTemp.ToStringTemperature());
            var celsiusTemp2 = GenTemperature.AverageTemperatureAtTileForTwelfth(selTileId, Season.Summer.GetMiddleTwelfth(y));

            ListingStandard.LabelDouble("AvgSummerTemp".Translate(), celsiusTemp2.ToStringTemperature());
            ListingStandard.LabelDouble("OutdoorGrowingPeriod".Translate(), Zone_Growing.GrowingQuadrumsDescription(selTileId));
            ListingStandard.LabelDouble("Rainfall".Translate(), selTile.rainfall.ToString("F0") + "mm");
            ListingStandard.LabelDouble("AnimalsCanGrazeNow".Translate(), (!VirtualPlantsUtility.EnvironmentAllowsEatingVirtualPlantsNowAt(selTileId)) ? "No".Translate() : "Yes".Translate());
            ListingStandard.GapLine();
            ListingStandard.LabelDouble("TimeZone".Translate(), GenDate.TimeZoneAt(Find.WorldGrid.LongLatOf(selTileId).x).ToStringWithSign());
            var rot = Find.World.CoastDirectionAt(selTileId);

            if (rot.IsValid)
            {
                ListingStandard.LabelDouble(string.Empty, ("HasCoast" + rot).Translate());
            }
            if (Prefs.DevMode)
            {
                ListingStandard.LabelDouble("Debug world tile ID", selTileId.ToString());
            }
        }
Ejemplo n.º 14
0
        protected void DrawUsableMinMaxFromRestrictedListItem <T>(MinMaxFromRestrictedListItem <T> item, string label, Func <T, string> itemToStringFunc = null)
            where T : struct, IConvertible
        {
            var tmpCheckedOn = item.Use;

            var textMin = "PLINT_UsableMinMaxNumFieldMin".Translate();
            var textMax = "PLINT_UsableMinMaxNumFieldMax".Translate();

            // Use
            ListingStandard.Gap();
            ListingStandard.CheckboxLabeled(label, ref tmpCheckedOn, $"{"PLINT_UsableMinMaxNumFieldUse".Translate()} {textMin}/{textMax} {label}");
            item.Use = tmpCheckedOn;

            // MIN
            if (ListingStandard.ButtonText($"{"PLINT_UsableMinMaxNumFieldMin".Translate()} {label}"))
            {
                var floatMenuOptions = new List <FloatMenuOption>();
                foreach (var itemOption in item.Options)
                {
                    var menuOptionString = itemToStringFunc == null
                        ? itemOption.ToString(CultureInfo.InvariantCulture)
                        : itemToStringFunc(itemOption);

                    var menuOption = new FloatMenuOption(menuOptionString, delegate { item.Min = itemOption; });
                    floatMenuOptions.Add(menuOption);
                }

                var floatMenu = new FloatMenu(floatMenuOptions, $"{"PLINT_MinMaxFromRestrictedListItemSelect".Translate()} {label}");
                Find.WindowStack.Add(floatMenu);
            }

            var minValueString = itemToStringFunc == null
                ? item.Min.ToString(CultureInfo.InvariantCulture)
                : itemToStringFunc(item.Min);

            ListingStandard.LabelDouble($"{"PLINT_UsableMinMaxNumFieldMin".Translate()} {label}:", minValueString);

            // MAX
            if (ListingStandard.ButtonText($"{"PLINT_UsableMinMaxNumFieldMax".Translate()} {label}"))
            {
                var floatMenuOptions = new List <FloatMenuOption>();
                foreach (var itemOption in item.Options)
                {
                    var menuOptionString = itemToStringFunc == null
                        ? itemOption.ToString(CultureInfo.InvariantCulture)
                        : itemToStringFunc(itemOption);

                    var menuOption = new FloatMenuOption(menuOptionString, delegate { item.Max = itemOption; });
                    floatMenuOptions.Add(menuOption);
                }

                var floatMenu = new FloatMenu(floatMenuOptions, $"{"PLINT_MinMaxFromRestrictedListItemSelect".Translate()} {label}");
                Find.WindowStack.Add(floatMenu);
            }

            var maxValueString = itemToStringFunc == null
                ? item.Min.ToString(CultureInfo.InvariantCulture)
                : itemToStringFunc(item.Max);

            ListingStandard.LabelDouble($"{"PLINT_UsableMinMaxNumFieldMax".Translate()} {label}:", maxValueString);
        }