Skip to content

Commit

Permalink
KSP 1.4.3 update
Browse files Browse the repository at this point in the history
* Move some UI code outside of the FixedUpdate () methods.
* Fix the fairing side staging icon states.
* Trim some useless code.
  • Loading branch information
PhineasFreak committed May 1, 2018
1 parent 71eb3d4 commit ae4aeb0
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 126 deletions.
Binary file modified GameData/ProceduralFairings/Plugins/ProceduralFairings.dll
Binary file not shown.
8 changes: 8 additions & 0 deletions GameData/ProceduralFairings/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
=======================================================
ProceduralFairings v1.4.3-1 for KSP 1.4.3 (2018-05-02)
=======================================================

• Recompiled for KSP 1.4.3.
• Fixed the fairing decouplers breaking the MechJeb delta-v calculations.
• Fixed (possibly) the UI of the Fairing Bases and Interstage Adapters locking up and being unable to toggle between automatic and manual fairing side shape.

=======================================================
ProceduralFairings v1.4.1-1 for KSP 1.4.1 (2018-03-14)
=======================================================
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ You should have received a copy of the license along with this work. If not, vis
[PF:contributor-rsparkyc-link]: https://github.com/rsparkyc
[PF:original-forum-link]: http://forum.kerbalspaceprogram.com/index.php?showtopic=36371
[PF:shield-license]: https://img.shields.io/badge/License-CC--BY%204.0-green.svg
[PF:shield-version]: https://img.shields.io/badge/KSP%20Version-1.4.1.2089-red.svg
[PF:shield-version]: https://img.shields.io/badge/KSP%20Version-1.4.3.2152-red.svg
64 changes: 29 additions & 35 deletions Source/ProceduralFairings/FairingBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public class ProceduralFairingBase : PartModule

Part topBasePart;

float lastManualMaxSize, lastManualCylStart, lastManualCylEnd;

LineRenderer line;

readonly List<LineRenderer> outline = new List<LineRenderer>();
Expand Down Expand Up @@ -109,6 +107,8 @@ public override void OnStart (StartState state)

ShowHideInterstageNodes ();

recalcShape ();

updateDelay = 0.1f;

needShapeUpdate = true;
Expand All @@ -135,29 +135,45 @@ public override void OnStart (StartState state)
}

SetUIChangedCallBacks ();

OnToggleAutoshapeUI ();
}

void SetUIChangedCallBacks ()
{
((UI_Toggle) Fields["autoShape"].uiControlEditor).onFieldChanged += UIChanged;
((UI_Toggle) Fields["autoShape"].uiControlEditor).onFieldChanged += OnChangeAutoshapeUI;

((UI_FloatEdit) Fields["manualMaxSize"].uiControlEditor).onFieldChanged += UIChanged;
((UI_FloatEdit) Fields["manualCylStart"].uiControlEditor).onFieldChanged += UIChanged;
((UI_FloatEdit) Fields["manualCylEnd"].uiControlEditor).onFieldChanged += UIChanged;
((UI_FloatEdit) Fields["manualMaxSize"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatEdit) Fields["manualCylStart"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatEdit) Fields["manualCylEnd"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
}

bool uiChanged_SomeFields = true;
void OnChangeAutoshapeUI (BaseField bf, object obj)
{
OnToggleAutoshapeUI ();

needShapeUpdate = true;
}

void UIChanged (BaseField bf, object obj)
void OnToggleAutoshapeUI ()
{
uiChanged_SomeFields = true;
Fields["manualMaxSize"].guiActiveEditor = !autoShape;
Fields["manualCylStart"].guiActiveEditor = !autoShape;
Fields["manualCylEnd"].guiActiveEditor = !autoShape;

PFUtils.refreshPartWindow ();
}

void onEditorVesselModified (ShipConstruct ship)
void OnChangeShapeUI (BaseField bf, object obj)
{
needShapeUpdate = true;
}

void onEditorVesselModified (ShipConstruct ship)
{
ShowHideInterstageNodes ();

needShapeUpdate = true;
}

public void ShowHideInterstageNodes ()
Expand Down Expand Up @@ -286,7 +302,7 @@ IEnumerator<YieldInstruction> createAutoStruts (List<Part> shieldedParts)
}
}

public void onShieldingDisabled(List<Part> shieldedParts)
public void onShieldingDisabled (List<Part> shieldedParts)
{
removeJoints ();
}
Expand Down Expand Up @@ -427,27 +443,6 @@ public void Update ()
{
if (HighLogic.LoadedSceneIsEditor)
{
if (uiChanged_SomeFields)
{
uiChanged_SomeFields = false;

needShapeUpdate |= (!lastManualMaxSize.Equals (manualMaxSize)
|| !lastManualCylStart.Equals (manualCylStart)
|| !lastManualCylEnd.Equals (manualCylEnd));

lastManualMaxSize = manualMaxSize;
lastManualCylStart = manualCylStart;
lastManualCylEnd = manualCylEnd;

bool old = Fields["manualMaxSize"].guiActiveEditor;

Fields["manualMaxSize"].guiActiveEditor = !autoShape;
Fields["manualCylStart"].guiActiveEditor = !autoShape;
Fields["manualCylEnd"].guiActiveEditor = !autoShape;

PFUtils.refreshPartWindow ();
}

if (updateDelay > 0)
{
updateDelay -= Time.deltaTime;
Expand All @@ -457,10 +452,9 @@ public void Update ()
if (needShapeUpdate)
{
needShapeUpdate = false;
updateDelay = 0.1f;

recalcShape ();

updateDelay = 0.5f;
}
}
}
Expand Down Expand Up @@ -652,7 +646,7 @@ AttachNode HasNodeComponent<type> (AttachNode [] nodes)
return null;
}

