Example #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);
        }
Example #2
0
        private void DrawOverLaySelection()
        {
            DrawEntryHeader("Overlay Selection", backgroundColor: ColorLibrary.BurntOrange);

            var boxRect = ListingStandard.GetRect(DefaultElementHeight);

            // draw the map colors
            GUI.DrawTexture(boxRect, _gameData.WorldData.TemperatureData.TemperatureGradientTexure);

            ListingStandard.GapLine(DefaultGapLineHeight);

            var buttonsRect            = ListingStandard.GetRect(DefaultElementHeight);
            var drawOverlayButtonRect  = buttonsRect.LeftHalf();
            var clearOverlayButtonRect = buttonsRect.RightHalf();

            if (Widgets.ButtonText(drawOverlayButtonRect, "Draw Overlay"))
            {
                _gameData.WorldData.TemperatureData.AllowDrawOverlay = true;
            }

            if (Widgets.ButtonText(clearOverlayButtonRect, "Clear Overlay"))
            {
                _gameData.WorldData.TemperatureData.AllowDrawOverlay = false;
            }

#if DEBUG
            if (ListingStandard.ButtonText("DebugLog"))
            {
                _gameData.WorldData.TemperatureData.DebugLog();
            }
#endif
        }
Example #3
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;
        }
        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;
        }
Example #5
0
        private void DrawTileSelection()
        {
            DrawEntryHeader("Tile Setup", backgroundColor: ColorLibrary.RoyalPurple);

            var tileId = Find.WorldSelector.selectedTile;

            if (!Find.WorldSelector.AnyObjectOrTileSelected || tileId < 0)
            {
                var labelRect = ListingStandard.GetRect(DefaultElementHeight);
                Widgets.Label(labelRect, "Pick a tile on world map!");
                _gameData.GodModeData.SelectedTileId = -1;
                return;
            }

            ListingStandard.LabelDouble("Selected Tile: ", tileId.ToString());

            if (_gameData.GodModeData.SelectedTileId != tileId)
            {
                _gameData.GodModeData.InitFromTileId(tileId);
            }

            if (ListingStandard.ButtonText("Set Tile"))
            {
                if (Find.WorldObjects.AnySettlementBaseAtOrAdjacent(tileId))
                {
                    Messages.Message("You're not allowed to settle on or near another settlement tile.", MessageTypeDefOf.RejectInput);
                    _gameData.GodModeData.SelectedTileId = -1;
                    return;
                }

                PrepareLanding.Instance.TileFilter.ClearMatchingTiles();

                //TODO: you need to clear the temperature cache for the tile, otherwise it's wrong after being changed...
                // see RimWorld.Planet.TileTemperaturesComp.RetrieveCachedData for the cache itself. It's private...
                // but could be cleaned with RimWorld.Planet.TileTemperaturesComp.ClearCaches() but that would invalidate *all* caches...

                _redrawMapEnabled = _gameData.GodModeData.SetupTile();
            }

            var heightBefore = ListingStandard.StartCaptureHeight();

            if (ListingStandard.ButtonText("Redraw Map"))
            {
                if (_redrawMapEnabled)
                {
                    LongEventHandler.QueueLongEvent(delegate { Find.World.renderer.SetAllLayersDirty(); },
                                                    "GeneratingWorld", true, null);
                }
                else
                {
                    Messages.Message("You need to change a tile first to be able to redraw the map.",
                                     MessageTypeDefOf.RejectInput);
                }
            }
            var tooltipRect = ListingStandard.EndCaptureHeight(heightBefore);

            TooltipHandler.TipRegion(tooltipRect,
                                     "[Warning: this redraws the map entirely; use it only when you have finished *all* your modifications.]");
        }
        protected virtual void DrawAnimalsCanGrazeNowSelection()
        {
            DrawEntryHeader("Animals", backgroundColor: ColorFromFilterSubjectThingDef("Animals Can Graze Now"));

            var rect          = ListingStandard.GetRect(DefaultElementHeight);
            var tmpCheckState = _userData.ChosenAnimalsCanGrazeNowState;

            Widgets.CheckBoxLabeledMulti(rect, "Animals Can Graze Now:", ref tmpCheckState);

            _userData.ChosenAnimalsCanGrazeNowState = tmpCheckState;
        }
        protected virtual void DrawCoastalSelection()
        {
            DrawEntryHeader("Coastal Tile", false, backgroundColor: ColorFromFilterSubjectThingDef("Coastal Tiles"));

            var rect          = ListingStandard.GetRect(DefaultElementHeight);
            var tmpCheckState = _userData.ChosenCoastalTileState;

            Widgets.CheckBoxLabeledMulti(rect, "Is Coastal Tile:", ref tmpCheckState);

            _userData.ChosenCoastalTileState = tmpCheckState;
        }
Example #8
0
        private void DrawAnimalsCanGrazeNowSelection()
        {
            DrawEntryHeader($"{"WorkTagAnimals".Translate().CapitalizeFirst()}",
                            backgroundColor: ColorFromFilterType(typeof(TileFilterAnimalsCanGrazeNow)));

            var rect          = ListingStandard.GetRect(DefaultElementHeight);
            var tmpCheckState = _gameData.UserData.ChosenAnimalsCanGrazeNowState;

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

            _gameData.UserData.ChosenAnimalsCanGrazeNowState = tmpCheckState;
        }
