/// <summary> /// Show and change blueprint selection radius /// </summary> private void OnUpdatePlacement(On.Player.orig_UpdatePlacement orig, Player self, bool takeInput, float dt) { orig(self, takeInput, dt); if (self.m_placementGhost) { var piece = self.m_placementGhost.GetComponent <Piece>(); if (piece != null) { if (piece.name == "make_blueprint" && !piece.IsCreator()) { if (!self.m_placementMarkerInstance) { return; } float scrollWheel = Input.GetAxis("Mouse ScrollWheel"); if (scrollWheel != 0f) { if (Input.GetKey(KeyCode.LeftShift)) { UpdateCameraOffset(scrollWheel); } else { UpdateSelectionRadius(scrollWheel); } } var circleProjector = self.m_placementMarkerInstance.GetComponent <CircleProjector>(); if (circleProjector == null) { circleProjector = self.m_placementMarkerInstance.AddComponent <CircleProjector>(); circleProjector.m_prefab = PrefabManager.Instance.GetPrefab("piece_workbench").GetComponentInChildren <CircleProjector>().m_prefab; // Force calculation of segment count circleProjector.m_radius = -1; circleProjector.Start(); } if (circleProjector.m_radius != Instance.selectionRadius) { circleProjector.m_radius = Instance.selectionRadius; circleProjector.m_nrOfSegments = (int)circleProjector.m_radius * 4; circleProjector.Update(); Jotunn.Logger.LogDebug($"Setting radius to {Instance.selectionRadius}"); } HighlightPieces(self.m_placementMarkerInstance.transform.position, Instance.selectionRadius, Color.green); } else if (piece.name.StartsWith(Blueprint.BlueprintPrefabName)) { // Destroy placement marker instance to get rid of the circleprojector if (self.m_placementMarkerInstance) { Object.DestroyImmediate(self.m_placementMarkerInstance); } // Reset rotation when changing camera float scrollWheel = Input.GetAxis("Mouse ScrollWheel"); if (scrollWheel != 0f) { if (Input.GetKey(KeyCode.LeftShift)) { UpdateCameraOffset(scrollWheel); UndoRotation(self, scrollWheel); } else if (Input.GetKey(KeyCode.LeftControl)) { UpdatePlacementOffset(scrollWheel); UndoRotation(self, scrollWheel); } } } else if (piece.name.StartsWith(BlueprintRunePrefab.DeletePlansName)) { if (!self.m_placementMarkerInstance) { return; } float scrollWheel = Input.GetAxis("Mouse ScrollWheel"); if (scrollWheel != 0) { if (Input.GetKey(KeyCode.LeftShift)) { UpdateCameraOffset(scrollWheel); UndoRotation(self, scrollWheel); } else { UpdateSelectionRadius(scrollWheel); } } var circleProjector = self.m_placementMarkerInstance.GetComponent <CircleProjector>(); if (circleProjector == null) { circleProjector = self.m_placementMarkerInstance.AddComponent <CircleProjector>(); circleProjector.m_prefab = PrefabManager.Instance.GetPrefab("piece_workbench").GetComponentInChildren <CircleProjector>().m_prefab; // Force calculation of segment count circleProjector.m_radius = -1; circleProjector.Start(); } if (circleProjector.m_radius != Instance.selectionRadius) { circleProjector.m_radius = Instance.selectionRadius; circleProjector.m_nrOfSegments = (int)circleProjector.m_radius * 4; circleProjector.Update(); Jotunn.Logger.LogDebug($"Setting radius to {Instance.selectionRadius}"); } if (Time.time > m_lastHightlight + HighlightTimeout) { HighlightPlans(self.m_placementMarkerInstance.transform.position, Instance.selectionRadius, Color.red); m_lastHightlight = Time.time; } } else if (piece.name.StartsWith(BlueprintRunePrefab.UndoBlueprintName)) { // Destroy placement marker instance to get rid of the circleprojector if (self.m_placementMarkerInstance) { Object.DestroyImmediate(self.m_placementMarkerInstance); } if (Time.time > m_lastHightlight + HighlightTimeout) { if (lastHoveredPiece) { if (lastHoveredPiece.TryGetComponent(out PlanPiece planPiece)) { ZDOID blueprintID = planPiece.GetBlueprintID(); if (blueprintID != ZDOID.None) { FlashBlueprint(blueprintID, Color.red); } } } m_lastHightlight = Time.time; } } else { // Destroy placement marker instance to get rid of the circleprojector if (self.m_placementMarkerInstance) { Object.DestroyImmediate(self.m_placementMarkerInstance); } Reset(); } } } }
/// <summary> /// Show and change blueprint selection radius /// </summary> private void ShowBlueprintRadius(On.Player.orig_UpdatePlacement orig, Player self, bool takeInput, float dt) { orig(self, takeInput, dt); if (self.m_placementGhost) { var piece = self.m_placementGhost.GetComponent <Piece>(); if (piece != null) { if (piece.name == "make_blueprint" && !piece.IsCreator()) { if (!self.m_placementMarkerInstance) { return; } self.m_maxPlaceDistance = 50f; if (!Input.GetKey(KeyCode.LeftShift)) { if (Input.GetAxis("Mouse ScrollWheel") < 0f) { Instance.selectionRadius -= 2f; if (Instance.selectionRadius < 2f) { Instance.selectionRadius = 2f; } } if (Input.GetAxis("Mouse ScrollWheel") > 0f) { Instance.selectionRadius += 2f; } } var circleProjector = self.m_placementMarkerInstance.GetComponent <CircleProjector>(); if (circleProjector == null) { circleProjector = self.m_placementMarkerInstance.AddComponent <CircleProjector>(); circleProjector.m_prefab = PrefabManager.Instance.GetPrefab("piece_workbench").GetComponentInChildren <CircleProjector>().m_prefab; // Force calculation of segment count circleProjector.m_radius = -1; circleProjector.Start(); } if (circleProjector.m_radius != Instance.selectionRadius) { circleProjector.m_radius = Instance.selectionRadius; circleProjector.m_nrOfSegments = (int)circleProjector.m_radius * 4; circleProjector.Update(); Jotunn.Logger.LogDebug($"Setting radius to {Instance.selectionRadius}"); } } else if (piece.name.StartsWith("piece_blueprint")) { // Destroy placement marker instance to get rid of the circleprojector if (self.m_placementMarkerInstance) { DestroyImmediate(self.m_placementMarkerInstance); } // Reset rotation when changing camera if (Input.GetAxis("Mouse ScrollWheel") != 0f && Input.GetKey(KeyCode.LeftShift)) { if (Input.GetAxis("Mouse ScrollWheel") < 0f) { self.m_placeRotation++; } if (Input.GetAxis("Mouse ScrollWheel") > 0f) { self.m_placeRotation--; } } } else { // Destroy placement marker instance to get rid of the circleprojector if (self.m_placementMarkerInstance) { DestroyImmediate(self.m_placementMarkerInstance); } // Restore placementDistance // default value, if we introduce config stuff for this, then change it here! self.m_maxPlaceDistance = 8; } } } }