void recalcShape ()
public void recalcShape ()
{
var scan = scanPayload ();

Expand Down
18 changes: 17 additions & 1 deletion Source/ProceduralFairings/FairingDecoupler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class ProceduralFairingDecoupler : PartModule

bool didForce;

bool decouplerStagingSet = true;

[KSPField] public string ejectSoundUrl = "Squad/Sounds/sound_decoupler_fire";
public FXGroup ejectFx;

Expand All @@ -37,7 +39,7 @@ public class ProceduralFairingDecoupler : PartModule
public float torqueAmount = 0.01f;

[KSPField (isPersistant = true, guiActiveEditor = true, guiName = "Fairing Decoupler")]
[UI_Toggle (disabledText = "Off", enabledText = "On")]
[UI_Toggle (disabledText = "Off", enabledText = "On", affectSymCounterparts = UI_Scene.All)]
public bool fairingStaged = true;

[KSPAction ("Jettison Fairing", actionGroup = KSPActionGroup.None)]
Expand All @@ -48,6 +50,20 @@ public void ActionJettison (KSPActionParam param)

public void FixedUpdate ()
{
// More hacky-hacky: for some reason the staging icons cannot be updated correctly
// via the OnStart () method but require an additional update here. This snippet
// sets the staging icon states one more time after transitioning a scene.

if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor)
{
if (decouplerStagingSet)
{
OnSetStagingIcons ();

decouplerStagingSet = false;
}
}

if (decoupled)
{
if (part.parent)
Expand Down
108 changes: 52 additions & 56 deletions Source/ProceduralFairings/FairingSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public class ProceduralFairingSide : PartModule, IPartCostModifier, IPartMassMod

public float totalMass;

public bool updateUICheck = true;

[KSPField (isPersistant = true)] public int numSegs = 12;
[KSPField (isPersistant = true)] public int numSideParts = 2;
[KSPField (isPersistant = true)] public float baseRad;
Expand Down Expand Up @@ -191,6 +189,8 @@ public override void OnStart (StartState state)
// Set up the GUI update callbacks.

OnUpdateFairingSideUI ();

OnToggleFairingShapeUI ();
}

public override void OnLoad (ConfigNode cfg)
Expand All @@ -205,30 +205,30 @@ public override void OnLoad (ConfigNode cfg)

void OnUpdateFairingSideUI ()
{
((UI_Toggle) Fields["baseAutoShape"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_Toggle) Fields["noseAutoShape"].uiControlEditor).onFieldChanged += OnUpdateUI;

((UI_FloatEdit) Fields["baseCurveStartX"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_FloatEdit) Fields["baseCurveStartY"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_FloatEdit) Fields["baseCurveEndX"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_FloatEdit) Fields["baseCurveEndY"].uiControlEditor).onFieldChanged += OnUpdateUI;

((UI_FloatEdit) Fields["noseCurveStartX"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_FloatEdit) Fields["noseCurveStartY"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_FloatEdit) Fields["noseCurveEndX"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_FloatEdit) Fields["noseCurveEndY"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_FloatEdit) Fields["noseHeightRatio"].uiControlEditor).onFieldChanged += OnUpdateUI;

((UI_FloatRange) Fields["baseConeSegments"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_FloatRange) Fields["noseConeSegments"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_FloatRange) Fields["density"].uiControlEditor).onFieldChanged += OnUpdateUI;
((UI_Toggle) Fields["baseAutoShape"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_Toggle) Fields["noseAutoShape"].uiControlEditor).onFieldChanged += OnChangeShapeUI;

((UI_FloatEdit) Fields["baseCurveStartX"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatEdit) Fields["baseCurveStartY"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatEdit) Fields["baseCurveEndX"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatEdit) Fields["baseCurveEndY"].uiControlEditor).onFieldChanged += OnChangeShapeUI;

((UI_FloatEdit) Fields["noseCurveStartX"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatEdit) Fields["noseCurveStartY"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatEdit) Fields["noseCurveEndX"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatEdit) Fields["noseCurveEndY"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatEdit) Fields["noseHeightRatio"].uiControlEditor).onFieldChanged += OnChangeShapeUI;

((UI_FloatRange) Fields["baseConeSegments"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatRange) Fields["noseConeSegments"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
((UI_FloatRange) Fields["density"].uiControlEditor).onFieldChanged += OnChangeShapeUI;
}

void OnUpdateUI (BaseField bf, object obj)
void OnChangeShapeUI (BaseField bf, object obj)
{
// Set the default values of the fairing side base parameters if the auto-shape is enabled.

if (baseAutoShape.Equals (true))
if (baseAutoShape)
{
baseCurveStartX = defaultBaseCurveStartX;
baseCurveStartY = defaultBaseCurveStartY;
Expand All @@ -239,7 +239,7 @@ void OnUpdateUI (BaseField bf, object obj)

// Set the default values of the fairing side nose parameters if the auto-shape is enabled.

if (noseAutoShape.Equals (true))
if (noseAutoShape)
{
noseCurveStartX = defaultNoseCurveStartX;
noseCurveStartY = defaultNoseCurveStartY;
Expand All @@ -249,7 +249,36 @@ void OnUpdateUI (BaseField bf, object obj)
noseHeightRatio = defaultNoseHeightRatio;
}

updateUICheck = true;
// Set the state of the advanced fairing side base and nose options.

OnToggleFairingShapeUI ();

// Update the fairing shape.

var fairingSide = part.GetComponent<ProceduralFairingBase>();

if (fairingSide != null)
{
// Rebuild the fairing mesh.

fairingSide.needShapeUpdate = true;
}
}

void OnToggleFairingShapeUI ()
{
Fields["baseCurveStartX"].guiActiveEditor = !baseAutoShape;
Fields["baseCurveStartY"].guiActiveEditor = !baseAutoShape;
Fields["baseCurveEndX"].guiActiveEditor = !baseAutoShape;
Fields["baseCurveEndY"].guiActiveEditor = !baseAutoShape;
Fields["baseConeSegments"].guiActiveEditor = !baseAutoShape;

Fields["noseCurveStartX"].guiActiveEditor = !noseAutoShape;
Fields["noseCurveStartY"].guiActiveEditor = !noseAutoShape;
Fields["noseCurveEndX"].guiActiveEditor = !noseAutoShape;
Fields["noseCurveEndY"].guiActiveEditor = !noseAutoShape;
Fields["noseHeightRatio"].guiActiveEditor = !noseAutoShape;
Fields["noseConeSegments"].guiActiveEditor = !noseAutoShape;
}

public void updateNodeSize ()
Expand Down Expand Up @@ -290,39 +319,6 @@ public void FixedUpdate ()
massDisplay = PFUtils.formatMass (totalMass * (nsym + 1)) + " (all " + (nsym + 1) + ")";
costDisplay = PFUtils.formatCost ((part.partInfo.cost + GetModuleCost (part.partInfo.cost, ModifierStagingSituation.CURRENT)) * (nsym + 1)) + " (all " + (nsym + 1) + ")";
}

// Check for GUI changes and update the fairing shape if applicable.

if (updateUICheck.Equals (true))
{
// Set the state of the advanced fairing base and nose options.

Fields["baseCurveStartX"].guiActiveEditor = !baseAutoShape;
Fields["baseCurveStartY"].guiActiveEditor = !baseAutoShape;
Fields["baseCurveEndX"].guiActiveEditor = !baseAutoShape;
Fields["baseCurveEndY"].guiActiveEditor = !baseAutoShape;
Fields["baseConeSegments"].guiActiveEditor = !baseAutoShape;

Fields["noseCurveStartX"].guiActiveEditor = !noseAutoShape;
Fields["noseCurveStartY"].guiActiveEditor = !noseAutoShape;
Fields["noseCurveEndX"].guiActiveEditor = !noseAutoShape;
Fields["noseCurveEndY"].guiActiveEditor = !noseAutoShape;
Fields["noseHeightRatio"].guiActiveEditor = !noseAutoShape;
Fields["noseConeSegments"].guiActiveEditor = !noseAutoShape;

var fairingSide = part.GetComponent<ProceduralFairingBase>();

if (fairingSide)
{
// Rebuild the fairing mesh.

fairingSide.needShapeUpdate = true;

// Tag as done.

updateUICheck = false;
}
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions Source/ProceduralFairings/NodeNumberTweaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ public void Update ()
continue;
}

// Fix for ghost node when inserting a new pf base in VAB.
// do not delete unused nodes, move them away instead
// be careful to check references to maximum number of nodes
// mentioned elsewhere retrieved from 'Findattachnodes("connect")'!
// Slightly hacky, but works...
// Fix for ghost node when inserting a new PF base in
// the editor scene: do not delete unused nodes, move
// them away instead. Be careful to check references
// of the maximum number of nodes, mentioned elsewhere
// and retrieved via 'Findattachnodes("connect")'!
// Slightly hacky, but it works...

HideUnusedNode (node);

Expand All @@ -102,7 +103,7 @@ public void Update ()
if (fbase)
{
fbase.needShapeUpdate = true;
fbase.updateDelay = 0;
fbase.updateDelay = 0.5f;
}
}
}
Expand Down Expand Up @@ -344,5 +345,4 @@ void updateNodePositions ()
}
}
}

}
Loading

0 comments on commit ae4aeb0

Please sign in to comment.