A game about forced loneliness, made by TACStudios
at master 5.7 kB view raw
1using UnityEditor; 2using UnityEngine; 3 4using Codice.Client.Common; 5 6namespace Unity.PlasticSCM.Editor.UI 7{ 8 internal class DialogWithCheckBox : PlasticDialog 9 { 10 protected override Rect DefaultRect 11 { 12 get 13 { 14 var baseRect = base.DefaultRect; 15 return new Rect(baseRect.x, baseRect.y, 535, baseRect.height); 16 } 17 } 18 19 internal static GuiMessage.GuiMessageResponseButton Show( 20 string title, 21 string message, 22 string positiveButtonText, 23 string neutralButtonText, 24 string negativeButtonText, 25 MultiLinkLabelData dontShowAgainContent, 26 EditorWindow parentWindow, 27 out bool checkBoxValue) 28 { 29 checkBoxValue = false; 30 31 DialogWithCheckBox dialog = Create( 32 title, 33 message, 34 positiveButtonText, 35 neutralButtonText, 36 negativeButtonText, 37 dontShowAgainContent); 38 39 ResponseType result = dialog.RunModal(parentWindow); 40 if (result == ResponseType.Cancel || result == ResponseType.None) 41 return GuiMessage.GuiMessageResponseButton.Neutral; 42 43 checkBoxValue = dialog.mCheckBox; 44 if (result == ResponseType.Ok) 45 return GuiMessage.GuiMessageResponseButton.Positive; 46 47 return GuiMessage.GuiMessageResponseButton.Negative; 48 } 49 50 protected override string GetTitle() 51 { 52 return mTitle; 53 } 54 55 protected override void OnModalGUI() 56 { 57 DoMainContentSection(); 58 59 DoButtonsArea(); 60 61 DoCheckboxSection(); 62 } 63 64 void DoMainContentSection() 65 { 66 using (new EditorGUILayout.VerticalScope()) 67 { 68 GUILayout.Label( 69 mTitle, 70 UnityStyles.Dialog.MessageTitle); 71 72 GUILayout.Space(3f); 73 74 GUILayout.Label( 75 mMessage, 76 UnityStyles.Dialog.MessageText); 77 } 78 } 79 80 void DoButtonsArea() 81 { 82 using (new EditorGUILayout.VerticalScope()) 83 { 84 GUILayout.Space(25f); 85 86 using (new EditorGUILayout.HorizontalScope()) 87 { 88 GUILayout.FlexibleSpace(); 89 90 if (Application.platform == RuntimePlatform.WindowsEditor) 91 { 92 DoPositiveButton(); 93 DoNegativeButton(); 94 DoNeutralButton(); 95 return; 96 } 97 98 DoNegativeButton(); 99 DoNeutralButton(); 100 DoPositiveButton(); 101 } 102 } 103 } 104 105 void DoPositiveButton() 106 { 107 GUILayout.Space(6f); 108 109 if (!AcceptButton(mPositiveButtonText, 110 30)) 111 return; 112 113 OkButtonAction(); 114 } 115 116 void DoNegativeButton() 117 { 118 if (string.IsNullOrEmpty(mNegativeButtonText)) 119 return; 120 121 GUILayout.Space(6f); 122 123 if (!NormalButton(mNegativeButtonText)) 124 return; 125 126 ApplyButtonAction(); 127 } 128 129 void DoNeutralButton() 130 { 131 if (string.IsNullOrEmpty(mNeutralButtonText)) 132 return; 133 134 GUILayout.Space(6f); 135 136 if (!NormalButton(mNeutralButtonText)) 137 return; 138 139 CancelButtonAction(); 140 } 141 142 void DoCheckboxSection() 143 { 144 GUILayout.Space(22f); 145 146 Rect backgroundRect = new Rect(0, GUILayoutUtility.GetLastRect().yMax, position.width, 50); 147 148 EditorGUI.DrawRect(backgroundRect, UnityStyles.Colors.DarkGray); 149 150 GUILayout.Space(4f); 151 152 using (new EditorGUILayout.HorizontalScope()) 153 { 154 mCheckBox = EditorGUILayout.ToggleLeft( 155 string.Empty, 156 mCheckBox, 157 EditorStyles.boldLabel); 158 GUILayout.FlexibleSpace(); 159 } 160 161 GUILayout.Space(-22); 162 163 using (new EditorGUILayout.HorizontalScope()) 164 { 165 GUILayout.Space(22); 166 DrawTextBlockWithLink.ForMultiLinkLabelInDialog(mDontShowAgainContent); 167 } 168 169 GUILayout.Space(-19); 170 } 171 172 static DialogWithCheckBox Create( 173 string title, 174 string message, 175 string positiveButtonText, 176 string neutralButtonText, 177 string negativeButtonText, 178 MultiLinkLabelData dontShowAgainContent) 179 { 180 DialogWithCheckBox instance = CreateInstance<DialogWithCheckBox>(); 181 instance.mEnterKeyAction = instance.OkButtonAction; 182 instance.mEscapeKeyAction = instance.CancelButtonAction; 183 184 instance.mTitle = title; 185 instance.mMessage = message; 186 instance.mPositiveButtonText = positiveButtonText; 187 instance.mNeutralButtonText = neutralButtonText; 188 instance.mNegativeButtonText = negativeButtonText; 189 instance.mDontShowAgainContent = dontShowAgainContent; 190 191 return instance; 192 } 193 194 string mTitle; 195 string mMessage; 196 string mPositiveButtonText; 197 string mNeutralButtonText; 198 string mNegativeButtonText; 199 MultiLinkLabelData mDontShowAgainContent; 200 201 bool mCheckBox; 202 } 203}