Skip to content

Commit

Permalink
Remove unnecessary UI updates
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Jul 25, 2024
1 parent 14e95d2 commit 94f890b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
8 changes: 6 additions & 2 deletions Source/ProceduralFairings/FairingSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ public override void OnLoad(ConfigNode node)
ReadBaseCurveFromVec4(false);
ReadNoseCurveFromVec4(false);
}

SetDensityField();
}

public override void OnStart(StartState state)
Expand Down Expand Up @@ -247,6 +245,8 @@ public override void OnStartFinished(StartState state)

private void SetDensityField()
{
if (!HighLogic.LoadedSceneIsEditor) return;

var floatRange = Fields[nameof(density)].uiControlEditor as UI_FloatRange;
floatRange.minValue = minDensity;
floatRange.maxValue = maxDensity;
Expand All @@ -265,6 +265,8 @@ private void ApplyShapeOnStart()

void SetUICallbacks()
{
if (!HighLogic.LoadedSceneIsEditor) return;

Fields[nameof(usePreset)].uiControlEditor.onFieldChanged += OnUsePresetToggled;
Fields[nameof(usePreset)].uiControlEditor.onSymmetryFieldChanged += OnUsePresetToggled;

Expand Down Expand Up @@ -344,6 +346,8 @@ internal void ReadNoseCurveFromVec4(bool fromPrefab = false)

void SetUIFieldVisibility()
{
if (!HighLogic.LoadedSceneIsEditor) return;

Fields[nameof(shapePreset)].guiActiveEditor = AllPresets.Count > 0 && usePreset;

Fields[nameof(baseCurveStartX)].guiActiveEditor = !usePreset;
Expand Down
36 changes: 23 additions & 13 deletions Source/ProceduralFairings/NodeNumberTweaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,7 @@ public override void OnStart(StartState state)
{
base.OnStart(state);

(Fields[nameof(radius)].uiControlEditor as UI_FloatEdit).incrementLarge = radiusStepLarge;
(Fields[nameof(radius)].uiControlEditor as UI_FloatEdit).incrementSmall = radiusStepSmall;
Fields[nameof(radius)].guiActiveEditor = shouldResizeNodes;
Fields[nameof(radius)].uiControlEditor.onFieldChanged += OnRadiusChanged;
Fields[nameof(radius)].uiControlEditor.onSymmetryFieldChanged += OnRadiusChanged;

// Change the GUI text if there are no fairing attachment nodes.
if (part.FindAttachNodes("connect") == null)
Fields[nameof(uiNumNodes)].guiName = "Side Nodes";

(Fields[nameof(uiNumNodes)].uiControlEditor as UI_FloatRange).maxValue = maxNumber;
Fields[nameof(uiNumNodes)].uiControlEditor.onFieldChanged += OnNumNodesChanged;
Fields[nameof(uiNumNodes)].uiControlEditor.onSymmetryFieldChanged += OnNumNodesChanged;
SetupUI();

uiNumNodes = numNodes;
numNodesBefore = numNodes;
Expand Down Expand Up @@ -102,6 +90,28 @@ private System.Collections.IEnumerator EditorChangeDetector()
}
}

private void SetupUI()
{
// Change the GUI text if there are no fairing attachment nodes.
if (part.FindAttachNodes("connect") == null)
Fields[nameof(uiNumNodes)].guiName = "Side Nodes";

if (HighLogic.LoadedSceneIsEditor)
{
Fields[nameof(radius)].uiControlEditor.onFieldChanged += OnRadiusChanged;
Fields[nameof(radius)].uiControlEditor.onSymmetryFieldChanged += OnRadiusChanged;

Fields[nameof(uiNumNodes)].uiControlEditor.onFieldChanged += OnNumNodesChanged;
Fields[nameof(uiNumNodes)].uiControlEditor.onSymmetryFieldChanged += OnNumNodesChanged;

(Fields[nameof(radius)].uiControlEditor as UI_FloatEdit).incrementLarge = radiusStepLarge;
(Fields[nameof(radius)].uiControlEditor as UI_FloatEdit).incrementSmall = radiusStepSmall;
Fields[nameof(radius)].guiActiveEditor = shouldResizeNodes;

(Fields[nameof(uiNumNodes)].uiControlEditor as UI_FloatRange).maxValue = maxNumber;
}
}

public void OnRadiusChanged(BaseField f, object obj)
{
UpdateNodePositions(true);
Expand Down

0 comments on commit 94f890b

Please sign in to comment.