Skip to content

Commit

Permalink
Add button to load settings
Browse files Browse the repository at this point in the history
Useful for editing the settings file then loading it into a running game
(ie, no need to restart KSP).

Also, update the controls.
  • Loading branch information
taniwha committed Oct 23, 2021
1 parent 87f9c3b commit 33485a2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 34 deletions.
18 changes: 9 additions & 9 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static ELSettings current
}
}

void ParseUseKAC (ConfigNode settings)
static void ParseUseKAC (ConfigNode settings)
{
if (!settings.HasValue ("UseKAC")) {
var val = use_KAC;
Expand All @@ -103,7 +103,7 @@ void ParseUseKAC (ConfigNode settings)
use_KAC = uk;
}

void ParseKACAction (ConfigNode settings)
static void ParseKACAction (ConfigNode settings)
{
if (!settings.HasValue ("KACAction")) {
var val = KACAction.ToString();
Expand All @@ -130,15 +130,15 @@ void ParseKACAction (ConfigNode settings)
};
}

void UpdateToolbarButton ()
static void UpdateToolbarButton ()
{
ELAppButton.UpdateVisibility ();
if (ELToolbar_SettingsWindow.Instance != null) {
ELToolbar_SettingsWindow.Instance.UpdateVisibility ();
}
}

void ParsePreferBlizzy (ConfigNode settings)
static void ParsePreferBlizzy (ConfigNode settings)
{
if (!settings.HasValue ("PreferBlizzy")) {
var val = PreferBlizzy.ToString();
Expand All @@ -153,7 +153,7 @@ void ParsePreferBlizzy (ConfigNode settings)
UpdateToolbarButton ();
}

void ParseShowCraftHull (ConfigNode settings)
static void ParseShowCraftHull (ConfigNode settings)
{
if (!settings.HasValue ("ShowCraftHull")) {
var val = ShowCraftHull.ToString();
Expand All @@ -168,7 +168,7 @@ void ParseShowCraftHull (ConfigNode settings)
UpdateToolbarButton ();
}

void ParseDebugCraftHull (ConfigNode settings)
static void ParseDebugCraftHull (ConfigNode settings)
{
if (!settings.HasValue ("DebugCraftHull")) {
var val = DebugCraftHull.ToString();
Expand All @@ -183,7 +183,7 @@ void ParseDebugCraftHull (ConfigNode settings)
UpdateToolbarButton ();
}

void ParseWindowManager (ConfigNode settings)
static void ParseWindowManager (ConfigNode settings)
{
if (settings.HasNode ("WindowManager")) {
var node = settings.GetNode ("WindowManager");
Expand Down Expand Up @@ -216,7 +216,7 @@ public override void OnSave(ConfigNode config)

public static string DataPath { get; private set; }

void LoadGlobalSettings ()
public static void Load ()
{
use_KAC = true;
KACAction = KACWrapper.KACAPI.AlarmActionEnum.KillWarp;
Expand Down Expand Up @@ -245,7 +245,7 @@ public override void OnAwake ()
KIS_Present = KIS.KISWrapper.Initialize ();
B9Wings_Present = AssemblyLoader.loadedAssemblies.Any (a => a.assembly.GetName ().Name.Equals ("B9_Aerospace_WingStuff", StringComparison.InvariantCultureIgnoreCase));
FAR_Present = AssemblyLoader.loadedAssemblies.Any (a => a.assembly.GetName ().Name.Equals ("FerramAerospaceResearch", StringComparison.InvariantCultureIgnoreCase));
LoadGlobalSettings ();
Load ();

enabled = false;
}
Expand Down
1 change: 1 addition & 0 deletions Source/UI/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static class ELLocalization
public static string Name { get; } = "Name";
public static string OK { get; } = "OK";
public static string Load { get; } = "Load";
public static string LoadSettings { get; } = "Load Settings";
public static string Cancel { get; } = "Cancel";
public static string StartTransfer { get; } = "Start Transfer";
public static string StopTransfer { get; } = "Stop Transfer";
Expand Down
70 changes: 45 additions & 25 deletions Source/UI/SettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ELSettingsWindow : Window
ToggleText showCraftHull;
ToggleText debugCraftHull;
UIDropdown kacAction;
UIButton loadButton;

void SelectKACAction (int index)
{
Expand Down Expand Up @@ -89,6 +90,10 @@ public override void CreateUI()
.OnValueChanged (SelectKACAction)
.FlexibleLayout (true, true)
.Finish ()
.Add<UIButton> (out loadButton)
.Text (ELLocalization.LoadSettings)
.OnClick (LoadSettings)
.Finish ()

.Finish ();

Expand All @@ -107,43 +112,58 @@ void CloseWindow ()
ELWindowManager.HideSettingsWindow ();
}

void LoadSettings ()
{
ELSettings.Load ();
UpdateControls ();
}

public override void Style ()
{
base.Style ();
}

List<OptionData> kacActionNames;

void UpdateControls ()
{
if (kacActionNames == null) {
kacActionNames = new List<OptionData> ();
kacActionNames.Add (new OptionData (ELLocalization.KillWarpMessage));
kacActionNames.Add (new OptionData (ELLocalization.KillWarpOnly));
kacActionNames.Add (new OptionData (ELLocalization.MessageOnly));
kacActionNames.Add (new OptionData (ELLocalization.PauseGame));

kacAction.Options (kacActionNames);
}
preferBlizzy.SetIsOnWithoutNotify (ELSettings.PreferBlizzy);
createKACAlarms.SetIsOnWithoutNotify (ELSettings.use_KAC);
showCraftHull.SetIsOnWithoutNotify (ELSettings.ShowCraftHull);
debugCraftHull.SetIsOnWithoutNotify (ELSettings.DebugCraftHull);
int actionIndex = 0;
switch (ELSettings.KACAction) {
case KACWrapper.KACAPI.AlarmActionEnum.KillWarp:
actionIndex = 0;
break;
case KACWrapper.KACAPI.AlarmActionEnum.KillWarpOnly:
actionIndex = 1;
break;
case KACWrapper.KACAPI.AlarmActionEnum.MessageOnly:
actionIndex = 2;
break;
case KACWrapper.KACAPI.AlarmActionEnum.PauseGame:
actionIndex = 3;
break;
}
kacAction.SetValueWithoutNotify (actionIndex);
}

public void SetVisible (bool visible)
{
if (!visible) {
ELSettings.Save ();
} else {
if (kacActionNames == null) {
kacActionNames = new List<OptionData> ();
kacActionNames.Add (new OptionData (ELLocalization.KillWarpMessage));
kacActionNames.Add (new OptionData (ELLocalization.KillWarpOnly));
kacActionNames.Add (new OptionData (ELLocalization.MessageOnly));
kacActionNames.Add (new OptionData (ELLocalization.PauseGame));

kacAction.Options (kacActionNames);
}
int actionIndex = 0;
switch (ELSettings.KACAction) {
case KACWrapper.KACAPI.AlarmActionEnum.KillWarp:
actionIndex = 0;
break;
case KACWrapper.KACAPI.AlarmActionEnum.KillWarpOnly:
actionIndex = 1;
break;
case KACWrapper.KACAPI.AlarmActionEnum.MessageOnly:
actionIndex = 2;
break;
case KACWrapper.KACAPI.AlarmActionEnum.PauseGame:
actionIndex = 3;
break;
}
kacAction.SetValueWithoutNotify (actionIndex);
UpdateControls ();
}
gameObject.SetActive (visible);
}
Expand Down

0 comments on commit 33485a2

Please sign in to comment.