Example #9
0
        /// <summary>
        ///     Draw the "Has Cave" selection.
        /// </summary>
        private void DrawCaveSelection()
        {
            DrawEntryHeader("SpecialFeatures".Translate(),
                            backgroundColor: ColorFromFilterType(typeof(TileFilterHasCave)));

            var rect          = ListingStandard.GetRect(DefaultElementHeight);
            var tmpCheckState = _gameData.UserData.HasCaveState;

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

            _gameData.UserData.HasCaveState = tmpCheckState;
        }
        protected void DrawSaveFileName(Rect inRect)
        {
            DrawEntryHeader("Preset Files: Save mode", backgroundColor: Color.red);

            var fileNameRect = ListingStandard.GetRect(DefaultElementHeight);

            var fileNameLabelRect = fileNameRect.LeftPart(0.2f);

            Widgets.Label(fileNameLabelRect, "FileName:");

            var fileNameTextRect = fileNameRect.RightPart(0.8f);

            if (string.IsNullOrEmpty(_selectedFileName))
            {
                _selectedFileName = _userData.PresetManager.NextPresetFileName;
            }

            _selectedFileName = Widgets.TextField(fileNameTextRect, _selectedFileName);

            ListingStandard.GapLine(DefaultGapLineHeight);

            ListingStandard.CheckboxLabeled("Save Options", ref _saveOptions,
                                            "Check to also save options alongside filters.");

            ListingStandard.GapLine(DefaultGapLineHeight);

            DrawEntryHeader($"Author: [optional; {MaxAuthorNameLength} chars max]");

            _presetAuthorSave = ListingStandard.TextEntry(_presetAuthorSave);
            if (_presetAuthorSave.Length >= MaxAuthorNameLength)
            {
                _presetAuthorSave = _presetAuthorSave.Substring(0, MaxAuthorNameLength);
            }

            ListingStandard.GapLine(DefaultGapLineHeight);

            DrawEntryHeader($"Description: [optional; {MaxDescriptionLength} chars max]");

            var descriptionRect = ListingStandard.GetRect(80f);

            _presetDescriptionSave = Widgets.TextAreaScrollable(descriptionRect, _presetDescriptionSave,
                                                                ref _scrollPosPresetDescription);
            if (_presetDescriptionSave.Length >= MaxDescriptionLength)
            {
                _presetDescriptionSave = _presetDescriptionSave.Substring(0, MaxDescriptionLength);
            }
        }
Example #11
0
        private void DrawTemperatureSelection()
        {
            DrawEntryHeader("Temperature", backgroundColor: ColorLibrary.RoyalPurple);

            var averageTemperature = _gameData.GodModeData.AverageTemperature;

            _chosenAverageTemperatureString = averageTemperature.ToString("F1", CultureInfo.InvariantCulture);

            var temperatureRectSpace = ListingStandard.GetRect(DefaultElementHeight);

            Widgets.Label(temperatureRectSpace.LeftPart(0.8f),
                          $"Avg. Temp. (°C) [{TemperatureTuning.MinimumTemperature}, {TemperatureTuning.MaximumTemperature}]");
            Widgets.TextFieldNumeric(temperatureRectSpace.RightPart(0.2f), ref averageTemperature,
                                     ref _chosenAverageTemperatureString, TemperatureTuning.MinimumTemperature,
                                     TemperatureTuning.MaximumTemperature);

            _gameData.GodModeData.AverageTemperature = averageTemperature;
        }
Example #12
0
        private void DrawRainfallSelection()
        {
            DrawEntryHeader("Rainfall", backgroundColor: ColorLibrary.RoyalPurple);

            // min is obviously 0; max is defined in RimWorld.Planet.WorldGenStep_Terrain.RainfallFinishFallAltitude
            const float minRainfall = 0f;
            const float maxRainfall = 7000f;

            var rainFall = _gameData.GodModeData.Rainfall;

            _chosenRainfallString = rainFall.ToString("F1", CultureInfo.InvariantCulture);

            var rainfallRectSpace = ListingStandard.GetRect(DefaultElementHeight);

            Widgets.Label(rainfallRectSpace.LeftPart(0.8f), $"Rainfall (mm) [{minRainfall}, {maxRainfall}]");
            Widgets.TextFieldNumeric(rainfallRectSpace.RightPart(0.2f), ref rainFall,
                                     ref _chosenRainfallString, minRainfall, maxRainfall);

            _gameData.GodModeData.Rainfall = rainFall;
        }
Example #13
0
        private void DrawElevationSelection()
        {
            DrawEntryHeader("Elevation", backgroundColor: ColorLibrary.RoyalPurple);

            // see RimWorld.Planet.WorldGenStep_Terrain.ElevationRange for min / max
            // max is also defined in RimWorld.Planet.WorldMaterials.ElevationMax
            const float minElevation = -500f;
            const float maxElevation = 5000f;

            var elevation = _gameData.GodModeData.Elevation;

            _chosenElevationString = elevation.ToString("F1", CultureInfo.InvariantCulture);

            var elevationRectSpace = ListingStandard.GetRect(DefaultElementHeight);

            Widgets.Label(elevationRectSpace.LeftPart(0.8f), $"Elevation (m) [{minElevation}, {maxElevation}]");
            Widgets.TextFieldNumeric(elevationRectSpace.RightPart(0.2f), ref elevation,
                                     ref _chosenElevationString, minElevation, maxElevation);

            _gameData.GodModeData.Elevation = elevation;
        }
