public override void SettingsWindow(VehicleDef def, Listing_Settings listing) { FieldInfo dictField = SettingsCache.GetCachedField(typeof(StatUpgrade), nameof(values)); Rect buttonRect = listing.GetRect(16); buttonRect.x = buttonRect.width - 24; buttonRect.width = 24; buttonRect.height = 24; listing.Header(label, GameFont.Medium, TextAnchor.MiddleCenter); if (Widgets.ButtonImage(buttonRect, VehicleTex.ResetPage)) { SettingsCustomizableFields.PopulateSaveableUpgrades(def, true); } listing.Gap(); foreach (var statUpgrade in values) { SaveableDefPair <StatUpgradeCategoryDef> saveable = new SaveableDefPair <StatUpgradeCategoryDef>(def, dictField, string.Concat(statUpgrade.Key.defName, "_", upgradeID), statUpgrade.Key, LookMode.Value); statUpgrade.Key.DrawStatLister(def, listing, saveable, statUpgrade.Value); } }
private void DrawVehicleOptions(Rect menuRect) { listingSplit = new Listing_Settings() { maxOneColumn = true, shiftRectScrollbar = true }; Rect vehicleIconContainer = menuRect.ContractedBy(10); vehicleIconContainer.width /= 4; vehicleIconContainer.height = vehicleIconContainer.width; vehicleIconContainer.x += vehicleIconContainer.width; Rect vehicleDetailsContainer = menuRect.ContractedBy(10); vehicleDetailsContainer.x += vehicleIconContainer.width - 1; vehicleDetailsContainer.width -= vehicleIconContainer.width; Widgets.DrawBoxSolid(vehicleDetailsContainer, Color.grey); Rect vehicleDetailsRect = vehicleDetailsContainer.ContractedBy(1); Widgets.DrawBoxSolid(vehicleDetailsRect, ListingExtension.MenuSectionBGFillColor); listingStandard = new Listing_Standard(); listingStandard.Begin(vehicleDetailsContainer.ContractedBy(1)); listingStandard.Header($"{VehicleMod.selectedDef?.LabelCap ?? string.Empty}", ListingExtension.BannerColor, GameFont.Medium, TextAnchor.MiddleCenter); listingStandard.End(); if (VehicleMod.selectedDef != null) { try { Rect iconRect = menuRect.ContractedBy(10); iconRect.width /= 5; iconRect.height = iconRect.width; iconRect.x += menuRect.width / 4; iconRect.y += 30; if (VehicleMod.selectedPatterns.Count > 1) { Rect paintBrushRect = new Rect(iconRect.x + iconRect.width, iconRect.y, 24, 24); Widgets.DrawTextureFitted(paintBrushRect, VehicleTex.Recolor, 1); if (Mouse.IsOver(paintBrushRect)) { TooltipHandler.TipRegion(paintBrushRect, "VehiclesRecolorDefaultMaskTooltip".Translate()); } if (Widgets.ButtonInvisible(paintBrushRect)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (PatternDef pattern in VehicleMod.selectedPatterns) { list.Add(new FloatMenuOption(pattern.LabelCap, () => defaultMasks[VehicleMod.selectedDef.defName] = pattern.defName)); } FloatMenu floatMenu = new FloatMenu(list) { vanishIfMouseDistant = true }; //floatMenu.onCloseCallback... Find.WindowStack.Add(floatMenu); } } PatternDef curPattern = DefDatabase <PatternDef> .GetNamed(defaultMasks[VehicleMod.selectedDef.defName]); RenderHelper.DrawVehicleTexInSettings(iconRect, VehicleMod.selectedDef, VehicleMod.graphicInt, VehicleMod.selectedVehicleTex, curPattern, Rot8.North); Rect enableButtonRect = menuRect.ContractedBy(10); enableButtonRect.x += enableButtonRect.width / 4 + 5; EnableButton(enableButtonRect); Rect compVehicleRect = menuRect.ContractedBy(10); compVehicleRect.x += vehicleIconContainer.width * 2 - 10; compVehicleRect.y += 30; compVehicleRect.width -= vehicleIconContainer.width * 2; compVehicleRect.height -= (30 + menuRect.height * 0.45f); listingSplit.Begin(compVehicleRect, 2); listingSplit.Header("CompVehicleStats".Translate(), Color.clear, GameFont.Small, TextAnchor.MiddleCenter); foreach (FieldInfo field in VehicleMod.vehicleDefFields) { if (field.TryGetAttribute(out PostToSettingsAttribute post)) { post.DrawLister(listingSplit, VehicleMod.selectedDef, field); } } listingSplit.End(); float scrollableFieldY = menuRect.height * 0.4f; Rect scrollableFieldsRect = new Rect(vehicleDetailsContainer.x + 1, menuRect.y + scrollableFieldY, vehicleDetailsContainer.width - 2, menuRect.height - scrollableFieldY - 10); Rect scrollableFieldsViewRect = new Rect(scrollableFieldsRect.x, scrollableFieldsRect.y, scrollableFieldsRect.width - 20, VehicleMod.scrollableViewHeight); UIElements.DrawLineHorizontalGrey(scrollableFieldsRect.x, scrollableFieldsRect.y - 1, scrollableFieldsRect.width); listingSplit.BeginScrollView(scrollableFieldsRect, ref VehicleMod.saveableFieldsScrollPosition, ref scrollableFieldsViewRect, 3); foreach (var saveableObject in VehicleMod.VehicleCompFields) { if (saveableObject.Value.NullOrEmpty() || saveableObject.Value.All(f => f.TryGetAttribute <PostToSettingsAttribute>(out var settings) && settings.VehicleType != VehicleType.Undefined && settings.VehicleType != VehicleMod.selectedDef.vehicleType)) { continue; } string header = string.Empty; if (saveableObject.Key.TryGetAttribute(out HeaderTitleAttribute title)) { header = title.Translate ? title.Label.Translate().ToString() : title.Label; } listingSplit.Header(header, ListingExtension.BannerColor, GameFont.Small, TextAnchor.MiddleCenter); foreach (FieldInfo field in saveableObject.Value) { if (field.TryGetAttribute(out PostToSettingsAttribute post)) { post.DrawLister(listingSplit, VehicleMod.selectedDef, field); } } } listingSplit.EndScrollView(ref scrollableFieldsViewRect); } catch (Exception ex) { Log.Error($"Exception thrown while trying to select {VehicleMod.selectedDef.defName}. Disabling vehicle to preserve mod settings.\nException={ex.Message}"); VehicleMod.settingsDisabledFor.Add(VehicleMod.selectedDef.defName); VehicleMod.selectedDef = null; VehicleMod.selectedPatterns.Clear(); VehicleMod.selectedDefUpgradeComp = null; VehicleMod.selectedNode = null; VehicleMod.SetVehicleTex(null); } } }