Example #1
0
        internal static int SortByObscurance(PrefsRecord n1, PrefsRecord n2)
        {
            var result = n1.Obscured.CompareTo(n2.Obscured);

            if (result == 0)
            {
                return(SortByNameAscending(n1, n2));
            }

            return(result);
        }
Example #2
0
        internal static int SortByType(PrefsRecord n1, PrefsRecord n2)
        {
            var result = string.CompareOrdinal(n1.DisplayType, n2.DisplayType);

            if (result == 0)
            {
                return(SortByNameAscending(n1, n2));
            }

            return(result);
        }
Example #3
0
        internal static int SortByNameDescending(PrefsRecord n1, PrefsRecord n2)
        {
            var result = string.CompareOrdinal(n2.key, n1.key);

            return(result);
        }
Example #4
0
 internal static int SortByNameAscending(PrefsRecord n1, PrefsRecord n2)
 {
     return(string.CompareOrdinal(n1.key, n2.key));
 }
Example #5
0
        private void ShowOtherMenu(PrefsRecord record)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Copy to clipboard"), false, () =>
            {
                EditorGUIUtility.systemCopyBuffer = record.ToString();
            });

            if (record.Obscured)
            {
                menu.AddItem(new GUIContent("Copy obscured raw data to clipboard"), false, () =>
                {
                    EditorGUIUtility.systemCopyBuffer = record.ToString(true);
                });
            }

            var valueToPaste = EditorGUIUtility.systemCopyBuffer;

            switch (record.prefType)
            {
            case PrefsRecord.PrefsType.Unknown:
                break;

            case PrefsRecord.PrefsType.String:
                if (!record.Obscured || record.IsEditableObscuredValue())
                {
                    menu.AddItem(new GUIContent("Paste string value from clipboard"), false, () =>
                    {
                        record.StringValue = valueToPaste;
                    });
                }
                break;

            case PrefsRecord.PrefsType.Int:
                menu.AddItem(new GUIContent("Paste int value from clipboard"), false, () =>
                {
                    int pastedInt;
                    if (int.TryParse(valueToPaste, out pastedInt))
                    {
                        record.IntValue = pastedInt;
                    }
                    else
                    {
                        Debug.LogWarning(ACTkConstants.LogPrefix + "Can't paste this value to Int pref:\n" + valueToPaste);
                    }
                });
                break;

            case PrefsRecord.PrefsType.Float:
                menu.AddItem(new GUIContent("Paste float value from clipboard"), false, () =>
                {
                    float pastedFloat;
                    if (float.TryParse(valueToPaste, out pastedFloat))
                    {
                        record.FloatValue = pastedFloat;
                    }
                    else
                    {
                        Debug.LogWarning(ACTkConstants.LogPrefix + "Can't paste this value to Float pref:\n" + valueToPaste);
                    }
                });
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            menu.ShowAsContext();
        }
