-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code from Rememberer mod at mod author @Krazy1 request, rememb…
…ers the last sort setting for the Editor part list. Original thread: https://forum.kerbalspaceprogram.com/index.php?/topic/203114-rememberer/&tab=comments#comment-3991624 Minor optimization of Rememberer initialization code Rememberer is automatically disabled if PRUNE is found
- Loading branch information
1 parent
06c87dd
commit 18f1500
Showing
7 changed files
with
100 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"VERSION": { | ||
"MAJOR": 3, | ||
"MINOR": 4, | ||
"PATCH": 2, | ||
"PATCH": 3, | ||
"BUILD": 0 | ||
}, | ||
"KSP_VERSION_MIN": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ | |
|
||
using System.Reflection; | ||
|
||
[assembly: AssemblyVersion("3.4.1.1")] | ||
[assembly: AssemblyVersion("3.4.2.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using UnityEngine; | ||
using KSP.UI.Screens; // has EditorPartList | ||
|
||
namespace Rememberer | ||
{ | ||
|
||
[KSPAddon(KSPAddon.Startup.EditorAny, false)] | ||
public class RememEditor : MonoBehaviour | ||
{ | ||
private static bool sortAsc = true; | ||
private static int sortIndex = 1; | ||
private static ConfigNode nodeFile = null; | ||
private static bool disabled = false; | ||
|
||
// capture part list sort method change | ||
private void SortCB(int index, bool asc) | ||
{ | ||
sortIndex = index; | ||
sortAsc = asc; | ||
} | ||
|
||
const string FILE = "GameData/EditorExtensionsRedux/RememEditor.cfg"; | ||
const string SORTASC_NAME = "partListSortAsc"; | ||
const string SORTINDEX_NAME = "partListSortIndex"; | ||
|
||
static public bool hasMod(string modIdent) | ||
{ | ||
foreach (AssemblyLoader.LoadedAssembly a in AssemblyLoader.loadedAssemblies) | ||
{ | ||
if (modIdent == a.name) | ||
return true; | ||
|
||
} | ||
return false; | ||
} | ||
|
||
|
||
|
||
public void Start() | ||
{ | ||
if (disabled) | ||
return; | ||
if (nodeFile == null) | ||
{ | ||
if (hasMod("PRUNE")) | ||
{ | ||
disabled = true; | ||
return; | ||
} | ||
EditorExtensionsRedux.Log.Info("RememEditor - Start"); | ||
|
||
// Imports initial sort settings from config file into a default "root" Config Node | ||
nodeFile = ConfigNode.Load(KSPUtil.ApplicationRootPath + FILE); | ||
sortAsc = Convert.ToBoolean(nodeFile.GetValue(SORTASC_NAME)); // true: ascending, false: descending | ||
sortIndex = Convert.ToInt32(nodeFile.GetValue(SORTINDEX_NAME)); // 0: mame, 1: mass, 2: cost, 3: size | ||
|
||
// set initial sort method | ||
EditorPartList.Instance.partListSorter.ClickButton(sortIndex); | ||
if (!sortAsc) | ||
{ | ||
EditorPartList.Instance.partListSorter.ClickButton(sortIndex); | ||
} | ||
} | ||
//Track the user's sort changes | ||
EditorPartList.Instance.partListSorter.AddOnSortCallback(SortCB); | ||
} | ||
|
||
public void OnDisable() | ||
{ | ||
if (nodeFile == null) | ||
return; | ||
|
||
EditorExtensionsRedux.Log.Info("RememEditor - Disable"); | ||
nodeFile.SetValue(SORTASC_NAME, sortAsc.ToString()); | ||
nodeFile.SetValue(SORTINDEX_NAME, sortIndex.ToString()); | ||
nodeFile.Save(KSPUtil.ApplicationRootPath + FILE); | ||
//EditorPartList is already disabled when OnDisable is called so remove callback gives NRE | ||
//EditorPartList.Instance.partListSorter.RemoveOnSortCallback(SortCB); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters