Skip to content

Commit

Permalink
Add option to display range to ping
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Oct 19, 2024
1 parent 4e13a68 commit d03745d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
Binary file modified Fika.Core/Bundles/Files/ping.bundle
Binary file not shown.
27 changes: 26 additions & 1 deletion Fika.Core/Coop/Factories/PingFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Fika.Core.Coop.Utils;
using Fika.Core.UI;
using Fika.Core.Utils;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Object = System.Object;
Expand Down Expand Up @@ -94,6 +95,8 @@ public abstract class AbstractPing : MonoBehaviour
protected Image image;
protected Vector3 hitPoint;
private RectTransform canvasRect;
private TextMeshProUGUI rangeText;
private bool displayRange;
private float screenScale = 1f;
private Color _pingColor = Color.white;
private CoopPlayer mainPlayer;
Expand All @@ -109,6 +112,9 @@ protected void Awake()
image.color = Color.clear;
mainPlayer = (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;
canvasRect = GetComponentInChildren<Canvas>().GetComponent<RectTransform>();
rangeText = GetComponentInChildren<TextMeshProUGUI>(true);
displayRange = FikaPlugin.ShowPingRange.Value;
rangeText.gameObject.SetActive(displayRange);
if (mainPlayer == null)
{
Destroy(gameObject);
Expand All @@ -124,6 +130,10 @@ protected void Update()
if (mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic && !FikaPlugin.ShowPingDuringOptics.Value)
{
image.color = Color.clear;
if (displayRange)
{
rangeText.color = Color.clear;
}
return;
}
}
Expand All @@ -145,11 +155,21 @@ protected void Update()

if (distanceToCenter < 200)
{
image.color = new(_pingColor.r, _pingColor.g, _pingColor.b, Mathf.Max(FikaPlugin.PingMinimumOpacity.Value, distanceToCenter / 200));
float alpha = Mathf.Max(FikaPlugin.PingMinimumOpacity.Value, distanceToCenter / 200);
Color newColor = new(_pingColor.r, _pingColor.g, _pingColor.b, alpha);
image.color = newColor;
if (displayRange)
{
rangeText.color = Color.white.SetAlpha(alpha);
}
}
else
{
image.color = _pingColor;
if (displayRange)
{
rangeText.color = Color.white;
}
}

if (screenPoint.z >= 0f
Expand Down Expand Up @@ -177,6 +197,11 @@ protected void Update()
}

image.transform.position = screenScale < 1 ? screenPoint : screenPoint * screenScale;
if (displayRange)
{
int distance = (int)CameraClass.Instance.Distance(hitPoint);
rangeText.text = $"[{distance}m]";
}
}
}

Expand Down
24 changes: 14 additions & 10 deletions Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public ManualLogSource FikaLogger
public static ConfigEntry<bool> PingUseOpticZoom { get; set; }
public static ConfigEntry<bool> PingScaleWithDistance { get; set; }
public static ConfigEntry<float> PingMinimumOpacity { get; set; }
public static ConfigEntry<bool> ShowPingRange { get; set; }
public static ConfigEntry<EPingSound> PingSound { get; set; }

// Coop | Debug
Expand Down Expand Up @@ -497,34 +498,37 @@ private void SetupConfig()
// Coop | Custom

UsePingSystem = Config.Bind("Coop | Custom", "Ping System", false,
new ConfigDescription("Toggle Ping System. If enabled you can receive and send pings by pressing the ping key.", tags: new ConfigurationManagerAttributes() { Order = 10 }));
new ConfigDescription("Toggle Ping System. If enabled you can receive and send pings by pressing the ping key.", tags: new ConfigurationManagerAttributes() { Order = 11 }));

PingButton = Config.Bind("Coop | Custom", "Ping Button", new KeyboardShortcut(KeyCode.U),
new ConfigDescription("Button used to send pings.", tags: new ConfigurationManagerAttributes() { Order = 9 }));
new ConfigDescription("Button used to send pings.", tags: new ConfigurationManagerAttributes() { Order = 10 }));

