Make a generic booster pack giver

This commit is contained in:
Michal Pikulski
2025-12-15 11:59:40 +01:00
parent e2b74b1ea5
commit bb332933ec
64 changed files with 1228 additions and 312 deletions

View File

@@ -307,6 +307,92 @@ namespace Core
}
}
/// <summary>
/// Displays the booster pack reward UI and grants the specified number of booster packs.
/// This method is awaitable and handles input mode switching automatically.
/// Supports awarding 1 to N booster packs with animated visuals.
/// </summary>
/// <param name="count">Number of booster packs to grant</param>
/// <returns>Task that completes when the UI sequence is finished</returns>
public async System.Threading.Tasks.Task GiveBoosterPacksAsync(int count)
{
Logging.Debug($"[GameManager] GiveBoosterPacksAsync called with count: {count}");
// Get prefab from settings
var settings = GetSettingsObject<ICardSystemSettings>();
if (settings?.BoosterPackRewardPrefab == null)
{
Logging.Warning("[GameManager] BoosterPackRewardPrefab not set in CardSystemSettings. Cannot show reward UI.");
return;
}
// Find main canvas
GameObject mainCanvasObj = GameObject.FindGameObjectWithTag("MainCanvas");
if (mainCanvasObj == null)
{
Logging.Warning("[GameManager] MainCanvas not found in scene. Cannot show reward UI.");
return;
}
// Switch to UI input mode
InputManager.Instance?.SetInputMode(InputMode.UI);
Logging.Debug("[GameManager] Switched to UI input mode");
// Instantiate UI prefab
GameObject uiInstance = Instantiate(settings.BoosterPackRewardPrefab);
var component = uiInstance.GetComponent<UI.CardSystem.MinigameBoosterGiver>();
if (component == null)
{
Logging.Warning("[GameManager] BoosterPackRewardPrefab does not have MinigameBoosterGiver component!");
Destroy(uiInstance);
InputManager.Instance?.SetInputMode(InputMode.GameAndUI);
return;
}
// Parent to main canvas and set stretch-fill anchoring
RectTransform rectTransform = uiInstance.GetComponent<RectTransform>();
if (rectTransform != null)
{
rectTransform.SetParent(mainCanvasObj.transform, false);
// Set anchors to stretch-fill (all corners)
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
Logging.Debug("[GameManager] UI parented to MainCanvas with stretch-fill anchoring");
}
else
{
// Fallback: just parent without RectTransform adjustments
uiInstance.transform.SetParent(mainCanvasObj.transform, false);
Logging.Warning("[GameManager] UI does not have RectTransform, parented without anchor adjustment");
}
// Create TaskCompletionSource for awaiting
var tcs = new System.Threading.Tasks.TaskCompletionSource<bool>();
// Initialize the component with pack count
component.Initialize(count);
// Call GiveBooster to start the sequence
component.GiveBooster(() =>
{
Logging.Debug("[GameManager] Booster reward UI sequence completed");
Destroy(uiInstance);
tcs.SetResult(true);
});
// Await completion
await tcs.Task;
// Restore input mode to GameAndUI (default gameplay mode)
InputManager.Instance?.SetInputMode(InputMode.GameAndUI);
Logging.Debug("[GameManager] Restored to GameAndUI input mode");
}
// Helper method to get settings
private T GetSettings<T>() where T : class

View File

@@ -1,6 +1,7 @@
using UnityEngine;
using AppleHills.Core.Settings;
using UnityEngine;
namespace AppleHills.Core.Settings
namespace Core.Settings
{
/// <summary>
/// Settings for the card system - controls animations, interactions, and progression
@@ -47,6 +48,10 @@ namespace AppleHills.Core.Settings
[Tooltip("Default animation duration when not specified in seconds")]
[SerializeField] private float defaultAnimationDuration = 0.3f;
[Header("UI Prefabs")]
[Tooltip("Prefab for the booster pack reward UI displayed after minigames")]
[SerializeField] private GameObject boosterPackRewardPrefab;
// ICardSystemSettings implementation - Idle Hover Animations
public float IdleHoverHeight => idleHoverHeight;
public float IdleHoverDuration => idleHoverDuration;
@@ -70,6 +75,9 @@ namespace AppleHills.Core.Settings
// ICardSystemSettings implementation - General Animation
public float DefaultAnimationDuration => defaultAnimationDuration;
// ICardSystemSettings implementation - UI Prefabs
public GameObject BoosterPackRewardPrefab => boosterPackRewardPrefab;
public override void OnValidate()
{
base.OnValidate();

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using Core.Settings;
using UnityEngine;
namespace AppleHills.Core.Settings
{

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Core.Settings;
using UnityEngine;
using Interactions;

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using Core.Settings;
using UnityEngine;
namespace AppleHills.Core.Settings
{

View File

@@ -1,8 +1,9 @@
using UnityEngine;
using System.Collections.Generic;
using System.Collections.Generic;
using AppleHills.Core.Settings;
using Minigames.StatueDressup.Data;
using UnityEngine;
namespace AppleHills.Core.Settings
namespace Core.Settings
{
/// <summary>
/// Enum defining the different input modes for photo taking
@@ -177,6 +178,9 @@ namespace AppleHills.Core.Settings
// General Animation
float DefaultAnimationDuration { get; }
// UI Prefabs
GameObject BoosterPackRewardPrefab { get; }
}
/// <summary>
@@ -244,8 +248,8 @@ namespace AppleHills.Core.Settings
Common.Input.SlingshotConfig SlingshotSettings { get; }
// Block configurations
System.Collections.Generic.List<Minigames.FortFight.Settings.BlockMaterialConfig> MaterialConfigs { get; }
System.Collections.Generic.List<Minigames.FortFight.Settings.BlockSizeConfig> SizeConfigs { get; }
List<Minigames.FortFight.Settings.BlockMaterialConfig> MaterialConfigs { get; }
List<Minigames.FortFight.Settings.BlockSizeConfig> SizeConfigs { get; }
// AI Difficulty Settings
Minigames.FortFight.Data.AIDifficulty DefaultAIDifficulty { get; } // Default difficulty level for AI
@@ -286,7 +290,7 @@ namespace AppleHills.Core.Settings
float CeilingFanDropSpeed { get; } // Downward velocity when dropping (m/s)
// Projectile Configurations
System.Collections.Generic.IReadOnlyList<Minigames.FortFight.Data.ProjectileConfig> ProjectileConfigs { get; }
IReadOnlyList<Minigames.FortFight.Data.ProjectileConfig> ProjectileConfigs { get; }
Minigames.FortFight.Data.ProjectileConfig GetProjectileConfig(Minigames.FortFight.Data.ProjectileType type);
Minigames.FortFight.Data.ProjectileConfig GetProjectileConfigById(string projectileId);

View File

@@ -1,4 +1,5 @@
using Core;
using Core.Settings;
using UnityEngine;
namespace AppleHills
@@ -103,7 +104,7 @@ namespace AppleHills
}
#endif
var settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IInteractionSettings>();
var settings = GameManager.GetSettingsObject<IInteractionSettings>();
return settings?.InteractionOutlineColors;
}