A game about forced loneliness, made by TACStudios
1using UnityEditor.Overlays;
2using UnityEngine;
3using UnityEngine.UIElements;
4
5namespace UnityEditor.Tilemaps
6{
7 internal abstract class BoolFieldOverlayPopupWindow : OverlayPopupWindow
8 {
9 private BaseField<bool> trigger;
10 private bool isLocked;
11 private Rect screenRect;
12 private Vector2 size;
13
14 protected virtual void OnDisable()
15 {
16 // Disable trigger state if closed outside of trigger
17 if (trigger != null && (trigger.pseudoStates & PseudoStates.Hover) == 0)
18 trigger.SetValueWithoutNotify(false);
19 }
20
21 protected void ToggleMode<T>(bool value) where T : BoolFieldOverlayPopupWindow
22 {
23 isLocked = value;
24 ShowOverlayPopup<T>(trigger, screenRect, size, isLocked);;
25 }
26
27 private void InitDropDown()
28 {
29 var mode = ShowMode.PopupMenu;
30 var giveFocus = true;
31
32 this.position = this.ShowAsDropDownFitToScreen(screenRect, size, null);
33 if (ContainerWindow.IsPopup(mode))
34 this.ShowPopupWithMode(mode, giveFocus);
35 else
36 this.ShowWithMode(mode);
37
38 this.position = this.ShowAsDropDownFitToScreen(screenRect, size, null);
39 double width1 = (double)this.position.width;
40 Rect position = this.position;
41 double height1 = (double)position.height;
42 this.minSize = new Vector2((float)width1, (float)height1);
43 position = this.position;
44 double width2 = (double)position.width;
45 position = this.position;
46 double height2 = (double)position.height;
47 this.maxSize = new Vector2((float)width2, (float)height2);
48
49 if (giveFocus && (UnityEngine.Object)EditorWindow.focusedWindow != (UnityEngine.Object) this)
50 this.Focus();
51 else
52 this.Repaint();
53
54 if (!isLocked)
55 this.m_Parent.AddToAuxWindowList();
56 this.m_Parent.window.m_DontSaveToLayout = true;
57 }
58
59 public static void ShowOverlayPopup<T>(BaseField<bool> trigger, Rect position, Vector2 size, bool isLocked) where T : BoolFieldOverlayPopupWindow
60 {
61 CloseAllWindows<T>();
62 var instance = ScriptableObject.CreateInstance<T>();
63 instance.trigger = trigger;
64 instance.size = size;
65 instance.screenRect = position;
66 instance.isLocked = isLocked;
67 instance.InitDropDown();
68 }
69
70 public static void ShowOverlayPopup<T>(BaseField<bool> trigger, Vector2 size, bool isLocked) where T : BoolFieldOverlayPopupWindow
71 {
72 var rect = GUIUtility.GUIToScreenRect(trigger.worldBound);
73 ShowOverlayPopup<T>(trigger, rect, size, isLocked);
74 }
75
76 public static void CloseAllWindows<T>() where T : BoolFieldOverlayPopupWindow
77 {
78 foreach (T obj in Resources.FindObjectsOfTypeAll<T>())
79 obj.Close();
80 }
81 }
82}