public override void ResetSettings() { base.ResetSettings(); VehicleMod.cachedFields.Clear(); VehicleMod.PopulateCachedFields(); fieldSettings.Clear(); if (VehicleMod.ModifiableSettings) { foreach (VehicleDef def in DefDatabase <VehicleDef> .AllDefs) { SettingsCustomizableFields.PopulateSaveableFields(def, true); } } }
static SettingsCustomizableFields() { if (VehicleMod.ModifiableSettings) { List <bool> successfulGenerations = new List <bool>(); VehicleMod.PopulateCachedFields(); foreach (VehicleDef def in DefDatabase <VehicleDef> .AllDefs) { bool fields = PopulateSaveableFields(def); bool upgrades = PopulateSaveableUpgrades(def); successfulGenerations.Add(fields); successfulGenerations.Add(upgrades); if (!fields || !upgrades) { VehicleMod.settingsDisabledFor.Add(def.defName); } } if (successfulGenerations.All(b => b == false)) { Log.Error($"SaveableFields have failed for every VehicleDef. Consider turning off the ModifiableSettings option in the ModSettings to bypass customizable field generation. This will require a restart."); } } }
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); } } }
public override void DrawSection(Rect rect) { DrawVehicleOptions(rect); VehicleMod.DrawVehicleList(rect, (bool valid) => valid ? string.Empty : "VehicleSettingsDisabledTooltip".Translate().ToString(), (VehicleDef def) => !VehicleMod.settingsDisabledFor.Contains(def.defName)); }
private void DrawVehicleUpgrades(Rect menuRect) { 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(); vehicleDetailsContainer.y += 5; if (VehicleMod.selectedDef != null && VehicleMod.selectedDefUpgradeComp != null) { try { foreach (UpgradeNode upgradeNode in VehicleMod.selectedDefUpgradeComp.upgrades) { if (!upgradeNode.prerequisiteNodes.NullOrEmpty()) { foreach (UpgradeNode prerequisite in VehicleMod.selectedDefUpgradeComp.upgrades.FindAll(x => upgradeNode.prerequisiteNodes.Contains(x.upgradeID))) { Vector2 start = new Vector2(vehicleDetailsContainer.x + ITab_Vehicle_Upgrades.GridOrigin.x + (ITab_Vehicle_Upgrades.GridSpacing.x * prerequisite.GridCoordinate.x), vehicleDetailsContainer.y + ITab_Vehicle_Upgrades.GridOrigin.y + (ITab_Vehicle_Upgrades.GridSpacing.y * prerequisite.GridCoordinate.z) + (ITab_Vehicle_Upgrades.TopPadding * 2)); Vector2 end = new Vector2(vehicleDetailsContainer.x + ITab_Vehicle_Upgrades.GridOrigin.x + (ITab_Vehicle_Upgrades.GridSpacing.x * upgradeNode.GridCoordinate.x), vehicleDetailsContainer.y + ITab_Vehicle_Upgrades.GridOrigin.y + (ITab_Vehicle_Upgrades.GridSpacing.y * upgradeNode.GridCoordinate.z) + (ITab_Vehicle_Upgrades.TopPadding * 2)); Color color = Color.grey; Widgets.DrawLine(start, end, color, 2f); } } } for (int i = 0; i < VehicleMod.selectedDefUpgradeComp.upgrades.Count; i++) { UpgradeNode upgradeNode = VehicleMod.selectedDefUpgradeComp.upgrades[i]; float imageWidth = ITab_Vehicle_Upgrades.TotalIconSizeScalar / upgradeNode.UpgradeImage.width; float imageHeight = ITab_Vehicle_Upgrades.TotalIconSizeScalar / upgradeNode.UpgradeImage.height; Rect upgradeRect = new Rect(vehicleDetailsContainer.x + ITab_Vehicle_Upgrades.GridOrigin.x + (ITab_Vehicle_Upgrades.GridSpacing.x * upgradeNode.GridCoordinate.x) - (imageWidth / 2), vehicleDetailsContainer.y + ITab_Vehicle_Upgrades.GridOrigin.y + (ITab_Vehicle_Upgrades.GridSpacing.y * upgradeNode.GridCoordinate.z) - (imageHeight / 2) + (ITab_Vehicle_Upgrades.TopPadding * 2), imageWidth, imageHeight); Widgets.DrawTextureFitted(upgradeRect, upgradeNode.UpgradeImage, 1); if (!upgradeNode.prerequisiteNodes.NotNullAndAny()) { if (!string.IsNullOrEmpty(upgradeNode.rootNodeLabel)) { float textWidth = Text.CalcSize(upgradeNode.rootNodeLabel).x; Rect nodeLabelRect = new Rect(upgradeRect.x - (textWidth - upgradeRect.width) / 2, upgradeRect.y - 20f, 10f * upgradeNode.rootNodeLabel.Length, 25f); Widgets.Label(nodeLabelRect, upgradeNode.rootNodeLabel); } } Rect buttonRect = new Rect(vehicleDetailsContainer.x + ITab_Vehicle_Upgrades.GridOrigin.x + (ITab_Vehicle_Upgrades.GridSpacing.x * upgradeNode.GridCoordinate.x) - (imageWidth / 2), vehicleDetailsContainer.y + ITab_Vehicle_Upgrades.GridOrigin.y + (ITab_Vehicle_Upgrades.GridSpacing.y * upgradeNode.GridCoordinate.z) - (imageHeight / 2) + (ITab_Vehicle_Upgrades.TopPadding * 2), imageWidth, imageHeight); if (Mouse.IsOver(upgradeRect) || VehicleMod.selectedNode == upgradeNode) { GUI.DrawTexture(upgradeRect, TexUI.HighlightTex); } if (Mouse.IsOver(upgradeRect)) { TooltipHandler.TipRegion(upgradeRect, upgradeNode.label); } if (Widgets.ButtonInvisible(buttonRect, true)) { if (VehicleMod.selectedNode != upgradeNode) { VehicleMod.selectedNode = upgradeNode; Find.WindowStack.Add(new Dialog_NodeSettings(VehicleMod.selectedDef, VehicleMod.selectedNode, new Vector2(buttonRect.x + imageWidth * 2, buttonRect.y + imageHeight / 2))); SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera(); } else { VehicleMod.selectedNode = null; SoundDefOf.Checkbox_TurnedOff.PlayOneShotOnCamera(); } } } } 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); } } }
public override void DrawSection(Rect rect) { DrawVehicleUpgrades(rect); VehicleMod.DrawVehicleList(rect, (bool valid) => valid ? string.Empty : "VehicleNonUpgradeableSettingsTooltip".Translate().ToString(), (VehicleDef def) => !VehicleMod.settingsDisabledFor.Contains(def.defName) && def.HasComp(typeof(CompUpgradeTree))); }