示例#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);
        }
        protected void DrawLoadPresetInfo(Rect inRect)
        {
            DrawEntryHeader("Preset Info:", backgroundColor: Color.green);

            if (_selectedItemIndex < 0)
            {
                return;
            }

            ListingStandard.TextEntryLabeled2("Preset Name:", _selectedFileName);

            var preset = _userData.PresetManager.PresetByPresetName(_selectedFileName);

            if (preset == null)
            {
                return;
            }

            ListingStandard.TextEntryLabeled2("Author:", preset.PresetInfo.Author);

            ListingStandard.Label("Description:");
            var descriptionRect = ListingStandard.GetRect(80f);

            Widgets.TextAreaScrollable(descriptionRect, preset.PresetInfo.Description,
                                       ref _scrollPosPresetLoadDescription);

            ListingStandard.Label("Filters:");
            const float maxOuterRectHeight = 130f;

            ListingStandard.ScrollableTextArea(maxOuterRectHeight, preset.PresetInfo.FilterInfo,
                                               ref _scrollPosPresetFilterInfo, _stylePresetInfo, DefaultScrollableViewShrinkWidth);

            ListingStandard.Label("Options:");
            ListingStandard.ScrollableTextArea(maxOuterRectHeight, preset.PresetInfo.OptionInfo,
                                               ref _scrollPosPresetOptionInfo, _stylePresetInfo, DefaultScrollableViewShrinkWidth);
        }
示例#3
0
        private void DrawMostLeastCharacteristicSelection()
        {
            DrawEntryHeader("PLMWT2T_MostLeastCharacteristics".Translate(),
                            backgroundColor: ColorFromFilterType(typeof(TileFilterMostLeastCharacteristic)));

            /*
             * Select Characteristic
             */
            var selectCharacteristic = "PLMWT2T_MostLeastSelectCharacteristic".Translate();

            if (ListingStandard.ButtonText(selectCharacteristic))
            {
                var floatMenuOptions = new List <FloatMenuOption>();
                foreach (var characteristic in Enum.GetValues(typeof(MostLeastCharacteristic)).Cast <MostLeastCharacteristic>())
                {
                    var menuOption = new FloatMenuOption(characteristic.ToString(),
                                                         delegate { _gameData.UserData.MostLeastItem.Characteristic = characteristic; });
                    floatMenuOptions.Add(menuOption);
                }

                var floatMenu = new FloatMenu(floatMenuOptions, selectCharacteristic);
                Find.WindowStack.Add(floatMenu);
            }

            /*
             * Number of tiles to select.
             */
            ListingStandard.GapLine(DefaultGapLineHeight);

            var tilesNumberRect = ListingStandard.GetRect(DefaultElementHeight);
            var leftRect        = tilesNumberRect.LeftPart(0.80f);
            var rightRect       = tilesNumberRect.RightPart(0.20f);

            Widgets.Label(leftRect, $"{"PLMWT2T_MostLeastNumberOfTiles".Translate()} [1, 10000]:");
            _numberOfTilesForCharacteristic = _gameData.UserData.MostLeastItem.NumberOfItems;
            Widgets.TextFieldNumeric(rightRect, ref _numberOfTilesForCharacteristic, ref _numberOfTilesForCharacteristicString,
                                     1, 10000);
            _gameData.UserData.MostLeastItem.NumberOfItems = _numberOfTilesForCharacteristic;

            /*
             * Select Characteristic Type (most / least)
             */

            var selectCharacteristicType = "PLMWT2T_MostLeastSelectCharacteristicType".Translate();

            if (ListingStandard.ButtonText(selectCharacteristicType))
            {
                var floatMenuOptions = new List <FloatMenuOption>();
                foreach (var characteristicType in Enum.GetValues(typeof(MostLeastType)).Cast <MostLeastType>())
                {
                    var menuOption = new FloatMenuOption(characteristicType.ToString(),
                                                         delegate { _gameData.UserData.MostLeastItem.CharacteristicType = characteristicType; });
                    floatMenuOptions.Add(menuOption);
                }

                var floatMenu = new FloatMenu(floatMenuOptions, selectCharacteristicType);
                Find.WindowStack.Add(floatMenu);
            }

            /*
             * Result label
             */
            string text;

            if (_gameData.UserData.MostLeastItem.Characteristic == MostLeastCharacteristic.None)
            {
                text = string.Format("PLMWT2T_MostLeastPressButtonFirst".Translate(), selectCharacteristic);
            }
            else if (_gameData.UserData.MostLeastItem.CharacteristicType == MostLeastType.None)
            {
                text = string.Format("PLMWT2T_MostLeastNowUseButton".Translate(), selectCharacteristicType);
            }
            else
            {
                var highestLowest = _gameData.UserData.MostLeastItem.CharacteristicType == MostLeastType.Most
                    ? "PLMWT2T_MostLeastHighest".Translate()
                    : "PLMWT2T_MostLeastLowest".Translate();
                var tileString = _gameData.UserData.MostLeastItem.NumberOfItems > 1 ? "PLMW_Tiles".Translate() : "PLMW_Tile".Translate();
                text = string.Format("PLMWT2T_MostLeastSelectingTiles".Translate(),
                                     _gameData.UserData.MostLeastItem.NumberOfItems, tileString, highestLowest,
                                     _gameData.UserData.MostLeastItem.Characteristic);
            }

            ListingStandard.Label($"{"PLMWT2T_MostLeastResult".Translate()}: {text}", DefaultElementHeight * 2);
        }
示例#4
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());
            }
        }
示例#5
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);
        }
        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);
        }
示例#7
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());
            }
        }