Move app switcher to hud
This commit is contained in:
@@ -1,89 +1,117 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using SkiaSharp.Unity;
|
||||
using Input;
|
||||
using AppleHills.Core;
|
||||
using UI.Core;
|
||||
using Pixelplacement;
|
||||
using Pixelplacement.TweenSystem;
|
||||
using UI;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AppSwitcher : MonoBehaviour
|
||||
public class AppSwitcher : UIPage
|
||||
{
|
||||
|
||||
public TextAsset iconIdle;
|
||||
public TextAsset iconEstablish;
|
||||
public TextAsset rainbowEstablish;
|
||||
public TextAsset rainbowRemove;
|
||||
public GameObject rainbow;
|
||||
public GameObject icon;
|
||||
public GameObject gameLayoutContainer;
|
||||
public GameObject exitButton;
|
||||
|
||||
private SkottiePlayerV2 iconPlayer;
|
||||
public RectMask2D rectMask;
|
||||
|
||||
[Header("Slide Animation Settings")]
|
||||
public float slideDuration = 0.5f;
|
||||
|
||||
private SkottiePlayerV2 rainbowPlayer;
|
||||
private Animator animator;
|
||||
private TweenBase slideInTween;
|
||||
private TweenBase slideOutTween;
|
||||
|
||||
|
||||
private void OnEnable()
|
||||
protected override void OnManagedAwake()
|
||||
{
|
||||
iconPlayer = icon.GetComponentInChildren<SkottiePlayerV2>();
|
||||
base.OnManagedAwake();
|
||||
|
||||
PageName = "AppSwitcher";
|
||||
rainbowPlayer = rainbow.GetComponentInChildren<SkottiePlayerV2>();
|
||||
animator = GetComponent<Animator>();
|
||||
rainbow.SetActive(false);
|
||||
|
||||
if (rectMask == null)
|
||||
{
|
||||
rectMask = GetComponent<RectMask2D>();
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenAppSwitcher()
|
||||
protected override void DoTransitionIn(Action onComplete)
|
||||
{
|
||||
PlayerHudManager.Instance.HideAllHudExcept(gameObject);
|
||||
|
||||
rainbow.SetActive(true);
|
||||
//Activate players
|
||||
rainbow.SetActive(true);
|
||||
gameLayoutContainer.SetActive(true);
|
||||
|
||||
// Play establishing animations
|
||||
rainbowPlayer.LoadAnimation(rainbowEstablish.text);
|
||||
rainbowPlayer.PlayAnimation(false);
|
||||
rainbowPlayer.loop = false;
|
||||
gameLayoutContainer.SetActive(true);
|
||||
animator.Play("GamesReveal");
|
||||
|
||||
|
||||
// Show the exit button
|
||||
exitButton.SetActive(true);
|
||||
|
||||
// Set input mode to UI
|
||||
QuickAccess.Instance.PlayerController.InterruptMoveTo();
|
||||
InputManager.Instance.SetInputMode(InputMode.UI);
|
||||
|
||||
rainbowPlayer.OnAnimationFinished += AnimFinished;
|
||||
|
||||
// Slide in animation - tween padding.left from 1700 to 0
|
||||
slideInTween = TweenPaddingLeft(1700f, 0f, Tween.EaseOutBack, () => onComplete?.Invoke());
|
||||
}
|
||||
|
||||
public void CloseAppSwitcher()
|
||||
protected override void DoTransitionOut(Action onComplete)
|
||||
{
|
||||
rainbowPlayer.resetAfterFinished = true;
|
||||
rainbowPlayer.LoadAnimation(rainbowRemove.text);
|
||||
rainbowPlayer.PlayAnimation(false);
|
||||
rainbowPlayer.PlayAnimation(true);
|
||||
rainbowPlayer.loop = false;
|
||||
animator.Play("GamesHide");
|
||||
|
||||
|
||||
// Set input mode to game and ui
|
||||
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
|
||||
|
||||
// Hide the exit button
|
||||
exitButton.SetActive(false);
|
||||
|
||||
PlayerHudManager.Instance.ShowAllHud();
|
||||
// Slide out animation - tween padding.left from 0 to 1700
|
||||
slideOutTween = TweenPaddingLeft(0f, 1700f, Tween.EaseInBack, () => {
|
||||
gameLayoutContainer.SetActive(false);
|
||||
PlayerHudManager.Instance.ShowAllHud();
|
||||
onComplete?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
public void GamesHiddenAnimationEvent()
|
||||
{
|
||||
rainbow.SetActive(false);
|
||||
gameLayoutContainer.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
private void AnimFinished(string str)
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Tweens the left padding of the rectMask from startValue to endValue.
|
||||
/// </summary>
|
||||
private TweenBase TweenPaddingLeft(float startValue, float endValue, AnimationCurve easeCurve, Action onComplete)
|
||||
{
|
||||
// Set starting position
|
||||
Vector4 startPadding = rectMask.padding;
|
||||
startPadding.x = startValue;
|
||||
rectMask.padding = startPadding;
|
||||
|
||||
return Tween.Value(
|
||||
startValue,
|
||||
endValue,
|
||||
(value) => {
|
||||
Vector4 padding = rectMask.padding;
|
||||
padding.x = value;
|
||||
rectMask.padding = padding;
|
||||
},
|
||||
slideDuration,
|
||||
0f, // no delay
|
||||
easeCurve,
|
||||
Tween.LoopType.None,
|
||||
null, // onStart
|
||||
onComplete
|
||||
);
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
// Clean up tweens
|
||||
slideInTween?.Stop();
|
||||
slideOutTween?.Stop();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -165,15 +165,6 @@ namespace UI.CardSystem
|
||||
UIPageController.Instance.PopPage();
|
||||
}
|
||||
}
|
||||
// If album exits while in Overworld, show AppSwitcher. If not, keep it hidden.
|
||||
if (PlayerHudManager.Instance.currentUIMode == PlayerHudManager.UIMode.Overworld)
|
||||
{
|
||||
PlayerHudManager.Instance.ToggleAppSwitcher(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayerHudManager.Instance.ToggleAppSwitcher(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBoosterCountChanged(int newCount)
|
||||
|
||||
@@ -70,11 +70,8 @@ namespace UI.CardSystem
|
||||
if (albumViewPage != null)
|
||||
{
|
||||
UIPageController.Instance.PushPage(albumViewPage);
|
||||
PlayerHudManager.Instance.appSwitcher.SetActive(false);
|
||||
}
|
||||
}
|
||||
PlayerHudManager.Instance.ToggleAppSwitcher(false);
|
||||
// If we're already on the album main page, do nothing
|
||||
}
|
||||
|
||||
private void OnPageChanged(UIPage currentPage)
|
||||
|
||||
@@ -31,7 +31,6 @@ namespace UI
|
||||
public GameObject CinematicBackground;
|
||||
|
||||
[Header("HUD Elements")]
|
||||
public GameObject appSwitcher;
|
||||
public GameObject eagleEye;
|
||||
|
||||
|
||||
@@ -64,12 +63,6 @@ namespace UI
|
||||
UnityEngine.Debug.LogError("[PlayerHudManager] UIPageController not found on same GameObject!");
|
||||
}
|
||||
|
||||
// Get AppSwitcher component reference
|
||||
if (appSwitcher != null)
|
||||
{
|
||||
_appSwitcherComponent = appSwitcher.GetComponent<AppSwitcher>();
|
||||
}
|
||||
|
||||
InitializeReferences();
|
||||
}
|
||||
|
||||
@@ -184,34 +177,23 @@ namespace UI
|
||||
case UIMode.Overworld:
|
||||
// Update currentUIMode var
|
||||
currentUIMode = UIMode.Overworld;
|
||||
// Show app switcher
|
||||
appSwitcher.SetActive(true);
|
||||
// Hide eagle eye
|
||||
eagleEye.SetActive(false);
|
||||
break;
|
||||
case UIMode.Puzzle:
|
||||
// Update currentUIMode var
|
||||
currentUIMode = UIMode.Puzzle;
|
||||
// Hide app switcher
|
||||
appSwitcher.SetActive(false);
|
||||
// show eagle eye
|
||||
eagleEye.SetActive(true);
|
||||
break;
|
||||
case UIMode.Minigame:
|
||||
// Update currentUIMode var
|
||||
currentUIMode = UIMode.Minigame;
|
||||
// Hide app switcher
|
||||
appSwitcher.SetActive(false);
|
||||
// Hide birds eye
|
||||
eagleEye.SetActive(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleAppSwitcher(bool boo)
|
||||
{
|
||||
appSwitcher.SetActive(boo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides all HUD button elements
|
||||
|
||||
Reference in New Issue
Block a user