Exemple #1
0
 private void OnEnable()
 {
     // Note that Enable is not called when opened as Preference item (via SettingsProvider api)
     // We implement it for old versions of Unity that just use a traditional EditorWindow for settings
     this.activePreferences = MulliganUserPreferences.LoadOrCreatePreferences();
     this.languageRetriever = new LanguageRetriever();
 }
        /// <summary>
        /// Loads the user's previous preferences (User specific savedata), or creates a new default one
        /// </summary>
        /// <returns>Loaded or newly created Preferences</returns>
        public static MulliganUserPreferences LoadOrCreatePreferences()
        {
            // When Preferences got into the mix, we needed to make sure the Mulligan Window and the
            // Preferences window referenced the same deserialized preferences, or else they'd compete
            // and could stomp eachother's values. So we made it a singleton.
            if (LoadedPreferenceInstance != null)
            {
                return(LoadedPreferenceInstance);
            }

            var serializedPreferences     = EditorPrefs.GetString(UserPreferencesPrefKey, string.Empty);
            MulliganUserPreferences prefs = null;

            if (!string.IsNullOrEmpty(serializedPreferences))
            {
                var loadedPreferences = JsonUtility.FromJson <MulliganUserPreferences>(serializedPreferences);
                prefs = loadedPreferences;
            }
            else
            {
                prefs = new MulliganUserPreferences();
            }

            prefs.UpgradePreferences();

            LoadedPreferenceInstance = prefs;
            return(prefs);
        }
 /// <summary>
 /// (Re)Initialize the LocaleManager. This loads the languages and sets the language to English, if unset.
 /// </summary>
 public void Initialize()
 {
     this.CacheAllLanguages();
     if (this.areLanguagesLoaded)
     {
         var preferences = MulliganUserPreferences.LoadOrCreatePreferences();
         this.ChangeLanguage(preferences.CurrentLanguageKey);
     }
 }
        public static void DeletePrefs()
        {
            var activePreferences = MulliganUserPreferences.LoadOrCreatePreferences();

            activePreferences.ResetToDefaults();
            activePreferences.SaveToEditorPrefs();
            MulliganUserPreferences.Debug_DeletePreferences();
            LocalizationManager.Instance.Initialize();
        }
Exemple #5
0
        private static void DrawSampleDeletionLabel(Rect rect, MulliganUserPreferences preferences)
        {
            var diffLabelStyle = new MulliganEditorGUIUtilities.DiffLabelStyle()
            {
                HideDiff            = false,
                OperationToShow     = DiffOperation.Deletion,
                DiffBackgroundColor = preferences.DeletionBackgroundColor,
                DiffTextColor       = preferences.DeletionTextColor,
            };

            var renameResult = CreateSampleTextForDiffOp(new string[] { "exampleSampleText", "exampleDeleted" }, DiffOperation.Deletion);

            MulliganEditorGUIUtilities.DrawDiffLabel(rect, renameResult, true, diffLabelStyle, SampleDiffLabelStyle);
        }
