A game about forced loneliness, made by TACStudios
at master 262 lines 8.4 kB view raw
1using System; 2using System.ComponentModel; 3using UnityEditor; 4using UnityEngine; 5using UnityEngine.UIElements; 6 7using Codice.Client.Common.EventTracking; 8using Codice.CM.Common; 9using PlasticGui; 10using Unity.PlasticSCM.Editor.UI; 11 12namespace Unity.PlasticSCM.Editor.Settings 13{ 14 class PlasticProjectSettingsProvider : SettingsProvider 15 { 16 // Internal usage. This isn't a public API. 17 [EditorBrowsable(EditorBrowsableState.Never)] 18 public PlasticProjectSettingsProvider( 19 string path, SettingsScope scope = SettingsScope.User) 20 : base(path, scope) 21 { 22 label = UnityConstants.PROJECT_SETTINGS_TAB_TITLE; 23 24 OpenAllFoldouts(); 25 } 26 27 // Internal usage. This isn't a public API. 28 [EditorBrowsable(EditorBrowsableState.Never)] 29 [SettingsProvider] 30 public static SettingsProvider CreateSettingsProvider() 31 { 32 if (!FindWorkspace.HasWorkspace(ApplicationDataPath.Get())) 33 return null; 34 35 PlasticApp.InitializeIfNeeded(); 36 37 return new PlasticProjectSettingsProvider( 38 UnityConstants.PROJECT_SETTINGS_TAB_PATH, SettingsScope.Project); 39 } 40 41 public override void OnActivate( 42 string searchContext, 43 VisualElement rootElement) 44 { 45 mIsPluginEnabled = PlasticPluginIsEnabledPreference.IsEnabled(); 46 47 mWkInfo = FindWorkspace.InfoForApplicationPath( 48 ApplicationDataPath.Get(), PlasticGui.Plastic.API); 49 50 mIsProjectSettingsActivated = true; 51 52 mPendingChangesOptionsFoldout.OnActivate(mWkInfo); 53 mDiffAndMergeOptionsFoldout.OnActivate(); 54 mShelveAndSwitchOptionsFoldout.OnActivate(); 55 mOtherOptionsFoldout.OnActivate(); 56 } 57 58 public override void OnDeactivate() 59 { 60 if (!mIsProjectSettingsActivated) 61 return; 62 63 mIsProjectSettingsActivated = false; 64 65 mPendingChangesOptionsFoldout.OnDeactivate(); 66 mDiffAndMergeOptionsFoldout.OnDeactivate(); 67 mShelveAndSwitchOptionsFoldout.OnDeactivate(); 68 mOtherOptionsFoldout.OnDeactivate(); 69 } 70 71 public override void OnGUI(string searchContext) 72 { 73 DrawSettingsSection( 74 DoIsEnabledSetting); 75 76 if (!mIsPluginEnabled) 77 return; 78 79 mIsPendingChangesFoldoutOpen = DrawFoldout( 80 mIsPendingChangesFoldoutOpen, 81 PlasticLocalization.Name.PendingChangesOptionsSectionTitle.GetString(), 82 mPendingChangesOptionsFoldout.OnGUI); 83 84 mIsDiffAndMergeFoldoutOpen = DrawFoldout( 85 mIsDiffAndMergeFoldoutOpen, 86 PlasticLocalization.Name.DiffAndMergeOptionsSectionTitle.GetString(), 87 mDiffAndMergeOptionsFoldout.OnGUI); 88 89 mIsShelveAndSwitchFoldoutOpen = DrawFoldout( 90 mIsShelveAndSwitchFoldoutOpen, 91 PlasticLocalization.Name.ShelveAndSwitchOptionsSectionTitle.GetString(), 92 mShelveAndSwitchOptionsFoldout.OnGUI); 93 94 mIsOtherFoldoutOpen = DrawFoldout( 95 mIsOtherFoldoutOpen, 96 PlasticLocalization.Name.OtherOptionsSectionTitle.GetString(), 97 mOtherOptionsFoldout.OnGUI); 98 } 99 100 internal void OpenAllFoldouts() 101 { 102 mIsPendingChangesFoldoutOpen = true; 103 mIsDiffAndMergeFoldoutOpen = true; 104 mIsShelveAndSwitchFoldoutOpen = true; 105 mIsOtherFoldoutOpen = true; 106 } 107 108 internal void OpenDiffAndMergeFoldout() 109 { 110 mIsShelveAndSwitchFoldoutOpen = false; 111 mIsPendingChangesFoldoutOpen = false; 112 mIsDiffAndMergeFoldoutOpen = true; 113 mIsOtherFoldoutOpen = false; 114 } 115 116 internal void OpenShelveAndSwitchFoldout() 117 { 118 mIsShelveAndSwitchFoldoutOpen = true; 119 mIsPendingChangesFoldoutOpen = false; 120 mIsDiffAndMergeFoldoutOpen = false; 121 mIsOtherFoldoutOpen = false; 122 } 123 124 internal void OpenOtherFoldout() 125 { 126 mIsOtherFoldoutOpen = true; 127 mIsPendingChangesFoldoutOpen = false; 128 mIsDiffAndMergeFoldoutOpen = false; 129 mIsShelveAndSwitchFoldoutOpen = false; 130 } 131 132 void DoIsEnabledSetting() 133 { 134 using (new EditorGUILayout.HorizontalScope()) 135 { 136 string message = PlasticLocalization.GetString( 137 mIsPluginEnabled ? 138 PlasticLocalization.Name.UnityVCSIsEnabled : 139 PlasticLocalization.Name.UnityVCSIsDisabled); 140 141 GUILayout.Label( 142 message, 143 EditorStyles.boldLabel, 144 GUILayout.Height(20)); 145 146 EditorGUILayout.Space(8); 147 148 DoIsEnabledButton(); 149 150 GUILayout.FlexibleSpace(); 151 } 152 } 153 154 void DoIsEnabledButton() 155 { 156 if (!GUILayout.Button(PlasticLocalization.GetString( 157 mIsPluginEnabled ? 158 PlasticLocalization.Name.DisableButton : 159 PlasticLocalization.Name.EnableButton), 160 UnityStyles.ProjectSettings.ToggleOn)) 161 { 162 return; 163 } 164 165 if (!mIsPluginEnabled) 166 { 167 mIsPluginEnabled = true; 168 169 TrackFeatureUseEvent.For( 170 PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo), 171 TrackFeatureUseEvent.Features.UnityPackage.EnableManually); 172 173 PlasticPlugin.Enable(); 174 PlasticPluginIsEnabledPreference.Enable(); 175 176 return; 177 } 178 179 if (mIsPluginEnabled) 180 { 181 mIsPluginEnabled = false; 182 183 TrackFeatureUseEvent.For( 184 PlasticGui.Plastic.API.GetRepositorySpec(mWkInfo), 185 TrackFeatureUseEvent.Features.UnityPackage.DisableManually); 186 187 PlasticPluginIsEnabledPreference.Disable(); 188 CloseWindowIfOpened.Plastic(); 189 PlasticShutdown.Shutdown(); 190 return; 191 } 192 } 193 194 static void DrawSettingsSection(Action drawSettings) 195 { 196 float originalLabelWidth = EditorGUIUtility.labelWidth; 197 198 try 199 { 200 EditorGUIUtility.labelWidth = UnityConstants.SETTINGS_GUI_WIDTH; 201 202 using (new EditorGUILayout.HorizontalScope()) 203 { 204 GUILayout.Space(10); 205 206 using (new EditorGUILayout.VerticalScope()) 207 { 208 GUILayout.Space(10); 209 210 drawSettings(); 211 212 GUILayout.Space(10); 213 } 214 215 GUILayout.Space(10); 216 } 217 } 218 finally 219 { 220 EditorGUIUtility.labelWidth = originalLabelWidth; 221 } 222 } 223 224 static bool DrawFoldout( 225 bool isFoldoutOpen, 226 string title, 227 Action drawContent) 228 { 229 EditorGUILayout.BeginVertical(EditorStyles.helpBox); 230 231 bool result = 232 EditorGUILayout.BeginFoldoutHeaderGroup( 233 isFoldoutOpen, 234 title, 235 UnityStyles.ProjectSettings.FoldoutHeader); 236 237 if (result) 238 drawContent(); 239 240 EditorGUILayout.EndFoldoutHeaderGroup(); 241 EditorGUILayout.EndVertical(); 242 243 return result; 244 } 245 246 bool mIsPendingChangesFoldoutOpen; 247 bool mIsDiffAndMergeFoldoutOpen; 248 bool mIsShelveAndSwitchFoldoutOpen; 249 bool mIsOtherFoldoutOpen; 250 251 bool mIsProjectSettingsActivated; 252 253 bool mIsPluginEnabled; 254 255 WorkspaceInfo mWkInfo; 256 257 PendingChangesOptionsFoldout mPendingChangesOptionsFoldout = new PendingChangesOptionsFoldout(); 258 DiffAndMergeOptionsFoldout mDiffAndMergeOptionsFoldout = new DiffAndMergeOptionsFoldout(); 259 ShelveAndSwitchOptionsFoldout mShelveAndSwitchOptionsFoldout = new ShelveAndSwitchOptionsFoldout(); 260 OtherOptionsFoldout mOtherOptionsFoldout = new OtherOptionsFoldout(); 261 } 262}