Skip to content

Commit

Permalink
added notification when toggle precision control & fix notification text
Browse files Browse the repository at this point in the history
  • Loading branch information
malahx committed Feb 24, 2024
1 parent 6e1ee4e commit ad96183
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ For more information, please refer to <http://unlicense.org/>
QuickMods are very small plugins which add a small feature.

Features:
* PrecisionControl: force precision control at flight loading
* Revert: disable revert when you pass the atmosphere
* Scroll: scroll the R&D view when click mouse
* StopWarp: stop warp when vessel situation change
* VesselNames: add a new vessel name when you create a new vessel in the VAB
* Pause: pause the game when you escape it.
* PrecisionControl: force precision control at flight loading, it also adds notification when you toggle precision control mode.
* Revert: disable revert when you pass the atmosphere.
* Scroll: scroll the R&D view when click mouse.
* StopWarp: stop warp when vessel situation change.
* VesselNames: add a new vessel name when you create a new vessel in the VAB.

All the features are disabled by default.
To enable them, go to Settings -> Mods -> QuickMods -> Choose what you want.
Expand Down
9 changes: 5 additions & 4 deletions plugin_template/localizations/localizations.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Key,Type,Description,English,French
QuickMods/StopWarp/Notifications/VesselSituationChange/Primary,Text,,[QuickStopWarp] Stop Warp,[QuickStopWarp] Stop Warp
QuickMods/StopWarp/Notifications/VesselSituationChange/FirstLine,Text,,The vessel's situation has changed from {0} to {1}.,La situation du vaisseau à changer de {0} à {1}.
QuickMods/QuickRevert/Notifications/LostRevert/Primary,Text,,[QuickRevert] Lost Revert,[QuickRevert] Lost Revert
QuickMods/QuickRevert/Notifications/LostRevert/FirstLine,Text,,Revert will no longer be possible.,Il ne sera plus possible de faire un Revert.
QuickMods/StopWarp/Notifications/VesselSituationChange/Primary,Text,,Stop Warp, vessel's situation changed,Stop Warp, La situation du vaisseau à changé
QuickMods/QuickRevert/Notifications/LostRevert/Primary,Text,,Lost Revert,Revert perdu
QuickMods/PrecisionControl/Notifications/Primary,Text,,Precision control mode: {0},Mode précis des contrôles : {0}
QuickMods/PrecisionControl/Notifications/Primary/Activated,Text,,ACTIVATED,ACTIVÉ
QuickMods/PrecisionControl/Notifications/Primary/Deactivated,Text,,DEACTIVATED,DÉSACTIVÉ
24 changes: 24 additions & 0 deletions src/QuickMods/quick/impl/PrecisionControl.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using I2.Loc;
using KSP.Game;
using KSP.Messages;
using QuickMods.configuration.impl;
using UnityEngine.InputSystem;

namespace QuickMods.quick.impl;

Expand All @@ -9,20 +12,41 @@ public override void Start()
{
base.Start();
MessageCenter.Subscribe<FlightViewEnteredMessage>(OnFlightViewEnteredMessage);
Game.Input.Flight.TogglePrecisionMode.performed += OnActivatePrecisionMode;
}

public override void OnDestroy()
{
base.OnDestroy();
MessageCenter.Unsubscribe<FlightViewEnteredMessage>(OnFlightViewEnteredMessage);
Game.Input.Flight.TogglePrecisionMode.performed -= OnActivatePrecisionMode;
}

private void OnFlightViewEnteredMessage(MessageCenterMessage msg)
{
if (!config.Enabled()) return;

Game.ViewController.flightInputHandler._isPrecisionMode = true;
SendNotification();

Logger.LogDebug("Set PrecisionControl to true");
}

private void OnActivatePrecisionMode(InputAction.CallbackContext context)
{
SendNotification();
}

private void SendNotification()
{
var isPrecisionMode = Game.ViewController.flightInputHandler.IsPrecisionMode;
var isPrecisionModeText = LocalizationManager.GetTranslation(isPrecisionMode ? "QuickMods/PrecisionControl/Notifications/Primary/Activated" : "QuickMods/PrecisionControl/Notifications/Primary/Deactivated");
var notificationData = new NotificationData
{
Tier = NotificationTier.Passive,
Primary = new NotificationLineItemData { LocKey = "QuickMods/PrecisionControl/Notifications/Primary", ObjectParams = [isPrecisionModeText] },
Importance = NotificationImportance.Low
};
Game.Notifications.ProcessNotification(notificationData);
}
}
1 change: 0 additions & 1 deletion src/QuickMods/quick/impl/Revert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ msg is not (VesselSituationChangedMessage { OldSituation: Flying, NewSituation:
{
Tier = NotificationTier.Passive,
Primary = new NotificationLineItemData { LocKey = "QuickMods/QuickRevert/Notifications/LostRevert/Primary" },
FirstLine = new NotificationLineItemData { LocKey = "QuickMods/QuickRevert/Notifications/LostRevert/FirstLine" },
Importance = NotificationImportance.Low
};
Game.Notifications.ProcessNotification(notificationData);
Expand Down
1 change: 0 additions & 1 deletion src/QuickMods/quick/impl/StopWarp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ private void OnVesselSituationChange(MessageCenterMessage msg)
{
Tier = NotificationTier.Passive,
Primary = new NotificationLineItemData { LocKey = "QuickMods/StopWarp/Notifications/VesselSituationChange/Primary" },
FirstLine = new NotificationLineItemData { LocKey = "QuickMods/StopWarp/Notifications/VesselSituationChange/FirstLine", ObjectParams = [message.OldSituation, message.NewSituation] },
Importance = NotificationImportance.Low
};
Game.Notifications.ProcessNotification(notificationData);
Expand Down

0 comments on commit ad96183

Please sign in to comment.