Skip to content

Commit

Permalink
Merge pull request #59 from Outshynd/dev-ping-options
Browse files Browse the repository at this point in the history
Additional advanced options for ping & name plates
  • Loading branch information
Lacyway authored Jun 3, 2024
2 parents a58736c + a70bfd5 commit 02ee282
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
6 changes: 3 additions & 3 deletions Fika.Core/Coop/Custom/FikaHealthBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ private void UpdateScreenSpacePosition(bool throttleUpdate)
playerPlate.ScalarObjectScreen.active = true;

float processedDistance = Mathf.Clamp(sqrDistance / 625, 0.6f, 1f);
Vector3 position = new(currentPlayer.PlayerBones.Neck.position.x, currentPlayer.PlayerBones.Neck.position.y + (1f * processedDistance), currentPlayer.PlayerBones.Neck.position.z);

if (!WorldToScreen.GetScreenPoint(position, mainPlayer, out Vector3 screenPoint))
Vector3 position = new(currentPlayer.PlayerBones.Neck.position.x, currentPlayer.PlayerBones.Neck.position.y + (1f * processedDistance), currentPlayer.PlayerBones.Neck.position.z);
if (!WorldToScreen.GetScreenPoint(position, mainPlayer, out Vector3 screenPoint, FikaPlugin.NamePlateUseOpticZoom.Value))
{
UpdateColorTextMeshProUGUI(playerPlate.playerNameScreen, 0);
UpdateColorImage(playerPlate.healthBarScreen, 0);
Expand Down
15 changes: 12 additions & 3 deletions Fika.Core/Coop/Factories/PingFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ protected void Update()
screenScale = outputWidth / inputWidth;
}

if (WorldToScreen.GetScreenPoint(hitPoint, mainPlayer, out Vector3 screenPoint))
if (WorldToScreen.GetScreenPoint(hitPoint, mainPlayer, out Vector3 screenPoint, FikaPlugin.PingUseOpticZoom.Value))
{
float distanceToCenter = Vector3.Distance(screenPoint, new Vector3(Screen.width, Screen.height, 0) / 2);

if (distanceToCenter < 200)
{
image.color = new Color(_pingColor.r, _pingColor.g, _pingColor.b, Mathf.Max(0.05f, distanceToCenter / 200));
image.color = new Color(_pingColor.r, _pingColor.g, _pingColor.b, Mathf.Max(FikaPlugin.PingMinimumOpacity.Value, distanceToCenter / 200));
}
else
{
Expand All @@ -108,7 +108,16 @@ public virtual void Initialize(ref Vector3 point, Object userObject, Color pingC

float distance = Mathf.Clamp(Vector3.Distance(CameraClass.Instance.Camera.transform.position, transform.position) / 100, 0.4f, 0.6f);
float pingSize = FikaPlugin.PingSize.Value;
image.rectTransform.localScale = new Vector3(pingSize, pingSize, pingSize) * distance;
Vector3 scaledSize = new Vector3(pingSize, pingSize, pingSize);
if (FikaPlugin.PingScaleWithDistance.Value == true)
{
scaledSize *= distance;
}
else
{
scaledSize *= 0.5f;
}
image.rectTransform.localScale = scaledSize;
}
}

Expand Down
36 changes: 24 additions & 12 deletions Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class FikaPlugin : BaseUnityPlugin
public static ConfigEntry<bool> UseHealthNumber { get; set; }
public static ConfigEntry<bool> UsePlateFactionSide { get; set; }
public static ConfigEntry<bool> HideNamePlateInOptic { get; set; }
public static ConfigEntry<bool> NamePlateUseOpticZoom { get; set; }
public static ConfigEntry<bool> DecreaseOpacityNotLookingAt { get; set; }
public static ConfigEntry<float> NamePlateScale { get; set; }
public static ConfigEntry<float> OpacityInADS { get; set; }
Expand All @@ -132,6 +133,9 @@ public class FikaPlugin : BaseUnityPlugin
public static ConfigEntry<int> PingTime { get; set; }
public static ConfigEntry<bool> PlayPingAnimation { get; set; }
public static ConfigEntry<bool> ShowPingDuringOptics { get; set; }
public static ConfigEntry<bool> PingUseOpticZoom { get; set; }
public static ConfigEntry<bool> PingScaleWithDistance { get; set; }
public static ConfigEntry<float> PingMinimumOpacity { get; set; }

// Coop | Debug
public static ConfigEntry<KeyboardShortcut> FreeCamButton { get; set; }
Expand Down Expand Up @@ -285,15 +289,17 @@ private void SetupConfig()

// Coop | Name Plates

UseNamePlates = Config.Bind("Coop | Name Plates", "Show Player Name Plates", false, new ConfigDescription("Toggle Health-Bars & Names.", tags: new ConfigurationManagerAttributes() { Order = 10 }));
UseNamePlates = Config.Bind("Coop | Name Plates", "Show Player Name Plates", false, new ConfigDescription("Toggle Health-Bars & Names.", tags: new ConfigurationManagerAttributes() { Order = 11 }));

HideHealthBar = Config.Bind("Coop | Name Plates", "Hide Health Bar", false, new ConfigDescription("Completely hides the health bar.", tags: new ConfigurationManagerAttributes() { Order = 9 }));
HideHealthBar = Config.Bind("Coop | Name Plates", "Hide Health Bar", false, new ConfigDescription("Completely hides the health bar.", tags: new ConfigurationManagerAttributes() { Order = 10 }));

UseHealthNumber = Config.Bind("Coop | Name Plates", "Show HP% instead of bar", false, new ConfigDescription("Shows health in % amount instead of using the bar.", tags: new ConfigurationManagerAttributes() { Order = 8 }));
UseHealthNumber = Config.Bind("Coop | Name Plates", "Show HP% instead of bar", false, new ConfigDescription("Shows health in % amount instead of using the bar.", tags: new ConfigurationManagerAttributes() { Order = 9 }));

UsePlateFactionSide = Config.Bind("Coop | Name Plates", "Show Player Faction Icon", true, new ConfigDescription("Shows the player faction icon next to the HP bar.", tags: new ConfigurationManagerAttributes() { Order = 7 }));
UsePlateFactionSide = Config.Bind("Coop | Name Plates", "Show Player Faction Icon", true, new ConfigDescription("Shows the player faction icon next to the HP bar.", tags: new ConfigurationManagerAttributes() { Order = 8 }));

HideNamePlateInOptic = Config.Bind("Coop | Name Plates", "Hide Name Plate in Optic", true, new ConfigDescription("Hides the name plate when viewing through PiP scopes since it's kinda janky.", tags: new ConfigurationManagerAttributes() { Order = 6 }));
HideNamePlateInOptic = Config.Bind("Coop | Name Plates", "Hide Name Plate in Optic", true, new ConfigDescription("Hides the name plate when viewing through PiP scopes.", tags: new ConfigurationManagerAttributes() { Order = 7 }));

NamePlateUseOpticZoom = Config.Bind("Coop | Name Plates", "Name Plates Use Optic Zoom", true, new ConfigDescription("If name plate location should be displayed using the PiP optic camera.", tags: new ConfigurationManagerAttributes() { Order = 6, IsAdvanced = true }));

DecreaseOpacityNotLookingAt = Config.Bind("Coop | Name Plates", "Decrease Opacity In Peripheral", true, new ConfigDescription("Decreases the opacity of the name plates when not looking at a player.", tags: new ConfigurationManagerAttributes() { Order = 5 }));

Expand All @@ -309,19 +315,25 @@ 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 = 7 }));
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 = 9 }));

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

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 = 7 }));

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 = 6 }));