Example #6
0
        // -------------------------------------------------------------------
        // GUI
        // -------------------------------------------------------------------

        private void OnGUI()
        {
            if (allRecords == null)
            {
                allRecords = new List <PrefsRecord>();
            }
            if (filteredRecords == null)
            {
                filteredRecords = new List <PrefsRecord>();
            }

            using (GUITools.Horizontal(GUITools.Toolbar))
            {
                if (GUILayout.Button(new GUIContent("+", "Create new prefs record."), EditorStyles.toolbarButton, GUILayout.Width(20)))
                {
                    addingNewRecord = true;
                }

                if (GUILayout.Button(new GUIContent("Refresh", "Re-read and re-parse all prefs."), EditorStyles.toolbarButton, GUILayout.Width(50)))
                {
                    RefreshData();
                    GUIUtility.keyboardControl = 0;
                    scrollPosition             = Vector2.zero;
                    recordsCurrentPage         = 0;
                }

                EditorGUI.BeginChangeCheck();
                sortingType = (SortingType)EditorGUILayout.EnumPopup(sortingType, EditorStyles.toolbarDropDown, GUILayout.Width(110));
                if (EditorGUI.EndChangeCheck())
                {
                    ApplySorting();
                }

                GUILayout.Space(10);

                EditorGUI.BeginChangeCheck();
                searchPattern = GUITools.SearchToolbar(searchPattern);
                if (EditorGUI.EndChangeCheck())
                {
                    ApplyFiltering();
                }
            }

            if (addingNewRecord)
            {
                using (GUITools.Horizontal(GUITools.PanelWithBackground))
                {
                    string[] types = { "String", "Int", "Float" };
                    newRecordType = EditorGUILayout.Popup(newRecordType, types, GUILayout.Width(50));

                    newRecordEncrypted = GUILayout.Toggle(newRecordEncrypted, new GUIContent("E", "Create new pref as encrypted ObscuredPref?"), GUITools.CompactButton, GUILayout.Width(25));

                    var guiColor = GUI.color;
                    if (newRecordEncrypted)
                    {
                        GUI.color = obscuredColor;
                    }

                    GUILayout.Label("Key:", GUILayout.ExpandWidth(false));
                    newRecordKey = EditorGUILayout.TextField(newRecordKey);
                    GUILayout.Label("Value:", GUILayout.ExpandWidth(false));

                    if (newRecordType == 0)
                    {
                        newRecordStringValue = EditorGUILayout.TextField(newRecordStringValue);
                    }
                    else if (newRecordType == 1)
                    {
                        newRecordIntValue = EditorGUILayout.IntField(newRecordIntValue);
                    }
                    else
                    {
                        newRecordFloatValue = EditorGUILayout.FloatField(newRecordFloatValue);
                    }

                    GUI.color = guiColor;

                    if (GUILayout.Button("OK", GUITools.CompactButton, GUILayout.Width(30)))
                    {
                        if (string.IsNullOrEmpty(newRecordKey) ||
                            (newRecordType == 0 && string.IsNullOrEmpty(newRecordStringValue)) ||
                            (newRecordType == 1 && newRecordIntValue == 0) ||
                            (newRecordType == 2 && Math.Abs(newRecordFloatValue) < 0.00000001f))
                        {
                            ShowNotification(new GUIContent("Please fill in the pref first!"));
                        }
                        else
                        {
                            PrefsRecord newRecord;

                            if (newRecordType == 0)
                            {
                                newRecord = new PrefsRecord(newRecordKey, newRecordStringValue, newRecordEncrypted);
                            }
                            else if (newRecordType == 1)
                            {
                                newRecord = new PrefsRecord(newRecordKey, newRecordIntValue, newRecordEncrypted);
                            }
                            else
                            {
                                newRecord = new PrefsRecord(newRecordKey, newRecordFloatValue, newRecordEncrypted);
                            }

                            if (newRecord.Save())
                            {
                                allRecords.Add(newRecord);
                                ApplySorting();
                                CloseNewRecordPanel();
                            }
                        }
                    }

                    if (GUILayout.Button("Cancel", GUITools.CompactButton, GUILayout.Width(60)))
                    {
                        CloseNewRecordPanel();
                    }
                }
            }

            using (GUITools.Vertical(GUITools.PanelWithBackground))
            {
                GUILayout.Space(5);

                DrawRecordsPages();

                GUILayout.Space(5);

                GUI.enabled = filteredRecords.Count > 0;
                using (GUITools.Horizontal())
                {
                    if (GUILayout.Button("Encrypt ALL", GUITools.CompactButton))
                    {
                        if (EditorUtility.DisplayDialog("Obscure ALL prefs in list?", "This will apply obscuration to ALL unobscured prefs in the list.\nAre you sure you wish to do this?", "Yep", "Oh, no!"))
                        {
                            foreach (var record in filteredRecords)
                            {
                                record.Encrypt();
                            }
                            GUIUtility.keyboardControl = 0;
                            ApplySorting();
                        }
                    }

                    if (GUILayout.Button("Decrypt ALL", GUITools.CompactButton))
                    {
                        if (EditorUtility.DisplayDialog("UnObscure ALL prefs in list?", "This will remove obscuration from ALL obscured prefs in the list if possible.\nAre you sure you wish to do this?", "Yep", "Oh, no!"))
                        {
                            foreach (var record in filteredRecords)
                            {
                                record.Decrypt();
                            }
                            GUIUtility.keyboardControl = 0;
                            ApplySorting();
                        }
                    }

                    if (GUILayout.Button("Save ALL", GUITools.CompactButton))
                    {
                        if (EditorUtility.DisplayDialog("Save changes to ALL prefs in list?", "Are you sure you wish to save changes to ALL prefs in the list? This can't be undone!", "Yep", "Oh, no!"))
                        {
                            foreach (var record in filteredRecords)
                            {
                                record.Save();
                            }
                            GUIUtility.keyboardControl = 0;
                            ApplySorting();
                        }
                    }

                    if (GUILayout.Button("Delete ALL", GUITools.CompactButton))
                    {
                        if (EditorUtility.DisplayDialog("Delete ALL prefs in list?", "Are you sure you wish to delete the ALL prefs in the list? This can't be undone!", "Yep", "Oh, no!"))
                        {
                            foreach (var record in filteredRecords)
                            {
                                record.Delete();
                            }

                            RefreshData();
                            GUIUtility.keyboardControl = 0;
                        }
                    }
                }
                GUI.enabled = true;
            }
        }