Update icons in minigame
This commit is contained in:
@@ -10,7 +10,8 @@ namespace UI.CardSystem
|
||||
/// <summary>
|
||||
/// Singleton UI component for granting booster packs from minigames.
|
||||
/// Displays a booster pack with glow effect, waits for user to click continue,
|
||||
/// then animates the pack flying to bottom-left corner before granting the reward.
|
||||
/// then shows the scrapbook button and animates the pack flying to it before granting the reward.
|
||||
/// The scrapbook button is automatically hidden after the animation completes.
|
||||
/// </summary>
|
||||
public class MinigameBoosterGiver : MonoBehaviour
|
||||
{
|
||||
@@ -187,23 +188,61 @@ namespace UI.CardSystem
|
||||
yield break;
|
||||
}
|
||||
|
||||
// Calculate bottom-left corner position in local space
|
||||
RectTransform canvasRect = GetComponentInParent<Canvas>()?.GetComponent<RectTransform>();
|
||||
Vector3 targetPosition;
|
||||
|
||||
if (canvasRect != null)
|
||||
// Show scrapbook button temporarily using HUD visibility context
|
||||
PlayerHudManager.HudVisibilityContext hudContext = null;
|
||||
GameObject scrapbookButton = null;
|
||||
|
||||
scrapbookButton = PlayerHudManager.Instance.GetScrabookButton();
|
||||
if (scrapbookButton != null)
|
||||
{
|
||||
// Convert bottom-left corner with offset to local position
|
||||
Vector2 bottomLeft = new Vector2(-canvasRect.rect.width / 2f, -canvasRect.rect.height / 2f);
|
||||
targetPosition = bottomLeft + targetBottomLeftOffset;
|
||||
hudContext = PlayerHudManager.Instance.ShowElementTemporarily(scrapbookButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback if no canvas found
|
||||
targetPosition = _boosterInitialPosition + new Vector3(-500f, -500f, 0f);
|
||||
Debug.LogWarning("[MinigameBoosterGiver] Scrapbook button not found in PlayerHudManager.");
|
||||
}
|
||||
|
||||
// Tween to bottom-left corner
|
||||
// Calculate target position - use scrapbook button position if available
|
||||
Vector3 targetPosition;
|
||||
|
||||
if (scrapbookButton != null)
|
||||
{
|
||||
// Get the scrapbook button's position in the same coordinate space as boosterImage
|
||||
RectTransform scrapbookRect = scrapbookButton.GetComponent<RectTransform>();
|
||||
if (scrapbookRect != null)
|
||||
{
|
||||
// Convert scrapbook button's world position to local position relative to boosterImage's parent
|
||||
Canvas canvas = GetComponentInParent<Canvas>();
|
||||
if (canvas != null && canvas.renderMode == RenderMode.ScreenSpaceOverlay)
|
||||
{
|
||||
// For overlay canvas, convert screen position to local position
|
||||
Vector2 screenPos = RectTransformUtility.WorldToScreenPoint(null, scrapbookRect.position);
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||||
boosterImage.parent as RectTransform,
|
||||
screenPos,
|
||||
null,
|
||||
out Vector2 localPoint);
|
||||
targetPosition = localPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
// For world space or camera canvas
|
||||
targetPosition = boosterImage.parent.InverseTransformPoint(scrapbookRect.position);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[MinigameBoosterGiver] Scrapbook button has no RectTransform, using fallback position.");
|
||||
targetPosition = GetFallbackPosition();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback to bottom-left corner
|
||||
targetPosition = GetFallbackPosition();
|
||||
}
|
||||
|
||||
// Tween to scrapbook button position
|
||||
Tween.LocalPosition(boosterImage, targetPosition, disappearDuration, 0f, Tween.EaseInBack);
|
||||
|
||||
// Scale down
|
||||
@@ -224,6 +263,9 @@ namespace UI.CardSystem
|
||||
Debug.LogWarning("[MinigameBoosterGiver] CardSystemManager not found, cannot grant booster pack.");
|
||||
}
|
||||
|
||||
// Hide scrapbook button by disposing the context
|
||||
hudContext?.Dispose();
|
||||
|
||||
// Hide the visual
|
||||
if (visualContainer != null)
|
||||
{
|
||||
@@ -237,6 +279,22 @@ namespace UI.CardSystem
|
||||
// Clear sequence reference
|
||||
_currentSequence = null;
|
||||
}
|
||||
|
||||
private Vector3 GetFallbackPosition()
|
||||
{
|
||||
RectTransform canvasRect = GetComponentInParent<Canvas>()?.GetComponent<RectTransform>();
|
||||
if (canvasRect != null)
|
||||
{
|
||||
// Convert bottom-left corner with offset to local position
|
||||
Vector2 bottomLeft = new Vector2(-canvasRect.rect.width / 2f, -canvasRect.rect.height / 2f);
|
||||
return bottomLeft + targetBottomLeftOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ultimate fallback if no canvas found
|
||||
return _boosterInitialPosition + new Vector3(-500f, -500f, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user