A game about forced loneliness, made by TACStudios
1using UnityEditor.U2D.Common;
2using UnityEngine.Assertions;
3using UnityEngine.U2D.Common;
4using UnityEngine.UIElements;
5
6namespace UnityEditor.U2D.Animation
7{
8#if ENABLE_UXML_SERIALIZED_DATA
9 [UxmlElement]
10#endif
11 internal partial class Toolbar : VisualElement
12 {
13 private const string k_UssPath = "SkinningModule/ToolbarStyle.uss";
14
15#if ENABLE_UXML_TRAITS
16 public class ToolbarFactory : UxmlFactory<Toolbar, ToolbarUxmlTraits> { }
17
18 public class ToolbarUxmlTraits : UxmlTraits { }
19#endif
20
21 protected ShortcutUtility m_ShortcutUtility;
22
23 protected static Toolbar GetClone(string uxmlPath, string toolbarId)
24 {
25 var visualTree = ResourceLoader.Load<VisualTreeAsset>(uxmlPath);
26 return visualTree.CloneTree().Q<Toolbar>(toolbarId);
27 }
28
29 public Toolbar()
30 {
31 AddToClassList("Toolbar");
32 styleSheets.Add(ResourceLoader.Load<StyleSheet>(k_UssPath));
33 if (EditorGUIUtility.isProSkin)
34 AddToClassList("Dark");
35 }
36
37 public void SetButtonChecked(Button toCheck)
38 {
39 var buttons = this.Query<Button>();
40 buttons.ForEach((button) => { button.SetChecked(button == toCheck); });
41 }
42
43 protected void SetButtonChecked(Button button, bool check)
44 {
45 if (button.IsChecked() != check)
46 {
47 if (check)
48 {
49 button.AddToClassList("Checked");
50 button.Focus();
51 }
52 else
53 button.RemoveFromClassList("Checked");
54
55 button.SetChecked(check);
56 }
57 }
58
59 public void CollapseToolBar(bool collapse)
60 {
61 if (collapse)
62 AddToClassList("Collapse");
63 else
64 RemoveFromClassList("Collapse");
65 }
66
67 protected void RestoreButtonTooltips(string uxmlPath, string toolbarId)
68 {
69 var clone = GetClone(uxmlPath, toolbarId);
70 var clonedButtons = clone.Query<Button>().ToList();
71 var originalButtons = this.Query<Button>().ToList();
72
73 Assert.AreEqual(originalButtons.Count, clonedButtons.Count);
74 for (var i = 0; i < clonedButtons.Count; ++i)
75 {
76 originalButtons[i].tooltip = clonedButtons[i].tooltip;
77 originalButtons[i].LocalizeTextInChildren();
78 }
79 }
80 }
81}