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 Aug 18, 2024
1 parent c86ec9b commit 6f230b2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 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
2 changes: 1 addition & 1 deletion src/RealAntennasProject/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.5.0.0")]
[assembly: AssemblyVersion("2.6.0.0")]
#if CIBUILD
[assembly: AssemblyFileVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")]
[assembly: KSPAssembly("RealAntennas", @MAJOR@, @MINOR@)]
Expand Down
2 changes: 1 addition & 1 deletion src/RealAntennasProject/RealAntennas.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<Compile Include="Tools.cs" />
<Compile Include="Network\RACommNetNetwork.cs" />
<Compile Include="RACommNode.cs" />
<Compile Include="UpgradeScripts\v2_5_AntennaState.cs" />
<Compile Include="UpgradeScripts\v2_6_AntennaState.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace RealAntennas.UpgradeScripts
{
[UpgradeModule(LoadContext.SFS | LoadContext.Craft, sfsNodeUrl = "GAME/FLIGHTSTATE/VESSEL/PART", craftNodeUrl = "PART")]
public class v2_5_AntennaState : UpgradeScript
public class v2_6_AntennaState : UpgradeScript
{
public override string Name => "RealAntennas Antenna Condition upgrader";
public override string Description => "Update crafts to use new condition enum";
Expand All @@ -29,37 +29,37 @@ public override void OnUpgrade(ConfigNode node, LoadContext loadContext, ConfigN
}
}

public class v2_5_AntennaState_KCTBase : v2_5_AntennaState
public class v2_6_AntennaState_KCTBase : v2_6_AntennaState
{
public override string Name { get => $"{base.Name} KCT-{nodeUrlSFS}"; }
public override TestResult OnTest(ConfigNode node, LoadContext loadContext, ref string nodeName) =>
loadContext == LoadContext.Craft ? TestResult.Pass : base.OnTest(node, loadContext, ref nodeName);
}

[UpgradeModule(LoadContext.SFS, sfsNodeUrl = "GAME/SCENARIO/KSC/VABList/KCTVessel/ShipNode/PART")]
public class v2_5_AntennaState_KCT1 : v2_5_AntennaState_KCTBase { }
public class v2_6_AntennaState_KCT1 : v2_6_AntennaState_KCTBase { }

[UpgradeModule(LoadContext.SFS, sfsNodeUrl = "GAME/SCENARIO/KSC/SPHList/KCTVessel/ShipNode/PART")]
public class v2_5_AntennaState_KCT2 : v2_5_AntennaState_KCTBase { }
public class v2_6_AntennaState_KCT2 : v2_6_AntennaState_KCTBase { }

[UpgradeModule(LoadContext.SFS, sfsNodeUrl = "GAME/SCENARIO/KSC/VABWarehouse/KCTVessel/ShipNode/PART")]
public class v2_5_AntennaState_KCT3 : v2_5_AntennaState_KCTBase { }
public class v2_6_AntennaState_KCT3 : v2_6_AntennaState_KCTBase { }

[UpgradeModule(LoadContext.SFS, sfsNodeUrl = "GAME/SCENARIO/KSC/SPHWarehouse/KCTVessel/ShipNode/PART")]
public class v2_5_AntennaState_KCT4 : v2_5_AntennaState_KCTBase { }
public class v2_6_AntennaState_KCT4 : v2_6_AntennaState_KCTBase { }

[UpgradeModule(LoadContext.SFS, sfsNodeUrl = "GAME/SCENARIO/KSC/VABPlans/KCTVessel/ShipNode/PART")]
public class v2_5_AntennaState_KCT5 : v2_5_AntennaState_KCTBase { }
public class v2_6_AntennaState_KCT5 : v2_6_AntennaState_KCTBase { }

[UpgradeModule(LoadContext.SFS, sfsNodeUrl = "GAME/SCENARIO/KSC/SPHPlans/KCTVessel/ShipNode/PART")]
public class v2_5_AntennaState_KCT6 : v2_5_AntennaState_KCTBase { }
public class v2_6_AntennaState_KCT6 : v2_6_AntennaState_KCTBase { }

[UpgradeModule(LoadContext.SFS, sfsNodeUrl = "GAME/SCENARIO/KSC/LaunchComplex/BuildList/KCTVessel/ShipNode/PART")]
public class v2_5_AntennaState_KCT7 : v2_5_AntennaState_KCTBase { }
public class v2_6_AntennaState_KCT7 : v2_6_AntennaState_KCTBase { }

[UpgradeModule(LoadContext.SFS, sfsNodeUrl = "GAME/SCENARIO/KSC/LaunchComplex/Warehouse/KCTVessel/ShipNode/PART")]
public class v2_5_AntennaState_KCT8 : v2_5_AntennaState_KCTBase { }
public class v2_6_AntennaState_KCT8 : v2_6_AntennaState_KCTBase { }

[UpgradeModule(LoadContext.SFS, sfsNodeUrl = "GAME/SCENARIO/KSC/LaunchComplex/Plans/KCTVessel/ShipNode/PART")]
public class v2_5_AntennaState_KCT9 : v2_5_AntennaState_KCTBase { }
public class v2_6_AntennaState_KCT9 : v2_6_AntennaState_KCTBase { }
}

0 comments on commit 6f230b2

Please sign in to comment.