Example #14
0
        private void DrawTemperatureSelection()
        {
            DrawEntryHeader("Temperature", backgroundColor: ColorLibrary.RoyalPurple);

            // min and max possible temperatures, in C/F/K (depending on user preferences).
            // note that TemperatureTuning temps are in Celsius.
            var tempMinUnit = GenTemperature.CelsiusTo(TemperatureTuning.MinimumTemperature, Prefs.TemperatureMode);
            var tempMaxUnit = GenTemperature.CelsiusTo(TemperatureTuning.MaximumTemperature, Prefs.TemperatureMode);

            var averageTemperature = _gameData.GodModeData.AverageTemperature;

            _chosenAverageTemperatureString = averageTemperature.ToString("F1", CultureInfo.InvariantCulture);

            var temperatureRectSpace = ListingStandard.GetRect(DefaultElementHeight * 1.25f);

            Widgets.Label(temperatureRectSpace.LeftPart(0.8f),
                          $"{"AvgTemp".Translate()} (°{Prefs.TemperatureMode.ToStringHuman()})\n[{tempMinUnit}, {tempMaxUnit}]");
            Widgets.TextFieldNumeric(temperatureRectSpace.RightPart(0.2f), ref averageTemperature,
                                     ref _chosenAverageTemperatureString, tempMinUnit, tempMaxUnit);

            _gameData.GodModeData.AverageTemperature = averageTemperature;
        }
        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);
        }
Example #16
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;
        }
Example #17
0
        private void DrawBiomeTypesSelection() // TODO : factorize this function with the one from TabTerrain
        {
            DrawEntryHeader("Biome Types", backgroundColor: ColorLibrary.RoyalPurple);

            var biomeDefs = _gameData.DefData.BiomeDefs;

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

                // add a dummy 'Any' fake biome type. This sets the chosen biome to null.
                Action actionClick = delegate { _gameData.GodModeData.Biome = null; };
                // tool-tip when hovering above the 'Any' biome name on the floating menu
                Action mouseOverAction = delegate
                {
                    var mousePos = Event.current.mousePosition;
                    var rect     = new Rect(mousePos.x, mousePos.y, DefaultElementHeight, DefaultElementHeight);

                    TooltipHandler.TipRegion(rect, "Any Biome");
                };
                var menuOption = new FloatMenuOption("Any", actionClick, MenuOptionPriority.Default, mouseOverAction);
                floatMenuOptions.Add(menuOption);

                // loop through all known biomes
                foreach (var currentBiomeDef in biomeDefs)
                {
                    // clicking on the floating menu saves the selected biome
                    actionClick = delegate { _gameData.GodModeData.Biome = currentBiomeDef; };
                    // tool-tip when hovering above the biome name on the floating menu
                    mouseOverAction = delegate
                    {
                        var mousePos = Event.current.mousePosition;
                        var rect     = new Rect(mousePos.x, mousePos.y, DefaultElementHeight, DefaultElementHeight);

                        TooltipHandler.TipRegion(rect, currentBiomeDef.description);
                    };

                    //create the floating menu
                    menuOption = new FloatMenuOption(currentBiomeDef.LabelCap, 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, "Select Biome Type");

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

            var currHeightBefore = ListingStandard.CurHeight;

            var rightLabel = _gameData.GodModeData.Biome != null ? _gameData.GodModeData.Biome.LabelCap : "Any";

            ListingStandard.LabelDouble("Biome:", rightLabel);

            var currHeightAfter = ListingStandard.CurHeight;

            // display tool-tip over label
            if (_gameData.GodModeData.Biome != null)
            {
                var currentRect = ListingStandard.GetRect(0f);
                currentRect.height = currHeightAfter - currHeightBefore;
                if (!string.IsNullOrEmpty(_gameData.GodModeData.Biome.description))
                {
                    TooltipHandler.TipRegion(currentRect, _gameData.GodModeData.Biome.description);
                }
            }
        }
        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);
        }
