using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEditor; using UnityEngine; namespace P4Connect { /// <summary> /// Enter Password Dialog /// </summary> public class PasswordPrompt : EditorWindow { public static ConnectionConfig Cfg { set; get; } public static bool Active { get; set; } public static PasswordPrompt Instance { get { return _instance; } } private static string _newPassword; private static PasswordPrompt _instance; public static void Init() { if (Active) { Instance.Focus(); return; } Active = true; _instance = ScriptableObject.CreateInstance<PasswordPrompt>(); if (Instance != null) { Config.DefaultConnection.FromConfig(); Cfg = Config.DefaultConnection; _newPassword = Cfg.Password; Instance.minSize = new UnityEngine.Vector2(300.0f, 200.0f); Instance.titleContent = new GUIContent("Password Entry"); Instance.ShowUtility(); } } // Close PasswordPrompt Windows if any exist (after restart or run/ pause) public static void CloseWindows() { PasswordPrompt[] windows = Resources.FindObjectsOfTypeAll<PasswordPrompt>(); if (windows != null) { foreach (var win in windows) { win.Close(); } } } private static GUIStyle _pwStyle; private static GUIStyle _labelStyle; private static GUIStyle _boldLabelStyle; private static GUIStyle _fatButtonStyle; private static GUIStyle _rButtonStyle; private static GUIStyle _gButtonStyle; static readonly GUILayoutOption ButtonWidth = GUILayout.Width(100.0f); static bool _stylesInitialized = false; // Static initializer called ONCE from OnGUI() after initialization private static void InitializeStyles() { GUI.skin = ConfigWindow.GetP4Skin(); _fatButtonStyle = GUI.skin.GetStyle("fatButton"); _rButtonStyle = GUI.skin.GetStyle("redFatButton"); _gButtonStyle = GUI.skin.GetStyle("greenFatButton"); _pwStyle = new GUIStyle(GUI.skin.textField) { alignment = TextAnchor.MiddleLeft, fontSize = 20, border = new RectOffset(2, 2, 2, 2), fixedHeight = 30, }; _labelStyle = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, richText = true, fontSize = 16, }; _boldLabelStyle = new GUIStyle("boldLabel") { alignment = TextAnchor.MiddleCenter, fontSize = 20, }; _newPassword = ""; } void OnFocus() { EditorGUI.FocusTextInControl("password"); } void OnGUI() { if (!_stylesInitialized) { InitializeStyles(); _stylesInitialized = true; } if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return)) { if (tryNewPassword()) CloseWindows(); } GUILayout.Label("Perforce Password Needed", _boldLabelStyle); EditorGUILayout.BeginVertical("Box"); GUILayout.Label("Server: <b>" + Cfg.Server + "</b>", _labelStyle); GUILayout.Label("Perforce User: <b>" + Cfg.User + "</b>", _labelStyle); GUILayout.Label("", _labelStyle); GUILayout.EndVertical(); EditorGUILayout.BeginHorizontal(); GUI.SetNextControlName("password"); _newPassword = EditorGUILayout.PasswordField(_newPassword, _pwStyle); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (GUILayout.Button("Cancel", _rButtonStyle, ButtonWidth)) { Active = false; CloseWindows(); } if (GUILayout.Button("Ok", Cfg.Password != _newPassword ? _gButtonStyle : _fatButtonStyle, ButtonWidth)) { tryNewPassword(); Active = false; CloseWindows(); } } GUILayout.EndHorizontal(); } public void OnDestroy() { Active = false; if (ConnectionWizard.Window != null) { ConnectionWizard.Window.Focus(); } } /// <summary> /// Try a new Password. /// If the Connection Wizard is showing, focus there. /// Copy test settings back to the Config /// </summary> /// <returns>true, if User/Password combination verified</returns> private bool tryNewPassword() { if (!_newPassword.Equals(Cfg.Password)) { // Password was changed Cfg.Password = _newPassword; Cfg.PasswordChanged = true; Cfg.PasswordValid = false; Cfg.ToConfig(); Active = false; if (ConfigWindow.ConnectionWizardShowing) { ConnectionWizard.Window.Focus(); } else { Config.DefaultConnection.FromConfig(); Config.Valid = Config.CheckSettings(Config.DefaultConnection); ConfigWindow.Refresh(); } return true; } return false; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 20275 | Norman Morse |
Update source to match 2016.2 patch 2 release Much thrashing of source during refactor. Proper caching of asset statuses, reducing fstats issued. Some bug fixes by Liz Lam Cleanup of Pending changes, rework of initialization and play/stop play transitions |
||
#5 | 19279 | Norman Morse |
Update workshop from internal changes. These Changes are the basis of the 2016.2 release - Dropped support for Unity 4 - Built in Unity 5 - Fixed assembly misidentifications. - Fixed problem where configuration dialog would pop up between runs |
||
#4 | 18942 | Norman Morse | 2016.1 Patch 2 changes | ||
#3 | 18462 | Norman Morse |
Final Changes needed for 2016.1 release New Icons. New Icon Packaging. Unity 4 compatibility changes. |
||
#2 | 18436 | Norman Morse |
A lot of clean up. PackageIcons was a mess Needed to remove GUIStyle Saving because textures are getting lost. |
||
#1 | 18418 | Norman Morse |
Many changes from the dev branch. Icons are packaged differently. Style Sheet is created / used New ConnectionWizard Dialog New PasswordDialog Generate -a tickets Update version to 2016.1.0.0 |
||
//guest/norman_morse/p4connect/main/src/P4Connect/P4Connect/P4Connect.PasswordPrompt.cs | |||||
#1 | 18385 | Norman Morse |
Mostly working, friday before release. Password needs styling. Debug Code needs to be disabled |