Skip to content

Commit

Permalink
Mouse sens + FOV range
Browse files Browse the repository at this point in the history
  • Loading branch information
space-commits committed Jan 31, 2025
1 parent f56bfe2 commit 4dcf393
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 520 deletions.
163 changes: 10 additions & 153 deletions FovController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public T WatchedValue
{
_watchedValue = value;
OnValueChanged?.Invoke(value);
Utils.Logger.LogWarning("Value changed: " + value);
}
}
}
Expand All @@ -40,14 +39,14 @@ public class FovController
private Player _player = null;
public AnimatedTextPanel OpticPanel = null;

ValueWatcher<bool> ADSWatcher = null;
public ValueWatcher<bool> ADSWatcher = null;
ValueWatcher<float> ScopeFOVWatcher = null;
ValueWatcher<bool> ToggleZoomWatcher = null;
ValueWatcher<bool> ScopeWatcher = null;
public ValueWatcher<bool> OpticWatcher = null;

public float CurrentScopeFOV = 0f;
public bool IsToggleZoom = false;
public bool IsPistol = false;
public float CurrentScopeFOV { get; set; } = 0f;
public bool IsToggleZoom { get; set; } = false;
public bool IsPistol { get; set; } = false;

public FovController()
{
Expand All @@ -57,75 +56,10 @@ public FovController()
ScopeFOVWatcher.OnValueChanged += newValue => HandleScopeFOVChange();
ToggleZoomWatcher = new ValueWatcher<bool>();
ToggleZoomWatcher.OnValueChanged += newValue => HandleToggleZoomChange();
ScopeWatcher = new ValueWatcher<bool>();
ScopeWatcher.OnValueChanged += newValue => HandleToggleZoomChange();
OpticWatcher = new ValueWatcher<bool>();
OpticWatcher.OnValueChanged += newValue => HandleToggleZoomChange();
}


/* public void ZoomScope(float currentZoom)
{
if (OpticPanel != null) OpticPanel.Show(Math.Round(currentZoom, 1) + "x");
Camera[] cams = Camera.allCameras;
foreach (Camera cam in cams)
{
if (cam.name == "BaseOpticCamera(Clone)")
{
cam.fieldOfView = Plugin.BaseScopeFOV.Value / Mathf.Pow(currentZoom, Plugin.MagPowerFactor.Value);
}
}
DoFov();
}*/


/* public void DoFov()
{
ProceduralWeaponAnimation pwa = _player.ProceduralWeaponAnimation;
if (pwa == null) return;
FirearmController fc = _player.HandsController as FirearmController;
float baseFOV = _player.ProceduralWeaponAnimation.Single_2;
int aimIndex = _player.ProceduralWeaponAnimation.AimIndex;
if (fc == null)
{
float targetFOV = baseFOV * TargetToggleZoomMulti;
CameraClass.Instance.SetFov(targetFOV, 1f, !IsAiming);
return;
}
if (_player != null && fc?.Weapon != null)
{
if (pwa.PointOfView == EPointOfView.FirstPerson && !pwa.Sprint && aimIndex < pwa.ScopeAimTransforms.Count)
{
float zoom = 1;
if (_player.ProceduralWeaponAnimation.CurrentAimingMod != null)
{
zoom = _player.ProceduralWeaponAnimation.CurrentAimingMod.GetCurrentOpticZoom();
CurrentScopeTempID = _player.ProceduralWeaponAnimation.CurrentAimingMod.Item.TemplateId;
}
bool isOptic = pwa.CurrentScope.IsOptic;
IsOptic = isOptic;
float zoomMulti = !isOptic ? Plugin.NonOpticFOVMulti.Value : Plugin.EnableVariableZoom.Value ? Utils.GetADSFoVMulti(CurrentZoom) : Utils.GetADSFoVMulti(zoom);
float sightFOV = baseFOV * zoomMulti * Plugin.GlobalADSMulti.Value;
float fov = pwa.IsAiming ? sightFOV : baseFOV;
float targetFOV = fov * TargetToggleZoomMulti;
CameraClass.Instance.SetFov(targetFOV, 1f, !IsAiming);
}
}
else if (pwa.PointOfView == EPointOfView.FirstPerson && !pwa.Sprint && aimIndex < pwa.ScopeAimTransforms.Count)
{
float sightFOV = baseFOV * Plugin.RangeFinderADSMulti.Value * Plugin.GlobalADSMulti.Value;
float fov = IsAiming ? sightFOV : baseFOV;
CameraClass.Instance.SetFov(fov, 1f, !IsAiming);
}
}*/