PingButton = Config.Bind("Coop | Custom", "Ping Button", new KeyboardShortcut(KeyCode.U), new ConfigDescription("Button used to send pings.", tags: new ConfigurationManagerAttributes() { Order = 6 }));
PingTime = Config.Bind("Coop | Custom", "Ping Time", 3, new ConfigDescription("How long pings should be displayed.", new AcceptableValueRange<int>(2, 10), new ConfigurationManagerAttributes() { Order = 5 }));

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 = 5 }));
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 = 4 }));

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 = 4 }));
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 = 3 }));

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

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 = 2 }));
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 = 1, IsAdvanced = true }));

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 = 1 }));
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 = 0, IsAdvanced = true }));

// Coop | Debug

Expand Down
4 changes: 2 additions & 2 deletions Fika.Core/Utils/WorldToScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Fika.Core.Utils
{
public static class WorldToScreen
{
public static bool GetScreenPoint(Vector3 worldPosition, CoopPlayer mainPlayer, out Vector3 screenPoint)
public static bool GetScreenPoint(Vector3 worldPosition, CoopPlayer mainPlayer, out Vector3 screenPoint, bool useOpticCamera = true)
{
CameraClass worldCameraInstance = CameraClass.Instance;
Camera worldCamera = worldCameraInstance.Camera;
Expand All @@ -22,7 +22,7 @@ public static bool GetScreenPoint(Vector3 worldPosition, CoopPlayer mainPlayer,

ProceduralWeaponAnimation weaponAnimation = mainPlayer.ProceduralWeaponAnimation;

if (weaponAnimation != null)
if (useOpticCamera && weaponAnimation != null)
{
if (weaponAnimation.IsAiming && weaponAnimation.CurrentScope.IsOptic)
{
Expand Down

0 comments on commit 02ee282

Please sign in to comment.