Skip to content

Commit

Permalink
Merge branch 'developing'
Browse files Browse the repository at this point in the history
  • Loading branch information
will258012 committed Sep 7, 2024
2 parents 7fc0f2f + 5eb3a06 commit c7e96bf
Show file tree
Hide file tree
Showing 13 changed files with 395 additions and 260 deletions.
326 changes: 187 additions & 139 deletions FPSCamera/.editorconfig

Large diffs are not rendered by default.

76 changes: 11 additions & 65 deletions FPSCamera/Code/Cam/Controller/FPSCamController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using AlgernonCommons;
using AlgernonCommons.Translation;
using FPSCamera.Game;
using FPSCamera.Settings;
using FPSCamera.UI;
using FPSCamera.Utils;
using System;
using System.Collections.Generic;
using UnityEngine;
using static FPSCamera.Utils.MathUtils;

Expand All @@ -18,7 +16,6 @@ public class FPSCamController : MonoBehaviour
{
public static FPSCamController Instance { get; private set; }
public IFPSCam FPSCam { get; private set; }

/// <summary>
/// Called when the script instance is being loaded. Initializes the singleton instance.
/// </summary>
Expand Down Expand Up @@ -70,14 +67,12 @@ private void DisableCam()
{
AfterTransition();
}
//StartCoroutine(ShadowsManager.ToggleShadowsOptimization(false));
//StartCoroutine(LodManager.ToggleLODOptimization(false));
}
private void AfterTransition()
{
if (ModSettings.HideGameUI)
{
GameCamController.Instance.MainCamera.rect = GameCamController.Instance._cachedRect;
GameCamController.Instance.MainCamera.rect = CameraController.kFullScreenWithoutMenuBarRect;
StartCoroutine(UIManager.ToggleUI(true));
}
GameCamController.Instance.Restore();
Expand All @@ -104,6 +99,7 @@ public void StartFreeCam()
{
FPSCam = new FreeCam();
EnableCam();
_offset = new Positioning(Vector3.zero, GameCamController.Instance.MainCamera.transform.rotation);
}

/// <summary>
Expand All @@ -124,7 +120,7 @@ public void StartTransitioningOnDisabled(Positioning endPos)
_targetFoV = ModSettings.CamFieldOfView;

if (!ModSettings.HideGameUI)
GameCamController.Instance.MainCamera.rect = GameCamController.Instance._cachedRect;
GameCamController.Instance.MainCamera.rect = CameraController.kFullScreenWithoutMenuBarRect;

var cameraTransform = GameCamController.Instance.MainCamera.transform;
if (cameraTransform.position.DistanceTo(endPos.pos) <= ModSettings.MinTransDistance ||
Expand Down Expand Up @@ -207,60 +203,7 @@ public bool OnEsc()
return false;
}

/// <summary>
/// Retrieves geographical information about the current camera position.
/// </summary>
/// <returns>A dictionary containing geographical information.</returns>
public Dictionary<string, string> GetGeoInfos()
{
var infos = new Dictionary<string, string>();

var pos = FPSCam.GetPositioning().pos;

if (MapUtils.RayCastDistrict(pos) is InstanceID disID && disID.District != default)
{
var name = DistrictManager.instance.GetDistrictName(disID.District);
if (!string.IsNullOrEmpty(name))
infos[Translations.Translate("INFO_DISTRICT")] = name;
}
if (MapUtils.RayCastPark(pos) is InstanceID parkID && parkID.Park != default)
{
var name = DistrictManager.instance.GetParkName(parkID.Park);
if (!string.IsNullOrEmpty(name))
{
switch (DistrictPark.GetParkGroup(DistrictManager.instance.m_parks.m_buffer[parkID.Park].m_parkType))
{
case DistrictPark.ParkGroup.ParkLife:
infos[Translations.Translate("INFO_DLCDISTRICT_PARK")] = name;
break;
case DistrictPark.ParkGroup.Industry:
infos[Translations.Translate("INFO_DLCDISTRICT_INDUSTRY")] = name;
break;
case DistrictPark.ParkGroup.Campus:
infos[Translations.Translate("INFO_DLCDISTRICT_CAMPUS")] = name;
break;
case DistrictPark.ParkGroup.Airport:
infos[Translations.Translate("INFO_DLCDISTRICT_AIRPORT")] = name;
break;
case DistrictPark.ParkGroup.PedestrianZone:
infos[Translations.Translate("INFO_DLCDISTRICT_PEDZONE")] = name;
break;
default:
infos["DLC District"] = name;
break;
}

}

}
if (MapUtils.RayCastRoad(pos) is InstanceID segID && segID.NetSegment != default)
{
var name = NetManager.instance.GetSegmentName(segID.NetSegment);
if (!string.IsNullOrEmpty(name))
infos[Translations.Translate("INFO_ROAD")] = name;
}
return infos;
}

/// <summary>
/// Checks if there is another camera to switch to for a citizen camera.
Expand Down Expand Up @@ -303,7 +246,7 @@ private void HandleInput()
{
if (FPSCam is WalkThruCam cam)
cam.SyncCamOffset();
else
else if (FPSCam is IFollowCam)
SyncCamOffset();
if (ModSettings.SmoothTransition)
_targetFoV = ModSettings.CamFieldOfView;
Expand Down Expand Up @@ -412,13 +355,16 @@ private void SaveCamOffset()
internal void SyncCamOffset(IFollowCam followCam = null)
{
if (followCam == null) followCam = FPSCam as IFollowCam;
OffsetsSettings.Load();

var name = followCam?.GetPrefabName() ?? null;
var newOffset = new Positioning(Vector3.zero);

if (name != null && OffsetsSettings.Offsets.TryGetValue(name, out var offset))
{
newOffset = offset;
}

newOffset.pos += ModSettings.FollowCamOffset;
if (followCam is CitizenCam)
newOffset.pos += ModSettings.PedestrianFixedOffset;
Expand All @@ -443,14 +389,14 @@ private void UpdateFollowCamPos()
var instancePos = FPSCam.GetPositioning().pos + (FPSCam.GetPositioning().rotation * _offset.pos);
var instanceRotation = FPSCam.GetPositioning().rotation * _offset.rotation;

// Adjust the y-axis to ensure the camera is above the terrain or road.
var terrainHeight = MapUtils.GetMinHeightAt(instancePos); // Get the minimum height of the terrain at the current position.

// Adjust the y-axis to ensure the camera is above the road.
var roadHeight = MapUtils.GetClosestSegmentLevel(instancePos) ?? default; // Get the height of the closest road segment, if available.
instancePos.y = Math.Max(instancePos.y, Math.Max(terrainHeight, roadHeight)); // Ensure the camera is at least at the height of the terrain or road.
instancePos.y = Math.Max(instancePos.y, roadHeight); // Ensure the camera is at least at the height of the road.


// Limit the camera's position to the allowed area.
instancePos = CameraController.ClampCameraPosition(instancePos);

// Apply the calculated position and rotation to the camera.
if (ModSettings.SmoothTransition)
{
Expand Down
31 changes: 17 additions & 14 deletions FPSCamera/Code/Cam/Controller/GameCamController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,21 @@ public TComp GetComponent<TComp>() where TComp : MonoBehaviour
public void Initialize()
{
_controller.enabled = false;
_cachedRect = _mainCamera.rect;
_mainCamera.rect = new Rect(0f, 0f, 1f, 1f);
_mainCamera.rect = CameraController.kFullScreenRect;
if (_camTiltEffect != null) _camTiltEffect.enabled = false;
if (ModSettings.Dof && _camDoF != null) _camDoF.enabled = true;
if (ModSettings.SetBackCamera)
if (ModSettings.Dof)
{
_cachedPositioning = new Positioning(_mainCamera.transform.position, _mainCamera.transform.rotation);
if (_camDoF != null)
_camDoF.enabled = true;
}
else
{
if (_camDoF != null && IsDoFEnabled)
_camDoF.enabled = false;
}

if (ModSettings.SetBackCamera) _cachedPositioning = new Positioning(_mainCamera.transform.position, _mainCamera.transform.rotation);

_cachedfieldOfView = _mainCamera.fieldOfView;
_mainCamera.fieldOfView = ModSettings.CamFieldOfView;
_cachednearClipPlane = _mainCamera.nearClipPlane;
Expand All @@ -50,15 +57,15 @@ public void Initialize()

public void Restore()
{
if (_camDoF != null) _camDoF.enabled = _IsDoFEnabled;
if (_camTiltEffect != null) _camTiltEffect.enabled = _IsTiltEffectEnabled;
if (_camDoF != null) _camDoF.enabled = IsDoFEnabled;
if (_camTiltEffect != null) _camTiltEffect.enabled = IsTiltEffectEnabled;
_mainCamera.fieldOfView = _cachedfieldOfView;
_mainCamera.nearClipPlane = _cachednearClipPlane;

if (!ModSettings.SetBackCamera)
{
_controller.m_currentPosition = _controller.m_targetPosition = _mainCamera.transform.position;
_controller.m_currentAngle = _controller.m_targetAngle = new Vector2(_mainCamera.transform.eulerAngles.y, _mainCamera.transform.eulerAngles.x);
_controller.m_currentAngle = _controller.m_targetAngle = new Vector2(_mainCamera.transform.eulerAngles.y, _mainCamera.transform.eulerAngles.x).ClampEulerAngles();
_controller.m_currentHeight = _controller.m_targetHeight = _mainCamera.transform.position.y;
}
_controller.enabled = true;
Expand All @@ -72,9 +79,6 @@ private GameCamController()

_camDoF = GetComponent<DepthOfField>();
_camTiltEffect = GetComponent<TiltShiftEffect>();

if (_camDoF != null) _IsDoFEnabled = _camDoF.enabled;
if (_camTiltEffect != null) _IsTiltEffectEnabled = _camTiltEffect.enabled;
}

private readonly CameraController _controller;
Expand All @@ -83,11 +87,10 @@ private GameCamController()
private readonly DepthOfField _camDoF;
private readonly TiltShiftEffect _camTiltEffect;

private readonly bool _IsDoFEnabled;
private readonly bool _IsTiltEffectEnabled;
private bool IsDoFEnabled => !CameraController.isDepthOfFieldDisabled;
private bool IsTiltEffectEnabled => !CameraController.isTiltShiftDisabled;

internal Positioning _cachedPositioning;
internal Rect _cachedRect;
private float _cachedfieldOfView;
private float _cachednearClipPlane;
}
Expand Down
3 changes: 2 additions & 1 deletion FPSCamera/Code/Cam/FreeCam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class FreeCam : IFPSCam
{
public FreeCam()
{
_positioning.pos = GameCamController.Instance.CameraController.transform.position;
var transform = GameCamController.Instance.CameraController.transform;
_positioning.pos = transform.position;
_positioning.rotation = Quaternion.identity;
_lastPositioning = _positioning;
IsActivated = true;
Expand Down
3 changes: 2 additions & 1 deletion FPSCamera/Code/Loading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected override void CreatedActions(ILoading loading)
protected override void LoadedActions(LoadMode mode)
{
base.LoadedActions(mode);
gameObject = new GameObject();
ModSupport.Initialize();
controller = GameCamController.Instance?.AddComponent<FPSCamController>();
gameObject.AddComponent<CamInfoPanel>();
Expand All @@ -53,6 +54,6 @@ protected override void LoadedActions(LoadMode mode)
}

private FPSCamController controller;
private readonly GameObject gameObject = new GameObject();
private GameObject gameObject = new GameObject();
}
}
4 changes: 2 additions & 2 deletions FPSCamera/Code/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public sealed class Mod : PatcherMod<OptionsPanel, PatcherBase>, IUserMod

public string Description => Translations.Translate("MODDESCRIPTION");

public override void SaveSettings() { ModSettings.Save(); OffsetsSettings.Save(); }
public override void SaveSettings() => ModSettings.Save();

public override void LoadSettings() { ModSettings.Load(); OffsetsSettings.Load(); }
public override void LoadSettings() => ModSettings.Load();

}
}
2 changes: 1 addition & 1 deletion FPSCamera/Code/Settings/ModSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public sealed class ModSettings : SettingsXMLBase
[XmlElement("KeyCursorToggle")]
public KeyOnlyBinding XMLKeyCursorToggle { get => KeyCursorToggle; set => KeyCursorToggle = value; }
[XmlIgnore]
internal static KeyOnlyBinding KeyCursorToggle = new KeyOnlyBinding(KeyCode.LeftControl);
internal static KeyOnlyBinding KeyCursorToggle = new KeyOnlyBinding(KeyCode.Tab);

[XmlElement("KeyAutoMove")]
public KeyOnlyBinding XMLKeyAutoMove { get => KeyAutoMove; set => KeyAutoMove = value; }
Expand Down
Loading

0 comments on commit c7e96bf

Please sign in to comment.