Skip to content
Open
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
Binary file modified GameData/KSPWheel/Plugin/KSPWheel.dll
Binary file not shown.
4 changes: 3 additions & 1 deletion VSProject/KSPWheel/KSPWheel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KSPWheel</RootNamespace>
<AssemblyName>KSPWheel</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand All @@ -21,6 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -30,6 +31,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
45 changes: 34 additions & 11 deletions VSProject/KSPWheel/PartModules/KSPWheelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public class KSPWheelBase : PartModule, IPartCostModifier, IPartMassModifier, IM
UI_FloatEdit(suppressEditorShipModified = true, minValue = 0.1f, maxValue = 10f, incrementLarge = 1f, incrementSmall = 0.25f, incrementSlide = 0.01f, sigFigs = 2)]
public float scale = 1f;

[KSPField(guiName = "Width", guiActive = false, guiActiveEditor = true, isPersistant = true, guiUnits = "x"),
UI_FloatEdit(suppressEditorShipModified = true, minValue = 0.1f, maxValue = 10f, incrementLarge = 1f, incrementSmall = 0.25f, incrementSlide = 0.01f, sigFigs = 2)]
public float width = 1f;

[KSPField]
public string scalingTransform = string.Empty;

Expand Down Expand Up @@ -248,6 +252,7 @@ public KSPWheelState wheelState
//serialize in editor/etc, should fix cloned-parts starting with improperly offset nodes
[SerializeField]
private float prevScale = 1f;
private float prevWidth = 1f;

private bool initializedWheels = false;

Expand Down Expand Up @@ -293,23 +298,33 @@ public void onShowUIUpdated(BaseField field, object obj)
Fields[nameof(wheelGroup)].guiActive = Fields[nameof(wheelGroup)].guiActiveEditor = showControls && showGUIWheelGroup;
Fields[nameof(antiRoll)].guiActive = Fields[nameof(antiRoll)].guiActiveEditor = showControls && showGUIAntiRoll;
Fields[nameof(scale)].guiActiveEditor = showControls && allowScaling && showGUIScale;
Fields[nameof(width)].guiActiveEditor = showControls && allowScaling && showGUIScale;
}

private void onScaleAdjusted(BaseField field, System.Object obj)
{
setScale(scale, true);
setScale(scale, width, true);
foreach (Part p in part.symmetryCounterparts)
{
p.GetComponent<KSPWheelBase>().setScale(scale, true);
p.GetComponent<KSPWheelBase>().setScale(scale, width, true);
}
}
private void onWidthAdjusted(BaseField field, System.Object obj)
{
setScale(scale, width, true);
foreach (Part p in part.symmetryCounterparts)
{
p.GetComponent<KSPWheelBase>().setScale(scale, width, true);
}
}

private void setScale(float newScale, bool userInput)
private void setScale(float newScale, float newWidth, bool userInput)
{
scale = newScale;
width = newWidth;
if (allowScaling)
{
Vector3 scale = new Vector3(newScale, newScale, newScale);
Vector3 scale = new Vector3(newScale * newWidth, newScale, newScale);
Transform modelRoot = part.transform.FindRecursive("model");
if (!string.IsNullOrEmpty(scalingTransform))
{
Expand All @@ -333,6 +348,7 @@ private void setScale(float newScale, bool userInput)
scale = newScale = 1f;
}
prevScale = newScale;

onScaleUpdated();
}

Expand Down Expand Up @@ -450,6 +466,12 @@ public override void OnStart(StartState state)
ufe.minValue = minScale;
ufe.maxValue = maxScale;

Fields[nameof(width)].uiControlEditor.onFieldChanged = onWidthAdjusted;
Fields[nameof(width)].guiActiveEditor = allowScaling;
UI_FloatEdit ufe2 = (UI_FloatEdit)Fields[nameof(width)].uiControlEditor;
ufe2.minValue = minScale;
ufe2.maxValue = maxScale;

bool frictionControlEnabled = HighLogic.CurrentGame.Parameters.CustomParams<KSPWheelSettings>().enableFrictionControl;
Callback<BaseField, System.Object> frictionAction = delegate (BaseField a, System.Object b)
{
Expand Down Expand Up @@ -774,7 +796,7 @@ private void initializeScaling()
{
if (initializedScaling) { return; }
initializedScaling = true;
setScale(scale, false);
setScale(scale, width, false);
}

private void updateSuspension()
Expand Down Expand Up @@ -900,14 +922,15 @@ private void onScaleUpdated()
{
KSPWheelScaleSettings scales = HighLogic.CurrentGame.Parameters.CustomParams<KSPWheelScaleSettings>();
float localScale = scale * part.rescaleFactor;
partMassScaleFactor = Mathf.Pow(localScale, scales.partMassScalingPower);
partCostScaleFactor = Mathf.Pow(localScale, scales.partCostScalingPower);
wheelMassScaleFactor = Mathf.Pow(localScale, scales.wheelMassScalingPower);
wheelMaxLoadScalingFactor = Mathf.Pow(localScale, scales.wheelMaxLoadScalingPower);
float localWidth = width;
partMassScaleFactor = Mathf.Pow(localScale, scales.partMassScalingPower) * localWidth;
partCostScaleFactor = Mathf.Pow(localScale, scales.partCostScalingPower) * localWidth;
wheelMassScaleFactor = Mathf.Pow(localScale, scales.wheelMassScalingPower) * localWidth;
wheelMaxLoadScalingFactor = Mathf.Pow(localScale, scales.wheelMaxLoadScalingPower) * localWidth;
wheelMaxSpeedScalingFactor = Mathf.Pow(localScale, scales.wheelMaxSpeedScalingPower);
motorMaxRPMScalingFactor = Mathf.Pow(localScale, scales.motorMaxRPMScalingPower);
motorPowerScalingFactor = Mathf.Pow(localScale, scales.motorPowerScalingPower);
motorTorqueScalingFactor = Mathf.Pow(localScale, scales.motorTorqueScalingPower);
motorPowerScalingFactor = Mathf.Pow(localScale, scales.motorPowerScalingPower) * localWidth;
motorTorqueScalingFactor = Mathf.Pow(localScale, scales.motorTorqueScalingPower) * localWidth;
}
if (wheelData != null)
{
Expand Down