// 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.Components.Internal; using Doozy.Editor.EditorUI.ScriptableObjects.Colors; using Doozy.Editor.UIElements; using Doozy.Runtime.Colors; using Doozy.Runtime.Common.Extensions; using Doozy.Runtime.Reactor.Internal; using Doozy.Runtime.UIElements; using Doozy.Runtime.UIElements.Extensions; using UnityEngine; using UnityEngine.UIElements; // ReSharper disable MemberCanBePrivate.Global namespace Doozy.Editor.EditorUI.Components { public class FluidToggleButtonTab : FluidToggle { public const float k_IconReactionDuration = 0.6f; public override void Reset() { base.Reset(); RemoveFromToggleGroup(); ResetElementSize(); ResetTabPosition(); ResetLayoutOrientation(); ResetTabContent(); ResetIconAnimationTrigger(); this.SetStyleMinWidth(StyleKeyword.Auto); this.SetStyleWidth(StyleKeyword.Auto); this.SetStyleMaxWidth(StyleKeyword.Auto); this.SetStyleMinHeight(StyleKeyword.Auto); this.SetStyleHeight(StyleKeyword.Auto); this.SetStyleMaxHeight(StyleKeyword.Auto); this.ResetLayout(); this.ResetAccentColor(); ClearIcon(); ClearLabelText(); ClearInfoContainer(); this.ClearOnClick(); this.ClearOnValueChanged(); this.SetTooltip(string.Empty); this.buttonLabel.SetStyleTextAlign(TextAnchor.MiddleLeft); selectionState = SelectionState.Normal; } public override void Dispose() { base.Dispose(); fluidElement.OnPointerEnter -= ExecuteOnPointerEnter; } #region ElementSize private ElementSize elementSize { get; set; } private List elementSizeDependentElements { get; } public FluidToggleButtonTab SetElementSize(ElementSize value) { UIElementsUtils.RemoveClass(elementSize.ToString(), elementSizeDependentElements); UIElementsUtils.AddClass(value.ToString(), elementSizeDependentElements); elementSize = value; return this; } public FluidToggleButtonTab ResetElementSize() => SetElementSize(ElementSize.Normal); #endregion #region TabPosition private TabPosition tabPosition { get; set; } private List tabPositionDependentElements { get; } public FluidToggleButtonTab SetTabPosition(TabPosition value) { UIElementsUtils.RemoveClass(tabPosition.ToString(), tabPositionDependentElements); UIElementsUtils.AddClass(value.ToString(), tabPositionDependentElements); tabPosition = value; return this; } public FluidToggleButtonTab ResetTabPosition() => SetTabPosition(TabPosition.FloatingTab); #endregion #region LayoutOrientation private LayoutOrientation layoutOrientation { get; set; } private List layoutOrientationDependentElements { get; } public FluidToggleButtonTab SetLayoutOrientation(LayoutOrientation value) { UIElementsUtils.RemoveClass(layoutOrientation.ToString(), layoutOrientationDependentElements); UIElementsUtils.AddClass(value.ToString(), layoutOrientationDependentElements); layoutOrientation = value; return this; } public FluidToggleButtonTab ResetLayoutOrientation() => SetLayoutOrientation(LayoutOrientation.Horizontal); #endregion #region TabContent private TabContent tabContent { get; set; } = TabContent.Undefined; private List contentDependentElements { get; } public FluidToggleButtonTab SetTabContent(TabContent value) { if (tabContent != TabContent.Undefined) UIElementsUtils.RemoveClass(tabContent.ToString(), contentDependentElements); if (value != TabContent.Undefined) UIElementsUtils.AddClass(value.ToString(), contentDependentElements); bool undefined = value == TabContent.Undefined; icon.SetStyleDisplay(value == TabContent.TextOnly || undefined ? DisplayStyle.None : DisplayStyle.Flex); buttonLabel.SetStyleDisplay(value == TabContent.IconOnly || undefined ? DisplayStyle.None : DisplayStyle.Flex); tabContent = value; return this; } public FluidToggleButtonTab ResetTabContent() => SetTabContent(TabContent.Undefined); #endregion #region IconAnimationTrigger private IconAnimationTrigger animationTrigger { get; set; } public FluidToggleButtonTab SetAnimationTrigger(IconAnimationTrigger trigger) { // Debug.Log($"{nameof(SetAnimationTrigger)} - from: {animationTrigger} to: {trigger}"); animationTrigger = trigger; return this; } public FluidToggleButtonTab ResetIconAnimationTrigger() => SetAnimationTrigger(IconAnimationTrigger.OnPointerEnter); #endregion #region IconType private IconType iconType { get; set; } = IconType.None; private List iconDependentComponents { get; } private void UpdateIconType(IconType value) { if (iconType != IconType.None) UIElementsUtils.RemoveClass(iconType.ToString(), iconDependentComponents); if (value != IconType.None) UIElementsUtils.AddClass(value.ToString(), iconDependentComponents); iconType = value; } #endregion private static Font font => EditorFonts.Ubuntu.Regular; protected internal Color ContainerColorOff = Color.clear; public override bool canHaveMixedValues => false; public TemplateContainer templateContainer { get; } public VisualElement layoutContainer { get; } public VisualElement buttonContainer { get; } public Label buttonLabel { get; } public VisualElement infoContainer { get; } public static FluidToggleButtonTab Get(string labelText, EditorSelectableColorInfo accentColor = null, string tooltip = "") => Get().SetLabelText(labelText).SetToggleAccentColor(accentColor).SetTooltip(tooltip); public static FluidToggleButtonTab Get(string labelText, Texture2D texture, EditorSelectableColorInfo accentColor = null, string tooltip = "") => Get(labelText, accentColor, tooltip).SetIcon(texture); public static FluidToggleButtonTab Get(Texture2D texture, EditorSelectableColorInfo accentColor, string tooltip = "") => Get(string.Empty, texture, accentColor, tooltip); public static FluidToggleButtonTab Get(Texture2D texture, string tooltip = "") => Get(string.Empty, texture, null, tooltip); public static FluidToggleButtonTab Get(string labelText, IEnumerable textures, EditorSelectableColorInfo accentColor = null, string tooltip = "") => Get(labelText, accentColor, tooltip).SetIcon(textures); public static FluidToggleButtonTab Get(IEnumerable textures, EditorSelectableColorInfo accentColor, string tooltip = "") => Get(string.Empty, textures, accentColor, tooltip); public static FluidToggleButtonTab Get(IEnumerable textures, string tooltip = "") => Get(string.Empty, textures, null, tooltip); public FluidToggleButtonTab() { Add(templateContainer = EditorLayouts.EditorUI.FluidToggleButton.CloneTree()); templateContainer // .AddStyle(EditorStyles.EditorUI.LayoutContainer) .AddStyle(EditorStyles.EditorUI.FieldIcon) .AddStyle(EditorStyles.EditorUI.FieldName) .AddStyle(EditorStyles.EditorUI.FluidToggleButton); layoutContainer = templateContainer.Q(nameof(layoutContainer)); buttonContainer = layoutContainer.Q(nameof(buttonContainer)); icon = layoutContainer.Q(nameof(icon)); buttonLabel = layoutContainer.Q