From 42338050d09956ef03e5c44d9675d107d540f60b Mon Sep 17 00:00:00 2001 From: siimav Date: Fri, 2 Feb 2024 02:10:25 +0200 Subject: [PATCH] Add tip about unpurchased RA TLs --- Source/RP0/Addons/GameplayTips.cs | 51 ++++++++++++++++++++++++++- Source/RP0/Settings/GameParameters.cs | 1 + 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/Source/RP0/Addons/GameplayTips.cs b/Source/RP0/Addons/GameplayTips.cs index 796206e6b3c..9d9d9de905d 100644 --- a/Source/RP0/Addons/GameplayTips.cs +++ b/Source/RP0/Addons/GameplayTips.cs @@ -12,6 +12,8 @@ public class GameplayTips : MonoBehaviour private static bool _isInterplanetaryWarningShown; private bool _subcribedToPAWEvent; + private bool _hasNewPurchasableRATL; + private int _highestUnlockableRALvl; public static GameplayTips Instance { get; private set; } @@ -56,7 +58,9 @@ internal void Start() } else if (HighLogic.LoadedSceneIsEditor) { - if (!rp0Settings.RealChuteTipShown) + LoadRAUpgradeStatus(rp0Settings); + + if (_hasNewPurchasableRATL || !rp0Settings.RealChuteTipShown) { GameEvents.onPartActionUIShown.Add(OnPartActionUIShown); _subcribedToPAWEvent = true; @@ -75,6 +79,11 @@ private void OnPartActionUIShown(UIPartActionWindow paw, Part part) { ShowRealChuteTip(); } + + if (_hasNewPurchasableRATL && part.Modules.Contains("ModuleRealAntenna")) + { + ShowRATechAvailableTip(); + } } public void ShowInterplanetaryAvionicsReminder() @@ -135,6 +144,23 @@ private void ShowRealChuteTip() HighLogic.UISkin).HideGUIsWhilePopup(); } + private void ShowRATechAvailableTip() + { + var rp0Settings = HighLogic.CurrentGame.Parameters.CustomParams(); + rp0Settings.RATLTipShown = _highestUnlockableRALvl; + _hasNewPurchasableRATL = false; + + string msg = $"Communications Tech Level {_highestUnlockableRALvl} has been researched but not purchased. Purchase it in the R&D building to use higher-tech comms."; + PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), + new Vector2(0.5f, 0.5f), + "ShowRATLTip", + "New comms tech available", + msg, + KSP.Localization.Localizer.GetStringByTag("#autoLOC_190905"), + false, + HighLogic.UISkin).HideGUIsWhilePopup(); + } + private IEnumerator CheckLandedWhileActuallyFlying() { while (true) @@ -254,5 +280,28 @@ public void ShowHSFProgramTip() KSP.Localization.Localizer.Format("#rp0_GameplayTip_LaunchUntrainedPart_Title"), null, 300, options); PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin).HideGUIsWhilePopup(); } + + private void LoadRAUpgradeStatus(RP0Settings rp0Settings) + { + _highestUnlockableRALvl = rp0Settings.RATLTipShown; + const int tlUpgradeCount = 9; + for (int i = rp0Settings.RATLTipShown + 1; i <= tlUpgradeCount; i++) + { + string upgradeName = "commsTL" + i; + if (PartUpgradeManager.Handler.IsEnabled(upgradeName)) + { + rp0Settings.RATLTipShown = i; + continue; + } + + if (PartUpgradeManager.Handler.IsAvailableToUnlock(upgradeName)) + { + _highestUnlockableRALvl = i; + _hasNewPurchasableRATL = true; + continue; + } + break; + } + } } } diff --git a/Source/RP0/Settings/GameParameters.cs b/Source/RP0/Settings/GameParameters.cs index ae13f8769d8..525d39f6e85 100644 --- a/Source/RP0/Settings/GameParameters.cs +++ b/Source/RP0/Settings/GameParameters.cs @@ -85,6 +85,7 @@ public class RP0Settings : GameParameters.CustomParameterNode public bool AvionicsWindow_ShowInfo3 = true; public bool NeverShowUntrainedReminders = false; public bool NeverShowHSFProgramReminders = false; + public int RATLTipShown = 0; public string CareerLog_URL; public string CareerLog_Token;