From f250b8987a6deaf4c760a0e2a6cb103bdf1580ab Mon Sep 17 00:00:00 2001 From: xen-42 Date: Fri, 16 Aug 2024 15:23:47 -0400 Subject: [PATCH 1/2] Allow navigating a bit on the iron rig, fix ooze rendering --- DredgeVR/DockNavigation/ActionDestination.cs | 34 ++++ .../DockNavigation/DockNavigationHandler.cs | 172 ++++++++++++++++++ DredgeVR/DredgeVR.csproj.user | 2 +- DredgeVR/TitleScreen/TitleScreenPatches.cs | 4 +- .../Patches/TriggerableTimelinePatches.cs | 4 - DredgeVR/VRCamera/RenderToScreen.cs | 104 ++++++----- DredgeVR/VRCamera/VRCameraManager.cs | 19 +- .../Patches/TIRDestinationButtonPatches.cs | 14 ++ DredgeVR/World/WorldManager.cs | 4 +- 9 files changed, 297 insertions(+), 60 deletions(-) create mode 100644 DredgeVR/DockNavigation/ActionDestination.cs create mode 100644 DredgeVR/DockNavigation/DockNavigationHandler.cs create mode 100644 DredgeVR/VRUI/Patches/TIRDestinationButtonPatches.cs diff --git a/DredgeVR/DockNavigation/ActionDestination.cs b/DredgeVR/DockNavigation/ActionDestination.cs new file mode 100644 index 0000000..142fc5d --- /dev/null +++ b/DredgeVR/DockNavigation/ActionDestination.cs @@ -0,0 +1,34 @@ +using HarmonyLib; +using System; + +namespace DredgeVR.DockNavigation; + +[HarmonyPatch] +public class ActionDestination : BaseDestination +{ + private Action _action; + + public void SetUp(Action action, string name) + { + this._action = action; + this.id = name; + + this.alwaysShow = true; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(DestinationButton), nameof(DestinationButton.OnButtonClicked))] + private static bool DestinationButton_OnButtonClicked(DestinationButton __instance) + { + if (__instance.destination is ActionDestination actionDestination) + { + actionDestination._action?.Invoke(); + return false; + } + else + { + return true; + } + } +} + diff --git a/DredgeVR/DockNavigation/DockNavigationHandler.cs b/DredgeVR/DockNavigation/DockNavigationHandler.cs new file mode 100644 index 0000000..59065f5 --- /dev/null +++ b/DredgeVR/DockNavigation/DockNavigationHandler.cs @@ -0,0 +1,172 @@ +using DredgeVR.Helpers; +using DredgeVR.VRCamera; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TMPro; +using UnityEngine; +using static DredgeVR.DockNavigation.DockNavigationHandler; + +namespace DredgeVR.DockNavigation; + +public class DockNavigationHandler : MonoBehaviour +{ + private DockUI _dockUI; + private List _customButtons = new(); + + public enum DockPosition + { + IronRigDock, + IronRigDeck, + Unknown + } + + private DockPosition _dockPosition = DockPosition.Unknown; + + public void Awake() + { + _dockUI = GameObject.FindObjectOfType(); + + GameEvents.Instance.OnPlayerDockedToggled += OnPlayerDockedToggled; + GameEvents.Instance.OnDialogueStarted += RefreshUI; + GameEvents.Instance.OnDialogueCompleted += RefreshUI; + ApplicationEvents.Instance.OnUIWindowToggled += OnUIWindowToggled; + OnPlayerDockedToggled(GameManager.Instance.Player.CurrentDock); + } + + public void OnDestroy() + { + GameEvents.Instance.OnPlayerDockedToggled -= OnPlayerDockedToggled; + GameEvents.Instance.OnDialogueStarted -= RefreshUI; + GameEvents.Instance.OnDialogueCompleted -= RefreshUI; + ApplicationEvents.Instance.OnUIWindowToggled -= OnUIWindowToggled; + } + + + private void OnUIWindowToggled(UIWindowType windowType, bool show) + { + if (windowType == UIWindowType.DOCK && show) + { + Delay.FireOnNextUpdate(RefreshUI); + } + } + + private void RefreshUI() + { + switch (_dockPosition) + { + case DockPosition.IronRigDock: + ShowIronRigDockUI(); + break; + case DockPosition.IronRigDeck: + ShowIronRigDeckUI(); + break; + default: + break; + } + + if (GameManager.Instance.DialogueRunner.Dialogue?.IsActive ?? false) + { + foreach (var button in _customButtons) button.SetActive(false); + } + } + + private GameObject _tirElevatorButton, _tirDockButton; + + private void OnPlayerDockedToggled(Dock dock) + { + try + { + if (dock == null) + { + // Reset anchor transform + VRCameraManager.Instance.ResetAnchorToBoat(); + _dockPosition = DockPosition.Unknown; + foreach (var button in _customButtons) + { + GameObject.Destroy(button); + } + _customButtons.Clear(); + } + if (dock.name.Contains("Iron Rig")) + { + _tirElevatorButton = MakeButton("Go up elevator", GoToIronRigDeck, new Vector2(0, 0)); + _tirDockButton = MakeButton("Return to dock", GoToIronRigDock, new Vector2(0, 0)); + + // Standing on the dock + GoToIronRigDock(); + } + } + catch (Exception e) + { + DredgeVRLogger.Error($"Something went wrong when docking/undocking - {e}"); + } + } + + private void GoToIronRigDock() + { + _dockPosition = DockPosition.IronRigDock; + VRCameraManager.MoveCameraTo(new Vector3(-13.5945f, 1.1673f, 690.1805f), Quaternion.identity); + ShowIronRigDockUI(); + } + + private void ShowIronRigDockUI() + { + // Hide upper deck buttons, only show elevator and fleet services + foreach (Transform button in _dockUI.destinationButtonContainer.transform) + { + button.gameObject.SetActive(false); + } + + _tirElevatorButton?.SetActive(true); + _dockUI.destinationButtonContainer?.Find("DestinationButton: FleetServices")?.gameObject?.SetActive(true); + } + + private void GoToIronRigDeck() + { + _dockPosition = DockPosition.IronRigDeck; + VRCameraManager.MoveCameraTo(new Vector3(-5.0297f, 15.2771f, 684.2171f), Quaternion.identity); + ShowIronRigDeckUI(); + } + + private void ShowIronRigDeckUI() + { + // Show upper deck buttons, only hide elevator and fleet services + foreach (Transform button in _dockUI.destinationButtonContainer.transform) + { + button.gameObject.SetActive(true); + } + + _tirElevatorButton?.SetActive(false); + _dockUI.destinationButtonContainer?.Find("DestinationButton: FleetServices")?.gameObject?.SetActive(false); + } + + private GameObject MakeButton(string text, Action action, Vector2 position) + { + try + { + var gameObject = UnityEngine.Object.Instantiate(_dockUI.destinationButtonPrefab, _dockUI.destinationButtonContainer); + Component.Destroy(gameObject.GetComponent()); + gameObject.name = text; + gameObject.transform.localPosition = new Vector3(position.x, position.y, 0); + gameObject.transform.Find("AttentionCallout").gameObject.SetActive(false); + var button = gameObject.transform.Find("ButtonWithIcon"); + button.transform.Find("Icon").gameObject.SetActive(false); + button.GetComponent().OnClick = action; + button.GetComponentInChildren().text = text; + + _customButtons.Add(gameObject); + + return gameObject; + } + catch (Exception e) + { + DredgeVRLogger.Error($"Couldn't make button - {e}"); + throw; + } + } + +} diff --git a/DredgeVR/DredgeVR.csproj.user b/DredgeVR/DredgeVR.csproj.user index 8964abe..7e30d35 100644 --- a/DredgeVR/DredgeVR.csproj.user +++ b/DredgeVR/DredgeVR.csproj.user @@ -1,6 +1,6 @@ - C:\Program Files (x86)\Steam\steamapps\common\DREDGE + E:\SteamLibrary\steamapps\common\DREDGE $(DredgePath)\Mods\xen.DredgeVR \ No newline at end of file diff --git a/DredgeVR/TitleScreen/TitleScreenPatches.cs b/DredgeVR/TitleScreen/TitleScreenPatches.cs index 1c9b4f2..262d91e 100644 --- a/DredgeVR/TitleScreen/TitleScreenPatches.cs +++ b/DredgeVR/TitleScreen/TitleScreenPatches.cs @@ -57,8 +57,8 @@ public static void TitleScreenView_SetAllDLC(TitleScreenView __instance) { DredgeVRLogger.Info("All DLC title screen"); - var camLookAt = new Vector3(86.9563f, 1.2f, -119.7114f); - var camPos = new Vector3(80.7999f, 1.2f, -115.8387f); + var camLookAt = new Vector3(86.9563f, 2f, -119.7114f); + var camPos = new Vector3(80.7999f, 2f, -115.8387f); SetUpTitleScreen(camPos, camLookAt); } diff --git a/DredgeVR/VRCamera/Patches/TriggerableTimelinePatches.cs b/DredgeVR/VRCamera/Patches/TriggerableTimelinePatches.cs index ecfd3d0..0a6ff20 100644 --- a/DredgeVR/VRCamera/Patches/TriggerableTimelinePatches.cs +++ b/DredgeVR/VRCamera/Patches/TriggerableTimelinePatches.cs @@ -2,12 +2,8 @@ using Cinemachine.Utility; using DredgeVR.VRUI; using HarmonyLib; -using System; using System.Collections; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using UnityEngine; namespace DredgeVR.VRCamera.Patches; diff --git a/DredgeVR/VRCamera/RenderToScreen.cs b/DredgeVR/VRCamera/RenderToScreen.cs index f898541..a355c1c 100644 --- a/DredgeVR/VRCamera/RenderToScreen.cs +++ b/DredgeVR/VRCamera/RenderToScreen.cs @@ -1,60 +1,64 @@ using DredgeVR.Helpers; using DredgeVR.Options; +using System.Collections.Generic; using UnityEngine; +using UnityEngine.Rendering; using UnityEngine.XR; namespace DredgeVR.VRCamera; public class RenderToScreen : MonoBehaviour { - private XRDisplaySubsystem _displaySubsystem; - private Texture _blackScreenTexture; - - public void Awake() - { - _displaySubsystem = SteamVRHelper.GetSubSystem(); - - _blackScreenTexture = Texture2D.blackTexture; - } - - // OnGUI drew a second copy of the textures in world space - // OnBeginContextRendering drew several copies - // OnEndContextRendering only drew worldspace - // LateUpdate worked then broke randomly somehow - // Update seems to work but we'll see - public void Update() - { - DrawToScreen(); - } - - private void DrawToScreen() - { - Graphics.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), _blackScreenTexture, null, pass: 0); - - if (!OptionsManager.Options.disableMonitor) - { - var texture = _displaySubsystem.GetRenderTextureForRenderPass(0); - if (texture != null) - { - // Have to flip it because it's upsidedown - Graphics.DrawTexture(FitToScreen(Screen.width, Screen.height, texture.width, texture.height), texture, AssetLoader.FlipYAxisMaterial, pass: 0); - } - } - } - - private Rect FitToScreen(float screenWidth, float screenHeight, float textureWidth, float textureHeight, bool fitWidth = true) - { - var ratioX = screenWidth / textureWidth; - var ratioY = screenHeight / textureHeight; - - var ratio = fitWidth || ratioX < ratioY ? ratioX : ratioY; - - var newHeight = textureHeight * ratio; - var newWidth = textureWidth * ratio; - - var posX = (screenWidth - (textureWidth * ratio)) / 2f; - var posY = (screenHeight - (textureHeight * ratio)) / 2f; - - return new Rect(posX, posY, newWidth, newHeight); - } + private XRDisplaySubsystem _displaySubsystem; + private Texture _blackScreenTexture; + + public void Awake() + { + _displaySubsystem = SteamVRHelper.GetSubSystem(); + + _blackScreenTexture = Texture2D.blackTexture; + } + + // OnGUI drew a second copy of the textures in world space + // OnBeginContextRendering drew several copies + // OnEndContextRendering only drew worldspace + // LateUpdate worked then broke randomly somehow + // Update seems to work but we'll see + public void Update() + { + DrawToScreen(); + } + + private void DrawToScreen() + { + // Null makes us render to the screen + RenderTexture.active = null; + Graphics.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), _blackScreenTexture, null, pass: 0); + + if (!OptionsManager.Options.disableMonitor) + { + var texture = _displaySubsystem.GetRenderTextureForRenderPass(0); + if (texture != null) + { + // Have to flip it because it's upsidedown + Graphics.DrawTexture(FitToScreen(Screen.width, Screen.height, texture.width, texture.height), texture, AssetLoader.FlipYAxisMaterial, pass: 0); + } + } + } + + private Rect FitToScreen(float screenWidth, float screenHeight, float textureWidth, float textureHeight, bool fitWidth = true) + { + var ratioX = screenWidth / textureWidth; + var ratioY = screenHeight / textureHeight; + + var ratio = fitWidth || ratioX < ratioY ? ratioX : ratioY; + + var newHeight = textureHeight * ratio; + var newWidth = textureWidth * ratio; + + var posX = (screenWidth - (textureWidth * ratio)) / 2f; + var posY = (screenHeight - (textureHeight * ratio)) / 2f; + + return new Rect(posX, posY, newWidth, newHeight); + } } diff --git a/DredgeVR/VRCamera/VRCameraManager.cs b/DredgeVR/VRCamera/VRCameraManager.cs index ac0c895..01e497c 100644 --- a/DredgeVR/VRCamera/VRCameraManager.cs +++ b/DredgeVR/VRCamera/VRCameraManager.cs @@ -157,7 +157,7 @@ public void Update() // In the game scene force a constant ResetTransform y position // Else you bump into something and dear god - if (SceneManager.GetActiveScene().name == "Game") + if (SceneManager.GetActiveScene().name == "Game" && !GameManager.Instance.Player.IsDocked) { if (InCutscene) { @@ -275,7 +275,22 @@ private void OnCutToCredits() [HarmonyPatch(typeof(FinaleCutsceneLogic), nameof(FinaleCutsceneLogic.CutToCredits))] public static void FinaleCutsceneLogic_CutToCredits() => Instance.OnCutToCredits(); - /* + public static void MoveCameraTo(Vector3 globalPosition, Quaternion rotation) + { + VRCameraManager.Instance.StartCoroutine(CoroutineMoveCameraTo(globalPosition, rotation)); + } + + private static IEnumerator CoroutineMoveCameraTo(Vector3 globalPosition, Quaternion rotation) + { + GameManager.Instance.Loader.loadingScreen.Fade(true, true); + yield return new WaitForSeconds(1f); + AnchorTransform.position = globalPosition; + AnchorTransform.rotation = rotation; + + GameManager.Instance.Loader.loadingScreen.Fade(false, true); + } + + /* [HarmonyPostfix] [HarmonyPatch(typeof(CinematicCamera), nameof(CinematicCamera.Play))] public static void CinematicCamera_Play(CinematicCamera __instance) diff --git a/DredgeVR/VRUI/Patches/TIRDestinationButtonPatches.cs b/DredgeVR/VRUI/Patches/TIRDestinationButtonPatches.cs new file mode 100644 index 0000000..96de93d --- /dev/null +++ b/DredgeVR/VRUI/Patches/TIRDestinationButtonPatches.cs @@ -0,0 +1,14 @@ +using HarmonyLib; + +namespace DredgeVR.VRUI.Patches; + +[HarmonyPatch(typeof(TIRDestinationButton))] +public static class TIRDestinationButtonPatches +{ + [HarmonyPostfix] + [HarmonyPatch(nameof(TIRDestinationButton.Init))] + public static void TIRDestinationButton_Init(TIRDestinationButton __instance) + { + __instance.uiLineRenderer.gameObject.SetActive(false); + } +} diff --git a/DredgeVR/World/WorldManager.cs b/DredgeVR/World/WorldManager.cs index 69d6466..95d34f7 100644 --- a/DredgeVR/World/WorldManager.cs +++ b/DredgeVR/World/WorldManager.cs @@ -1,4 +1,5 @@ -using DredgeVR.Helpers; +using DredgeVR.DockNavigation; +using DredgeVR.Helpers; using DredgeVR.Items; using DredgeVR.Options; using System.Linq; @@ -101,6 +102,7 @@ public void OnPlayerSpawned() // Set up held items GameObject.FindObjectOfType().gameObject.AddComponent().SetOffset(650, 300); GameObject.FindObjectOfType().gameObject.AddComponent().SetOffset(650, 300); + GameObject.FindObjectOfType().gameObject.AddComponent(); // This has to happen here else the shader is null // Put a giant black square at the bottom of the sea From 71290193f7d5e481512ac44b210377af74912e6d Mon Sep 17 00:00:00 2001 From: xen-42 Date: Fri, 16 Aug 2024 18:04:59 -0400 Subject: [PATCH 2/2] "Remove smoke" setting, pull player camera back more, fix spiral minigame ui, fix TIR buttons, improve TIR cutscenes but not fully --- .editorconfig | 13 + .../Ability/Spyglass/SpyglassHarvestPOIUI.cs | 36 +- .../DockNavigation/DockNavigationHandler.cs | 342 ++++++++++-------- DredgeVR/Options/OptionsConfig.cs | 8 +- .../Patches/TriggerableTimelinePatches.cs | 12 +- DredgeVR/VRCamera/RenderToScreen.cs | 2 - DredgeVR/VRCamera/VRCameraManager.cs | 2 +- .../VRUI/Minigames/SpiralMinigamePatches.cs | 14 + .../VRUI/Patches/DestinationButtonPatches.cs | 9 + DredgeVR/World/WorldManager.cs | 12 +- DredgeVR/mod_meta.json | 2 +- 11 files changed, 269 insertions(+), 183 deletions(-) create mode 100644 .editorconfig create mode 100644 DredgeVR/VRUI/Minigames/SpiralMinigamePatches.cs diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..167594b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ + +# All files +[*] +indent_style = tab + +# Xml files +[*.xml] +indent_size = 2 + +[*.cs] +csharp_style_namespace_declarations=file_scoped:suggestion +csharp_indent_braces=false +csharp_style_var_elsewhere=true \ No newline at end of file diff --git a/DredgeVR/Ability/Spyglass/SpyglassHarvestPOIUI.cs b/DredgeVR/Ability/Spyglass/SpyglassHarvestPOIUI.cs index 461412d..83b86d6 100644 --- a/DredgeVR/Ability/Spyglass/SpyglassHarvestPOIUI.cs +++ b/DredgeVR/Ability/Spyglass/SpyglassHarvestPOIUI.cs @@ -30,10 +30,12 @@ public class SpyglassHarvestPOIUI : MonoBehaviour private AbilityData _spyglassAbilityData; private bool _usingSpyglass; - + private float _updateTimer; public const float UPDATE_TIME = 1f; + private SpyglassUI _spyglassUI; + private void Awake() { GameEvents.Instance.OnPlayerAbilityToggled += this.OnPlayerAbilityToggled; @@ -46,12 +48,12 @@ private void OnDestroy() public void Start() { - var spyglassUI = GameManager.Instance.UI.spyglassUI; - _spyglassAbilityData = spyglassUI.spyglassAbilityData; + _spyglassUI = GameManager.Instance.UI.spyglassUI; + _spyglassAbilityData = _spyglassUI.spyglassAbilityData; if (_prefab == null) { - _prefab = GameObject.Instantiate(spyglassUI.container); + _prefab = GameObject.Instantiate(_spyglassUI.container); _prefab.SetActive(false); // Needs to be worldspace var canvas = _prefab.AddComponent(); @@ -67,12 +69,12 @@ public void Start() _container.transform.localScale = Vector3.zero; // Grab all the components - _itemNameString = _container.transform.Find("Backplate/BackplateInner/NameText").GetComponent(); - _itemImage = _container.transform.Find("Backplate/BackplateInner/Image").GetComponent(); - _invalidEquipmentImage = _container.transform.Find("Backplate/BackplateInner/InvalidEquipmentImage").GetComponent(); - _hiddenItemSprite = spyglassUI.hiddenItemSprite; + _itemNameString = _container.transform.Find("Backplate/BasicContainer/NameText").GetComponent(); + _itemImage = _container.transform.Find("Backplate/BasicContainer/Image").GetComponent(); + _invalidEquipmentImage = _container.transform.Find("Backplate/BasicContainer/InvalidEquipmentImage").GetComponent(); + _hiddenItemSprite = _spyglassUI.hiddenItemSprite; _harvestableTypeTagUI = _container.transform.Find("Backplate/HarvestableTypeTag").GetComponent(); - _obscuredString = spyglassUI.obscuredString; + _obscuredString = _spyglassUI.obscuredString; _updateTimer = Random.Range(0, UPDATE_TIME); } @@ -93,7 +95,7 @@ public void Update() } // Lerp scale based on if active - var targetScale = _shouldShowContainer ? Vector3.one * _containerScale : Vector3.zero; + var targetScale = _shouldShowContainer ? 2f * Vector3.one * _containerScale : Vector3.zero; if (_container.transform.localScale != targetScale) { var t = Mathf.Clamp01(Mathf.InverseLerp(_shouldShowContainer ? 0f : _containerScale, targetScale.x, _container.transform.localScale.x) + Time.deltaTime); @@ -104,12 +106,20 @@ public void Update() _container.SetActive(false); } } + + if (_container.activeInHierarchy) + { + // LookAt makes them backwards though + _container.transform.LookAt(VRCameraManager.VRPlayer.transform.position); + _container.transform.Rotate(Vector3.up, 180f); + } + } private void CheckPlayerPosition() { // Only show objects within a certain range - if ((GameManager.Instance.Player.transform.position - transform.position).magnitude < 60) + if ((GameManager.Instance.Player.transform.position - transform.position).magnitude < (_spyglassUI.hasAdvancedSpyglass ? 90 : 60)) { _shouldShowContainer = true; @@ -130,10 +140,6 @@ private void CheckPlayerPosition() // TODO: Ideally we'd also check that you're looking towards it GameManager.Instance.SaveData.SetHasSpiedHarvestCategory(_firstHarvestableItem.harvestableType, true); GameManager.Instance.AchievementManager.EvaluateAchievement(DredgeAchievementId.ABILITY_SPYGLASS); - - // LookAt makes them backwards though - _container.transform.LookAt(VRCameraManager.VRPlayer.transform.position); - _container.transform.Rotate(Vector3.up, 180f); } } else diff --git a/DredgeVR/DockNavigation/DockNavigationHandler.cs b/DredgeVR/DockNavigation/DockNavigationHandler.cs index 59065f5..54d32a2 100644 --- a/DredgeVR/DockNavigation/DockNavigationHandler.cs +++ b/DredgeVR/DockNavigation/DockNavigationHandler.cs @@ -1,172 +1,196 @@ using DredgeVR.Helpers; using DredgeVR.VRCamera; -using HarmonyLib; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using TMPro; using UnityEngine; -using static DredgeVR.DockNavigation.DockNavigationHandler; namespace DredgeVR.DockNavigation; public class DockNavigationHandler : MonoBehaviour { - private DockUI _dockUI; - private List _customButtons = new(); - - public enum DockPosition - { - IronRigDock, - IronRigDeck, - Unknown - } - - private DockPosition _dockPosition = DockPosition.Unknown; - - public void Awake() - { - _dockUI = GameObject.FindObjectOfType(); - - GameEvents.Instance.OnPlayerDockedToggled += OnPlayerDockedToggled; - GameEvents.Instance.OnDialogueStarted += RefreshUI; - GameEvents.Instance.OnDialogueCompleted += RefreshUI; - ApplicationEvents.Instance.OnUIWindowToggled += OnUIWindowToggled; - OnPlayerDockedToggled(GameManager.Instance.Player.CurrentDock); - } - - public void OnDestroy() - { - GameEvents.Instance.OnPlayerDockedToggled -= OnPlayerDockedToggled; - GameEvents.Instance.OnDialogueStarted -= RefreshUI; - GameEvents.Instance.OnDialogueCompleted -= RefreshUI; - ApplicationEvents.Instance.OnUIWindowToggled -= OnUIWindowToggled; - } - - - private void OnUIWindowToggled(UIWindowType windowType, bool show) - { - if (windowType == UIWindowType.DOCK && show) - { - Delay.FireOnNextUpdate(RefreshUI); - } - } - - private void RefreshUI() - { - switch (_dockPosition) - { - case DockPosition.IronRigDock: - ShowIronRigDockUI(); - break; - case DockPosition.IronRigDeck: - ShowIronRigDeckUI(); - break; - default: - break; - } - - if (GameManager.Instance.DialogueRunner.Dialogue?.IsActive ?? false) - { - foreach (var button in _customButtons) button.SetActive(false); - } - } - - private GameObject _tirElevatorButton, _tirDockButton; - - private void OnPlayerDockedToggled(Dock dock) - { - try - { - if (dock == null) - { - // Reset anchor transform - VRCameraManager.Instance.ResetAnchorToBoat(); - _dockPosition = DockPosition.Unknown; - foreach (var button in _customButtons) - { - GameObject.Destroy(button); - } - _customButtons.Clear(); - } - if (dock.name.Contains("Iron Rig")) - { - _tirElevatorButton = MakeButton("Go up elevator", GoToIronRigDeck, new Vector2(0, 0)); - _tirDockButton = MakeButton("Return to dock", GoToIronRigDock, new Vector2(0, 0)); - - // Standing on the dock - GoToIronRigDock(); - } - } - catch (Exception e) - { - DredgeVRLogger.Error($"Something went wrong when docking/undocking - {e}"); - } - } - - private void GoToIronRigDock() - { - _dockPosition = DockPosition.IronRigDock; - VRCameraManager.MoveCameraTo(new Vector3(-13.5945f, 1.1673f, 690.1805f), Quaternion.identity); - ShowIronRigDockUI(); - } - - private void ShowIronRigDockUI() - { - // Hide upper deck buttons, only show elevator and fleet services - foreach (Transform button in _dockUI.destinationButtonContainer.transform) - { - button.gameObject.SetActive(false); - } - - _tirElevatorButton?.SetActive(true); - _dockUI.destinationButtonContainer?.Find("DestinationButton: FleetServices")?.gameObject?.SetActive(true); - } - - private void GoToIronRigDeck() - { - _dockPosition = DockPosition.IronRigDeck; - VRCameraManager.MoveCameraTo(new Vector3(-5.0297f, 15.2771f, 684.2171f), Quaternion.identity); - ShowIronRigDeckUI(); - } - - private void ShowIronRigDeckUI() - { - // Show upper deck buttons, only hide elevator and fleet services - foreach (Transform button in _dockUI.destinationButtonContainer.transform) - { - button.gameObject.SetActive(true); - } - - _tirElevatorButton?.SetActive(false); - _dockUI.destinationButtonContainer?.Find("DestinationButton: FleetServices")?.gameObject?.SetActive(false); - } - - private GameObject MakeButton(string text, Action action, Vector2 position) - { - try - { - var gameObject = UnityEngine.Object.Instantiate(_dockUI.destinationButtonPrefab, _dockUI.destinationButtonContainer); - Component.Destroy(gameObject.GetComponent()); - gameObject.name = text; - gameObject.transform.localPosition = new Vector3(position.x, position.y, 0); - gameObject.transform.Find("AttentionCallout").gameObject.SetActive(false); - var button = gameObject.transform.Find("ButtonWithIcon"); - button.transform.Find("Icon").gameObject.SetActive(false); - button.GetComponent().OnClick = action; - button.GetComponentInChildren().text = text; - - _customButtons.Add(gameObject); - - return gameObject; - } - catch (Exception e) - { - DredgeVRLogger.Error($"Couldn't make button - {e}"); - throw; - } - } + private DockUI _dockUI; + private List _customButtons = new(); + + public enum DockPosition + { + IronRigDock, + IronRigDeck, + Unknown + } + + public DockPosition CurrentDockPosition { get; private set; } = DockPosition.Unknown; + + public static DockNavigationHandler Instance { get; private set; } + + public void Awake() + { + Instance = this; + + _dockUI = GameObject.FindObjectOfType(); + + GameEvents.Instance.OnPlayerDockedToggled += OnPlayerDockedToggled; + GameEvents.Instance.OnDialogueStarted += RefreshUI; + GameEvents.Instance.OnDialogueCompleted += RefreshUI; + ApplicationEvents.Instance.OnUIWindowToggled += OnUIWindowToggled; + OnPlayerDockedToggled(GameManager.Instance.Player.CurrentDock); + } + + public void OnDestroy() + { + GameEvents.Instance.OnPlayerDockedToggled -= OnPlayerDockedToggled; + GameEvents.Instance.OnDialogueStarted -= RefreshUI; + GameEvents.Instance.OnDialogueCompleted -= RefreshUI; + ApplicationEvents.Instance.OnUIWindowToggled -= OnUIWindowToggled; + } + + + private void OnUIWindowToggled(UIWindowType windowType, bool show) + { + if (windowType == UIWindowType.DOCK && show) + { + Delay.FireOnNextUpdate(RefreshUI); + } + } + + private void RefreshUI() + { + switch (CurrentDockPosition) + { + case DockPosition.IronRigDock: + ShowIronRigDockUI(); + break; + case DockPosition.IronRigDeck: + ShowIronRigDeckUI(); + break; + default: + break; + } + + if (GameManager.Instance.DialogueRunner.Dialogue?.IsActive ?? false) + { + foreach (var button in _customButtons) button.SetActive(false); + } + } + + public void RefreshPosition() + { + switch (CurrentDockPosition) + { + case DockPosition.IronRigDock: + GoToIronRigDock(); + break; + case DockPosition.IronRigDeck: + GoToIronRigDeck(); + break; + default: + break; + } + + RefreshUI(); + } + + private GameObject _tirElevatorButton, _tirDockButton; + + private void OnPlayerDockedToggled(Dock dock) + { + try + { + if (dock == null) + { + // Reset anchor transform + VRCameraManager.Instance.ResetAnchorToBoat(); + CurrentDockPosition = DockPosition.Unknown; + foreach (var button in _customButtons) + { + GameObject.Destroy(button); + } + _customButtons.Clear(); + } + if (dock.name.Contains("Iron Rig")) + { + _tirElevatorButton = MakeButton("Go up elevator", GoToIronRigDeck, new Vector2(0, 0)); + _tirDockButton = MakeButton("Return to dock", GoToIronRigDock, new Vector2(0, 0)); + + // Standing on the dock + GoToIronRigDock(); + } + } + catch (Exception e) + { + DredgeVRLogger.Error($"Something went wrong when docking/undocking - {e}"); + } + } + + private void GoToIronRigDock() + { + CurrentDockPosition = DockPosition.IronRigDock; + VRCameraManager.MoveCameraTo(new Vector3(-13.5945f, 1.1673f, 690.1805f), Quaternion.identity); + ShowIronRigDockUI(); + } + + private void ShowIronRigDockUI() + { + // Hide upper deck buttons, only show elevator and fleet services + foreach (Transform button in _dockUI.destinationButtonContainer.transform) + { + if (button.name.Contains("BoatActionsDestinationUI")) continue; + button.gameObject.SetActive(false); + } + + var cargoElevatorButton = _dockUI.destinationButtonContainer?.Find("DestinationButton: RigBase"); + + _tirElevatorButton?.SetActive(cargoElevatorButton == null); + _dockUI.destinationButtonContainer?.Find("DestinationButton: FleetServices")?.gameObject?.SetActive(true); + _dockUI.destinationButtonContainer?.Find("DestinationButton: StorageOnLowerPlatform")?.gameObject?.SetActive(true); + _dockUI.destinationButtonContainer?.Find("DestinationButton: RigBase")?.gameObject?.SetActive(true); + } + + private void GoToIronRigDeck() + { + CurrentDockPosition = DockPosition.IronRigDeck; + VRCameraManager.MoveCameraTo(new Vector3(-5.0297f, 15.2771f, 684.2171f), Quaternion.identity); + ShowIronRigDeckUI(); + } + + private void ShowIronRigDeckUI() + { + // Show upper deck buttons, only hide elevator and fleet services + foreach (Transform button in _dockUI.destinationButtonContainer.transform) + { + button.gameObject.SetActive(true); + } + + _tirElevatorButton?.SetActive(false); + _dockUI.destinationButtonContainer?.Find("DestinationButton: FleetServices")?.gameObject?.SetActive(false); + _dockUI.destinationButtonContainer?.Find("DestinationButton: StorageOnLowerPlatform")?.gameObject?.SetActive(false); + _dockUI.destinationButtonContainer?.Find("DestinationButton: RigBase")?.gameObject?.SetActive(false); + } + + private GameObject MakeButton(string text, Action action, Vector2 position) + { + try + { + var gameObject = UnityEngine.Object.Instantiate(_dockUI.destinationButtonPrefab, _dockUI.destinationButtonContainer); + Component.Destroy(gameObject.GetComponent()); + gameObject.name = text; + gameObject.transform.localPosition = new Vector3(position.x, position.y, 0); + gameObject.transform.Find("AttentionCallout").gameObject.SetActive(false); + var button = gameObject.transform.Find("ButtonWithIcon"); + button.transform.Find("Icon").gameObject.SetActive(false); + button.GetComponent().OnClick = action; + button.GetComponentInChildren().text = text; + + _customButtons.Add(gameObject); + gameObject.SetActive(false); + + return gameObject; + } + catch (Exception e) + { + DredgeVRLogger.Error($"Couldn't make button - {e}"); + throw; + } + } } diff --git a/DredgeVR/Options/OptionsConfig.cs b/DredgeVR/Options/OptionsConfig.cs index bb1ba0c..b04723f 100644 --- a/DredgeVR/Options/OptionsConfig.cs +++ b/DredgeVR/Options/OptionsConfig.cs @@ -97,7 +97,13 @@ public class OptionsConfig public float playerScale = 1f; [JsonProperty] - public float[] playerPosition = new float[] { 0, 1.13f, -1.5f }; + public float[] playerPosition = new float[] { 0, 1.5f, -1.8f }; + + /// + /// Don't render the smoke columns coming from the ship + /// + [JsonProperty] + public bool removeSmoke = true; public Vector3 PlayerPosition => new(playerPosition[0], playerPosition[1], playerPosition[2]); } diff --git a/DredgeVR/VRCamera/Patches/TriggerableTimelinePatches.cs b/DredgeVR/VRCamera/Patches/TriggerableTimelinePatches.cs index 0a6ff20..550c9d2 100644 --- a/DredgeVR/VRCamera/Patches/TriggerableTimelinePatches.cs +++ b/DredgeVR/VRCamera/Patches/TriggerableTimelinePatches.cs @@ -1,5 +1,6 @@ using Cinemachine; using Cinemachine.Utility; +using DredgeVR.DockNavigation; using DredgeVR.VRUI; using HarmonyLib; using System.Collections; @@ -41,7 +42,7 @@ private static IEnumerator TriggerableTimelineLogic(TriggerableTimeline __instan while (_playing) { var prevCamera = _camera; - + if (_camera == null || !_camera.gameObject.activeInHierarchy) { // Try to update the camera to an active one @@ -69,7 +70,14 @@ private static IEnumerator TriggerableTimelineLogic(TriggerableTimeline __instan VRCameraManager.Instance.InCutscene = false; - VRCameraManager.Instance.ResetAnchorToBoat(); + if (DockNavigationHandler.Instance.CurrentDockPosition != DockNavigationHandler.DockPosition.Unknown) + { + DockNavigationHandler.Instance.RefreshPosition(); + } + else + { + VRCameraManager.Instance.ResetAnchorToBoat(); + } yield return ShowLoadingScreen(false); diff --git a/DredgeVR/VRCamera/RenderToScreen.cs b/DredgeVR/VRCamera/RenderToScreen.cs index a355c1c..eac8542 100644 --- a/DredgeVR/VRCamera/RenderToScreen.cs +++ b/DredgeVR/VRCamera/RenderToScreen.cs @@ -1,8 +1,6 @@ using DredgeVR.Helpers; using DredgeVR.Options; -using System.Collections.Generic; using UnityEngine; -using UnityEngine.Rendering; using UnityEngine.XR; namespace DredgeVR.VRCamera; diff --git a/DredgeVR/VRCamera/VRCameraManager.cs b/DredgeVR/VRCamera/VRCameraManager.cs index 01e497c..3c9d4e0 100644 --- a/DredgeVR/VRCamera/VRCameraManager.cs +++ b/DredgeVR/VRCamera/VRCameraManager.cs @@ -173,7 +173,7 @@ public void Update() } // If the camera y is locked but the boat is moving around the anchor point gets offset - if (OptionsManager.Options.lockCameraYPosition && !OptionsManager.Options.removeWaves) + if (OptionsManager.Options.lockCameraYPosition) { ResetAnchorToBoat(); } diff --git a/DredgeVR/VRUI/Minigames/SpiralMinigamePatches.cs b/DredgeVR/VRUI/Minigames/SpiralMinigamePatches.cs new file mode 100644 index 0000000..9946bfc --- /dev/null +++ b/DredgeVR/VRUI/Minigames/SpiralMinigamePatches.cs @@ -0,0 +1,14 @@ +using HarmonyLib; + +namespace DredgeVR.VRUI.Minigames; + +[HarmonyPatch] +public static class SpiralMinigamePatches +{ + [HarmonyPostfix] + [HarmonyPatch(typeof(SpiralComponent), nameof(SpiralComponent.SetRotation))] + public static void SpiralComponent_SetRotation(SpiralComponent __instance) + { + __instance.transform.localRotation = UnityEngine.Quaternion.Euler(0, 0, __instance.transform.rotation.eulerAngles.z - 90); + } +} diff --git a/DredgeVR/VRUI/Patches/DestinationButtonPatches.cs b/DredgeVR/VRUI/Patches/DestinationButtonPatches.cs index 608f1de..ee5962d 100644 --- a/DredgeVR/VRUI/Patches/DestinationButtonPatches.cs +++ b/DredgeVR/VRUI/Patches/DestinationButtonPatches.cs @@ -94,6 +94,15 @@ public static bool DestinationButton_LateUpdate(DestinationButton __instance) // Again since we're docked so close set a max size scaleModifier = Mathf.Min(scaleModifier, 12f); } + else if (GameManager.Instance.Player.CurrentDock.name.Contains("Iron Rig")) + { + scaleModifier *= 0.3f; + if (__instance.destination.name.Contains("RigBase")) + { + planeOffset *= 2.5f; + yOffset = Vector3.zero; + } + } if (OptionsManager.Options.playerScale > 1) { diff --git a/DredgeVR/World/WorldManager.cs b/DredgeVR/World/WorldManager.cs index 95d34f7..471dc10 100644 --- a/DredgeVR/World/WorldManager.cs +++ b/DredgeVR/World/WorldManager.cs @@ -48,7 +48,7 @@ private void OnSceneStart(string scene) { terrain.heightmapMaximumLOD = Mathf.Max(terrain.heightmapMaximumLOD, 3); } - if (OptionsManager.Options.disableUnderseaDetails) + if (OptionsManager.Options.disableUnderseaDetails) { // The "trees and foliage" are actually rocks on the sea floor terrain.drawTreesAndFoliage = false; @@ -102,7 +102,7 @@ public void OnPlayerSpawned() // Set up held items GameObject.FindObjectOfType().gameObject.AddComponent().SetOffset(650, 300); GameObject.FindObjectOfType().gameObject.AddComponent().SetOffset(650, 300); - GameObject.FindObjectOfType().gameObject.AddComponent(); + GameObject.FindObjectOfType().gameObject.AddComponent(); // This has to happen here else the shader is null // Put a giant black square at the bottom of the sea @@ -117,5 +117,13 @@ public void OnPlayerSpawned() var material = new Material(AssetLoader.UnlitShader); seaFloorCover.AddComponent().material = material; material.mainTexture = Texture2D.blackTexture; + + if (OptionsManager.Options.removeSmoke) + { + foreach (var smoke in GameObject.FindObjectsOfType(true)) + { + smoke.gameObject.GetComponent().forceRenderingOff = true; + } + } } } diff --git a/DredgeVR/mod_meta.json b/DredgeVR/mod_meta.json index 5a08bac..ab60cd4 100644 --- a/DredgeVR/mod_meta.json +++ b/DredgeVR/mod_meta.json @@ -1,7 +1,7 @@ { "Name": "DredgeVR", "ModGUID": "xen.DredgeVR", - "Version": "0.4.0", + "Version": "0.4.1", "ModAssembly": "DredgeVR.dll", "MinWinchVersion": "0.4.0", "Entrypoint": "DredgeVR.Loader/Initialize",