Skip to content

Commit

Permalink
Ensure only one callback is called
Browse files Browse the repository at this point in the history
KSP 1.10.1 brought back the file selected callback, but this messes with
the multi-version fix, so if the new callback exists, don't set the old.
What a mess.
  • Loading branch information
taniwha committed Aug 27, 2020
1 parent d315aa0 commit ae90718
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Source/GUI/CraftBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class ELCraftBrowser : CraftBrowserDialog
[SerializeField]
private Toggle tabSub;

private SelectFileCallback onFileSelected;

static EditorFacility []craftFacility = new EditorFacility[] {
EditorFacility.VAB,
EditorFacility.SPH,
Expand Down Expand Up @@ -148,7 +150,7 @@ static void CreatePrefab ()
void selCB (ConfigNode n, LoadType t)
{
Debug.Log($"[CraftBrowserDialog] OnConfigNodeSelected - " + selectedEntry.fullFilePath);
OnFileSelected(selectedEntry.fullFilePath, t);
onFileSelected(selectedEntry.fullFilePath, t);
}

public static ELCraftBrowser Spawn (ELCraftType type, string profile, SelectFileCallback onFileSelected, CancelledCallback onCancel, bool showMergeOption)
Expand All @@ -164,10 +166,12 @@ public static ELCraftBrowser Spawn (ELCraftType type, string profile, SelectFile
cb.facility = craftFacility[(int) type];
cb.showMergeOption = showMergeOption;
cb.OnBrowseCancelled = onCancel;
cb.OnFileSelected = onFileSelected;
cb.onFileSelected = onFileSelected;
if (onConfigNodeSelected != null) {
var callback = Delegate.CreateDelegate (onConfigNodeSelected.FieldType, cb, typeof(ELCraftBrowser).GetMethod("selCB", bindingFlags));
onConfigNodeSelected.SetValue (cb, callback);
} else {
cb.OnFileSelected = onFileSelected;
}
cb.title = "Select a craft to load";
cb.profile = profile;
Expand Down

0 comments on commit ae90718

Please sign in to comment.