using System; using System.Collections.Generic; using CIGEnums; using SUISS.Core; using UnityEngine; namespace SUISSEngine { public class GridTileIconManager : MonoBehaviour { private void Start() { SingletonMonobehaviour.Instance.InteractionEnabledChangedEvent += this.OnInteractionEnabledChanged; } private void OnDestroy() { if (SingletonMonobehaviour.IsAvailable) { SingletonMonobehaviour.Instance.InteractionEnabledChangedEvent -= this.OnInteractionEnabledChanged; } } public T SetIcon(GridTileIconType iconType) where T : GridTileIcon { if (this._icons.ContainsKey(iconType)) { return (T)((object)this._icons[iconType]); } GridTileIcon asset = SingletonMonobehaviour.Instance.GetAsset(iconType); GridTileIcon gridTileIcon = SingletonMonobehaviour.Instance.CreateOverlay(base.gameObject, asset.gameObject); gridTileIcon.GridTileIconDestroyedEvent += this.OnGridTileIconDestroyed; this._icons.Add(iconType, gridTileIcon); this.RefreshCurrentIcon(); return (T)((object)gridTileIcon); } public void RemoveIcon(GridTileIconType iconType) { GridTileIcon gridTileIcon; if (this._icons.TryGetValue(iconType, out gridTileIcon)) { gridTileIcon.Remove(); this._icons.Remove(iconType); this.RefreshCurrentIcon(); } } public void HideIcon() { if (this._currentIcon != null) { this._currentIcon.Hide(); } } public void ShowIcon() { if (this._currentIcon != null && !SingletonMonobehaviour.Instance.InteractionDisabled) { this._currentIcon.Show(); } } private void RefreshCurrentIcon() { GridTileIcon gridTileIcon = null; foreach (KeyValuePair keyValuePair in this._icons) { if (gridTileIcon == null || keyValuePair.Value.Priority > gridTileIcon.Priority) { gridTileIcon = keyValuePair.Value; } keyValuePair.Value.Hide(); } this._currentIcon = gridTileIcon; this.ShowIcon(); } private void OnInteractionEnabledChanged(bool interactionEnabled) { if (interactionEnabled) { this.ShowIcon(); } else { this.HideIcon(); } } private void OnGridTileIconDestroyed(GridTileIcon icon) { foreach (KeyValuePair keyValuePair in this._icons) { if (keyValuePair.Value == icon) { this._icons.Remove(keyValuePair.Key); break; } } icon.GridTileIconDestroyedEvent -= this.OnGridTileIconDestroyed; } private readonly Dictionary _icons = new Dictionary(); private GridTileIcon _currentIcon; } }