A game about forced loneliness, made by TACStudios
at master 227 lines 7.1 kB view raw
1using UnityEditor; 2using UnityEngine; 3 4using Codice.Client.Common.EventTracking; 5using Codice.CM.Common; 6using PlasticGui; 7using Unity.PlasticSCM.Editor.UI; 8 9namespace Unity.PlasticSCM.Editor.Views.PendingChanges.Dialogs 10{ 11 internal class EmptyCommentDialog : PlasticDialog 12 { 13 internal bool UserChoseToNotDisplayWarningAgain { get; private set; } 14 15 internal static bool ShouldContinueWithCheckin( 16 EditorWindow parentWindow, 17 WorkspaceInfo wkInfo) 18 { 19 var dialog = Create( 20 wkInfo, 21 PlasticLocalization.Name.NoCheckinCommentTitle.GetString(), 22 PlasticLocalization.Name.NoCheckinCommentMessage.GetString(), 23 PlasticLocalization.Name.SkipAndCheckin.GetString()); 24 25 // using the apply response as the 'Skip & Check in' button click 26 if (dialog.RunModal(parentWindow) != ResponseType.Apply) 27 return false; 28 29 if (dialog.UserChoseToNotDisplayWarningAgain) 30 { 31 PlasticGuiConfig.Get().Configuration.ShowEmptyCommentWarning = false; 32 PlasticGuiConfig.Get().Save(); 33 } 34 35 return true; 36 } 37 38 internal static bool ShouldContinueWithShelve( 39 EditorWindow parentWindow, 40 WorkspaceInfo wkInfo) 41 { 42 var dialog = Create( 43 wkInfo, 44 PlasticLocalization.Name.NoShelveCommentTitle.GetString(), 45 PlasticLocalization.Name.NoShelveCommentMessage.GetString(), 46 PlasticLocalization.Name.SkipAndShelve.GetString()); 47 48 // using the apply response as the 'Skip & Shelve' button click 49 if (dialog.RunModal(parentWindow) != ResponseType.Apply) 50 return false; 51 52 if (dialog.UserChoseToNotDisplayWarningAgain) 53 { 54 PlasticGuiConfig.Get().Configuration.ShowEmptyShelveCommentWarning = false; 55 PlasticGuiConfig.Get().Save(); 56 } 57 58 return true; 59 } 60 61 protected override string GetTitle() 62 { 63 return string.Empty; 64 } 65 66 protected override void OnModalGUI() 67 { 68 DoMainContentSection(); 69 70 DoCheckboxSection(); 71 72 DoButtonsArea(); 73 } 74 75 void DoMainContentSection() 76 { 77 using (new EditorGUILayout.HorizontalScope()) 78 { 79 80 DoIconArea(); 81 82 using (new EditorGUILayout.VerticalScope()) 83 { 84 GUILayout.Label( 85 mDialogTitle, 86 UnityStyles.Dialog.MessageTitle); 87 88 GUILayout.Space(3f); 89 90 GUILayout.Label( 91 mDialogMessage, 92 UnityStyles.Dialog.MessageText); 93 94 GUILayout.Space(15f); 95 } 96 } 97 } 98 99 void DoCheckboxSection() 100 { 101 using (new EditorGUILayout.HorizontalScope()) 102 { 103 GUILayout.Space(70f); 104 105 UserChoseToNotDisplayWarningAgain = TitleToggle( 106 PlasticLocalization.GetString( 107 PlasticLocalization.Name.DoNotShowMessageAgain), 108 UserChoseToNotDisplayWarningAgain); 109 } 110 } 111 112 void DoButtonsArea() 113 { 114 using (new EditorGUILayout.VerticalScope()) 115 { 116 GUILayout.Space(25f); 117 118 using (new EditorGUILayout.HorizontalScope()) 119 { 120 GUILayout.FlexibleSpace(); 121 122 if (Application.platform == RuntimePlatform.WindowsEditor) 123 { 124 DoAddCommentButton(); 125 GUILayout.Space(13f); 126 DoSkipAndContinueButton(); 127 return; 128 } 129 130 DoSkipAndContinueButton(); 131 GUILayout.Space(13f); 132 DoAddCommentButton(); 133 } 134 } 135 } 136 137 void DoSkipAndContinueButton() 138 { 139 if (!AcceptButton(mDialogNeutralButtonText, 140 30)) 141 return; 142 143 if (!mSentCheckinAnywayTrackEvent) 144 { 145 TrackFeatureUseEvent.For( 146 PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo), 147 TrackFeatureUseEvent.Features.EmptyComment.PendingChangesCheckinDialogCheckinAnyway); 148 149 mSentCheckinAnywayTrackEvent = true; 150 } 151 152 if (UserChoseToNotDisplayWarningAgain && !mSentCheckboxTrackEvent) 153 { 154 TrackFeatureUseEvent.For( 155 PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo), 156 TrackFeatureUseEvent.Features.EmptyComment.PendingChangesCheckinDialogDoNotShowMessageAgain); 157 158 mSentCheckboxTrackEvent = true; 159 } 160 161 ApplyButtonAction(); 162 } 163 164 void DoAddCommentButton() 165 { 166 if (!NormalButton(PlasticLocalization.GetString( 167 PlasticLocalization.Name.AddComment))) 168 return; 169 170 if (!mSentCancelTrackEvent) 171 { 172 TrackFeatureUseEvent.For( 173 PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo), 174 TrackFeatureUseEvent.Features.EmptyComment.PendingChangesCheckinDialogCancel); 175 176 mSentCancelTrackEvent = true; 177 } 178 179 CancelButtonAction(); 180 } 181 182 void DoIconArea() 183 { 184 GUILayout.BeginVertical(); 185 GUILayout.Space(10); 186 187 Rect iconRect = GUILayoutUtility.GetRect( 188 GUIContent.none, GUIStyle.none, 189 GUILayout.Width(60), GUILayout.Height(60)); 190 iconRect.x -= 10; 191 192 GUI.DrawTexture( 193 iconRect, 194 Images.GetPlasticIcon(), 195 ScaleMode.ScaleToFit); 196 197 GUILayout.EndVertical(); 198 } 199 200 static EmptyCommentDialog Create( 201 WorkspaceInfo wkInfo, 202 string dialogTitle, 203 string dialogMessage, 204 string dialogNeutralButtonText) 205 { 206 var instance = CreateInstance<EmptyCommentDialog>(); 207 instance.mEnterKeyAction = instance.OkButtonAction; 208 instance.mEscapeKeyAction = instance.CancelButtonAction; 209 instance.mWkInfo = wkInfo; 210 instance.mDialogTitle = dialogTitle; 211 instance.mDialogMessage = dialogMessage; 212 instance.mDialogNeutralButtonText = dialogNeutralButtonText; 213 214 return instance; 215 } 216 217 WorkspaceInfo mWkInfo; 218 string mDialogTitle; 219 string mDialogMessage; 220 string mDialogNeutralButtonText; 221 222 // IMGUI evaluates every frame, need to make sure feature tracks get sent only once 223 bool mSentCheckinAnywayTrackEvent = false; 224 bool mSentCancelTrackEvent = false; 225 bool mSentCheckboxTrackEvent = false; 226 } 227}