Update icons in minigame
This commit is contained in:
@@ -7,6 +7,7 @@ using UnityEngine.Playables;
|
||||
using UnityEngine.UI;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
@@ -19,6 +20,73 @@ namespace UI
|
||||
{
|
||||
public enum UIMode { Overworld, Puzzle, Minigame, HideAll };
|
||||
|
||||
/// <summary>
|
||||
/// Context object for managing temporary HUD element visibility.
|
||||
/// Automatically restores previous visibility state when disposed.
|
||||
/// Usage: using (var ctx = PlayerHudManager.Instance.ShowElementTemporarily(myButton)) { ... }
|
||||
/// </summary>
|
||||
public class HudVisibilityContext : IDisposable
|
||||
{
|
||||
private readonly GameObject _element;
|
||||
private readonly bool _previousState;
|
||||
private bool _disposed;
|
||||
|
||||
internal HudVisibilityContext(GameObject element, bool show)
|
||||
{
|
||||
_element = element;
|
||||
_previousState = element.activeSelf;
|
||||
_element.SetActive(show);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
|
||||
if (_element != null)
|
||||
{
|
||||
_element.SetActive(_previousState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multi-element visibility context for managing multiple HUD elements at once.
|
||||
/// Automatically restores previous visibility states when disposed.
|
||||
/// </summary>
|
||||
public class MultiHudVisibilityContext : IDisposable
|
||||
{
|
||||
private readonly List<(GameObject element, bool previousState)> _elements;
|
||||
private bool _disposed;
|
||||
|
||||
internal MultiHudVisibilityContext(IEnumerable<GameObject> elements, bool show)
|
||||
{
|
||||
_elements = new List<(GameObject, bool)>();
|
||||
foreach (var element in elements)
|
||||
{
|
||||
if (element != null)
|
||||
{
|
||||
_elements.Add((element, element.activeSelf));
|
||||
element.SetActive(show);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
|
||||
foreach (var (element, previousState) in _elements)
|
||||
{
|
||||
if (element != null)
|
||||
{
|
||||
element.SetActive(previousState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UIMode currentUIMode;
|
||||
|
||||
[Header("HUD Management")]
|
||||
@@ -33,6 +101,7 @@ namespace UI
|
||||
[Header("HUD Elements")]
|
||||
public GameObject eagleEye;
|
||||
public GameObject ramaSjangButton;
|
||||
public GameObject scrabBookButton;
|
||||
|
||||
[HideInInspector] public Image cinematicSprites;
|
||||
[HideInInspector] public Image cinematicBackgroundSprites;
|
||||
@@ -254,6 +323,9 @@ namespace UI
|
||||
if (visible)
|
||||
{
|
||||
eagleEye.SetActive(false);
|
||||
ramaSjangButton.SetActive(false);
|
||||
scrabBookButton.SetActive(false);
|
||||
|
||||
}
|
||||
break;
|
||||
case UIMode.HideAll:
|
||||
@@ -318,6 +390,64 @@ namespace UI
|
||||
UnityEngine.Debug.LogError("[PlayerHudManager] Cannot push page - UIPageController not found!");
|
||||
}
|
||||
}
|
||||
|
||||
#region HUD Element Getters
|
||||
|
||||
public GameObject GetEagleEye() => eagleEye;
|
||||
public GameObject GetRamaSjangButton() => ramaSjangButton;
|
||||
public GameObject GetScrabookButton() => scrabBookButton;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Context-Based Visibility Management
|
||||
|
||||
/// <summary>
|
||||
/// Temporarily shows a HUD element. Returns a context object that restores the previous state when disposed.
|
||||
/// Usage: using (var ctx = PlayerHudManager.Instance.ShowElementTemporarily(myButton)) { /* element is visible */ }
|
||||
/// </summary>
|
||||
public HudVisibilityContext ShowElementTemporarily(GameObject element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
Logging.Warning("[PlayerHudManager] Attempted to show null element");
|
||||
return null;
|
||||
}
|
||||
return new HudVisibilityContext(element, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Temporarily hides a HUD element. Returns a context object that restores the previous state when disposed.
|
||||
/// Usage: using (var ctx = PlayerHudManager.Instance.HideElementTemporarily(myButton)) { /* element is hidden */ }
|
||||
/// </summary>
|
||||
public HudVisibilityContext HideElementTemporarily(GameObject element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
Logging.Warning("[PlayerHudManager] Attempted to hide null element");
|
||||
return null;
|
||||
}
|
||||
return new HudVisibilityContext(element, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Temporarily shows multiple HUD elements. Returns a context object that restores all previous states when disposed.
|
||||
/// Usage: using (var ctx = PlayerHudManager.Instance.ShowElementsTemporarily(button1, button2, button3)) { /* elements are visible */ }
|
||||
/// </summary>
|
||||
public MultiHudVisibilityContext ShowElementsTemporarily(params GameObject[] elements)
|
||||
{
|
||||
return new MultiHudVisibilityContext(elements, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Temporarily hides multiple HUD elements. Returns a context object that restores all previous states when disposed.
|
||||
/// Usage: using (var ctx = PlayerHudManager.Instance.HideElementsTemporarily(button1, button2, button3)) { /* elements are hidden */ }
|
||||
/// </summary>
|
||||
public MultiHudVisibilityContext HideElementsTemporarily(params GameObject[] elements)
|
||||
{
|
||||
return new MultiHudVisibilityContext(elements, false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user