/// <summary>
        /// Load the saved priorities
        /// </summary>
        /// <returns></returns>
        internal static Dictionary <string, ModDelegateDefinition> LoadUserPriority()
        {
            Log.Info("LoadUserPriority");
            Dictionary <string, ModDelegateDefinition> allSavedDelegateRef = new Dictionary <string, ModDelegateDefinition>();

            if (System.IO.File.Exists(KSPUtil.ApplicationRootPath + Constants.SAVED_PRIORITIES_FILE))
            {
                ConfigNode file = ConfigNode.Load(KSPUtil.ApplicationRootPath + Constants.SAVED_PRIORITIES_FILE);
                ConfigNode node = file.GetNode(Constants.MODNAME);
                foreach (var buttonNode in node.GetNodes())
                {
                    int    userPriority = int.Parse(buttonNode.GetValue("userPriority"));
                    string modName      = buttonNode.GetValue("modName");

                    GameScenes scene = GameScenes.CREDITS;
                    buttonNode.TryGetEnum("scene", ref scene, GameScenes.CREDITS);

                    ModDelegateDefinition mdd = new ModDelegateDefinition(userPriority, modName, scene);
                    //mdd.scene = scene;

                    {
                        Log.Info("User Priority Loaded: " + mdd.userPriority + ", modName: " + mdd.modName + ", scene: " + mdd.scene.ToString() + ",  UniqueKey: " + mdd.UniqueKey);
                    }
                    allSavedDelegateRef.Add(mdd.UniqueKey, mdd);
                }
            }
            return(allSavedDelegateRef);
        }
        /// <summary>
        /// Adds a new listener to a specified button
        /// </summary>
        /// <param name="button">Game button</param>
        /// <param name="delegateMethod">Method to call in the mod when this button is pressed</param>
        /// <param name="modName"></param>
        /// <param name="modDisplayName"></param>
        /// <param name="priority"></param>
        /// <returns>delegateID assigned to this listener</returns>
        public static int AddListener(UnityEngine.UI.Button button, UnityAction delegateMethod, string modName, string modDisplayName, int priority = 5)
        {
            if (HighLogic.CurrentGame.Parameters.CustomParams <BM>().debugMode)
            {
                Log.Detail("AddListener: " + modName);
            }

            string uniqueKey = SceneButton.GetUniqueKey(HighLogic.LoadedScene, button.gameObject.name);

            if (!activeSceneButtons.ContainsKey(uniqueKey))
            {
                Log.Error("Unknown button passed in to AddListener");
                return(-1);
            }

            priority = Math.Max(Math.Min(priority, 10), 1);

            var bd = new ModDelegateDefinition(button, activeSceneButtons[uniqueKey].sortedListRef.Count, priority, delegateMethod, modName, modDisplayName);

            if (allSavedDelegateRef.ContainsKey(bd.UniqueKey))
            {
                bd.userPriority = allSavedDelegateRef[bd.UniqueKey].userPriority;
                allSavedDelegateRef.Remove(bd.UniqueKey);
            }
            Log.Info("AddListener 2");

            if (allDelegateRef.ContainsKey(bd.UniqueKey))
            {
                Log.Info("AddListener 2.1");
                var oldBd = allDelegateRef[bd.UniqueKey];
                oldBd.UpdateButton(button);
                if (oldBd.SortKey != "")
                {
                    string sortKey = oldBd.SortKey;
                    activeSceneButtons[uniqueKey].sortedListRef.Add(oldBd.SortKey, oldBd);
                }
            }
            else
            {
                Log.Info("AddListener 2.2");
                allDelegateRef.Add(bd.UniqueKey, bd);
                string sortKey = bd.SortKey;
                activeSceneButtons[uniqueKey].sortedListRef.Add(bd.SortKey, bd);
            }

            return(activeSceneButtons[uniqueKey].id);
        }
        void Display(int id)
        {
            if (BtnManager.activeSceneButtons.Count == 1)
            {
                selectedButtonMods = BtnManager.activeSceneButtons.Values.First();
            }
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();

            GUILayout.Label("Select Button:");

            btnScrollPos = GUILayout.BeginScrollView(btnScrollPos);
            foreach (ButtonManager.SceneButton b in BtnManager.activeSceneButtons.Values)
            {
                var s = b.buttonObjectName;
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(s))
                {
                    selectedButtonMods = b;
                    resortNeeded       = true;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();

            GUILayout.EndVertical();

            if (selectedButtonMods != null && resortNeeded)
            {
                selectedButtonMods.resortList();
                ModDelegateDefinition.SaveUserPriority(BtnManager.allSavedDelegateRef);
                resortNeeded = false;
            }

            GUILayout.BeginVertical();
            if (selectedButtonMods != null)
            {
                modScrollPos = GUILayout.BeginScrollView(modScrollPos);
                foreach (var m in selectedButtonMods.sortedListRef)
                {
                    ModDelegateDefinition bdd = null; // =  BtnManager.activeSceneButtons[br.uniqueKey];
                    bdd = m.Value;
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(bdd.modDisplayName + ":" + bdd.userPriority);
                        GUILayout.BeginVertical();
                        if (GUILayout.Button(upArrow, buttonStyleUp, GUILayout.Width(butW)))
                        {
                            bdd.userPriority++;
                            resortNeeded = true;
                        }
                        if (GUILayout.Button(downArrow, buttonStyleDown, GUILayout.Width(butW)))
                        {
                            bdd.userPriority--;
                            resortNeeded = true;
                        }
                        GUILayout.EndVertical();
                        GUILayout.EndHorizontal();
                    }
                }
                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("No button selected");
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("OK"))
            {
                isVisible = false;
            }
            GUILayout.EndHorizontal();
            GUI.DragWindow();
        }