Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tip about unpurchased RA TLs #2330

Merged
merged 1 commit into from
Feb 4, 2024
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
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
Loading