Files
AppleHillsProduction/Assets/Scripts/Minigames/FortFight/UI/ModeSelectionPage.cs
Michal Pikulski d5ab69d944 Stash work
2025-12-04 02:16:47 +01:00

151 lines
4.4 KiB
C#

using Core;
using UnityEngine;
using UnityEngine.UI;
using UI.Core;
using Minigames.FortFight.Core;
using Minigames.FortFight.Data;
using Pixelplacement;
namespace Minigames.FortFight.UI
{
/// <summary>
/// UI page for selecting single-player or two-player mode
/// </summary>
public class ModeSelectionPage : UIPage
{
[Header("Mode Selection Buttons")]
[SerializeField] private Button singlePlayerButton;
[SerializeField] private Button twoPlayerButton;
[Header("Optional Visual Elements")]
[SerializeField] private GameObject titleText;
[SerializeField] private CanvasGroup canvasGroup;
#region Initialization
internal override void OnManagedAwake()
{
base.OnManagedAwake();
// Validate button references
if (singlePlayerButton == null)
{
Logging.Error("[ModeSelectionPage] Single player button not assigned!");
}
else
{
singlePlayerButton.onClick.AddListener(OnSinglePlayerSelected);
}
if (twoPlayerButton == null)
{
Logging.Error("[ModeSelectionPage] Two player button not assigned!");
}
else
{
twoPlayerButton.onClick.AddListener(OnTwoPlayerSelected);
}
// Set up canvas group if available
if (canvasGroup == null)
{
canvasGroup = GetComponent<CanvasGroup>();
}
}
#endregion
#region Button Callbacks
/// <summary>
/// Called when single player button is clicked
/// </summary>
private void OnSinglePlayerSelected()
{
Logging.Debug("[ModeSelectionPage] Single player mode selected");
if (FortFightGameManager.Instance != null)
{
FortFightGameManager.Instance.SelectGameMode(FortFightGameMode.SinglePlayer);
}
else
{
Logging.Error("[ModeSelectionPage] FortFightGameManager instance not found!");
}
}
/// <summary>
/// Called when two player button is clicked
/// </summary>
private void OnTwoPlayerSelected()
{
Logging.Debug("[ModeSelectionPage] Two player mode selected");
if (FortFightGameManager.Instance != null)
{
FortFightGameManager.Instance.SelectGameMode(FortFightGameMode.TwoPlayer);
}
else
{
Logging.Error("[ModeSelectionPage] FortFightGameManager instance not found!");
}
}
#endregion
#region Transitions
protected override void DoTransitionIn(System.Action onComplete)
{
// Simple fade in if canvas group is available
if (canvasGroup != null)
{
canvasGroup.alpha = 0f;
Tween.CanvasGroupAlpha(canvasGroup, 1f, transitionDuration, 0f, Tween.EaseOut,
completeCallback: () => onComplete?.Invoke());
}
else
{
onComplete?.Invoke();
}
}
protected override void DoTransitionOut(System.Action onComplete)
{
// Simple fade out if canvas group is available
if (canvasGroup != null)
{
Tween.CanvasGroupAlpha(canvasGroup, 0f, transitionDuration, 0f, Tween.EaseIn,
completeCallback: () => onComplete?.Invoke());
}
else
{
onComplete?.Invoke();
}
}
#endregion
#region Cleanup
internal override void OnManagedDestroy()
{
base.OnManagedDestroy();
// Unsubscribe from button events
if (singlePlayerButton != null)
{
singlePlayerButton.onClick.RemoveListener(OnSinglePlayerSelected);
}
if (twoPlayerButton != null)
{
twoPlayerButton.onClick.RemoveListener(OnTwoPlayerSelected);
}
}
#endregion
}
}