예제 #1
0
        private void DrawStoneTypesSelection()
        {
            DrawEntryHeader("StoneTypesHere".Translate(), backgroundColor: ColorLibrary.RoyalPurple);

            var selectedStoneDefs = _gameData.GodModeData.SelectedStoneDefs;
            var orderedStoneDefs  = _gameData.GodModeData.OrderedStoneDefs;

            // Reset button: reset all entries to Off state
            if (ListingStandard.ButtonText("Reset"))
            {
                _gameData.GodModeData.ResetSelectedStoneDefs();
            }

            // re-orderable list group
            var reorderableGroup = ReorderableWidget.NewGroup(delegate(int from, int to)
            {
                orderedStoneDefs.ReorderElements(from, to);
                SoundDefOf.Tick_High.PlayOneShotOnCamera();
            }, ReorderableDirection.Vertical);

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

            // stone types, standard selection

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

            foreach (var currentOrderedStoneDef in orderedStoneDefs)
            {
                var itemRect = inLs.GetRect(DefaultElementHeight);


                var tmpState = selectedStoneDefs[currentOrderedStoneDef];
                var selected = currentOrderedStoneDef == _selectedStoneDef;

                if (Widgets.CheckboxLabeledSelectable(itemRect, currentOrderedStoneDef.LabelCap, ref selected,
                                                      ref tmpState))
                {
                    _selectedStoneDef = currentOrderedStoneDef;
                }

                // if the state changed, update the item with the new state
                if (tmpState != selectedStoneDefs[currentOrderedStoneDef])
                {
                    selectedStoneDefs[currentOrderedStoneDef] = tmpState;
                }

                ReorderableWidget.Reorderable(reorderableGroup, itemRect);

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

            ListingStandard.EndScrollView(inLs);
        }
예제 #2
0
        private void DrawRiverTypesSelection()
        {
            DrawEntryHeader("River Types", backgroundColor: ColorLibrary.RoyalPurple);

            var riverDefs         = _gameData.DefData.RiverDefs;
            var selectedRiverDefs = _gameData.GodModeData.SelectedRiverDefs;

            if (ListingStandard.ButtonText("Reset"))
            {
                _gameData.GodModeData.ResetSelectedRiverDefs();
            }

            /*
             * ScrollView
             */

            var scrollViewHeight = riverDefs.Count * DefaultElementHeight;
            var inLs             = ListingStandard.BeginScrollView(5 * DefaultElementHeight, scrollViewHeight,
                                                                   ref _scrollPosRiverSelection, DefaultScrollableViewShrinkWidth);

            // display road elements
            foreach (var riverDef in riverDefs)
            {
                // save temporary state as it might change in CheckBoxLabeledMulti
                var tmpState = selectedRiverDefs[riverDef];

                var itemRect = inLs.GetRect(DefaultElementHeight);
                Widgets.CheckboxLabeled(itemRect, riverDef.LabelCap, ref tmpState);

                // if the state changed, update the item with the new state
                if (tmpState != selectedRiverDefs[riverDef])
                {
                    if (tmpState)
                    {
                        var countTrue = selectedRiverDefs.Values.Count(selectedRiverDefValue => selectedRiverDefValue);
                        if (countTrue >= MaxNumberOfRivers)
                        {
                            Messages.Message($"Can't have more than {MaxNumberOfRivers} types of river per tile.",
                                             MessageTypeDefOf.RejectInput);
                            tmpState = false;
                        }
                    }

                    selectedRiverDefs[riverDef] = tmpState;
                }

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

            ListingStandard.EndScrollView(inLs);
        }
예제 #3
0
        protected virtual void DrawRoadTypesSelection()
        {
            DrawEntryHeader("Road Types", backgroundColor: ColorFromFilterSubjectThingDef("Roads"));

            var roadDefs         = _userData.RoadDefs;
            var selectedRoadDefs = _userData.SelectedRoadDefs;

            // Reset button: reset all entries to Off state
            if (ListingStandard.ButtonText("Reset All"))
            {
                foreach (var roadDefEntry in selectedRoadDefs)
                {
                    roadDefEntry.Value.State = MultiCheckboxState.Partial;
                }
            }

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

            // display road elements
            foreach (var roadDef in roadDefs)
            {
                ThreeStateItem threeStateItem;
                if (!selectedRoadDefs.TryGetValue(roadDef, out 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);
        }
예제 #4
0
        protected virtual void DrawWorldInfo()
        {
            DrawEntryHeader("World Info", backgroundColor: Color.yellow);

            var maxHeight    = InRect.height - ListingStandard.CurHeight - 30f;
            var scrollHeight = Text.CalcHeight(WorldInfo, ListingStandard.ColumnWidth);

            scrollHeight = Mathf.Max(maxHeight, scrollHeight);

            var innerLs = ListingStandard.BeginScrollView(maxHeight, scrollHeight, ref _scrollPosWorldInfo);

            GUI.TextField(innerLs.GetRect(maxHeight), WorldInfo, _styleWorldInfo);

            ListingStandard.EndScrollView(innerLs);
        }
예제 #5
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());
        }
예제 #6
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);
        }
예제 #7
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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        private void DrawWorldRecord()
        {
            DrawEntryHeader("PLMWINF_WorldRecords".Translate(), backgroundColor: Color.yellow);

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

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

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

            /*
             * Calculate heights
             */

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

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

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

            var selectedTileIndex = 0;

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

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

                /*
                 *   lowest
                 */

                var lowestCharacteristicKvp = characteristicData.WorldTilesCharacteristics.First();

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

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

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

                selectedTileIndex++;

                /*
                 *   highest
                 */

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

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

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

                selectedTileIndex++;

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

            ListingStandard.EndScrollView(innerLs);
        }
예제 #10
0
        protected void DrawLoadPresetList(Rect inRect)
        {
            DrawEntryHeader("Preset Files: Load mode", backgroundColor: Color.green);

            var presetFiles = _userData.PresetManager.AllPresetFiles;

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

            var presetFilesCount = presetFiles.Count;

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

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

            /*
             * Buttons
             */

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

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

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

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

            /*
             * Label
             */

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

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

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

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

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

            /*
             * Calculate heights
             */

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

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

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

            var endIndex = _listDisplayStartIndex + itemsToDisplay;

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

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

            ListingStandard.EndScrollView(innerLs);
        }