Example #19
0
        private void DrawFeatureSelection()
        {
            DrawEntryHeader("PLMWT2T_WorldFeatureSelection".Translate(),
                            backgroundColor: ColorFromFilterType(typeof(TileFilterWorldFeature)));

            var features = _gameData.WorldData.WorldFeatures;

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

                // add a dummy 'Any' fake feature type. This sets the chosen feature to null.
                Action actionClick = delegate { _gameData.UserData.WorldFeature = null; };
                // tool-tip when hovering above the 'Any' feature name on the floating menu
                void MouseOverAction()
                {
                    var mousePos = Event.current.mousePosition;
                    var rect     = new Rect(mousePos.x, mousePos.y, DefaultElementHeight, DefaultElementHeight);

                    TooltipHandler.TipRegion(rect, "PLMWT2T_AnyWorldFeature".Translate());
                }

                var menuOption = new FloatMenuOption("PLMW_SelectAny".Translate(), actionClick, MenuOptionPriority.Default, MouseOverAction);
                floatMenuOptions.Add(menuOption);

                // loop through all known feature
                foreach (var currentFeature in features)
                {
                    // do not allow ocean and lakes
                    if (currentFeature.def.rootBiomes.Count != 0)
                    {
                        if (currentFeature.def.rootBiomes.Contains(BiomeDefOf.Ocean) ||
                            currentFeature.def.rootBiomes.Contains(BiomeDefOf.Lake))
                        {
                            continue;
                        }
                    }
                    // TODO: handle other water bodies, you'll need to parse the def name as there are no other ways
                    // see \Mods\Core\Defs\Misc\FeatureDefs\Features.xml
                    // or another solution would be to patch the definition (e.g. OuterOcean) to have a root biome as "Ocean" (or lake or whatever water body).
                    //if(currentFeature.def.defName contains "Ocean")

                    // clicking on the floating menu saves the selected feature
                    actionClick = delegate { _gameData.UserData.WorldFeature = currentFeature; };

                    //create the floating menu
                    menuOption = new FloatMenuOption(currentFeature.name, actionClick);
                    // add it to the list of floating menu options
                    floatMenuOptions.Add(menuOption);
                }

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

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

            var currHeightBefore = ListingStandard.CurHeight;

            var rightLabel = _gameData.UserData.WorldFeature != null ? _gameData.UserData.WorldFeature.name : (string)"PLMW_SelectAny".Translate();

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

            var currHeightAfter = ListingStandard.CurHeight;

            // display tool-tip over label
            if (_gameData.UserData.WorldFeature != null)
            {
                var currentRect = ListingStandard.GetRect(0f);
                currentRect.height = currHeightAfter - currHeightBefore;
                if (!string.IsNullOrEmpty(_gameData.UserData.WorldFeature.name))
                {
                    TooltipHandler.TipRegion(currentRect, _gameData.UserData.WorldFeature.name);
                }
            }
        }
Example #20
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);
        }
        protected virtual void DrawStoneTypesSelection()
        {
            DrawEntryHeader("StoneTypesHere".Translate(), backgroundColor: ColorFromFilterSubjectThingDef("Stones"));

            var selectedStoneDefs = _userData.SelectedStoneDefs;
            var orderedStoneDefs  = _userData.OrderedStoneDefs;

            // Reset button: reset all entries to Off state
            if (ListingStandard.ButtonText("Reset All"))
            {
                foreach (var stoneDefEntry in selectedStoneDefs)
                {
                    stoneDefEntry.Value.State = stoneDefEntry.Value.DefaultState;
                }

                _userData.StoneTypesNumberOnly = false;
            }

            // re-orderable list group
            var reorderableGroup = ReorderableWidget.NewGroup(delegate(int from, int to)
            {
                //TODO find a way to raise an event to tell an observer that the list order has changed
                ReorderElements(from, to, orderedStoneDefs);
                SoundDefOf.TickHigh.PlayOneShotOnCamera();
            });

            var maxNumStones = (InRect.height - ListingStandard.CurHeight - DefaultGapLineHeight - DefaultElementHeight - 15f) / DefaultElementHeight;
            var maxHeight    = maxNumStones * DefaultElementHeight;
            var height       = Mathf.Min(selectedStoneDefs.Count * DefaultElementHeight, maxHeight);

            if (!_userData.StoneTypesNumberOnly)
            {
                // stone types, standard selection

                var inLs = ListingStandard.BeginScrollView(height, selectedStoneDefs.Count * DefaultElementHeight,
                                                           ref _scrollPosStoneSelection, DefaultScrollableViewShrinkWidth);

                foreach (var currentOrderedStoneDef in orderedStoneDefs)
                {
                    ThreeStateItem threeStateItem;

                    if (!selectedStoneDefs.TryGetValue(currentOrderedStoneDef, out threeStateItem))
                    {
                        Log.Message("A stoneDef wasn't found in selectedStoneDefs");
                        continue;
                    }

                    var flag = currentOrderedStoneDef == _selectedStoneDef;

                    // save temporary state as it might change in CheckBoxLabeledMulti
                    var tmpState = threeStateItem.State;

                    var itemRect = inLs.GetRect(DefaultElementHeight);
                    if (Widgets.CheckBoxLabeledSelectableMulti(itemRect, currentOrderedStoneDef.LabelCap,
                                                               ref flag, ref tmpState))
                    {
                        _selectedStoneDef = currentOrderedStoneDef;
                    }

                    // if the state changed, update the item with the new state
                    threeStateItem.State = tmpState;

                    ReorderableWidget.Reorderable(reorderableGroup, itemRect);
                    TooltipHandler.TipRegion(itemRect, currentOrderedStoneDef.description);
                }

                ListingStandard.EndScrollView(inLs);
            }
            else
            {
                // just keep the height of what should have been the scroll view but don't draw it. Put a big red cross on it.
                var scrollViewRect = ListingStandard.GetRect(height);
                GUI.DrawTexture(scrollViewRect, Verse.Widgets.CheckboxOffTex);
            }

            // choose stone types depending on their number on tiles.
            ListingStandard.GapLine(DefaultGapLineHeight);

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

            var filterByStoneNumber = _userData.StoneTypesNumberOnly;

            Verse.Widgets.CheckboxLabeled(leftRect, "Use # of stone types [2,3]:", ref filterByStoneNumber);
            _userData.StoneTypesNumberOnly = filterByStoneNumber;

            var numberOfStones = _userData.StoneTypesNumber;

            Verse.Widgets.TextFieldNumeric(rightRect, ref numberOfStones, ref _bufferStringNumberOfStones, 2, 3);
            _userData.StoneTypesNumber = numberOfStones;

            const string tooltipText =
                "Filter tiles that have only the given number of stone types (whatever the types are). This disables the other stone filters.";

            TooltipHandler.TipRegion(leftRect, tooltipText);
        }
