Skip to content

Commit

Permalink
Add UI options for permanently disabling antennas
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Jul 18, 2024
1 parent 4270246 commit 448b0d0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/RealAntennasProject/ModuleRealAntenna.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ private void SetFieldVisibility()
Fields[nameof(sIdlePowerConsumed)].guiActiveEditor = Fields[nameof(sIdlePowerConsumed)].guiActive = showFields;
Fields[nameof(sAntennaTarget)].guiActive = showFields;
Fields[nameof(plannerActiveTxTime)].guiActiveEditor = Kerbalism.Kerbalism.KerbalismAssembly is System.Reflection.Assembly;
Actions[nameof(PermanentShutdownAction)].active = showFields;
Events[nameof(PermanentShutdownEvent)].guiActive = showFields;
Events[nameof(PermanentShutdownEvent)].active = showFields;
Events[nameof(AntennaPlanningGUI)].active = showFields;
Events[nameof(AntennaPlanningGUI)].guiActive = showFields;
Events[nameof(DebugAntenna)].active = showFields;
Expand Down Expand Up @@ -302,6 +305,29 @@ private void OnTechLevelChange(BaseField f, object obj) // obj is the OLD va

private void OnTechLevelChangeSymmetry(BaseField f, object obj) => ConfigBandOptions();

[KSPEvent(guiActive = true, guiActiveEditor = false, guiName = "Disable antenna permanently", groupName = PAWGroup)]
public void PermanentShutdownEvent()
{
var options = new DialogGUIBase[] {
new DialogGUIButton("Yes", () => PermanentShutdownAction(null)),
new DialogGUIButton("No", () => {})
};
var dialog = new MultiOptionDialog("ConfirmDisableAntenna", "Are you sure you want to permanently disable the antenna? Doing this will prevent it from consuming power but the operation is irreversible.", "Disable antenna", HighLogic.UISkin, 300, options);
PopupDialog.SpawnPopupDialog(dialog, true, HighLogic.UISkin);
}

[KSPAction("Disable antenna permanently")]
public void PermanentShutdownAction(KSPActionParam _)
{
_enabled = false;
Condition = AntennaCondition.PermanentShutdown;
SetFieldVisibility();
SetupIdlePower();
GameEvents.onVesselWasModified.Fire(vessel); // Need to notify RACommNetVessel about disabling antennas
RACommNetScenario scen = RACommNetScenario.Instance as RACommNetScenario;
scen?.Network?.ResetNetwork();
}

private void ApplyGameSettings()
{
StockRateModifier = HighLogic.CurrentGame.Parameters.CustomParams<RAParameters>().StockRateModifier;
Expand Down

0 comments on commit 448b0d0

Please sign in to comment.