Files
AppleHillsProduction/Assets/Scripts/UI/AppSwitcher.cs

104 lines
2.6 KiB
C#
Raw Normal View History

using System;
using UnityEngine;
using UnityEngine.UI;
2025-11-06 17:49:44 +01:00
using Input;
using AppleHills.Core;
using UI.Core;
using Pixelplacement;
using Pixelplacement.TweenSystem;
2025-11-09 13:23:03 +01:00
using UI;
public class AppSwitcher : UIPage
{
2025-11-06 17:49:44 +01:00
public GameObject gameLayoutContainer;
public GameObject exitButton;
public RectMask2D rectMask;
[Header("Slide Animation Settings")]
public float slideDuration = 0.5f;
private TweenBase slideInTween;
private TweenBase slideOutTween;
2025-11-06 17:49:44 +01:00
Lifecycle System Refactor & Logging Centralization (#56) ## ManagedBehaviour System Refactor - **Sealed `Awake()`** to prevent override mistakes that break singleton registration - **Added `OnManagedAwake()`** for early initialization (fires during registration) - **Renamed lifecycle hook:** `OnManagedAwake()` → `OnManagedStart()` (fires after boot, mirrors Unity's Awake→Start) - **40 files migrated** to new pattern (2 core, 38 components) - Eliminated all fragile `private new void Awake()` patterns - Zero breaking changes - backward compatible ## Centralized Logging System - **Automatic tagging** via `CallerMemberName` and `CallerFilePath` - logs auto-tagged as `[ClassName][MethodName] message` - **Unified API:** Single `Logging.Debug/Info/Warning/Error()` replaces custom `LogDebugMessage()` implementations - **~90 logging call sites** migrated across 10 files - **10 redundant helper methods** removed - All logs broadcast via `Logging.OnLogEntryAdded` event for real-time monitoring ## Custom Log Console (Editor Window) - **Persistent filter popups** for multi-selection (classes, methods, log levels) - windows stay open during selection - **Search** across class names, methods, and message content - **Time range filter** with MinMaxSlider - **Export** filtered logs to timestamped `.txt` files - **Right-click context menu** for quick filtering and copy actions - **Visual improvements:** White text, alternating row backgrounds, color-coded log levels - **Multiple instances** supported for simultaneous system monitoring - Open via `AppleHills > Custom Log Console` Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com> Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: https://homelab.tailf7f81b.ts.net/tschesky/AppleHillsProduction/pulls/56
2025-11-11 08:48:29 +00:00
internal override void OnManagedAwake()
2025-11-06 15:36:02 +01:00
{
base.OnManagedAwake();
Lifecycle System Refactor & Logging Centralization (#56) ## ManagedBehaviour System Refactor - **Sealed `Awake()`** to prevent override mistakes that break singleton registration - **Added `OnManagedAwake()`** for early initialization (fires during registration) - **Renamed lifecycle hook:** `OnManagedAwake()` → `OnManagedStart()` (fires after boot, mirrors Unity's Awake→Start) - **40 files migrated** to new pattern (2 core, 38 components) - Eliminated all fragile `private new void Awake()` patterns - Zero breaking changes - backward compatible ## Centralized Logging System - **Automatic tagging** via `CallerMemberName` and `CallerFilePath` - logs auto-tagged as `[ClassName][MethodName] message` - **Unified API:** Single `Logging.Debug/Info/Warning/Error()` replaces custom `LogDebugMessage()` implementations - **~90 logging call sites** migrated across 10 files - **10 redundant helper methods** removed - All logs broadcast via `Logging.OnLogEntryAdded` event for real-time monitoring ## Custom Log Console (Editor Window) - **Persistent filter popups** for multi-selection (classes, methods, log levels) - windows stay open during selection - **Search** across class names, methods, and message content - **Time range filter** with MinMaxSlider - **Export** filtered logs to timestamped `.txt` files - **Right-click context menu** for quick filtering and copy actions - **Visual improvements:** White text, alternating row backgrounds, color-coded log levels - **Multiple instances** supported for simultaneous system monitoring - Open via `AppleHills > Custom Log Console` Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com> Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: https://homelab.tailf7f81b.ts.net/tschesky/AppleHillsProduction/pulls/56
2025-11-11 08:48:29 +00:00
PageName = "AppSwitcher";
if (rectMask == null)
{
rectMask = GetComponent<RectMask2D>();
}
2025-11-10 15:55:28 +01:00
// Initially hide
exitButton.SetActive(false);
2025-11-06 15:36:02 +01:00
}
protected override void DoTransitionIn(Action onComplete)
{
2025-11-06 17:49:44 +01:00
InputManager.Instance.SetInputMode(InputMode.UI);
gameLayoutContainer.SetActive(true);
2025-11-06 17:49:44 +01:00
// Slide in animation - tween padding.left from 1700 to 0
slideInTween = TweenPaddingLeft(1700f, 0f, Tween.EaseOut, () =>
{
onComplete?.Invoke();
exitButton.SetActive(true);
});
2025-11-06 17:49:44 +01:00
}
protected override void DoTransitionOut(Action onComplete)
2025-11-06 17:49:44 +01:00
{
2025-11-06 17:49:44 +01:00
// Hide the exit button
exitButton.SetActive(false);
2025-11-09 13:23:03 +01:00
// Slide out animation - tween padding.left from 0 to 1700
slideOutTween = TweenPaddingLeft(0f, 1700f, Tween.EaseIn, () => {
gameLayoutContainer.SetActive(false);
onComplete?.Invoke();
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
});
2025-11-06 17:49:44 +01:00
}
/// <summary>
/// Tweens the left padding of the rectMask from startValue to endValue.
/// </summary>
private TweenBase TweenPaddingLeft(float startValue, float endValue, AnimationCurve easeCurve, Action onComplete)
2025-11-06 17:49:44 +01:00
{
// 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
);
}
2025-11-06 17:49:44 +01:00
internal override void OnManagedDestroy()
{
// Clean up tweens
slideInTween?.Stop();
slideOutTween?.Stop();
2025-11-06 17:49:44 +01:00
}
}