public void ChangeMainCamFOV()
{
if (IsPWANull()) return;
Expand All @@ -146,13 +80,11 @@ public void ChangeMainCamFOV()
bool fcIsNull = fc != null && fc?.Weapon != null;
if (fcIsNull && pwa.PointOfView == EPointOfView.FirstPerson && !pwa.Sprint && pwa.IsAiming && aimIndex < pwa.ScopeAimTransforms.Count)
{
var hasOptic = pwa?.CurrentScope != null && pwa.CurrentScope.IsOptic;
toggleZoomMulti = !IsToggleZoom ? 1f : hasOptic ? Plugin.OpticToggleZoomMulti.Value : Plugin.NonOpticToggleZoomMulti.Value;
magnificationModifier = hasOptic ? Plugin.GlobalADSMulti.Value : Plugin.NonOpticFOVMulti.Value; //in future once scope FOV is standardized, will need to use current scope FOV to figure out what equiivalent scope mag it is, and use that to modify main cam FOV
toggleZoomMulti = !IsToggleZoom ? 1f : OpticWatcher.WatchedValue ? Plugin.OpticToggleZoomMulti.Value : Plugin.NonOpticToggleZoomMulti.Value;
magnificationModifier = OpticWatcher.WatchedValue ? Plugin.GlobalADSMulti.Value : Plugin.NonOpticFOVMulti.Value; //in future once scope FOV is standardized, will need to use current scope FOV to figure out what equiivalent scope mag it is, and use that to modify main cam FOV
}

float zoom = baseFOV * magnificationModifier * toggleZoomMulti;
Utils.Logger.LogWarning($"base fov: {baseFOV}, scope: {magnificationModifier}, toggle: {toggleZoomMulti} ");
CameraClass.Instance.SetFov(zoom, 1f, !pwa.IsAiming);
}

Expand Down Expand Up @@ -193,7 +125,7 @@ public void CheckScope()
{
if (IsPWANull() || !Utils.WeaponReady) return;
var pwa = _player.ProceduralWeaponAnimation;
if (pwa.AimIndex < pwa.ScopeAimTransforms.Count) ScopeWatcher.WatchedValue = pwa.CurrentScope.IsOptic;
if (pwa.AimIndex < pwa.ScopeAimTransforms.Count) OpticWatcher.WatchedValue = pwa.CurrentScope.IsOptic;
}

public void CheckToggleZoom()
Expand Down Expand Up @@ -243,81 +175,6 @@ public void ControllerUpdate()
CheckToggleZoom();
CheckScope();
}





/*
if (Plugin.ToggleZoomOnHoldBreath.Value)
{
if (_player.Physical.HoldingBreath && !CalledToggleZoomBreath)
{
CalledToggleZoomBreath = true;
SetToggleZoomMulti();
DoFov();
}
else if (!_player.Physical.HoldingBreath && CalledToggleZoomBreath)
{
CalledToggleZoomBreath = false;
SetToggleZoomMulti();
DoFov();
}
}
if (Plugin.HoldZoom.Value)
{
if (Input.GetKey(Plugin.ZoomKeybind.Value.MainKey) && Plugin.ZoomKeybind.Value.Modifiers.All(Input.GetKey) && !CalledToggleZoom && !(!IsAiming && Plugin.UnaimedToggleZoomMulti.Value == 1f))
{
CalledToggleZoom = true;
SetToggleZoomMulti();
DoFov();
}
if (!Input.GetKey(Plugin.ZoomKeybind.Value.MainKey) && CalledToggleZoom)
{
CalledToggleZoom = false;
SetToggleZoomMulti();
DoFov();
}
}
else
{
if (Input.GetKeyDown(Plugin.ZoomKeybind.Value.MainKey) && Plugin.ZoomKeybind.Value.Modifiers.All(Input.GetKey))
{
CalledToggleZoom = !CalledToggleZoom;
SetToggleZoomMulti();
DoFov();
}
}
if (!IsAiming && Plugin.UnaimedToggleZoomMulti.Value == 1f && CalledToggleZoom)
{
CalledToggleZoom = false;
SetToggleZoomMulti();
DoFov();
}
if (IsAiming && !CalledADSZoom)
{
SetToggleZoomMulti();
DoFov();
CalledADSZoom = true;
}
else if (!IsAiming && CalledADSZoom)
{
SetToggleZoomMulti();
CalledADSZoom = false;
}*/


/* if (!Utils.IsReady && !_haveResetDict)
{
WeaponScopeValues.Clear();
_haveResetDict = true;
}*/
}

}
}
Loading

0 comments on commit 4dcf393

Please sign in to comment.