A game about forced loneliness, made by TACStudios
1using System; 2using System.Linq; 3using UnityEngine; 4using UnityEngine.UIElements; 5 6namespace UnityEditor.ShaderGraph.Drawing 7{ 8 // Similar in function to the old EditorGUILayout.HelpBox 9 class HelpBoxRow : VisualElement 10 { 11 VisualElement m_ContentContainer; 12 VisualElement m_LabelContainer; 13 14 public override VisualElement contentContainer 15 { 16 get { return m_ContentContainer; } 17 } 18 19 public HelpBoxRow(MessageType type) 20 { 21 styleSheets.Add(Resources.Load<StyleSheet>("Styles/HelpBoxRow")); 22 VisualElement container = new VisualElement { name = "container" }; 23 m_ContentContainer = new VisualElement { name = "content" }; 24 m_LabelContainer = new VisualElement { name = "label" }; 25 26 switch (type) 27 { 28 case MessageType.None: 29 container.AddToClassList("help-box-row-style-info"); 30 break; 31 case MessageType.Info: 32 container.AddToClassList("help-box-row-style-info"); 33 break; 34 case MessageType.Warning: 35 container.AddToClassList("help-box-row-style-warning"); 36 break; 37 case MessageType.Error: 38 container.AddToClassList("help-box-row-style-error"); 39 break; 40 default: 41 break; 42 } 43 44 container.Add(m_LabelContainer); 45 container.Add(m_ContentContainer); 46 47 hierarchy.Add(container); 48 } 49 50 public static VisualElement CreateVariantLimitHelpBox(int currentVariantCount, int maxVariantCount) 51 { 52 var messageType = MessageType.Error; 53 HelpBoxRow help = new HelpBoxRow(messageType); 54 var label = new Label("Variant limit exceeded: Hover for more info") 55 { 56 tooltip = ShaderKeyword.kVariantLimitWarning, 57 name = "message-" + (messageType == MessageType.Warning ? "warn" : "info") 58 }; 59 help.Add(label); 60 return help; 61 } 62 63 public static VisualElement TryGetDeprecatedHelpBoxRow(string deprecatedTypeName, Action upgradeAction, Action dismissAction, string deprecationText = null, string buttonText = null, string labelText = null, MessageType messageType = MessageType.Warning) 64 { 65 if (deprecationText == null) 66 { 67 deprecationText = $"The {deprecatedTypeName} has new updates. This version maintains the old behavior. " + 68 $"If you update a {deprecatedTypeName}, you can use Undo to change it back. See the {deprecatedTypeName} " + 69 $"documentation for more information."; 70 } 71 if (buttonText == null) 72 { 73 buttonText = "Update"; 74 } 75 if (labelText == null) 76 { 77 labelText = $"The {deprecatedTypeName} has new updates. This version maintains the old behavior. " + 78 $"If you update a {deprecatedTypeName}, you can use Undo to change it back. See the {deprecatedTypeName} " + 79 $"documentation for more information."; 80 } 81 82 Button upgradeButton = new Button(upgradeAction) { text = buttonText, tooltip = deprecationText }; 83 Button dismissButton = null; 84 if (dismissAction != null) 85 dismissButton = new Button(dismissAction) { text = "Dismiss" }; 86 87 if (dismissAction != null) 88 { 89 HelpBoxRow help = new HelpBoxRow(messageType); 90 var label = new Label(labelText) 91 { 92 tooltip = labelText, 93 name = "message-" + (messageType == MessageType.Warning ? "warn" : "info") 94 }; 95 help.Add(label); 96 help.contentContainer.Add(upgradeButton); 97 if (dismissButton != null) 98 help.contentContainer.Add(dismissButton); 99 return help; 100 } 101 else 102 { 103 var box = new VisualElement(); 104 box.Add(upgradeButton); 105 if (dismissButton != null) 106 box.Add(dismissButton); 107 return box; 108 } 109 } 110 } 111}