// Copyright (c) 2015 - 2023 Doozy Entertainment. All Rights Reserved. // This code can only be used under the standard Unity Asset Store End User License Agreement // A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms using System; using System.Collections.Generic; using Doozy.Editor.EditorUI.Utils; using Doozy.Editor.Reactor.Internal; using Doozy.Editor.UIElements; using Doozy.Runtime.Colors; using Doozy.Runtime.Common.Extensions; using Doozy.Runtime.Reactor.Internal; using Doozy.Runtime.Reactor.Reactions; using Doozy.Runtime.UIElements; using Doozy.Runtime.UIElements.Extensions; using UnityEditor; using UnityEngine; using UnityEngine.Events; using UnityEngine.UIElements; namespace Doozy.Editor.EditorUI.Components { public class FluidComponentHeader : PoolableElement { public override void Reset() { this.ResetLayout(); this.SetTooltip(string.Empty); ResetElementSize(); ResetAccentColor(); ClearIcon(); ClearRotatedIcon(); ClearSecondaryIcon(); ClearBarRightContainer(); ClearComponentNameText(); ClearComponentTypeText(); OnClick = TriggerAnimations; OnPointerEnter = null; OnPointerLeave = null; OnPointerDown = null; OnPointerUp = null; } public override void Dispose() { base.Dispose(); iconReaction?.Recycle(); rotatedIconReaction?.Recycle(); secondaryIconReaction?.Recycle(); } #region ElementSize private ElementSize elementSize { get; set; } private List elementSizeDependentElements { get; } public FluidComponentHeader SetElementSize(ElementSize value) { UIElementsUtils.RemoveClass(elementSize.ToString(), elementSizeDependentElements); UIElementsUtils.AddClass(value.ToString(), elementSizeDependentElements); elementSize = value; return this; } public FluidComponentHeader ResetElementSize() => SetElementSize(ElementSize.Large); #endregion public static Color componentBarColor => EditorColors.Default.Background; public static Color componentNameTextColor => EditorColors.Default.TextTitle; public static Color componentTypeTextColor => EditorColors.Default.TextSubtitle; public static Font componentNameFont => EditorFonts.Ubuntu.Regular; public static Font componentTypeFont => EditorFonts.Ubuntu.Light; public TemplateContainer templateContainer { get; } public VisualElement layoutContainer { get; } public VisualElement iconContainer { get; } public Image icon { get; } public VisualElement barContainer { get; } public VisualElement barLeftContainer { get; } public Image secondaryIcon { get; } public Label componentNameLabel { get; } public Label componentTypeLabel { get; } public Image rotatedIcon { get; } public VisualElement barRightContainer { get; } public IconType iconType { get; private set; } = IconType.None; public Texture2DReaction iconReaction { get; private set; } public bool hasAnimatedIcon => iconReaction != null; public IconType rotatedIconType { get; private set; } = IconType.None; public Texture2DReaction rotatedIconReaction { get; private set; } public bool hasAnimatedRotatedIcon => rotatedIconReaction != null; public IconType secondaryIconType { get; private set; } = IconType.None; public Texture2DReaction secondaryIconReaction { get; private set; } public bool hasAnimatedSecondaryIcon => secondaryIconReaction != null; public Clickable clickable { get; } public UnityAction OnClick; // ReSharper disable UnassignedField.Global public UnityAction OnPointerEnter; public UnityAction OnPointerLeave; public UnityAction OnPointerDown; public UnityAction OnPointerUp; // ReSharper restore UnassignedField.Global public FluidComponentHeader() { Add(templateContainer = EditorLayouts.EditorUI.FluidComponentHeader.CloneTree()); templateContainer .AddStyle(EditorStyles.EditorUI.FluidComponentHeader) .SetStyleFlexShrink(0) .SetStyleOverflow(Overflow.Hidden); layoutContainer = templateContainer.Q(nameof(layoutContainer)); iconContainer = layoutContainer.Q(nameof(iconContainer)); icon = iconContainer.Q(nameof(icon)); barContainer = layoutContainer.Q(nameof(barContainer)); barLeftContainer = barContainer.Q(nameof(barLeftContainer)); secondaryIcon = barLeftContainer.Q(nameof(secondaryIcon)); componentNameLabel = barLeftContainer.Q