Example #22
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);
            }
        }
Example #23
0
        private void DrawForageability()
        {
            DrawEntryHeader($"{"Forageability".Translate()} (%)", false,
                            backgroundColor: ColorFromFilterType(typeof(TileFilterForageability)));

            DrawUsableMinMaxNumericField(_gameData.UserData.Forageability, "Forageability".Translate());

            ListingStandard.GapLine();

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

                // add a dummy 'Any' fake biome type. This sets the chosen biome to null.
                Action actionClick = delegate { _gameData.UserData.ForagedFood = null; };

                // tool-tip when hovering above the 'Any' biome name on the floating menu
                Action mouseOverAction = delegate
                {
                    var mousePos = Event.current.mousePosition;
                    var rect     = new Rect(mousePos.x, mousePos.y, DefaultElementHeight, DefaultElementHeight);

                    TooltipHandler.TipRegion(rect, "Any Food");
                };
                var menuOption = new FloatMenuOption("PLMW_SelectAny".Translate(), actionClick, MenuOptionPriority.Default, mouseOverAction);
                floatMenuOptions.Add(menuOption);

                var foragedFoods = _gameData.DefData.ForagedFoodsPerBiome.Values.Where(x => x != null).Distinct().ToList();

                // loop through all known biomes
                foreach (var foragedFood in foragedFoods)
                {
                    Log.Message($"[PL] foragedFood: label: {foragedFood.label}; labelCap: {foragedFood.LabelCap}");

                    // clicking on the floating menu saves the selected biome
                    actionClick = delegate { _gameData.UserData.ForagedFood = foragedFood; };
                    // tool-tip when hovering above the biome name on the floating menu
                    mouseOverAction = delegate
                    {
                        var mousePos = Event.current.mousePosition;
                        var rect     = new Rect(mousePos.x, mousePos.y, DefaultElementHeight, DefaultElementHeight);

                        TooltipHandler.TipRegion(rect, foragedFood.description);
                    };

                    //create the floating menu
                    menuOption = new FloatMenuOption(foragedFood.LabelCap, 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, "Select Forageable Food");

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

            var currHeightBefore = ListingStandard.CurHeight;

            var rightLabel = _gameData.UserData.ForagedFood != null ? _gameData.UserData.ForagedFood.LabelCap : "Select Any";

            ListingStandard.LabelDouble("Forageable Food: ", rightLabel);

            var currHeightAfter = ListingStandard.CurHeight;

            // display tool-tip over label
            if (_gameData.UserData.ForagedFood != null)
            {
                var currentRect = ListingStandard.GetRect(0f);
                currentRect.height = currHeightAfter - currHeightBefore;
                if (!string.IsNullOrEmpty(_gameData.UserData.ForagedFood.description))
                {
                    TooltipHandler.TipRegion(currentRect, _gameData.UserData.ForagedFood.description);
                }
            }
        }
Example #24
0
        private void DrawBiomeTypesSelection()
        {
            DrawEntryHeader("PLMWTT_BiomeTypes".Translate(), false, backgroundColor: ColorFromFilterType(typeof(TileFilterBiomes)));

            var biomeDefs = _gameData.DefData.BiomeDefs;

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

                // add a dummy 'Any' fake biome type. This sets the chosen biome to null.
                Action actionClick = delegate { _gameData.UserData.ChosenBiome = null; };
                // tool-tip when hovering above the 'Any' biome name on the floating menu
                Action mouseOverAction = delegate
                {
                    var mousePos = Event.current.mousePosition;
                    var rect     = new Rect(mousePos.x, mousePos.y, DefaultElementHeight, DefaultElementHeight);

                    TooltipHandler.TipRegion(rect, "PLMWTT_AnyBiome".Translate());
                };
                var menuOption = new FloatMenuOption("PLMW_SelectAny".Translate(), actionClick, MenuOptionPriority.Default, mouseOverAction);
                floatMenuOptions.Add(menuOption);

                // loop through all known biomes
                foreach (var currentBiomeDef in biomeDefs)
                {
                    // clicking on the floating menu saves the selected biome
                    actionClick = delegate { _gameData.UserData.ChosenBiome = currentBiomeDef; };
                    // tool-tip when hovering above the biome name on the floating menu
                    mouseOverAction = delegate
                    {
                        var mousePos = Event.current.mousePosition;
                        var rect     = new Rect(mousePos.x, mousePos.y, DefaultElementHeight, DefaultElementHeight);

                        TooltipHandler.TipRegion(rect, currentBiomeDef.description);
                    };

                    //create the floating menu
                    menuOption = new FloatMenuOption(currentBiomeDef.LabelCap, 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_SelectBiomeType".Translate());

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

            var currHeightBefore = ListingStandard.CurHeight;

            var rightLabel = _gameData.UserData.ChosenBiome != null ? _gameData.UserData.ChosenBiome.LabelCap : "PLMW_SelectAny".Translate();

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

            var currHeightAfter = ListingStandard.CurHeight;

            // display tool-tip over label
            if (_gameData.UserData.ChosenBiome != null)
            {
                var currentRect = ListingStandard.GetRect(0f);
                currentRect.height = currHeightAfter - currHeightBefore;
                if (!string.IsNullOrEmpty(_gameData.UserData.ChosenBiome.description))
                {
                    TooltipHandler.TipRegion(currentRect, _gameData.UserData.ChosenBiome.description);
                }
            }
        }
Example #25
0
        private void DrawStoneTypesSelection()
        {
            DrawEntryHeader("PLMWTT_StoneTypes".Translate(), backgroundColor: ColorFromFilterType(typeof(TileFilterStones)));

            var selectedStoneDefs = _gameData.UserData.SelectedStoneDefs;

            /*
             * Buttons
             */
            const int numButtons  = 2;
            var       buttonsRect = ListingStandard.GetRect(DefaultElementHeight).SplitRectWidthEvenly(numButtons);

            if (buttonsRect.Count != numButtons)
            {
                Log.ErrorOnce($"[PrepareLanding] DrawStoneTypesSelection: couldn't get the right number of buttons: {numButtons}", 0x123acafe);
                return;
            }

            // Reset button: reset all entries to Partial state
            if (Verse.Widgets.ButtonText(buttonsRect[0], "PLMW_Reset".Translate()))
            {
                selectedStoneDefs.Reset(_gameData.DefData.StoneDefs, nameof(_gameData.UserData.SelectedStoneDefs));

                _gameData.UserData.StoneTypesNumberOnly = false;
            }

            // order / no order button
            TooltipHandler.TipRegion(buttonsRect[1], "PLMWTT_StoneOrderTooltip".Translate());
            var orderText  = selectedStoneDefs.OrderedFiltering ? "PLMWTT_Ordered".Translate() : "PLMWTT_NoOrder".Translate();
            var savedColor = GUI.color;

            GUI.color = selectedStoneDefs.OrderedFiltering ? Color.green : Color.red;
            if (Verse.Widgets.ButtonText(buttonsRect[1], $"{"PLMWTT_Filter".Translate()}: {orderText}"))
            {
                selectedStoneDefs.OrderedFiltering = !selectedStoneDefs.OrderedFiltering;
            }
            GUI.color = savedColor;

            // re-orderable list group
            var reorderableGroup = ReorderableWidget.NewGroup(delegate(int from, int to)
            {
                //TODO find a way to raise an event to tell an observer that the list order has changed
                selectedStoneDefs.ReorderElements(from, to);
                SoundDefOf.TickHigh.PlayOneShotOnCamera();
            });

            var maxNumStones = (InRect.height - ListingStandard.CurHeight - DefaultGapLineHeight - DefaultElementHeight - 15f) / DefaultElementHeight;
            var maxHeight    = maxNumStones * DefaultElementHeight;
            var height       = Mathf.Min(selectedStoneDefs.Count * DefaultElementHeight, maxHeight);

            if (!_gameData.UserData.StoneTypesNumberOnly)
            {
                // stone types, standard selection

                var inLs = ListingStandard.BeginScrollView(height, selectedStoneDefs.Count * DefaultElementHeight,
                                                           ref _scrollPosStoneSelection, DefaultScrollableViewShrinkWidth);

                foreach (var currentOrderedStoneDef in selectedStoneDefs.OrderedItems)
                {
                    if (!selectedStoneDefs.TryGetValue(currentOrderedStoneDef, out var threeStateItem))
                    {
                        Log.ErrorOnce("A stoneDef wasn't found in selectedStoneDefs", 0x1cafe9);
                        continue;
                    }

                    var flag = currentOrderedStoneDef == _selectedStoneDef;

                    // save temporary state as it might change in CheckBoxLabeledMulti
                    var tmpState = threeStateItem.State;

                    var itemRect = inLs.GetRect(DefaultElementHeight);
                    if (Widgets.CheckBoxLabeledSelectableMulti(itemRect, currentOrderedStoneDef.LabelCap,
                                                               ref flag, ref tmpState))
                    {
                        _selectedStoneDef = currentOrderedStoneDef;
                    }

                    // if the state changed, update the item with the new state
                    threeStateItem.State = tmpState;

                    ReorderableWidget.Reorderable(reorderableGroup, itemRect);
                    TooltipHandler.TipRegion(itemRect, currentOrderedStoneDef.description);
                }

                ListingStandard.EndScrollView(inLs);
            }
            else
            {
                // just keep the height of what should have been the scroll view but don't draw it. Put a big red cross on it.
                var scrollViewRect = ListingStandard.GetRect(height);
                GUI.DrawTexture(scrollViewRect, Verse.Widgets.CheckboxOffTex);
            }

            // choose stone types depending on their number on tiles.
            ListingStandard.GapLine(DefaultGapLineHeight);

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

            var filterByStoneNumber = _gameData.UserData.StoneTypesNumberOnly;

            Verse.Widgets.CheckboxLabeled(leftRect, $"{"PLMWTT_UseNumberOfStoneTypes".Translate()}:", ref filterByStoneNumber);
            _gameData.UserData.StoneTypesNumberOnly = filterByStoneNumber;

            var numberOfStones = _gameData.UserData.StoneTypesNumber;

            Verse.Widgets.TextFieldNumeric(rightRect, ref numberOfStones, ref _bufferStringNumberOfStones, 2, 3);
            _gameData.UserData.StoneTypesNumber = numberOfStones;

            TooltipHandler.TipRegion(leftRect, "PLMWTT_UseNumberOfStoneTypesToolTip".Translate());
        }
Example #26
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);
        }
Example #27
0
        private void DrawRoadTypesSelection()
        {
            DrawEntryHeader("PLMWTT_RoadTypes".Translate(), backgroundColor: ColorFromFilterType(typeof(TileFilterRoads)));

            var roadDefs         = _gameData.DefData.RoadDefs;
            var selectedRoadDefs = _gameData.UserData.SelectedRoadDefs;

            /*
             * Buttons
             */
            var numButtons = 4;

            if (_gameData.UserData.Options.ViewPartialOffNoSelect)
            {
                numButtons += 1;
            }

            var buttonsRect = ListingStandard.GetRect(DefaultElementHeight).SplitRectWidthEvenly(numButtons);

            if (buttonsRect.Count != numButtons)
            {
                Log.ErrorOnce($"[PrepareLanding] DrawRoadTypesSelection: couldn't get the right number of buttons: {numButtons}", 0x1239cafe);
                return;
            }

            // Reset button: reset the container
            if (Widgets.ButtonTextToolTip(buttonsRect[0], "PLMW_Reset".Translate(), "PLMWTT_ButtonResetTooltip".Translate()))
            {
                selectedRoadDefs.Reset(roadDefs, nameof(_gameData.UserData.SelectedRoadDefs));
            }

            // all roads
            if (Widgets.ButtonTextToolTip(buttonsRect[1], "PLMW_All".Translate(), "PLMWTT_ButtonAllTooltip".Translate()))
            {
                selectedRoadDefs.All();
            }

            // no roads
            if (Widgets.ButtonTextToolTip(buttonsRect[2], "PLMW_None".Translate(), "PLMWTT_ButtonNoneTooltip".Translate()))
            {
                selectedRoadDefs.None();
            }

            // boolean filtering type
            if (Widgets.ButtonTextToolTipColor(buttonsRect[3], selectedRoadDefs.FilterBooleanState.ToStringHuman(), "PLMWTT_ORANDTooltip".Translate(), selectedRoadDefs.FilterBooleanState.Color()))
            {
                selectedRoadDefs.FilterBooleanState = selectedRoadDefs.FilterBooleanState.Next();
            }

            if (_gameData.UserData.Options.ViewPartialOffNoSelect)
            {
                var color = selectedRoadDefs.OffPartialNoSelect ? Color.green : Color.red;
                if (Widgets.ButtonTextToolTipColor(buttonsRect[4], $"{"PLMWTT_SelectedShort".Translate()} {selectedRoadDefs.OffPartialNoSelect}", "PLMWTT_OffPartialTooltip".Translate(), color))
                {
                    selectedRoadDefs.OffPartialNoSelect = !selectedRoadDefs.OffPartialNoSelect;
                }
            }

            /*
             * ScrollView
             */
            var scrollViewHeight = selectedRoadDefs.Count * DefaultElementHeight;
            var inLs             = ListingStandard.BeginScrollView(5 * DefaultElementHeight, scrollViewHeight,
                                                                   ref _scrollPosRoadSelection, DefaultScrollableViewShrinkWidth);

            // display road elements
            foreach (var roadDef in roadDefs)
            {
                if (!selectedRoadDefs.TryGetValue(roadDef, out var threeStateItem))
                {
                    Log.Error(
                        $"[PrepareLanding] [DrawRoadTypesSelection] an item in RoadDefs is not in SelectedRoadDefs: {roadDef.LabelCap}");
                    continue;
                }

                // save temporary state as it might change in CheckBoxLabeledMulti
                var tmpState = threeStateItem.State;

                var itemRect = inLs.GetRect(DefaultElementHeight);
                Widgets.CheckBoxLabeledMulti(itemRect, roadDef.LabelCap, ref tmpState);

                // if the state changed, update the item with the new state
                // ReSharper disable once RedundantCheckBeforeAssignment
                if (tmpState != threeStateItem.State)
                {
                    threeStateItem.State = tmpState;
                }

                if (!string.IsNullOrEmpty(roadDef.description))
                {
                    TooltipHandler.TipRegion(itemRect, roadDef.description);
                }
            }

            ListingStandard.EndScrollView(inLs);
        }
Example #28
0
        protected virtual void DrawOptions()
        {
            DrawEntryHeader("Filter Options", backgroundColor: Color.cyan);

            var allowLiveFiltering = _userData.Options.AllowLiveFiltering;

            ListingStandard.CheckboxLabeled("Allow Live Filtering", ref allowLiveFiltering,
                                            "[Warning: CPU heavy] Allow filtering without pressing the \"Filter\" button.");
            _userData.Options.AllowLiveFiltering = allowLiveFiltering;

            //TODO: allow unimplemented biomes

            var allowImpassableHilliness = _userData.Options.AllowImpassableHilliness;

            ListingStandard.CheckboxLabeled("Allow Impassable Tiles", ref allowImpassableHilliness,
                                            "Allow selection and filtering of impassable tiles.");
            _userData.Options.AllowImpassableHilliness = allowImpassableHilliness;

            //TODO: allow saving / reading the set of currently applied filters

            // allow to show the debug tile ID on the highlighted tile (instead of 'X')
            var showDebugTileId = _userData.Options.ShowDebugTileId;

            ListingStandard.CheckboxLabeled("Show Debug Tile ID", ref showDebugTileId,
                                            "Show the Debug Tile ID (instead of 'X') for the highlighted tiles.");
            _userData.Options.ShowDebugTileId = showDebugTileId;

            var bypassMaxHighlightedTiles = _userData.Options.BypassMaxHighlightedTiles;

            ListingStandard.CheckboxLabeled("Bypass TileHighlighter Maximum", ref bypassMaxHighlightedTiles,
                                            $"Allow highlighting more than {TileHighlighter.MaxHighlightedTiles} tiles.");
            _userData.Options.BypassMaxHighlightedTiles = bypassMaxHighlightedTiles;

            var disablePreFilterCheck = _userData.Options.DisablePreFilterCheck;

            ListingStandard.CheckboxLabeled("Disable PreFilter Check", ref disablePreFilterCheck,
                                            "Disable the check where Biomes and Terrains must be selected with a world coverage >= 50%.");
            _userData.Options.DisablePreFilterCheck = disablePreFilterCheck;

            var resetAllFieldsOnNewGeneratedWorld = _userData.Options.ResetAllFieldsOnNewGeneratedWorld;

            ListingStandard.CheckboxLabeled("Reset all filters on new world", ref resetAllFieldsOnNewGeneratedWorld,
                                            "If ON, all filters are reset to their default state on a new generated world, otherwise the filters are kept in their previous state.");
            _userData.Options.ResetAllFieldsOnNewGeneratedWorld = resetAllFieldsOnNewGeneratedWorld;

            var disableTileHighligthing = _userData.Options.DisableTileHighlighting;

            ListingStandard.CheckboxLabeled("Disable Tile Highligthing", ref disableTileHighligthing,
                                            "Disable tile highlighting altogether.");
            _userData.Options.DisableTileHighlighting = disableTileHighligthing;

            var disableTileBlinking = _userData.Options.DisableTileBlinking;

            ListingStandard.CheckboxLabeled("Disable Tile Blinking", ref disableTileBlinking,
                                            "Disable tile blinking (\"breathing\") for filtered tiles on the world map.");
            _userData.Options.DisableTileBlinking = disableTileBlinking;

            var showFilterHeaviness = _userData.Options.ShowFilterHeaviness;

            ListingStandard.CheckboxLabeled("Show Filter Heaviness", ref showFilterHeaviness,
                                            "Show filter heaviness (possible filter CPU calculation heaviness) on filter header in the GUI.");
            _userData.Options.ShowFilterHeaviness = showFilterHeaviness;

            var allowInvalidTilesForNewSettlement = _userData.Options.AllowInvalidTilesForNewSettlement;

            ListingStandard.CheckboxLabeled("Allow Invalid Tiles for New Settlement",
                                            ref allowInvalidTilesForNewSettlement,
                                            "If on, this prevents a last pass that would have removed tiles deemed as not valid for a new settlement.");
            _userData.Options.AllowInvalidTilesForNewSettlement = allowInvalidTilesForNewSettlement;

            var goToTileOptionRectSpace = ListingStandard.GetRect(30f);
            var rects = goToTileOptionRectSpace.SplitRectWidth(_goToTileSplitPct);

            Widgets.Label(rects[0], "Go to Tile:");
            Widgets.TextFieldNumeric(rects[1], ref _tileNumber, ref _tileNumberString, -1, 300000);
            if (Widgets.ButtonText(rects[2], "Go!"))
            {
                if ((_tileNumber < 0) || (_tileNumber >= Find.WorldGrid.TilesCount))
                {
                    Messages.Message($"Out of Range: {_tileNumber}; Range: [0, {Find.WorldGrid.TilesCount}).",
                                     MessageSound.RejectInput);
                }
                else
                {
                    Find.WorldInterface.SelectedTile = _tileNumber;
                    Find.WorldCameraDriver.JumpTo(Find.WorldGrid.GetTileCenter(Find.WorldInterface.SelectedTile));
                }
            }
        }