diff --git a/Assemblies/RimNauts2.dll b/Assemblies/RimNauts2.dll index 0138829a..019ab75e 100644 Binary files a/Assemblies/RimNauts2.dll and b/Assemblies/RimNauts2.dll differ diff --git a/Changelog.md b/Changelog.md index 825c32f0..2a3fc559 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1 +1,3 @@ # Changelog +- Increased world camera max altitude allowing the user to zoom more out +- Increased the FOV for a better visual effect diff --git a/Source/RimNauts2/RimNauts2/Constants.cs b/Source/RimNauts2/RimNauts2/Constants.cs index 9c49516e..f17e38d4 100644 --- a/Source/RimNauts2/RimNauts2/Constants.cs +++ b/Source/RimNauts2/RimNauts2/Constants.cs @@ -1,7 +1,7 @@ namespace RimNauts2 { public static class Info { public static readonly string name = "RimNauts 2"; - public static readonly string version = "4.13.0"; + public static readonly string version = "4.14.0"; } public static class Style { diff --git a/Source/RimNauts2/RimNauts2/Defs/Of.cs b/Source/RimNauts2/RimNauts2/Defs/Of.cs index a357a4d4..08f30fe5 100644 --- a/Source/RimNauts2/RimNauts2/Defs/Of.cs +++ b/Source/RimNauts2/RimNauts2/Defs/Of.cs @@ -10,6 +10,10 @@ public static class Of { } public class General : Def { + public float max_altitude = 1600.0f; + public float field_of_view = 40.0f; + public float drag_sensitivity_multiplier = 0.50f; + public float zoom_sensitivity_multiplier = 0.75f; public List allowed_incidents; public string space_station_wall; public string space_station_floor; diff --git a/Source/RimNauts2/RimNauts2/RimNauts2.csproj b/Source/RimNauts2/RimNauts2/RimNauts2.csproj index d3cced0c..60451ba8 100644 --- a/Source/RimNauts2/RimNauts2/RimNauts2.csproj +++ b/Source/RimNauts2/RimNauts2/RimNauts2.csproj @@ -68,6 +68,10 @@ ..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.IMGUIModule.dll False + + ..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.InputLegacyModule.dll + False + ..\..\..\..\..\RimWorldWin64_Data\Managed\UnityEngine.TextRenderingModule.dll False @@ -103,6 +107,7 @@ + diff --git a/Source/RimNauts2/RimNauts2/World/Patch/CameraDriver.cs b/Source/RimNauts2/RimNauts2/World/Patch/CameraDriver.cs new file mode 100644 index 00000000..7c28d990 --- /dev/null +++ b/Source/RimNauts2/RimNauts2/World/Patch/CameraDriver.cs @@ -0,0 +1,136 @@ +using HarmonyLib; +using UnityEngine; +using Verse.Steam; +using Verse; + +namespace RimNauts2.World.Patch { + [HarmonyPatch(typeof(RimWorld.Planet.WorldCameraDriver), "AltitudePercent", MethodType.Getter)] + class WorldCameraDriver_AltitudePercent { + public static bool Prefix(ref RimWorld.Planet.WorldCameraDriver __instance, ref float __result) { + __result = Mathf.InverseLerp(RimWorld.Planet.WorldCameraDriver.MinAltitude, Defs.Of.general.max_altitude, __instance.altitude); + return false; + } + } + + [HarmonyPatch(typeof(RimWorld.Planet.WorldCameraDriver), "WorldCameraDriverOnGUI")] + class WorldCameraDriver_WorldCameraDriverOnGUI { + public static bool Prefix(ref RimWorld.Planet.WorldCameraDriver __instance) { + if (Input.GetMouseButtonUp(0) && Input.GetMouseButton(2)) + __instance.releasedLeftWhileHoldingMiddle = true; + else if (Event.current.rawType == EventType.MouseDown || Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(2)) + __instance.releasedLeftWhileHoldingMiddle = false; + __instance.mouseCoveredByUI = false; + if (Find.WindowStack.GetWindowAt(UI.MousePositionOnUIInverted) != null) + __instance.mouseCoveredByUI = true; + if (__instance.AnythingPreventsCameraMotion) + return false; + if (!UnityGUIBugsFixer.IsSteamDeckOrLinuxBuild && Event.current.type == EventType.MouseDrag && Event.current.button == 2 || UnityGUIBugsFixer.IsSteamDeckOrLinuxBuild && Input.GetMouseButton(2) && (!SteamDeck.IsSteamDeck || !Find.WorldSelector.AnyCaravanSelected)) { + Vector2 currentEventDelta = UnityGUIBugsFixer.CurrentEventDelta; + if (Event.current.type == EventType.MouseDrag) + Event.current.Use(); + if (currentEventDelta != Vector2.zero) { + RimWorld.PlayerKnowledgeDatabase.KnowledgeDemonstrated(RimWorld.ConceptDefOf.WorldCameraMovement, RimWorld.KnowledgeAmount.FrameInteraction); + currentEventDelta.x *= -1f; + __instance.desiredRotationRaw += currentEventDelta / RimWorld.Planet.GenWorldUI.CurUITileSize() * 0.273f * (Prefs.MapDragSensitivity * Defs.Of.general.drag_sensitivity_multiplier); + } + } + float num = 0.0f; + if (Event.current.type == EventType.ScrollWheel) { + num -= Event.current.delta.y * 0.1f; + RimWorld.PlayerKnowledgeDatabase.KnowledgeDemonstrated(RimWorld.ConceptDefOf.WorldCameraMovement, RimWorld.KnowledgeAmount.SpecificInteraction); + } + if (RimWorld.KeyBindingDefOf.MapZoom_In.KeyDownEvent) { + num += 2f; + RimWorld.PlayerKnowledgeDatabase.KnowledgeDemonstrated(RimWorld.ConceptDefOf.WorldCameraMovement, RimWorld.KnowledgeAmount.SpecificInteraction); + } + if (RimWorld.KeyBindingDefOf.MapZoom_Out.KeyDownEvent) { + num -= 2f; + RimWorld.PlayerKnowledgeDatabase.KnowledgeDemonstrated(RimWorld.ConceptDefOf.WorldCameraMovement, RimWorld.KnowledgeAmount.SpecificInteraction); + } + __instance.desiredAltitude -= (float) ((double) num * (double) (__instance.config.zoomSpeed * Defs.Of.general.zoom_sensitivity_multiplier) * (double) __instance.altitude / 12.0); + __instance.desiredAltitude = Mathf.Clamp(__instance.desiredAltitude, RimWorld.Planet.WorldCameraDriver.MinAltitude, Defs.Of.general.max_altitude); + __instance.desiredRotation = Vector2.zero; + if (RimWorld.KeyBindingDefOf.MapDolly_Left.IsDown) { + __instance.desiredRotation.x = -__instance.config.dollyRateKeys; + RimWorld.PlayerKnowledgeDatabase.KnowledgeDemonstrated(RimWorld.ConceptDefOf.WorldCameraMovement, RimWorld.KnowledgeAmount.SpecificInteraction); + } + if (RimWorld.KeyBindingDefOf.MapDolly_Right.IsDown) { + __instance.desiredRotation.x = __instance.config.dollyRateKeys; + RimWorld.PlayerKnowledgeDatabase.KnowledgeDemonstrated(RimWorld.ConceptDefOf.WorldCameraMovement, RimWorld.KnowledgeAmount.SpecificInteraction); + } + if (RimWorld.KeyBindingDefOf.MapDolly_Up.IsDown) { + __instance.desiredRotation.y = __instance.config.dollyRateKeys; + RimWorld.PlayerKnowledgeDatabase.KnowledgeDemonstrated(RimWorld.ConceptDefOf.WorldCameraMovement, RimWorld.KnowledgeAmount.SpecificInteraction); + } + if (RimWorld.KeyBindingDefOf.MapDolly_Down.IsDown) { + __instance.desiredRotation.y = -__instance.config.dollyRateKeys; + RimWorld.PlayerKnowledgeDatabase.KnowledgeDemonstrated(RimWorld.ConceptDefOf.WorldCameraMovement, RimWorld.KnowledgeAmount.SpecificInteraction); + } + __instance.config.ConfigOnGUI(); + return false; + } + } + + [HarmonyPatch(typeof(RimWorld.Planet.WorldCameraDriver), "Update")] + class WorldCameraDriver_Update { + public static bool Prefix(ref RimWorld.Planet.WorldCameraDriver __instance) { + if (LongEventHandler.ShouldWaitForEvent) + return false; + if (Find.World == null) { + __instance.MyCamera.gameObject.SetActive(false); + } else { + if (!Find.WorldInterface.everReset) + Find.WorldInterface.Reset(); + Vector2 curInputDollyVect = __instance.CalculateCurInputDollyVect(); + if (curInputDollyVect != Vector2.zero) { + float num = (float) (((double) __instance.altitude - (double) RimWorld.Planet.WorldCameraDriver.MinAltitude) / (Defs.Of.general.max_altitude - (double) RimWorld.Planet.WorldCameraDriver.MinAltitude) * 0.850000023841858 + 0.150000005960464); + __instance.rotationVelocity = new Vector2(curInputDollyVect.x, curInputDollyVect.y) * num; + } + if ((!Input.GetMouseButton(2) || SteamDeck.IsSteamDeck && __instance.releasedLeftWhileHoldingMiddle) && __instance.dragTimeStamps.Any()) { + __instance.rotationVelocity += CameraDriver.GetExtraVelocityFromReleasingDragButton(__instance.dragTimeStamps, 5f); + __instance.dragTimeStamps.Clear(); + } + if (!__instance.AnythingPreventsCameraMotion) { + float num = Time.deltaTime * CameraDriver.HitchReduceFactor; + __instance.sphereRotation *= Quaternion.AngleAxis(__instance.rotationVelocity.x * num * __instance.config.rotationSpeedScale, __instance.MyCamera.transform.up); + __instance.sphereRotation *= Quaternion.AngleAxis(-__instance.rotationVelocity.y * num * __instance.config.rotationSpeedScale, __instance.MyCamera.transform.right); + if (__instance.desiredRotationRaw != Vector2.zero) { + __instance.sphereRotation *= Quaternion.AngleAxis(__instance.desiredRotationRaw.x, __instance.MyCamera.transform.up); + __instance.sphereRotation *= Quaternion.AngleAxis(-__instance.desiredRotationRaw.y, __instance.MyCamera.transform.right); + } + __instance.dragTimeStamps.Add(new CameraDriver.DragTimeStamp() { + posDelta = __instance.desiredRotationRaw, + time = Time.time + }); + } + __instance.desiredRotationRaw = Vector2.zero; + int num1 = Gen.FixedTimeStepUpdate(ref __instance.fixedTimeStepBuffer, 60f); + for (int index = 0; index < num1; ++index) { + if (__instance.rotationVelocity != Vector2.zero) { + __instance.rotationVelocity *= __instance.config.camRotationDecayFactor; + if ((double) __instance.rotationVelocity.magnitude < 0.0500000007450581) + __instance.rotationVelocity = Vector2.zero; + } + if (__instance.config.smoothZoom) { + float num2 = Mathf.Lerp(__instance.altitude, __instance.desiredAltitude, 0.05f); + __instance.desiredAltitude += (num2 - __instance.altitude) * __instance.config.zoomPreserveFactor; + __instance.altitude = num2; + } else { + float num2 = (float) (((double) __instance.desiredAltitude - (double) __instance.altitude) * 0.400000005960464); + __instance.desiredAltitude += __instance.config.zoomPreserveFactor * num2; + __instance.altitude += num2; + } + } + __instance.rotationAnimation_lerpFactor += Time.deltaTime * 8f; + if (Find.PlaySettings.lockNorthUp) { + __instance.RotateSoNorthIsUp(false); + __instance.ClampXRotation(ref __instance.sphereRotation); + } + for (int index = 0; index < num1; ++index) + __instance.config.ConfigFixedUpdate_60(ref __instance.rotationVelocity); + __instance.ApplyPositionToGameObject(); + } + return false; + } + } +} diff --git a/Source/RimNauts2/RimNauts2/World/Patch/HideIcons.cs b/Source/RimNauts2/RimNauts2/World/Patch/HideIcons.cs index b53fcc97..5610d9db 100644 --- a/Source/RimNauts2/RimNauts2/World/Patch/HideIcons.cs +++ b/Source/RimNauts2/RimNauts2/World/Patch/HideIcons.cs @@ -38,7 +38,7 @@ public static bool check(Vector3 pos) { Vector3 normalized = pos.normalized; float mag = pos.magnitude; float min_alt = 125; - float max_alt = 1100; + float max_alt = Defs.Of.general.max_altitude; float alt = RenderingManager.altitude_percent * (max_alt - min_alt) + max_alt; bool hide = Vector3.Angle(normalized, RenderingManager.center) > (Math.Acos(115 / alt) + Math.Acos(115 / mag)) * (degree / 3.14d); if (mag < 115) hide = Vector3.Angle(normalized, RenderingManager.center) > 73.0f; diff --git a/Source/RimNauts2/RimNauts2/World/RenderingManager.cs b/Source/RimNauts2/RimNauts2/World/RenderingManager.cs index c79dfcb0..e213e3e7 100644 --- a/Source/RimNauts2/RimNauts2/World/RenderingManager.cs +++ b/Source/RimNauts2/RimNauts2/World/RenderingManager.cs @@ -193,7 +193,9 @@ public static void init() { tick_manager = Find.TickManager; camera_driver = Find.WorldCameraDriver; camera = Find.WorldCamera.GetComponent(); - camera.farClipPlane = 1600.0f; + camera.farClipPlane = 500.0f + Defs.Of.general.max_altitude; + camera.fieldOfView = Defs.Of.general.field_of_view; + RimWorld.Planet.WorldCameraManager.worldSkyboxCameraInt.farClipPlane = 500.0f + Defs.Of.general.max_altitude; } public static void update() {