Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ DYNAMICBATTERYSTORAGE
// Field to poll in editor
editorFieldName = CurrentElectricalGeneration
// Field to poll in flight
flightFieldName = MaximumElectricalGeneration
flightFieldName = MaxElectricalGeneration
// Multiply the output by these if you need to. Convention is that a consumer is negative.
editorValueScalar = 1.0
flightValueScalar = 1.0
Expand Down
Binary file modified GameData/DynamicBatteryStorage/Plugins/DynamicBatteryStorage.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"MAJOR":2,
"MINOR":3,
"PATCH":6,
"PATCH":7,
"BUILD":0
},
"KSP_VERSION":
Expand Down
4 changes: 2 additions & 2 deletions Source/DynamicBatteryStorage/UI/SystemsMonitorUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ protected void OnGUIAppLauncherReady()
showWindow = false;

Utils.Log("[SystemsMonitorUI]: App Launcher Ready", Utils.LogType.UI);
if (ApplicationLauncher.Ready && stockToolbarButton == null)
if (ApplicationLauncher.Ready && stockToolbarButton == null && Settings.Enabled)
{
if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor)
stockToolbarButton = ApplicationLauncher.Instance.AddModApplication(
Expand Down Expand Up @@ -293,7 +293,7 @@ public void ResetAppLauncher()

Utils.Log("[SystemsMonitorUI]: Reset App Launcher", Utils.LogType.UI);
FindData();
if (stockToolbarButton == null)
if (stockToolbarButton == null && Settings.Enabled)
{
stockToolbarButton = ApplicationLauncher.Instance.AddModApplication(
OnToolbarButtonOn,
Expand Down
43 changes: 41 additions & 2 deletions Source/DynamicBatteryStorage/UI/ToolbarAdvanced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,25 @@ public void Initialize(Transform root, ToolbarPanel parentPanel)
constantOnButton.onClick.AddListener(delegate { SetConstantState(true); });

userConsumptionInput.contentType = InputField.ContentType.DecimalNumber;
userConsumptionInput.characterValidation = InputField.CharacterValidation.Decimal;
userConsumptionInput.onValueChanged.AddListener(delegate { OnManualGenerationChange(); });
userGenerationInput.contentType = InputField.ContentType.DecimalNumber;
userGenerationInput.characterValidation = InputField.CharacterValidation.Decimal;
userGenerationInput.onValueChanged.AddListener(delegate { OnManualGenerationChange(); });


SectionEnabled = false;
advancedObject.SetActive(false);
dbsObject.SetActive(false);
Localize();

SetupTooltips(root, Tooltips.FindTextTooltipPrefab());
}
protected void OnDestroy()
{

InputLockManager.RemoveControlLock("DBSFocus");
}
protected void Localize()
{
headerText.text = Localizer.Format("#LOC_DynamicBatteryStorage_AdvancedPanel_AdvancedTitle");
Expand Down Expand Up @@ -189,6 +197,22 @@ public void Update(VesselElectricalData data)
protected void UpdateAdvanced()
{
/// what, all event driven? you monster
if (userGenerationInput.isFocused || userConsumptionInput
.isFocused)
{
if (InputLockManager.IsUnlocked(ControlTypes.KEYBOARDINPUT))
{
InputLockManager.SetControlLock(ControlTypes.KEYBOARDINPUT, "DBSFocus");
}

}
else
{
if (InputLockManager.IsLocked(ControlTypes.KEYBOARDINPUT))
{
InputLockManager.RemoveControlLock("DBSFocus");
}
}
}
protected void UpdateDBS()
{
Expand Down Expand Up @@ -269,7 +293,22 @@ public void SetTabState(bool state)
}
public void OnManualGenerationChange()
{
mainPanel.PowerUI.SetManualPowerInputs(float.Parse(userGenerationInput.text), float.Parse(userConsumptionInput.text));


mainPanel.PowerUI.SetManualPowerInputs(
ValidateManualInput(userGenerationInput),
ValidateManualInput(userConsumptionInput));
}

protected float ValidateManualInput(InputField handler)
{
string input = handler.text;

if (!float.TryParse(input, out float result))
{
result = 0f;
}
return result;
}
public void SetConstantState(bool state)
{
Expand Down
10 changes: 8 additions & 2 deletions Source/DynamicBatteryStorage/UI/ToolbarPower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,14 @@ protected void UpdatePowerFlowAndBatteryFields(VesselElectricalData data)
double netPower = data.CurrentConsumption + data.GetSimulatedElectricalProdution() + userGeneration - userConsumption;
data.GetElectricalChargeLevels(out double EC, out double maxEC);


batteryText.text = String.Format("{0:F0} / {1:F0} ({2:F1}%)", EC, maxEC, EC / maxEC * 100d);
if (maxEC > 0)
{
batteryText.text = String.Format("{0:F0} / {1:F0} ({2:F1}%)", EC, maxEC, EC / maxEC * 100d);
}
else
{
batteryText.text = "-";
}
if (EC <= 0.001)
{
batteryText.color = colorBadText;
Expand Down
2 changes: 1 addition & 1 deletion Source/DynamicBatteryStorage/UI/ToolbarSituation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ protected double CalculateOcclusionTime(CelestialBody body, double bodyOrbitHeig
{
if (bodyOrbitHeight == 0d)
{
return body.rotationPeriod;
return body.rotationPeriod /2d;

}
else
Expand Down
9 changes: 9 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v2.3.7
------
- Fixed a config issue that stopped fission reactors being measured in flight
- Added input locking to the advanced generation/consumption text fields
- Added input validation to the advanced generation/consumption text fields
- Fixed NaN displayed when vessel maximum power is 0
- Fixed missing divide by two in dark time calculation at the surface of bodies
- SM window will now disable itself when Kerbalism is enabled as well as the rest of the mod

v2.3.6
------
- Changed how fission reactors are measured in-flight so they don't result in miscalculation of vessel generation (requires latest SH version)
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
==============================
Dynamic Battery Storage v2.3.6
Dynamic Battery Storage v2.3.7
==============================

A small utility mod for Kerbal Space Program, intended to support my other projects. Effectively required by Near Future Electrical, CryoEngines, KerballAtomics and CryoTanks.
Expand Down