Skip to content

Commit

Permalink
Add tip about unpurchased RA TLs (#2330)
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav authored Feb 4, 2024
1 parent 9fb0ef2 commit 335b0e4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
51 changes: 50 additions & 1 deletion Source/RP0/Addons/GameplayTips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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;
Expand All @@ -75,6 +79,11 @@ private void OnPartActionUIShown(UIPartActionWindow paw, Part part)
{
ShowRealChuteTip();
}

if (_hasNewPurchasableRATL && part.Modules.Contains("ModuleRealAntenna"))
{
ShowRATechAvailableTip();
}
}

public void ShowInterplanetaryAvionicsReminder()
Expand Down Expand Up @@ -135,6 +144,23 @@ private void ShowRealChuteTip()
HighLogic.UISkin).HideGUIsWhilePopup();
}

private void ShowRATechAvailableTip()
{
var rp0Settings = HighLogic.CurrentGame.Parameters.CustomParams<RP0Settings>();
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)
Expand Down Expand Up @@ -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;
}
}
}
}
1 change: 1 addition & 0 deletions Source/RP0/Settings/GameParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 335b0e4

Please sign in to comment.