public override void DoWindowContents(Rect inRect) { inRect.yMin += 72f; Widgets.DrawMenuSection(inRect); TabController.DrawTabs(inRect); inRect = inRect.ContractedBy(17f); TabController.DrawSelectedTab(inRect); DoBottomsButtons(inRect); }
private static bool ExtraPart(Rect rect, Favourite favourite) { var rects = new Grid(rect, gutters: Vector2.zero).Columns(1, 1); var size = Mathf.Min(16f, rects[0].Rect.width, rects[0].Rect.height); var iconRect = new Rect(0f, 0f, size, size); GUI.DrawTexture(iconRect.CenteredIn(rects[0]), favourite.Icon); if (Widgets.ButtonImage(new Rect(0f, 0f, size, size).CenteredIn(rects[1]), Resources.Edit)) { Find.WindowStack.Add(new Dialog_EditFavourite(favourite)); } return(false); }
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); } }
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); }
private void DrawFilteredTiles() { DrawEntryHeader("PLMWFTIL_FilteredTiles".Translate(), backgroundColor: Color.yellow); // default line height const float gapLineHeight = 4f; //check if we have something to display (tiles) var matchingTiles = PrepareLanding.Instance.TileFilter.AllMatchingTiles; var matchingTilesCount = matchingTiles.Count; if (matchingTilesCount == 0) { return; } /* * Buttons */ if (ListingStandard.ButtonText("PLMWFTIL_ClearFilteredTiles".Translate())) { // clear everything PrepareLanding.Instance.TileFilter.ClearMatchingTiles(); // reset starting display index _tileDisplayIndexStart = 0; // reset selected index _selectedTileIndex = -1; // don't go further as there are no tile content to draw return; } var buttonsRectSpace = ListingStandard.GetRect(30f); var splittedRect = buttonsRectSpace.SplitRectWidthEvenly(_minimizedWindowButtonsDescriptorList.Count); for (var i = 0; i < _minimizedWindowButtonsDescriptorList.Count; i++) { // get button descriptor var buttonDescriptor = _minimizedWindowButtonsDescriptorList[i]; // display button; if clicked: call the related action if (Widgets.ButtonText(splittedRect[i], buttonDescriptor.Label)) { buttonDescriptor.Action(); } // display tool-tip (if any) if (!string.IsNullOrEmpty(buttonDescriptor.ToolTip)) { TooltipHandler.TipRegion(splittedRect[i], buttonDescriptor.ToolTip); } } /* * Label */ // number of elements (tiles) to display var itemsToDisplay = Math.Min(matchingTilesCount - _tileDisplayIndexStart, MaxDisplayedTileWhenMinimized); // label to display where we actually are in the tile list GenUI.SetLabelAlign(TextAnchor.MiddleCenter); var heightBefore = ListingStandard.StartCaptureHeight(); ListingStandard.Label( $"{_tileDisplayIndexStart}: {_tileDisplayIndexStart + itemsToDisplay - 1} / {matchingTilesCount - 1}", DefaultElementHeight); GenUI.ResetLabelAlign(); var counterLabelRect = ListingStandard.EndCaptureHeight(heightBefore); Core.Gui.Widgets.DrawHighlightColor(counterLabelRect, Color.cyan, 0.50f); // add a gap before the scroll view ListingStandard.Gap(gapLineHeight); /* * Calculate heights */ // height of the scrollable outer Rect (visible portion of the scroll view, not the 'virtual' one) var maxScrollViewOuterHeight = InRect.height - ListingStandard.CurHeight - 30f; // height of the 'virtual' portion of the scroll view var scrollableViewHeight = itemsToDisplay * DefaultElementHeight + gapLineHeight * MaxDisplayedTileWhenMinimized; /* * Scroll view */ var innerLs = ListingStandard.BeginScrollView(maxScrollViewOuterHeight, scrollableViewHeight, ref _scrollPosMatchingTiles, 16f); var endIndex = _tileDisplayIndexStart + itemsToDisplay; for (var i = _tileDisplayIndexStart; i < endIndex; i++) { var selectedTileId = matchingTiles[i]; var selectedTile = Find.World.grid[selectedTileId]; // get latitude & longitude for the tile var vector = Find.WorldGrid.LongLatOf(selectedTileId); var labelText = $"{i}: {vector.y.ToStringLatitude()} {vector.x.ToStringLongitude()} - {selectedTile.biome.LabelCap} ; {selectedTileId}"; // display the label var labelRect = innerLs.GetRect(DefaultElementHeight); var selected = i == _selectedTileIndex; if (Core.Gui.Widgets.LabelSelectable(labelRect, labelText, ref selected, TextAnchor.MiddleCenter)) { // go to the location of the selected tile _selectedTileIndex = i; Find.WorldInterface.SelectedTile = selectedTileId; Find.WorldCameraDriver.JumpTo(Find.WorldGrid.GetTileCenter(Find.WorldInterface.SelectedTile)); } // add a thin line between each label innerLs.GapLine(gapLineHeight); } ListingStandard.EndScrollView(innerLs); }
protected void DrawLoadPresetList(Rect inRect) { DrawEntryHeader("Preset Files: Load mode", backgroundColor: Color.green); var presetFiles = _userData.PresetManager.AllPresetFiles; if (presetFiles == null) { Log.ErrorOnce("[PrepareLanding] PresetManager.AllPresetFiles is null.", 0x1238cafe); return; } var presetFilesCount = presetFiles.Count; if (presetFiles.Count == 0) { ListingStandard.Label("No existing presets."); return; } // add a gap before the scroll view ListingStandard.Gap(DefaultGapLineHeight); /* * Buttons */ var buttonsRectSpace = ListingStandard.GetRect(30f); var splittedRect = buttonsRectSpace.SplitRectWidthEvenly(_buttonList.Count); for (var i = 0; i < _buttonList.Count; i++) { // get button descriptor var buttonDescriptor = _buttonList[i]; // display button; if clicked: call the related action if (Widgets.ButtonText(splittedRect[i], buttonDescriptor.Label)) { buttonDescriptor.Action(); } // display tool-tip (if any) if (!string.IsNullOrEmpty(buttonDescriptor.ToolTip)) { TooltipHandler.TipRegion(splittedRect[i], buttonDescriptor.ToolTip); } } /* * Label */ // number of elements (tiles) to display var itemsToDisplay = Math.Min(presetFilesCount - _listDisplayStartIndex, MaxItemsToDisplay); // label to display where we actually are in the tile list GenUI.SetLabelAlign(TextAnchor.MiddleCenter); var heightBefore = ListingStandard.StartCaptureHeight(); ListingStandard.Label( $"{_listDisplayStartIndex}: {_listDisplayStartIndex + itemsToDisplay - 1} / {presetFilesCount - 1}", DefaultElementHeight); GenUI.ResetLabelAlign(); var counterLabelRect = ListingStandard.EndCaptureHeight(heightBefore); Core.Gui.Widgets.DrawHighlightColor(counterLabelRect, Color.cyan, 0.50f); // add a gap before the scroll view ListingStandard.Gap(DefaultGapLineHeight); /* * Calculate heights */ // height of the scrollable outer Rect (visible portion of the scroll view, not the 'virtual' one) var maxScrollViewOuterHeight = InRect.height - ListingStandard.CurHeight - 30f; // height of the 'virtual' portion of the scroll view var scrollableViewHeight = itemsToDisplay * DefaultElementHeight + DefaultGapLineHeight * MaxItemsToDisplay; /* * Scroll view */ var innerLs = ListingStandard.BeginScrollView(maxScrollViewOuterHeight, scrollableViewHeight, ref _scrollPosPresetFiles, 16f); var endIndex = _listDisplayStartIndex + itemsToDisplay; for (var i = _listDisplayStartIndex; i < endIndex; i++) { var selectedPresetFile = presetFiles[i]; var labelText = Path.GetFileNameWithoutExtension(selectedPresetFile.Name); // display the label var labelRect = innerLs.GetRect(DefaultElementHeight); var selected = i == _selectedItemIndex; if (Core.Gui.Widgets.LabelSelectable(labelRect, labelText, ref selected, TextAnchor.MiddleCenter)) { // save item index _selectedItemIndex = i; _selectedFileName = labelText; } // add a thin line between each label innerLs.GapLine(DefaultGapLineHeight); } ListingStandard.EndScrollView(innerLs); }
protected void DrawBottomButtons(Rect inRect) { var buttonsY = inRect.height - 30f; const int numButtons = 2; var buttonRects = inRect.SpaceEvenlyFromCenter(buttonsY, numButtons, _bottomButtonSize.x, _bottomButtonSize.y, 20f); if (buttonRects.Count != numButtons) { return; } string verb; switch (LoadSaveMode) { case LoadSaveMode.Unknown: // shouldn't happen verb = "Load / Save"; break; case LoadSaveMode.Load: verb = "Load"; break; case LoadSaveMode.Save: verb = "Save"; break; default: throw new ArgumentOutOfRangeException(); } var presetExistsProtectFromOverwrite = false; if (!string.IsNullOrEmpty(_selectedFileName)) { presetExistsProtectFromOverwrite = PresetManager.PresetExists(_selectedFileName) && !_allowOverwriteExistingPreset; } var savedColor = GUI.color; if (LoadSaveMode == LoadSaveMode.Save) { GUI.color = presetExistsProtectFromOverwrite ? Color.red : Color.green; } else { GUI.color = Color.green; } if (Widgets.ButtonText(buttonRects[0], $"{verb} Preset")) { switch (LoadSaveMode) { case LoadSaveMode.Load: LoadPreset(); break; case LoadSaveMode.Save: SavePreset(presetExistsProtectFromOverwrite); break; } } GUI.color = savedColor; if (Widgets.ButtonText(buttonRects[1], $"Exit {verb}")) { LoadSaveMode = LoadSaveMode.Unknown; _allowOverwriteExistingPreset = false; _selectedItemIndex = -1; _selectedFileName = null; PrepareLanding.Instance.MainWindow.TabController.SetPreviousTabAsSelectedTab(); } }
protected void AddMinimizedWindowContent(Listing_Standard listingStandard, Rect inRect) { /* constants used for GUI elements */ // default line height const float gapLineHeight = 4f; // default visual element height const float elementHeight = 30f; //check if we have something to display (tiles) var matchingTiles = PrepareLanding.Instance.TileFilter.AllMatchingTiles; var matchingTilesCount = matchingTiles.Count; if (matchingTilesCount == 0) { // revert to initial window size if needed MinimizedWindow.windowRect.height = MinimizedWindow.InitialSize.y; return; } /* * Buttons */ if (listingStandard.ButtonText("Clear Filtered Tiles")) { // 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); } } /* * Display label (where we actually are in the tile list) */ // 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}", elementHeight); 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; // recalculate window height: initial size + visible scroll view height + current height of the listing standard (hence accounting for all buttons above) var newWindowHeight = MinimizedWindow.InitialSize.y + maxScrollViewOuterHeight + listingStandard.CurHeight; // minimized window height can't be more than 70% of the screen height MinimizedWindow.windowRect.height = Mathf.Min(newWindowHeight, UI.screenHeight * 0.70f); // height of the 'virtual' portion of the scroll view var scrollableViewHeight = itemsToDisplay * elementHeight + 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]; // get latitude & longitude for the tile var vector = Find.WorldGrid.LongLatOf(selectedTileId); var labelText = $"{i}: {vector.y.ToStringLatitude()} {vector.x.ToStringLongitude()}"; // display the label var labelRect = innerLs.GetRect(elementHeight); 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); }