Exemple #6
0
        private static void DrawSampleDiffLabel(bool insertion, MulliganUserPreferences preferences)
        {
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField(string.Empty, GUILayout.MaxWidth(LabelWidth));
            var rect = EditorGUILayout.GetControlRect();

            if (insertion)
            {
                DrawSampleInsertionLabel(rect, preferences);
            }
            else
            {
                DrawSampleDeletionLabel(rect, preferences);
            }

            EditorGUILayout.EndHorizontal();
        }
        private static void DrawSampleDeletionLabel(Rect rect, MulliganUserPreferences preferences)
        {
            var diffLabelStyle = new MulliganEditorGUIUtilities.DiffLabelStyle()
            {
                HideDiff            = false,
                OperationToShow     = DiffOperation.Deletion,
                DiffBackgroundColor = preferences.DeletionBackgroundColor,
                DiffTextColor       = preferences.DeletionTextColor,
            };

            var renameResult = new RenameResult();

            renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleThisIs") + " ", DiffOperation.Equal));
            renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleSampleText"), DiffOperation.Deletion));
            renameResult.Add(new Diff(" " + LocalizationManager.Instance.GetTranslation("exampleWithWords") + " ", DiffOperation.Equal));
            renameResult.Add(new Diff(LocalizationManager.Instance.GetTranslation("exampleDeleted"), DiffOperation.Deletion));

            MulliganEditorGUIUtilities.DrawDiffLabel(rect, renameResult, true, diffLabelStyle, SampleDiffLabelStyle);
        }
        public static SettingsProvider CreateMyCustomSettingsProvider()
        {
            // First parameter is the path in the Settings window.
            // Second parameter is the scope of this setting: it only appears in the Project Settings window.
            var provider = new SettingsProvider(Path, SettingsScope.User)
            {
                // By default the last token of the path is used as display name if no label is provided.
                label           = LocalizationManager.Instance.GetTranslation("preferencesMenuItem"),
                activateHandler = (searchContext, rootElement) =>
                {
                    ActivePreferences = MulliganUserPreferences.LoadOrCreatePreferences();
                    LanguageRetriever = new LanguageRetriever();
                },

                // Create the SettingsProvider and initialize its drawing (IMGUI) function in place:
                guiHandler = DrawPreferences,

                // Populate the search keywords to enable smart search filtering and label highlighting:
                keywords = new HashSet <string>(new[] { "Diff", "Color" })
            };

            return(provider);
        }
Exemple #9
0
        /// <summary>
        /// Draw the Preferences using Unity GUI framework.
        /// </summary>
        /// <param name="preferences">Preferences to draw and update</param>
        public static void DrawPreferences(MulliganUserPreferences preferences, LanguageRetriever languageRetriever)
        {
            // I override LabelWidth (and MaxWidth) just to look more like Unity's native preferences
            EditorGUIUtility.labelWidth = LabelWidth;

            var prefsChanged = false;

            EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(MaxWidth));
            var newLanguage = DrawLanguageDropdown(LocalizationManager.Instance.CurrentLanguage);

            if (newLanguage != LocalizationManager.Instance.CurrentLanguage)
            {
                preferences.CurrentLanguageKey = newLanguage.Key;
                LocalizationManager.Instance.ChangeLanguage(newLanguage.Key);
            }

            DrawUpdateLanguagesButton(languageRetriever);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            GUILayout.Label(LocalizationManager.Instance.GetTranslation("preferencesDiffLabel"), EditorStyles.boldLabel);

            EditorGUI.BeginChangeCheck();
            preferences.InsertionTextColor = EditorGUILayout.ColorField(
                LocalizationManager.Instance.GetTranslation("preferencesInsertionText"),
                preferences.InsertionTextColor,
                GUILayout.MaxWidth(MaxWidth));
            preferences.InsertionBackgroundColor = EditorGUILayout.ColorField(
                LocalizationManager.Instance.GetTranslation("preferencesInsertionBackground"),
                preferences.InsertionBackgroundColor,
                GUILayout.MaxWidth(MaxWidth));
            EditorGUILayout.Space();
            DrawSampleDiffLabel(true, preferences);
            EditorGUILayout.Space();

            EditorGUILayout.Space();
            preferences.DeletionTextColor = EditorGUILayout.ColorField(
                LocalizationManager.Instance.GetTranslation("preferencesDeletionText"),
                preferences.DeletionTextColor,
                GUILayout.MaxWidth(MaxWidth));
            preferences.DeletionBackgroundColor = EditorGUILayout.ColorField(
                LocalizationManager.Instance.GetTranslation("preferencesDeletionBackground"),
                preferences.DeletionBackgroundColor,
                GUILayout.MaxWidth(MaxWidth));
            EditorGUILayout.Space();
            DrawSampleDiffLabel(false, preferences);

            if (EditorGUI.EndChangeCheck())
            {
                prefsChanged = true;
            }

            if (GUILayout.Button(LocalizationManager.Instance.GetTranslation("preferencesReset"), GUILayout.Width(150)))
            {
                preferences.ResetColorsToDefault(EditorGUIUtility.isProSkin);
                prefsChanged = true;
            }

            if (prefsChanged)
            {
                preferences.SaveToEditorPrefs();
            }
        }