PingColor = Config.Bind("Coop | Custom", "Ping Color", Color.white,
new ConfigDescription("The color of your pings when displayed for other players.", tags: new ConfigurationManagerAttributes() { Order = 8 }));
new ConfigDescription("The color of your pings when displayed for other players.", tags: new ConfigurationManagerAttributes() { Order = 9 }));

PingSize = Config.Bind("Coop | Custom", "Ping Size", 1f,
new ConfigDescription("The multiplier of the ping size.", new AcceptableValueRange<float>(0.1f, 2f), new ConfigurationManagerAttributes() { Order = 7 }));
new ConfigDescription("The multiplier of the ping size.", new AcceptableValueRange<float>(0.1f, 2f), new ConfigurationManagerAttributes() { Order = 8 }));

PingTime = Config.Bind("Coop | Custom", "Ping Time", 3,
new ConfigDescription("How long pings should be displayed.", new AcceptableValueRange<int>(2, 10), new ConfigurationManagerAttributes() { Order = 6 }));
new ConfigDescription("How long pings should be displayed.", new AcceptableValueRange<int>(2, 10), new ConfigurationManagerAttributes() { Order = 7 }));

PlayPingAnimation = Config.Bind("Coop | Custom", "Play Ping Animation", false,
new ConfigDescription("Plays the pointing animation automatically when pinging. Can interfere with gameplay.", tags: new ConfigurationManagerAttributes() { Order = 5 }));
new ConfigDescription("Plays the pointing animation automatically when pinging. Can interfere with gameplay.", tags: new ConfigurationManagerAttributes() { Order = 6 }));

ShowPingDuringOptics = Config.Bind("Coop | Custom", "Show Ping During Optics", false,
new ConfigDescription("If pings should be displayed while aiming down an optics scope.", tags: new ConfigurationManagerAttributes() { Order = 4 }));
new ConfigDescription("If pings should be displayed while aiming down an optics scope.", tags: new ConfigurationManagerAttributes() { Order = 5 }));

PingUseOpticZoom = Config.Bind("Coop | Custom", "Ping Use Optic Zoom", true,
new ConfigDescription("If ping location should be displayed using the PiP optic camera.", tags: new ConfigurationManagerAttributes() { Order = 3, IsAdvanced = true }));
new ConfigDescription("If ping location should be displayed using the PiP optic camera.", tags: new ConfigurationManagerAttributes() { Order = 4, IsAdvanced = true }));

PingScaleWithDistance = Config.Bind("Coop | Custom", "Ping Scale With Distance", true,
new ConfigDescription("If ping size should scale with distance from player.", tags: new ConfigurationManagerAttributes() { Order = 2, IsAdvanced = true }));
new ConfigDescription("If ping size should scale with distance from player.", tags: new ConfigurationManagerAttributes() { Order = 3, IsAdvanced = true }));

PingMinimumOpacity = Config.Bind("Coop | Custom", "Ping Minimum Opacity", 0.05f,
new ConfigDescription("The minimum opacity of pings when looking straight at them.", new AcceptableValueRange<float>(0f, 0.5f), new ConfigurationManagerAttributes() { Order = 1, IsAdvanced = true }));
new ConfigDescription("The minimum opacity of pings when looking straight at them.", new AcceptableValueRange<float>(0f, 0.5f), new ConfigurationManagerAttributes() { Order = 2, IsAdvanced = true }));

ShowPingRange = Config.Bind("Coop | Custom", "Show Ping Range", false,
new ConfigDescription("Shows the range from your player to the ping if enabled.", tags: new ConfigurationManagerAttributes() { Order = 1 }));

PingSound = Config.Bind("Coop | Custom", "Ping Sound", EPingSound.SubQuestComplete,
new ConfigDescription("The audio that plays on ping", tags: new ConfigurationManagerAttributes() { Order = 0 }));
Expand Down

0 comments on commit d03745d

Please sign in to comment.