AuriRex / GTFO_TheArchive

GTFO Quality of Life mod for almost* any version of the game
MIT License
28 stars 10 forks source link

Show ammo percentage of sentries #59

Open Neubulae opened 1 year ago

Neubulae commented 1 year ago

...is that possible?

randomuserhi commented 7 months ago

What do you specifically mean?

All should be possible, but not sure what exactly you are looking for.

Neubulae commented 7 months ago

What do you specifically mean?

* on HUD -> instead of displaying "DEPLOYED" still show sentry percentage?

* on in-game Sentry screen -> show percentage instead of raw bullet count

* on Sentry Marker (extension to sentry marker feature)

All should be possible, but not sure what exactly you are looking for.

Ah I initially meant the third choice but any of these three are interesting options....

randomuserhi commented 7 months ago

In the case of the third choice, I assume something like this can work (possibly wrapped under a Feature option or something):

Just replace this area with something along the lines of:

// Attach a behaviour to update marker name accordingly in real time
UpdateMarkerInfo info = navMarkerPlacer.gameObject.GetComponent<UpdateMarkerInfo>();
if (info == null)
{
    info = navMarkerPlacer.gameObject.AddComponent<UpdateMarkerInfo>();
}
info.ammo = PlayerBackpackManager.GetBackpack(snetPlayer).AmmoStorage.GetInventorySlotAmmo(AmmoType.Class);
info.navMarkerPlacer = navMarkerPlacer;
info.sentry = __instance;
info.snetPlayer = snetPlayer;

Then use a behaviour to update the marker:

#if IL2CPP
public override void Init()
{
    LoaderWrapper.ClassInjector.RegisterTypeInIl2Cpp<UpdateMarkerInfo>();
}
#endif

private class UpdateMarkerInfo : MonoBehaviour
{
    public PlaceNavMarkerOnGO navMarkerPlacer;
    public InventorySlotAmmo ammo;
    public SentryGunInstance sentry;
    public SNet_Player snetPlayer;

    private void Update()
    {
        if (!navMarkerPlacer.m_marker.IsVisible) return;

        var col = MARKER_GREEN;
        var name = string.Empty;

        if (Settings.DisplayPlayerNameAboveMarker)
        {
            name = $"<size={Settings.PlayerNameSize * 100f}%>{snetPlayer.NickName}</size>";
        }

        if (Settings.UsePlayerColorForMarkers)
        {
            col = snetPlayer.PlayerColor;
            name = $"<#{ColorUtility.ToHtmlStringRGB(snetPlayer.PlayerColor)}>{name}</color>";
        }
        else
        {
            name = $"<color=white>{name}</color>";
        }

        var sentryArch = string.Empty;

        if (Settings.ShowSentryArchetype)
        {
            int bulletsInPack = (int)(sentry.m_ammo / ammo.CostOfBullet);
            int percentage = (int)(bulletsInPack * ammo.BulletsToRelConv * 100);
            sentryArch = $"<color=white><size={Settings.PlayerNameSize * 100f}%>{sentry.ArchetypeName} [{percentage}%]</size></color>";
        }

        navMarkerPlacer.UpdateName(name, sentryArch);
        navMarkerPlacer.UpdatePlayerColor(col);
    }
}

image

Ig for flavour you can alter this to change colour for different ammo states (green=full, yellow=medium/low, red=completely out)