photo_input_switch (#27)
Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #27
This commit is contained in:
@@ -57,6 +57,9 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
|
||||
// Store settings
|
||||
private IDivingMinigameSettings settings;
|
||||
|
||||
// New field to store the current input mode
|
||||
private PhotoInputModes currentInputMode;
|
||||
|
||||
// Events for progress milestones
|
||||
public event Action<float> OnProgressUpdated; // Continuous progress updates (0-1)
|
||||
@@ -89,6 +92,9 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
{
|
||||
settings = GameManager.GetSettingsObject<IDivingMinigameSettings>();
|
||||
mainCamera = UnityEngine.Camera.main;
|
||||
|
||||
// Get the photo input mode from settings
|
||||
currentInputMode = settings.PhotoInputMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -135,7 +141,7 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
{
|
||||
viewfinderComponent.Initialize(this);
|
||||
viewfinderComponent.SetupInputOverride();
|
||||
viewfinderComponent.OnViewfinderTapped += HandleViewfinderTapped;
|
||||
InitializeViewfinder(viewfinderComponent);
|
||||
}
|
||||
|
||||
// Reset state
|
||||
@@ -450,10 +456,13 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
{
|
||||
if (viewfinderInstance != null)
|
||||
{
|
||||
// Unsubscribe from the viewfinder's tap event
|
||||
// Unsubscribe from all viewfinder events
|
||||
if (viewfinderComponent != null)
|
||||
{
|
||||
viewfinderComponent.OnViewfinderTapped -= HandleViewfinderTapped;
|
||||
viewfinderComponent.OnViewfinderTapped -= HandleViewfinderTappedDuringAnimation;
|
||||
viewfinderComponent.OnViewfinderHoldStarted -= HandleViewfinderHoldStarted;
|
||||
viewfinderComponent.OnViewfinderHoldEnded -= HandleViewfinderHoldEnded;
|
||||
}
|
||||
|
||||
Destroy(viewfinderInstance);
|
||||
@@ -507,8 +516,7 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
{
|
||||
viewfinderComponent.Initialize(this);
|
||||
viewfinderComponent.SetupInputOverride();
|
||||
viewfinderComponent.OnViewfinderTapped += HandleViewfinderTapped;
|
||||
|
||||
InitializeViewfinder(viewfinderComponent);
|
||||
}
|
||||
|
||||
// Determine canvas width for full-screen sizing
|
||||
@@ -583,6 +591,20 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
viewfinderComponent.OnViewfinderTapped += HandleViewfinderTappedDuringAnimation;
|
||||
}
|
||||
|
||||
// Initialize viewfinder with appropriate event handlers based on input mode
|
||||
if (viewfinderComponent != null)
|
||||
{
|
||||
viewfinderComponent.Initialize(this);
|
||||
viewfinderComponent.SetupInputOverride();
|
||||
InitializeViewfinder(viewfinderComponent);
|
||||
|
||||
// For animation sequence, we need additional handling for tapping during animation
|
||||
if (currentInputMode == PhotoInputModes.Tap)
|
||||
{
|
||||
viewfinderComponent.OnViewfinderTapped += HandleViewfinderTappedDuringAnimation;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset state
|
||||
animationProgress = 0f;
|
||||
isAnimating = true;
|
||||
@@ -772,5 +794,80 @@ namespace Minigames.DivingForPictures.PictureCamera
|
||||
HandleViewfinderTapped();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the viewfinder with appropriate event handlers based on input mode
|
||||
/// </summary>
|
||||
/// <param name="viewfinder">The viewfinder component to initialize</param>
|
||||
public void InitializeViewfinder(Viewfinder viewfinder)
|
||||
{
|
||||
if (viewfinder != null)
|
||||
{
|
||||
// Clean up any existing event subscriptions
|
||||
viewfinder.OnViewfinderTapped -= HandleViewfinderTapped;
|
||||
viewfinder.OnViewfinderHoldStarted -= HandleViewfinderHoldStarted;
|
||||
viewfinder.OnViewfinderHoldEnded -= HandleViewfinderHoldEnded;
|
||||
|
||||
// Set up handlers based on the current input mode
|
||||
switch (currentInputMode)
|
||||
{
|
||||
case PhotoInputModes.Tap:
|
||||
// For tap mode, only subscribe to tap events
|
||||
viewfinder.OnViewfinderTapped += HandleViewfinderTapped;
|
||||
break;
|
||||
|
||||
case PhotoInputModes.Hold:
|
||||
// For hold mode, subscribe to hold start/end events
|
||||
viewfinder.OnViewfinderHoldStarted += HandleViewfinderHoldStarted;
|
||||
viewfinder.OnViewfinderHoldEnded += HandleViewfinderHoldEnded;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles hold start event from the viewfinder
|
||||
/// </summary>
|
||||
private void HandleViewfinderHoldStarted()
|
||||
{
|
||||
if (currentInputMode == PhotoInputModes.Hold)
|
||||
{
|
||||
// Start the photo sequence when hold begins (same behavior as first tap in tap mode)
|
||||
OnViewfinderTapped?.Invoke();
|
||||
Debug.Log("[CameraViewfinderManager] Hold started - initiating photo sequence");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles hold end event from the viewfinder
|
||||
/// </summary>
|
||||
private void HandleViewfinderHoldEnded()
|
||||
{
|
||||
if (currentInputMode == PhotoInputModes.Hold && isAnimating)
|
||||
{
|
||||
// Complete the sequence when hold ends (same behavior as second tap in tap mode)
|
||||
OnViewfinderTappedDuringAnimation?.Invoke(currentProximity);
|
||||
Debug.Log("[CameraViewfinderManager] Hold ended - completing photo sequence with proximity: " + currentProximity);
|
||||
|
||||
// Complete the animation immediately
|
||||
if (animationCoroutine != null)
|
||||
{
|
||||
StopCoroutine(animationCoroutine);
|
||||
animationCoroutine = null;
|
||||
}
|
||||
|
||||
// Fire completed event
|
||||
OnAnimationCompleted?.Invoke();
|
||||
isAnimating = false;
|
||||
isReversePhase = false;
|
||||
|
||||
// Hide the viewfinder
|
||||
if (viewfinderComponent != null)
|
||||
{
|
||||
viewfinderComponent.RemoveInputOverride();
|
||||
}
|
||||
HideViewfinder();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user