Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions Source/Tanks/ModuleFuelTanks.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Reflection;
using UniLinq;
using UnityEngine;
using UnityEngine.Profiling;

using KSP.UI.Screens;
using System.Reflection;
using KSP.Localization;
using ROUtils;
using UnityEngine.Profiling;

// ReSharper disable InconsistentNaming, CompareOfFloatsByEqualityOperator

Expand Down Expand Up @@ -57,6 +56,8 @@ public void ChooseTankDefinition()
}
private TankDefinitionSelectionGUI tankDefinitionSelectionGUI = null;

private bool onLoadFiredInEditor;

// The total tank volume. This is prior to utilization
public double totalVolume;

Expand Down Expand Up @@ -238,6 +239,8 @@ public override void OnLoad(ConfigNode node)
// Setup the mass
massDirty = true;
CalculateMass();

onLoadFiredInEditor = HighLogic.LoadedSceneIsEditor;
}
OnLoadRF(node);
}
Expand Down Expand Up @@ -280,6 +283,7 @@ public override void OnStart(StartState state)
if (MFSSettings.previewAllLockedTypes)
GatherLockedTypesFromAllPossible();
InitializeTankType();
TrySetBestTankDef();
UpdateTankType(false);
InitUtilization();
Fields[nameof(utilization)].uiControlEditor.onFieldChanged += OnUtilizationChanged;
Expand Down Expand Up @@ -375,6 +379,21 @@ private void InitializeTankType()
c.display = typesAvailable.Select(t => ConstructColoredTypeTitle(t)).ToArray();
}

private void TrySetBestTankDef()
{
if (!onLoadFiredInEditor)
{
var match = typesAvailable
.Where(t => t.orderOfPreference >= 0 && !lockedTypes.Contains(t))
.OrderByDescending((e) => e.orderOfPreference)
.FirstOrDefault();
if (match != null)
{
type = match.name;
}
}
}

private string ConstructColoredTypeTitle(TankDefinition def)
{
if (!MFSSettings.previewAllLockedTypes || HighLogic.LoadedScene == GameScenes.LOADING)
Expand Down
7 changes: 7 additions & 0 deletions Source/Tanks/TankDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ public class TankDefinition : IConfigNode
[Persistent]
public float maxUtilization = 0;

/// <summary>
/// When picking a new part from catalog, the definition with highest preference number will be set as the default type.
/// Use -1 to prevent a definition from being chosen. If all definitions have -1 then no preference-based override will happen.
/// </summary>
[Persistent]
public int orderOfPreference = -1;

public Dictionary<string, FuelTank> tankList = new Dictionary<string, FuelTank>();

public List<string> tags = new List<string>();
Expand Down
Loading