A game about forced loneliness, made by TACStudios
at master 11 kB view raw
1using System; 2using UnityEditor; 3using UnityEngine; 4using UnityEngine.UIElements; 5 6using PlasticGui; 7using Codice.CM.Common; 8using Codice.Client.Common; 9using Codice.Client.Common.WebApi; 10using Unity.PlasticSCM.Editor.UI.UIElements; 11using PlasticGui.Configuration.TeamEdition; 12using PlasticGui.Configuration; 13using Unity.PlasticSCM.Editor.Views.Welcome; 14 15namespace Unity.PlasticSCM.Editor.Configuration.TeamEdition 16{ 17 internal class TeamEditionConfigurationWindow : EditorWindow 18 { 19 internal static void ShowWindow(IPlasticWebRestApi restApi, WelcomeView welcomeView) 20 { 21 TeamEditionConfigurationWindow window = GetWindow<TeamEditionConfigurationWindow>(); 22 window.mRestApi = restApi; 23 window.mWelcomeView = welcomeView; 24 window.titleContent = new GUIContent( 25 PlasticLocalization.GetString(PlasticLocalization.Name.WelcomeToUnityVCS)); 26 window.minSize = window.maxSize = new Vector2(650, 300); 27 window.Show(); 28 } 29 30 void OnEnable() 31 { 32 InitializeLayoutAndStyles(); 33 34 BuildComponents(); 35 } 36 37 void Dispose() 38 { 39 mConnectButton.clicked -= ConnectButton_Clicked; 40 mCheckConnectionButton.clicked -= CheckConnectionButton_Clicked; 41 mOkButton.clicked -= OkButton_Clicked; 42 mCancelButton.clicked -= CancelButton_Clicked; 43 mServerTextField.UnregisterValueChangedCallback(OnServerTextFieldChanged); 44 mUseSslToggle.UnregisterValueChangedCallback(OnUseSslToggleChanged); 45 46 mLoadingSpinner.Dispose(); 47 } 48 49 void ConnectButton_Clicked() 50 { 51 ConfigurationConnectServerButtonClickEvent.ClickInThreadWaiter( 52 server: mUserAssistant.GetProposedServer(), 53 HideValidation: HideValidation, 54 ShowError: ShowServerValidationError, 55 ShowProgress: ShowProgress, 56 HideProgress: HideProgress, 57 ShowNotification: ShowServerNotificationMessage, 58 DisableButtons: () => { mConnectButton.SetEnabled(false); }, 59 EnableButtons: () => { mConnectButton.SetEnabled(true); }, 60 UpdatePasswordEntries: (seidWorkingMode) => 61 { 62 UpdatePasswordEntries(seidWorkingMode); 63 }, 64 NotifyWorkingMode: (mode) => { mSEIDWorkingMode = mode; }, 65 NotifyConnectedStatus: (b) => { }); 66 67 mUserTextField.SetEnabled(true); 68 } 69 70 void OnDestroy() 71 { 72 Dispose(); 73 74 if (mWelcomeView != null) 75 mWelcomeView.OnUserClosedConfigurationWindow(); 76 } 77 78 void CheckConnectionButton_Clicked() 79 { 80 ConfigurationCheckCredentialsButtonClickEvent.ClickInThreadWaiter( 81 mSEIDWorkingMode, 82 mUserTextField.value, 83 mPasswordTextField.value, 84 Edition.Team, 85 mUserAssistant, 86 HideCredentialsValidationError, 87 ShowCheckCredentialsError, 88 ShowProgress, 89 HideProgress, 90 ShowNotification: ShowCredentialsNotificationMessage, 91 DisableButtons: () => { mCheckConnectionButton.SetEnabled(false); mConnectButton.SetEnabled(false); }, 92 EnableButtons: () => { mCheckConnectionButton.SetEnabled(true); mConnectButton.SetEnabled(true); }, 93 NotifyWorkingMode: (mode) => { mSEIDWorkingMode = mode; }, 94 NotifyConnectedStatus: (status) => { }, 95 restApi: mRestApi); 96 } 97 98 void CancelButton_Clicked() 99 { 100 Close(); 101 } 102 103 void OkButton_Clicked() 104 { 105 if (!ValidateServerAndCreds.IsValidInput( 106 mUserAssistant.GetProposedServer(), 107 mUserTextField.value, 108 mSEIDWorkingMode, 109 mPasswordTextField.value, 110 ShowCheckCredentialsError)) 111 { 112 return; 113 } 114 115 ConfigurationActions.SaveClientConfig( 116 mServerTextField.value, 117 mSEIDWorkingMode, 118 mUserTextField.value, 119 mPasswordTextField.value); 120 121 Close(); 122 } 123 124 void HideCredentialsValidationError() 125 { 126 mCredentialsLabel.RemoveFromClassList("error"); 127 mCredentialsLabel.Hide(); 128 } 129 130 void BuildComponents() 131 { 132 VisualElement root = rootVisualElement; 133 134 root.Query<Label>("plasticConfigurationTitle").First().text = 135 PlasticLocalization.GetString(PlasticLocalization.Name.PlasticConfigurationTitleUnityVCS); 136 137 root.SetControlText<Label>( 138 "plasticConfigurationExplanation", 139 PlasticLocalization.Name.PlasticConfigurationExplanation); 140 141 root.SetControlText<Label>("configurationServerInfo", 142 PlasticLocalization.Name.PlasticSCMServerLabel); 143 144 root.SetControlText<Button>( 145 "connect", 146 PlasticLocalization.Name.Connect); 147 148 root.SetControlText<Label>("useSsl", 149 PlasticLocalization.Name.UseSsl); 150 151 root.SetControlText<Label>("configurationUserNameInfo", 152 PlasticLocalization.Name.ConfigurationUserNameInfo); 153 154 root.SetControlText<Label>("configurationCredentialsInfo", 155 PlasticLocalization.Name.ConfigurationCredentialsInfo); 156 157 root.SetControlText<Button>("check", 158 PlasticLocalization.Name.Check); 159 160 root.SetControlText<Label>("credentialsOk", 161 PlasticLocalization.Name.CredentialsOK); 162 163 root.SetControlText<Button>("okButton", 164 PlasticLocalization.Name.OkButton); 165 166 root.SetControlText<Button>("cancelButton", 167 PlasticLocalization.Name.CancelButton); 168 169 mSpinnerContainer = root.Query<VisualElement>("spinnerContainer").First(); 170 mSpinnerLabel = root.Query<Label>("spinnerLabel").First(); 171 172 mLoadingSpinner = new LoadingSpinner(); 173 mSpinnerContainer.Add(mLoadingSpinner); 174 mSpinnerContainer.Hide(); 175 176 mCheckConnectionButton = root.Query<Button>("check").First(); 177 mCheckConnectionButton.clicked += CheckConnectionButton_Clicked; 178 179 mConnectButton = root.Query<Button>("connect").First(); 180 mConnectButton.clicked += ConnectButton_Clicked; 181 182 mServerTextField = root.Query<TextField>("serverTextField").First(); 183 mServerTextField.RegisterValueChangedCallback(OnServerTextFieldChanged); 184 185 mUseSslToggle = root.Query<Toggle>("useSslToogle").First(); 186 mUseSslToggle.RegisterValueChangedCallback(OnUseSslToggleChanged); 187 188 mUserTextField = root.Query<TextField>("userTextField").First(); 189 mUserTextField.SetEnabled(false); 190 191 mPasswordTextField = root.Query<TextField>("passwordTextField").First(); 192 mPasswordTextField.isPasswordField = true; 193 194 mConnectedLabel = root.Query<Label>("connectedLabel").First(); 195 196 mCredentialsLabel = root.Query<Label>("credentialsOk").First(); 197 198 mOkButton = root.Query<Button>("okButton").First(); 199 mOkButton.clicked += OkButton_Clicked; 200 201 mCancelButton = root.Query<Button>("cancelButton").First(); 202 mCancelButton.clicked += CancelButton_Clicked; 203 } 204 205 void OnUseSslToggleChanged(ChangeEvent<bool> evt) 206 { 207 mUserAssistant.OnSslChanged(mServerTextField.value, evt.newValue); 208 mServerTextField.value = mUserAssistant.GetProposedServer(); 209 } 210 211 void InitializeLayoutAndStyles() 212 { 213 VisualElement root = rootVisualElement; 214 215 root.LoadLayout(typeof(TeamEditionConfigurationWindow).Name); 216 217 root.LoadStyle(typeof(TeamEditionConfigurationWindow).Name); 218 } 219 220 void OnServerTextFieldChanged(ChangeEvent<string> evt) 221 { 222 mUserAssistant.OnServerChanged(evt.newValue); 223 mUseSslToggle.value = mUserAssistant.IsSslServer(evt.newValue); 224 } 225 226 void ShowServerNotificationMessage(string message) 227 { 228 mConnectedLabel.text = message; 229 mConnectedLabel.Show(); 230 } 231 232 void ShowServerValidationError(string message) 233 { 234 mConnectedLabel.text = message; 235 mConnectedLabel.AddToClassList("error"); 236 mConnectedLabel.Show(); 237 } 238 239 void ShowCredentialsNotificationMessage(string message) 240 { 241 mCredentialsLabel.text = message; 242 mCredentialsLabel.Show(); 243 } 244 245 void ShowCheckCredentialsError(string message) 246 { 247 mCredentialsLabel.text = message; 248 mCredentialsLabel.AddToClassList("error"); 249 mCredentialsLabel.Show(); 250 } 251 252 void HideValidation() 253 { 254 mConnectedLabel.RemoveFromClassList("error"); 255 mConnectedLabel.Hide(); 256 } 257 258 void ShowProgress(string text) 259 { 260 mSpinnerLabel.text = text; 261 262 mSpinnerContainer.Show(); 263 mSpinnerLabel.Show(); 264 mLoadingSpinner.Start(); 265 } 266 267 void HideProgress() 268 { 269 mLoadingSpinner.Stop(); 270 mSpinnerContainer.Hide(); 271 mSpinnerLabel.Hide(); 272 } 273 274 void UpdatePasswordEntries(SEIDWorkingMode workingMode) 275 { 276 bool bIsPasswordRequired = 277 ValidateServerAndCreds.IsPasswordRequired(workingMode); 278 279 if (!bIsPasswordRequired) 280 { 281 mPasswordTextField.Collapse(); 282 mUserTextField.SetEnabled(false); 283 mUserTextField.value = Environment.UserName; 284 return; 285 } 286 287 mUserTextField.SetEnabled(true); 288 mPasswordTextField.Show(); 289 mUserTextField.SelectAll(); 290 mUserTextField.FocusWorkaround(); 291 } 292 293 Button mConnectButton; 294 Label mConnectedLabel; 295 TextField mServerTextField; 296 TextField mPasswordTextField; 297 Toggle mUseSslToggle; 298 LoadingSpinner mLoadingSpinner; 299 Label mSpinnerLabel; 300 VisualElement mSpinnerContainer; 301 Button mCheckConnectionButton; 302 Label mCredentialsLabel; 303 Button mOkButton; 304 Button mCancelButton; 305 306 SEIDWorkingMode mSEIDWorkingMode = SEIDWorkingMode.UPWorkingMode; 307 308 ConfigurationDialogUserAssistant mUserAssistant = 309 new ConfigurationDialogUserAssistant(); 310 311 IPlasticWebRestApi mRestApi; 312 WelcomeView mWelcomeView; 313 TextField mUserTextField; 314 } 315}