Exemple #1
0
        private static void     OnGUISettings()
        {
            if (HQ.Settings == null)
            {
                return;
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.LabelField("Add an offset on NG Hub's window Y-axis.", GeneralStyles.WrapLabel);
            float offset = EditorGUILayout.FloatField("Y Offset Window", HQ.Settings.Get <HubSettings>().NGHubYOffset);

            EditorGUILayout.HelpBox("This is a workaround. Most of the time NG Hub is correctly placed, but in some cases, it is not.", MessageType.Info);
            EditorGUILayout.HelpBox("If you have the offset bug and you are willing to fix it, contact me through " + Constants.SupportEmail + ".", MessageType.Info);

            if (GUILayout.Button("Contact the author") == true)
            {
                ContactFormWizard.Open(ContactFormWizard.Subject.Support);
            }

            if (EditorGUI.EndChangeCheck() == true)
            {
                HQ.Settings.Get <HubSettings>().NGHubYOffset = offset;
                HQ.InvalidateSettings();
            }
        }
        private static void     OnGUIPresets()
        {
            if (ConsoleSettingsEditor.presetTypes == null)
            {
                List <Type>   types = new List <Type>(4);
                List <string> names = new List <string>(4);

                foreach (Type c in Utility.EachNGTSubClassesOf(typeof(Preset)))
                {
                    types.Add(c);
                    names.Add(Utility.NicifyVariableName(c.Name));
                }

                ConsoleSettingsEditor.presetTypes = types.ToArray();
                ConsoleSettingsEditor.presetNames = names.ToArray();
            }

            for (int i = 0; i < ConsoleSettingsEditor.presetTypes.Length; i++)
            {
                if (GUILayout.Button(ConsoleSettingsEditor.presetNames[i]) == true &&
                    ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 || EditorUtility.DisplayDialog(ConsoleSettingsEditor.presetNames[i], LC.G("NGSettings_ConfirmApply"), LC.G("Yes"), LC.G("No")) == true))
                {
                    Preset preset = Activator.CreateInstance(ConsoleSettingsEditor.presetTypes[i]) as Preset;

                    preset.SetSettings(HQ.Settings);

                    EditorUtility.UnloadUnusedAssetsImmediate();
                    HQ.InvalidateSettings();
                    InternalNGDebug.Log("Preset \"" + ConsoleSettingsEditor.presetNames[i] + "\" applied on " + HQ.Settings + ".");
                }
            }
        }
Exemple #3
0
        private static void     OnGUISettings()
        {
            if (Utility.IsCustomEditorCompatible == false)
            {
                EditorGUILayout.HelpBox("NG Tools has detected a change in Unity code. Please contact the author.", MessageType.Error);

                if (GUILayout.Button("Contact the author") == true)
                {
                    ContactFormWizard.Open(ContactFormWizard.Subject.BugReport, "MonoScriptEditor is incompatible with " + Utility.UnityVersion + ".");
                }
                return;
            }

            InspectorGadgetSettings settings = HQ.Settings.Get <InspectorGadgetSettings>();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Script visualizer lets you select the text when you inspect a script.", GeneralStyles.WrapLabel);
            bool active = NGEditorGUILayout.Switch("Script Visualizer", settings.activeScriptVisualizer);

            if (EditorGUI.EndChangeCheck() == true)
            {
                bool mustUpdate = active == true?Utility.AddCustomEditor(typeof(MonoScript), typeof(MonoScriptEditor)) : Utility.RemoveCustomEditor(typeof(MonoScriptEditor));

                if (mustUpdate == true)
                {
                    MonoScriptEditor.UpdateInspector();
                }

                settings.activeScriptVisualizer = active;
                HQ.InvalidateSettings();
            }
        }
        private static void     OnGUI()
        {
            if (HQ.Settings == null)
            {
                GUILayout.Label(LC.G("ConsoleSettings_NullTarget"));
                return;
            }

            if (ConsoleSettingsEditor.menuButtonStyle == null)
            {
                ConsoleSettingsEditor.menuButtonStyle = new GUIStyle("ToolbarButton");
            }

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Toggle(ConsoleSettingsEditor.currentTab == MainTab.General, LC.G("ConsoleSettings_General"), ConsoleSettingsEditor.menuButtonStyle) == true)
                {
                    ConsoleSettingsEditor.currentTab = MainTab.General;
                }
                if (GUILayout.Toggle(ConsoleSettingsEditor.currentTab == MainTab.Inputs, LC.G("ConsoleSettings_Inputs"), ConsoleSettingsEditor.menuButtonStyle) == true)
                {
                    ConsoleSettingsEditor.currentTab = MainTab.Inputs;
                }
                if (GUILayout.Toggle(ConsoleSettingsEditor.currentTab == MainTab.Themes, LC.G("ConsoleSettings_Themes"), ConsoleSettingsEditor.menuButtonStyle) == true)
                {
                    ConsoleSettingsEditor.currentTab = MainTab.Themes;
                }
                if (GUILayout.Toggle(ConsoleSettingsEditor.currentTab == MainTab.Presets, LC.G("ConsoleSettings_Presets"), ConsoleSettingsEditor.menuButtonStyle) == true)
                {
                    ConsoleSettingsEditor.currentTab = MainTab.Presets;
                }
            }
            GUILayout.EndHorizontal();

            EditorGUI.BeginChangeCheck();
            {
                if (ConsoleSettingsEditor.currentTab == MainTab.General)
                {
                    ConsoleSettingsEditor.OnGUIGeneral();
                }
                else if (ConsoleSettingsEditor.currentTab == MainTab.Inputs)
                {
                    ConsoleSettingsEditor.OnGUIInputs();
                }
                else if (ConsoleSettingsEditor.currentTab == MainTab.Themes)
                {
                    ConsoleSettingsEditor.OnGUIThemes();
                }
                else if (ConsoleSettingsEditor.currentTab == MainTab.Presets)
                {
                    ConsoleSettingsEditor.OnGUIPresets();
                }
            }
            if (EditorGUI.EndChangeCheck() == true)
            {
                HQ.InvalidateSettings();
            }
        }
Exemple #5
0
        public void     SaveComponents()
        {
            EditorApplication.delayCall += this.Repaint;
            HubSettings settings = HQ.Settings.Get <HubSettings>();

            Undo.RecordObject(settings, "Change HubComponent");
            settings.hubData.Serialize(this.components);
            HQ.InvalidateSettings();
        }
 private void    OnAddSlave(ReorderableList r)
 {
     Undo.RecordObject(HQ.Settings.Get <SyncFoldersSettings>(), "Add slave");
     this.profile.slaves.Add(new Project()
     {
         folderPath = this.profile.slaves.Count > 0 ? this.profile.slaves[this.profile.slaves.Count - 1].folderPath : string.Empty
     });
     HQ.InvalidateSettings();
     this.cachedSlaves = null;
 }
Exemple #7
0
            public override void    OnGUI(Rect r)
            {
                ScenesSettings settings = HQ.Settings.Get <ScenesSettings>();

                for (int i = 0; i < settings.profiles.Count; i++)
                {
                    GUILayout.BeginHorizontal();
                    {
                        using (BgColorContentRestorer.Get(i == this.animOn && this.anim.af.isAnimating, Color.Lerp(GUI.contentColor, OptionPopup.HighlightColor, this.anim.Value)))
                        {
                            if (GUILayout.Button("Save In", GeneralStyles.ToolbarButton, GUILayoutOptionPool.ExpandWidthFalse) == true)
                            {
                                this.animOn = i;
                                this.anim.Start();

                                settings.profiles[i].Save();
                                HQ.InvalidateSettings();
                                this.window.Repaint();
                            }

                            EditorGUI.BeginChangeCheck();
                            string name = EditorGUILayout.TextField(settings.profiles[i].name);
                            if (EditorGUI.EndChangeCheck() == true)
                            {
                                settings.profiles[i].name = name;
                                HQ.InvalidateSettings();
                            }
                        }

                        if (GUILayout.Button("X", GeneralStyles.ToolbarCloseButton, GUILayoutOptionPool.ExpandWidthFalse) == true)
                        {
                            settings.profiles.RemoveAt(i);
                            HQ.InvalidateSettings();
                            return;
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                if (GUILayout.Button("Add") == true &&
                    this.window.CheckMaxBuildSceneProfiles(settings.profiles.Count) == true)
                {
                    Profile p = new Profile()
                    {
                        name = "New"
                    };

                    p.Save();

                    settings.profiles.Add(p);

                    r.height = (settings.profiles.Count + 1) * 19F;
                    this.editorWindow.position = r;
                }
            }
        private void    OnDrawHeaderSlaves(Rect r)
        {
            if (this.cachedSlaves == null)
            {
                int countActive = 0;

                for (int i = 0; i < this.profile.slaves.Count; i++)
                {
                    if (this.profile.slaves[i].active == true)
                    {
                        ++countActive;
                    }
                }

                this.cachedSlaves = new GUIContent("Slaves (" + countActive + " / " + this.profile.slaves.Count + ")");
            }

            r.width -= 100F;
            EditorGUI.BeginChangeCheck();
            this.showSlaves = EditorGUI.Foldout(r, this.showSlaves, this.cachedSlaves, true);
            if (EditorGUI.EndChangeCheck() == true)
            {
                this.slavesList.elementHeight = this.showSlaves == true ? NGSyncFoldersWindow.SlaveHeight : 0F;
                this.slavesList.displayAdd    = this.showSlaves;
            }
            r.x += r.width;

            r.width = 50F;
            if (GUI.Button(r, "All") == true)
            {
                Undo.RecordObject(HQ.Settings.Get <SyncFoldersSettings>(), "Enable all slaves");
                for (int i = 0; i < this.profile.slaves.Count; i++)
                {
                    this.profile.slaves[i].active = true;
                }
                HQ.InvalidateSettings();
                this.cachedSlaves = null;
            }
            r.x += r.width;

            if (GUI.Button(r, "None") == true)
            {
                Undo.RecordObject(HQ.Settings.Get <SyncFoldersSettings>(), "Disable all slaves");
                for (int i = 0; i < this.profile.slaves.Count; i++)
                {
                    this.profile.slaves[i].active = false;
                }
                HQ.InvalidateSettings();
                this.cachedSlaves = null;
            }
        }
        private void    EraseProfile()
        {
            SyncFoldersSettings settings = HQ.Settings.Get <SyncFoldersSettings>();

            Undo.RecordObjects(new Object[] { settings, this }, "Erase profile");
            settings.syncProfiles.RemoveAt(this.currentProfile);
            this.UpdateCacheFiles(this.currentProfile);
            this.currentProfile           = Mathf.Clamp(this.currentProfile, 0, settings.syncProfiles.Count - 1);
            this.cachedSlaves             = null;
            this.cacheFileSize            = null;
            this.cachedFiltersFolderLabel = null;
            NGSyncFoldersWindow.cachePath = null;
            HQ.InvalidateSettings();
        }
Exemple #10
0
        private static void     AddFrameFilter(string filter)
        {
            StackTraceSettings stackTrace = HQ.Settings.Get <StackTraceSettings>();

            if (stackTrace.filters.Contains(filter) == false)
            {
                stackTrace.filters.Add(filter);
                HQ.InvalidateSettings();
                EditorUtility.DisplayDialog(Constants.PackageTitle, "\"" + filter + "\" has been added to the filters.", "OK");
            }
            else
            {
                EditorUtility.DisplayDialog(Constants.PackageTitle, "\"" + filter + "\" is already a filter.", "OK");
            }
        }
Exemple #11
0
        private void    AddFavorite()
        {
            FavSettings settings = HQ.Settings.Get <FavSettings>();

            if (this.CheckMaxFavorites(settings.favorites.Count) == true)
            {
                Undo.RecordObject(settings, "Add favorite");
                settings.favorites.Add(new Favorites()
                {
                    name = "Favorite " + (settings.favorites.Count + 1)
                });
                this.currentSave = settings.favorites.Count - 1;
                HQ.InvalidateSettings();
            }
        }
Exemple #12
0
        private void    CreateSelection(Object[] objects)
        {
            AssetsSelection selection = new AssetsSelection(objects);

            if (selection.refs.Count > 0)
            {
                FavSettings settings = HQ.Settings.Get <FavSettings>();

                if (this.CheckMaxAssetsPerSelection(selection.refs.Count) == true &&
                    this.CheckMaxSelections(settings.favorites[this.currentSave].favorites.Count) == true)
                {
                    Undo.RecordObject(settings, "Add Selection as favorite");
                    settings.favorites[this.currentSave].favorites.Add(selection);
                    HQ.InvalidateSettings();
                }
            }
        }
        private void    AddProfile()
        {
            SyncFoldersSettings settings = HQ.Settings.Get <SyncFoldersSettings>();

            if (this.CheckMaxSyncFoldersProfiles(settings.syncProfiles.Count) == true)
            {
                Undo.RecordObjects(new Object[] { settings, this }, "Add profile");
                settings.syncProfiles.Add(new Profile()
                {
                    name = "Profile " + (settings.syncProfiles.Count + 1)
                });
                this.currentProfile           = settings.syncProfiles.Count - 1;
                this.cachedSlaves             = null;
                this.cacheFileSize            = null;
                this.cachedFiltersFolderLabel = null;
                NGSyncFoldersWindow.cachePath = null;
                HQ.InvalidateSettings();
            }
        }
        private static void     PickType(int i)
        {
            FullscreenBindingsSettings settings = HQ.Settings.Get <FullscreenBindingsSettings>();
            GenericTypesSelectorWizard wizard   = GenericTypesSelectorWizard.Start(NGFullscreenBindingsWindow.Title, typeof(EditorWindow), (t) =>
            {
                if (t != null)
                {
                    settings.bindings[i].type = t.GetShortAssemblyType();
                }
                else
                {
                    settings.bindings[i].type = string.Empty;
                }
                HQ.InvalidateSettings();
                Utility.RepaintEditorWindow(typeof(NGSettingsWindow));
            }, true, true);

            wizard.EnableNullValue = true;
            wizard.SelectedType    = Type.GetType(settings.bindings[i].type);
        }
Exemple #15
0
        private static void     OnGUISettings()
        {
            if (HQ.Settings == null)
            {
                return;
            }

            if (DragObjectDrawer.ScriptAttributeUtility == null)
            {
                EditorGUILayout.HelpBox("NG Tools has detected a change in Unity code. Please contact the author.", MessageType.Error);

                if (GUILayout.Button("Contact the author") == true)
                {
                    ContactFormWizard.Open(ContactFormWizard.Subject.BugReport, "DragObjectDrawer is incompatible with " + Utility.UnityVersion + ".");
                }
                return;
            }

            DraggableObjectSettings settings = HQ.Settings.Get <DraggableObjectSettings>();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Allows to drag & drop between Object fields in Inspector.", GeneralStyles.WrapLabel);
            bool active = EditorGUILayout.Toggle("Drag & Drop with Object", settings.active);

            if (EditorGUI.EndChangeCheck() == true)
            {
                HQ.InvalidateSettings();

                if (active == true)
                {
                    DragObjectDrawer.AddType();
                }
                else
                {
                    DragObjectDrawer.RemoveType();
                }

                settings.active = active;
            }
        }
Exemple #16
0
        private void    DelayedRefreshStreams()
        {
            NGConsoleWindow[] consoles = Resources.FindObjectsOfTypeAll <NGConsoleWindow>();

            if (consoles.Length == 0)
            {
                return;
            }

            MainModule main = consoles[0].GetModule("Main") as MainModule;

            if (main != null)
            {
                for (int i = 0; i < main.Streams.Count; i++)
                {
                    main.Streams[i].RefreshFilteredRows();
                }

                HQ.InvalidateSettings();
                Utility.RepaintEditorWindow(typeof(NGConsoleWindow));
            }
        }
Exemple #17
0
        protected virtual void  OnEnable()
        {
            Utility.RestoreIcon(this, NGFavWindow.TitleColor);

            Metrics.UseTool(3);             // NGFav

            NGChangeLogWindow.CheckLatestVersion(NGAssemblyInfo.Name);

            this.wantsMouseMove = true;

            this.minSize = new Vector2(this.minSize.x, 0F);

            this.horizontalScrolls = new List <HorizontalScrollbar>();
            this.delayToDelete     = -1;

            this.list = new ReorderableList(null, typeof(GameObject), true, false, false, false);
            this.list.showDefaultBackground = false;
            this.list.headerHeight          = 0F;
            this.list.footerHeight          = 0F;
            this.list.drawElementCallback   = this.DrawElement;
            this.list.onReorderCallback     = (ReorderableList list) => { HQ.InvalidateSettings(); };

            if (this.backgroundColor.a == 0F)
            {
                this.backgroundColor = (Color)Utility.LoadEditorPref(this.backgroundColor, typeof(Color), "NGFav.backgroundColor");
            }

            NGDiagnostic.DelayDiagnostic(this.Diagnose);

            HQ.SettingsChanged += this.CheckSettings;
            Utility.RegisterIntervalCallback(this.TryReconnectkNullObjects, NGFavWindow.ForceRepaintRefreshTick);
            RootGameObjectsManager.RootChanged += this.OnRootObjectsChanged;
            Undo.undoRedoPerformed             += this.Repaint;

            this.CheckSettings();
        }
        private static void     OnGUISettings()
        {
            if (HQ.Settings == null)
            {
                return;
            }

            NavSettings settings = HQ.Settings.Get <NavSettings>();

            if (Application.platform != RuntimePlatform.WindowsEditor)
            {
                EditorGUILayout.LabelField(LC.G("NGNavSelection_OnlyAvailableOnWindows"), GeneralStyles.WrapLabel);
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            using (BgColorContentRestorer.Get(settings.enable == true ? Color.green : Color.red))
            {
                EditorGUILayout.BeginVertical("ButtonLeft");
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        settings.enable = NGEditorGUILayout.Switch(LC.G("Enable"), settings.enable);
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.LabelField(LC.G("NGNavSelection_EnableDescription"), GeneralStyles.WrapLabel);
                }
                EditorGUILayout.EndVertical();
            }

            if (EditorGUI.EndChangeCheck() == true)
            {
                if (settings.enable == false)
                {
                    Selection.selectionChanged -= NGNavSelectionWindow.UpdateSelection;
#if !UNITY_2017_2_OR_NEWER
                    EditorApplication.playmodeStateChanged -= NGNavSelectionWindow.OnPlayStateChanged;
#else
                    EditorApplication.playModeStateChanged -= NGNavSelectionWindow.OnPlayStateChanged;
#endif
                }
                else
                {
                    Selection.selectionChanged += NGNavSelectionWindow.UpdateSelection;
#if !UNITY_2017_2_OR_NEWER
                    EditorApplication.playmodeStateChanged += NGNavSelectionWindow.OnPlayStateChanged;
#else
                    EditorApplication.playModeStateChanged += NGNavSelectionWindow.OnPlayStateChanged;
#endif
                }
                HQ.InvalidateSettings();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(LC.G("NGNavSelection_MaxHistoricDescription"), GeneralStyles.WrapLabel);
            settings.maxHistoric = EditorGUILayout.IntField(LC.G("NGNavSelection_MaxHistoric"), settings.maxHistoric);
            if (EditorGUI.EndChangeCheck() == true)
            {
                settings.maxHistoric = Mathf.Clamp(settings.maxHistoric, 1, NGNavSelectionWindow.MaxHistoric);
                HQ.InvalidateSettings();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(LC.G("NGNavSelection_MaxDisplayHierarchyDescription"), GeneralStyles.WrapLabel);
            settings.maxDisplayHierarchy = EditorGUILayout.IntField(LC.G("NGNavSelection_MaxDisplayHierarchy"), settings.maxDisplayHierarchy);
            if (EditorGUI.EndChangeCheck() == true)
            {
                if (settings.maxDisplayHierarchy < -1)
                {
                    settings.maxDisplayHierarchy = -1;
                }
                HQ.InvalidateSettings();
            }
        }
        private static void     OnGUIThemes()
        {
            Type[]   types;
            string[] names;

            if (ConsoleSettingsEditor.themeTypes == null)
            {
                List <Type>   completeThemeTypes = new List <Type>(2);
                List <string> completeThemeNames = new List <string>(2);
                List <Type>   themeTypes         = new List <Type>(2);
                List <string> themeNames         = new List <string>(2);

                foreach (Type c in Utility.EachNGTSubClassesOf(typeof(Theme)))
                {
                    if (c.IsDefined(typeof(CompleteThemeAttribute), false) == true)
                    {
                        completeThemeTypes.Add(c);
                        completeThemeNames.Add(Utility.NicifyVariableName(c.Name));
                    }
                    else
                    {
                        themeTypes.Add(c);
                        themeNames.Add(Utility.NicifyVariableName(c.Name));
                    }
                }

                ConsoleSettingsEditor.completeThemeTypes = completeThemeTypes.ToArray();
                ConsoleSettingsEditor.completeThemeNames = completeThemeNames.ToArray();

                ConsoleSettingsEditor.themeTypes = themeTypes.ToArray();
                ConsoleSettingsEditor.themeNames = themeNames.ToArray();
            }

            for (int j = 0; j < 2; j++)
            {
                if (j == 0)
                {
                    GUILayout.Label("Main Themes");
                    types = ConsoleSettingsEditor.completeThemeTypes;
                    names = ConsoleSettingsEditor.completeThemeNames;
                }
                else
                {
                    GUILayout.Label("Partial Themes");
                    types = ConsoleSettingsEditor.themeTypes;
                    names = ConsoleSettingsEditor.themeNames;
                }

                for (int i = 0; i < types.Length; i++)
                {
                    if (GUILayout.Button(names[i]) == true &&
                        ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 || EditorUtility.DisplayDialog(names[i], LC.G("NGSettings_ConfirmApply"), LC.G("Yes"), LC.G("No")) == true))
                    {
                        Theme theme = Activator.CreateInstance(types[i]) as Theme;

                        theme.SetTheme(HQ.Settings);

                        EditorUtility.UnloadUnusedAssetsImmediate();
                        HQ.InvalidateSettings();
                        InternalNGDebug.Log("Theme \"" + names[i] + "\" applied on " + HQ.Settings + ".");
                    }
                }
            }
        }
Exemple #20
0
 public void     SaveModules(bool directSave)
 {
     this.settings.Get <ConsoleSettings>().serializedModules.Serialize(this.modules);
     HQ.InvalidateSettings(this.settings, directSave);
 }
        private static void     OnGUISettings()
        {
            if (HQ.Settings == null)
            {
                return;
            }

            EditorGUILayout.Space();

            FullscreenBindingsSettings settings = HQ.Settings.Get <FullscreenBindingsSettings>();

            // Rebuild and restore as much as we can the previous bindings.
            if (settings.bindings == null ||
                settings.bindings.Length != 12)
            {
                FullscreenBindingsSettings.Binding[] newBindings = new FullscreenBindingsSettings.Binding[12];
                Type type = Utility.GetType("NGToolsEditor.NGFullscreenBindings", "ExternalNGFullscreenBindings");

                if (settings.bindings != null)
                {
                    for (int i = 0; i < settings.bindings.Length && i < newBindings.Length; i++)
                    {
                        newBindings[i] = new FullscreenBindingsSettings.Binding(settings.bindings[i].label, settings.bindings[i].type)
                        {
                            active = settings.bindings[i].active,
                            ctrl   = settings.bindings[i].ctrl,
                            shift  = settings.bindings[i].shift,
                            alt    = settings.bindings[i].alt,
                        };
                    }

                    for (int i = 0; i < settings.bindings.Length; i++)
                    {
                        FieldInfo field = type.GetField("F" + (i + 1));

                        if (field != null)
                        {
                            newBindings[i] = new FullscreenBindingsSettings.Binding((string)field.GetRawConstantValue(), string.Empty)
                            {
                                active = type.GetMethod("ToggleFullscreenF" + (i + 1)) != null
                            }
                        }
                        ;
                    }
                }

                for (int i = 0; i < newBindings.Length; i++)
                {
                    if (newBindings[i] == null)
                    {
                        newBindings[i] = new FullscreenBindingsSettings.Binding(string.Empty, string.Empty);
                    }
                }

                settings.bindings = newBindings;
            }

            using (LabelWidthRestorer.Get(30F))
            {
                for (int i = 0; i < settings.bindings.Length; i++)
                {
                    FullscreenBindingsSettings.Binding binding = settings.bindings[i];

                    EditorGUILayout.BeginHorizontal();
                    {
                        binding.active = EditorGUILayout.Toggle(binding.active, GUILayoutOptionPool.Width(12F));

                        EditorGUI.BeginDisabledGroup(binding.active == false);
                        {
                            GUILayout.Label("F" + (i + 1), GUILayoutOptionPool.Width(25F));

                            binding.ctrl  = GUILayout.Toggle(binding.ctrl, "Ctrl", "ToolbarButton", GUILayoutOptionPool.Width(35F));
                            binding.shift = GUILayout.Toggle(binding.shift, "Shift", "ToolbarButton", GUILayoutOptionPool.Width(35F));
                            binding.alt   = GUILayout.Toggle(binding.alt, "Alt", "ToolbarButton", GUILayoutOptionPool.Width(35F));
                            binding.label = EditorGUILayout.TextField(binding.label);

                            GUILayout.FlexibleSpace();

                            Type t = NGFullscreenBindingsWindow.GetType(settings.bindings[i].type);
                            if (t != null)
                            {
                                GUILayout.Label(t.Name, GUILayoutOptionPool.ExpandWidthFalse);
                            }

                            if (GUILayout.Button("Pick", GUILayoutOptionPool.Width(50F)) == true)
                            {
                                NGFullscreenBindingsWindow.PickType(i);
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                    }
                    EditorGUILayout.EndHorizontal();

                    if (NGFullscreenBindingsWindow.regex.IsMatch(binding.label) == false)
                    {
                        EditorGUILayout.HelpBox("Must contains only alpha numeric chars, space, tab, dash, underscore.", MessageType.Error, true);
                    }

                    if (i == 0 && binding.ctrl == false && binding.shift == false && binding.alt == true)
                    {
                        EditorGUILayout.HelpBox("This binding is already used. You must change it.", MessageType.Error, true);
                    }
                }
            }

            if (EditorApplication.isCompiling == true)
            {
                using (BgColorContentRestorer.Get(GeneralStyles.HighlightResultButton))
                {
                    GUILayout.Button("Compiling...");
                }
            }
            else if (GUILayout.Button("Save") == true)
            {
                HQ.InvalidateSettings();
                NGFullscreenBindingsWindow.Generate();
            }
        }
        private void    OnDrawFilter(Rect r, int index, bool isActive, bool isFocused)
        {
            if (this.showFilters == false)
            {
                return;
            }

            SyncFoldersSettings settings = HQ.Settings.Get <SyncFoldersSettings>();
            FilterText          filter   = this.profile.filters[index];
            float width = r.width;

            r.width = NGSyncFoldersWindow.ToggleFilterWidth;
            EditorGUI.BeginChangeCheck();
            GUI.Toggle(r, filter.active, string.Empty);
            if (EditorGUI.EndChangeCheck() == true)
            {
                Undo.RecordObject(settings, "Toggle filter");
                filter.active = !filter.active;
                HQ.InvalidateSettings();
                this.cachedFiltersFolderLabel = null;
                GUI.FocusControl(null);
            }
            r.x += r.width;

            r.height -= 2F;

            EditorGUI.BeginChangeCheck();
            r.width = width - NGSyncFoldersWindow.ToggleFilterWidth - 2F - NGSyncFoldersWindow.FilterTypeWidth - NGSyncFoldersWindow.DeleteButtonWidth;
            string text = EditorGUI.TextField(r, filter.text);

            if (EditorGUI.EndChangeCheck() == true)
            {
                Undo.RecordObject(settings, "Alter filter");
                filter.text = text;
                HQ.InvalidateSettings();
                this.cachedFiltersFolderLabel = null;
            }

            if (filter.active == true)
            {
                r.x      -= 1F;
                r.y      -= 1F;
                r.width  += 2F;
                r.height += 2F;
                Utility.DrawUnfillRect(r, NGSyncFoldersWindow.ActiveFilterOutline);
                r.x      += 1F;
                r.y      += 1F;
                r.width  -= 2F;
                r.height -= 2F;
            }

            r.x += r.width + 2F;

            EditorGUI.BeginChangeCheck();
            r.width = NGSyncFoldersWindow.FilterTypeWidth;
            GUI.Toggle(r, filter.type == Filter.Type.Inclusive, filter.type == Filter.Type.Inclusive ? "Inclusive" : "Exclusive", GeneralStyles.ToolbarToggle);
            if (EditorGUI.EndChangeCheck() == true)
            {
                Undo.RecordObject(settings, "Toggle filter");
                filter.type = (Filter.Type)(((int)filter.type + 1) & 1);
                HQ.InvalidateSettings();
                this.cachedFiltersFolderLabel = null;
            }
            r.x += r.width;

            r.width = NGSyncFoldersWindow.DeleteButtonWidth;
            if (GUI.Button(r, "X", GeneralStyles.ToolbarCloseButton) == true)
            {
                Undo.RecordObject(settings, "Delete filter");
                this.profile.filters.RemoveAt(index);
                HQ.InvalidateSettings();
                this.cachedFiltersFolderLabel = null;
                EditorGUIUtility.ExitGUI();
            }
        }
Exemple #23
0
        protected virtual void  OnGUI()
        {
            if (HQ.Settings == null)
            {
                GUILayout.Label(string.Format(LC.G("RequiringConfigurationFile"), NGFavWindow.Title));
                if (GUILayout.Button(LC.G("ShowPreferencesWindow")) == true)
                {
                    Utility.ShowPreferencesWindowAt(Constants.PreferenceTitle);
                }
                return;
            }

            FreeLicenseOverlay.First(this, NGAssemblyInfo.Name + " Pro", NGFavWindow.FreeAdContent);

            FavSettings settings = HQ.Settings.Get <FavSettings>();

            // Guarantee there is always one in the list.
            if (settings.favorites.Count == 0)
            {
                settings.favorites.Add(new Favorites()
                {
                    name = "default"
                });
            }

            this.currentSave = Mathf.Clamp(this.currentSave, 0, settings.favorites.Count - 1);

            Favorites fav = settings.favorites[this.currentSave];

            this.list.list = fav.favorites;

            EditorGUILayout.BeginHorizontal(GeneralStyles.Toolbar);
            {
                if (GUILayout.Button("", GeneralStyles.ToolbarDropDown, GUILayoutOptionPool.Width(20F)) == true)
                {
                    GenericMenu menu = new GenericMenu();

                    for (int i = 0; i < settings.favorites.Count; i++)
                    {
                        menu.AddItem(new GUIContent((i + 1) + " - " + settings.favorites[i].name), i == this.currentSave, this.SwitchFavorite, i);
                    }

                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent(LC.G("Add")), false, this.AddFavorite);

                    Rect r = GUILayoutUtility.GetLastRect();
                    r.y += 16F;
                    menu.DropDown(r);
                    GUI.FocusControl(null);
                }

                EditorGUI.BeginChangeCheck();
                fav.name = EditorGUILayout.TextField(fav.name, GeneralStyles.ToolbarTextField, GUILayoutOptionPool.ExpandWidthTrue);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    HQ.InvalidateSettings();
                }

                if (GUILayout.Button(LC.G("Clear"), GeneralStyles.ToolbarButton) == true && ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 || EditorUtility.DisplayDialog(LC.G("NGFav_ClearSave"), string.Format(LC.G("NGFav_ClearSaveQuestion"), fav.name), LC.G("Yes"), LC.G("No")) == true))
                {
                    Undo.RecordObject(settings, "Clear favorite");
                    fav.favorites.Clear();
                    HQ.InvalidateSettings();
                    this.Focus();
                    return;
                }

                EditorGUI.BeginDisabledGroup(settings.favorites.Count <= 1);
                if (GUILayout.Button(LC.G("Erase"), GeneralStyles.ToolbarButton) == true && ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 || EditorUtility.DisplayDialog(LC.G("NGFav_EraseSave"), string.Format(LC.G("NGFav_EraseSaveQuestion"), fav.name), LC.G("Yes"), LC.G("No")) == true))
                {
                    Undo.RecordObject(settings, "Erase favorite");
                    settings.favorites.RemoveAt(this.currentSave);
                    this.currentSave = Mathf.Clamp(this.currentSave, 0, settings.favorites.Count - 1);
                    this.list.list   = fav.favorites;
                    HQ.InvalidateSettings();
                    this.Focus();
                    return;
                }
                EditorGUI.EndDisabledGroup();

                Rect r2 = GUILayoutUtility.GetRect(40F, 16F);
                r2.x += 5F;
                this.backgroundColor = EditorGUI.ColorField(r2, this.backgroundColor);
            }
            EditorGUILayout.EndHorizontal();

            Rect overallDropZone = this.position;

            overallDropZone.x = 0F;
            overallDropZone.y = 0F;

            if (Event.current.type == EventType.Repaint && this.backgroundColor.a > 0F)
            {
                overallDropZone.y       = 16F;
                overallDropZone.height -= 16F;
                EditorGUI.DrawRect(overallDropZone, this.backgroundColor);
                overallDropZone.y = 0;
            }

            overallDropZone.height = 16F;

            // Drop zone to add a new selection.
            if (Event.current.type == EventType.Repaint &&
                DragAndDrop.objectReferences.Length > 0)
            {
                Utility.DropZone(overallDropZone, "Create new selection");
                this.Repaint();
            }
            else if (Event.current.type == EventType.DragUpdated &&
                     overallDropZone.Contains(Event.current.mousePosition) == true)
            {
                if (DragAndDrop.objectReferences.Length > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }
            }
            else if (Event.current.type == EventType.DragPerform &&
                     overallDropZone.Contains(Event.current.mousePosition) == true)
            {
                DragAndDrop.AcceptDrag();

                this.CreateSelection(DragAndDrop.objectReferences);

                DragAndDrop.PrepareStartDrag();
                Event.current.Use();
            }

            this.errorPopup.OnGUILayout();

            if (this.currentSave >= 0)
            {
                this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition);
                {
                    try
                    {
                        while (this.horizontalScrolls.Count < fav.favorites.Count)
                        {
                            this.horizontalScrolls.Add(new HorizontalScrollbar(0F, 0F, this.position.width, 4F, 0F));
                        }

                        this.list.DoLayoutList();
                    }
                    catch (Exception ex)
                    {
                        this.errorPopup.exception = ex;
                        InternalNGDebug.LogFileException(ex);
                    }
                    finally
                    {
                        Utility.content.tooltip = string.Empty;
                    }
                }
                EditorGUILayout.EndScrollView();

                if (this.delayToDelete != -1)
                {
                    Undo.RecordObject(settings, "Delete favorite");
                    fav.favorites.RemoveAt(this.delayToDelete);
                    HQ.InvalidateSettings();
                    this.delayToDelete = -1;
                }
            }

            if (Event.current.type == EventType.MouseDown)
            {
                DragAndDrop.PrepareStartDrag();
                this.dragOriginPosition = Vector2.zero;
            }

            FreeLicenseOverlay.Last(NGAssemblyInfo.Name + " Pro");
        }
        private void    OnDrawSlave(Rect r, int index, bool isActive, bool isFocused)
        {
            if (this.showSlaves == false)
            {
                return;
            }

            SyncFoldersSettings settings = HQ.Settings.Get <SyncFoldersSettings>();
            Project             slave    = this.profile.slaves[index];
            float x     = r.x;
            float width = r.width;

            EditorGUI.BeginChangeCheck();
            r.y     += 2F;
            r.width  = NGSyncFoldersWindow.ToggleSlaveWidth;
            r.height = Constants.SingleLineHeight;

            string content = index < NGSyncFoldersWindow.CachedSlaveIndexes.Length ? NGSyncFoldersWindow.CachedSlaveIndexes[index] : "#" + (index + 1);
            bool   active  = EditorGUI.ToggleLeft(r, content, slave.active);

            if (EditorGUI.EndChangeCheck() == true)
            {
                Undo.RecordObject(settings, "Toggle slave");
                slave.active = active;
                HQ.InvalidateSettings();
                this.cachedSlaves = null;
            }
            r.x += r.width;

            EditorGUI.BeginDisabledGroup(slave.active == false);
            EditorGUI.BeginChangeCheck();
            r.width = width - NGSyncFoldersWindow.ToggleSlaveWidth - NGSyncFoldersWindow.DeleteButtonWidth - 5F;
            string folderPath = NGEditorGUILayout.OpenFolderField(r, "", slave.folderPath);

            if (EditorGUI.EndChangeCheck() == true)
            {
                Undo.RecordObject(settings, "Alter slave path");
                slave.folderPath = folderPath;
                HQ.InvalidateSettings();
            }
            EditorGUI.EndDisabledGroup();
            r.x += r.width + 5F;

            r.width   = NGSyncFoldersWindow.DeleteButtonWidth;
            r.y      -= 1F;
            r.height += 1F;
            if (GUI.Button(r, "X") == true)
            {
                Undo.RecordObject(settings, "Delete slave");
                this.profile.slaves.RemoveAt(index);
                HQ.InvalidateSettings();
                this.cachedSlaves = null;
                EditorGUIUtility.ExitGUI();
            }

            r.x      = 0F;
            r.y     += r.height + 2F;
            r.width  = x + width;
            r.height = Constants.SingleLineHeight;

            this.PreviewPath(r, slave.GetFullPath(this.profile.relativePath));
        }
 private void    OnAddFilter(ReorderableList r)
 {
     Undo.RecordObject(HQ.Settings.Get <SyncFoldersSettings>(), "Add filter");
     r.list.Add(new FilterText());
     HQ.InvalidateSettings();
 }
Exemple #26
0
        private void    DrawElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            FavSettings     settings        = HQ.Settings.Get <FavSettings>();
            AssetsSelection assetsSelection = settings.favorites[this.currentSave].favorites[index];
            float           x     = rect.x;
            float           width = rect.width;

            if (rect.Contains(Event.current.mousePosition) == true)
            {
                float totalWidth = 0F;

                for (int i = 0; i < assetsSelection.refs.Count; i++)
                {
                    SelectionItem selection = assetsSelection.refs[i];

                    if (selection.@object == null)
                    {
                        if (selection.hierarchy.Count > 0)
                        {
                            Utility.content.text = (string.IsNullOrEmpty(selection.resolverAssemblyQualifiedName) == false ? "(R)" : "") + selection.hierarchy[selection.hierarchy.Count - 1];
                        }
                        else
                        {
                            Utility.content.text = "Unknown";
                        }
                    }
                    else
                    {
                        Utility.content.text = [email protected];

                        if (Utility.GetIcon([email protected]()) != null)
                        {
                            totalWidth += rect.height;
                        }
                    }

                    totalWidth += GUI.skin.label.CalcSize(Utility.content).x + NGFavWindow.FavSpacing;
                }

                if (index < 10)
                {
                    if (index < 9)
                    {
                        totalWidth += 24F;
                    }
                    else
                    {
                        totalWidth += 22F;                         // Number 10 is centralized.
                    }
                }

                if (assetsSelection.refs.Count > 1)
                {
                    Utility.content.text = "(" + assetsSelection.refs.Count + ")";
                    totalWidth          += GUI.skin.label.CalcSize(Utility.content).x;
                }

                this.horizontalScrolls[index].RealWidth = totalWidth;
                this.horizontalScrolls[index].SetPosition(rect.x, rect.y);
                this.horizontalScrolls[index].SetSize(rect.width);
                this.horizontalScrolls[index].OnGUI();

                if (Event.current.type == EventType.MouseMove)
                {
                    this.Repaint();
                }

                rect.width   = 20F;
                rect.x       = x + width - rect.width;
                rect.height -= 4F;

                if (GUI.Button(rect, "X") == true)
                {
                    this.delayToDelete = index;
                    return;
                }

                rect.height += 4F;
                rect.x       = x;
                rect.width   = width;
            }

            rect.x -= this.horizontalScrolls[index].Offset;

            if (index <= 9)
            {
                rect.width              = 24F;
                Utility.content.text    = NGFavWindow.CacheIndexes[index];
                Utility.content.tooltip = NGFavWindow.CacheTooltips[index];
                if (index <= 8)
                {
                    EditorGUI.LabelField(rect, Utility.content, GeneralStyles.HorizontalCenteredText);
                }
                else
                {
                    rect.width = 27F;
                    rect.x    -= 4F;
                    EditorGUI.LabelField(rect, Utility.content, GeneralStyles.HorizontalCenteredText);
                    rect.x += 4F;
                }
                Utility.content.tooltip = string.Empty;
                rect.x    += rect.width;
                rect.width = width - rect.x;
            }

            if (assetsSelection.refs.Count >= 2)
            {
                Utility.content.text = "(" + assetsSelection.refs.Count + ")";
                rect.width           = GeneralStyles.HorizontalCenteredText.CalcSize(Utility.content).x;
                GUI.Label(rect, Utility.content, GeneralStyles.HorizontalCenteredText);
                rect.x    += rect.width;
                rect.width = width - rect.x;
            }

            Rect dropZone = rect;

            dropZone.xMin = dropZone.xMax - dropZone.width / 3F;

            for (int i = 0; i < assetsSelection.refs.Count; i++)
            {
                SelectionItem selectionItem = assetsSelection.refs[i];;
                if (selectionItem.@object == null)
                {
                    selectionItem.TryReconnect();
                }

                Texture icon = null;

                Utility.content.tooltip = selectionItem.resolverFailedError;

                EditorGUI.BeginDisabledGroup(selectionItem.@object == null);
                {
                    if (selectionItem.@object == null)
                    {
                        if (selectionItem.hierarchy.Count > 0)
                        {
                            Utility.content.text = (string.IsNullOrEmpty(selectionItem.resolverAssemblyQualifiedName) == false ? "(R)" : "") + selectionItem.hierarchy[selectionItem.hierarchy.Count - 1];
                        }
                        else
                        {
                            Utility.content.text = "Unknown";
                        }
                    }
                    else
                    {
                        Utility.content.text = [email protected];
                        icon = Utility.GetIcon([email protected]());
                    }

                    if (icon != null)
                    {
                        rect.width = rect.height;
                        GUI.DrawTexture(rect, icon);
                        rect.x += rect.width;
                    }

                    rect.width = GeneralStyles.HorizontalCenteredText.CalcSize(Utility.content).x;

                    if (string.IsNullOrEmpty(selectionItem.resolverFailedError) == false)
                    {
                        GeneralStyles.HorizontalCenteredText.normal.textColor = Color.red;
                    }

                    GUI.Label(rect, Utility.content, GeneralStyles.HorizontalCenteredText);
                    Utility.content.tooltip = string.Empty;
                    GeneralStyles.HorizontalCenteredText.normal.textColor = EditorStyles.label.normal.textColor;

                    if (icon != null)
                    {
                        rect.xMin -= rect.height;
                    }
                }
                EditorGUI.EndDisabledGroup();

                if (selectionItem.@object != null)
                {
                    if (Event.current.type == EventType.MouseDrag &&
                        (this.dragOriginPosition - Event.current.mousePosition).sqrMagnitude >= Constants.MinStartDragDistance &&
                        DragAndDrop.GetGenericData("t") as Object == selectionItem.@object)
                    {
                        DragAndDrop.StartDrag("Drag favorite");
                        Event.current.Use();
                    }
                    else if (Event.current.type == EventType.MouseDown &&
                             rect.Contains(Event.current.mousePosition) == true)
                    {
                        this.dragOriginPosition = Event.current.mousePosition;

                        DragAndDrop.PrepareStartDrag();
                        // Add this data to force drag on this object only because user has click down on it.
                        DragAndDrop.SetGenericData("t", selectionItem.@object);
                        DragAndDrop.objectReferences = new Object[] { selectionItem.@object };

                        Event.current.Use();
                    }
                    else if (Event.current.type == EventType.MouseUp &&
                             rect.Contains(Event.current.mousePosition) == true)
                    {
                        DragAndDrop.PrepareStartDrag();

                        if (Event.current.button == 0 && (int)Event.current.modifiers == ((int)settings.deleteModifiers >> 1))
                        {
                            Undo.RecordObject(settings, "Delete element in favorite");
                            assetsSelection.refs.RemoveAt(i);

                            if (assetsSelection.refs.Count == 0)
                            {
                                this.delayToDelete = index;
                            }
                        }
                        else if (Event.current.button == 1 ||
                                 settings.changeSelection == FavSettings.ChangeSelection.SimpleClick ||
                                 ((settings.changeSelection == FavSettings.ChangeSelection.DoubleClick || settings.changeSelection == FavSettings.ChangeSelection.ModifierOrDoubleClick) &&
                                  this.lastClick + Constants.DoubleClickTime > EditorApplication.timeSinceStartup) ||
                                 ((settings.changeSelection == FavSettings.ChangeSelection.Modifier || settings.changeSelection == FavSettings.ChangeSelection.ModifierOrDoubleClick) &&
                                  // HACK We need to shift the event modifier's value. Bug ref #720211_8cg6m8s7akdbf1r5
                                  (int)Event.current.modifiers == ((int)settings.selectModifiers >> 1)))
                        {
                            NGFavWindow.SelectFav(index);
                        }
                        else
                        {
                            EditorGUIUtility.PingObject(assetsSelection.refs[i].@object);
                        }

                        this.lastClick = EditorApplication.timeSinceStartup;

                        this.list.index = index;
                        this.Repaint();

                        Event.current.Use();
                    }
                }
                else
                {
                    // Clean drag on null object, to prevent starting a drag when passing over non-null one without click down.
                    if (Event.current.type == EventType.MouseDown &&
                        rect.Contains(Event.current.mousePosition) == true &&
                        HQ.Settings != null)
                    {
                        if ((int)Event.current.modifiers == ((int)settings.deleteModifiers >> 1))
                        {
                            Undo.RecordObject(settings, "Delete element in favorite");
                            assetsSelection.refs.RemoveAt(i);

                            if (assetsSelection.refs.Count == 0)
                            {
                                this.delayToDelete = index;
                            }

                            Event.current.Use();
                        }

                        DragAndDrop.PrepareStartDrag();
                    }
                }

                rect.x += rect.width + NGFavWindow.FavSpacing;

                if (rect.x >= this.position.width)
                {
                    break;
                }
            }

            rect.x     = x;
            rect.width = width;

            // Drop zone to append new Object to the current selection.
            if (Event.current.type == EventType.Repaint &&
                DragAndDrop.objectReferences.Length > 0 &&
                rect.Contains(Event.current.mousePosition) == true)
            {
                Utility.DropZone(dropZone, "Add to selection");
            }
            else if (Event.current.type == EventType.DragUpdated &&
                     dropZone.Contains(Event.current.mousePosition) == true)
            {
                if (DragAndDrop.objectReferences.Length > 0)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }
            }
            else if (Event.current.type == EventType.DragPerform &&
                     dropZone.Contains(Event.current.mousePosition) == true)
            {
                DragAndDrop.AcceptDrag();

                for (int i = 0; i < DragAndDrop.objectReferences.Length; i++)
                {
                    int j = 0;

                    for (; j < assetsSelection.refs.Count; j++)
                    {
                        if (assetsSelection.refs[j].@object == DragAndDrop.objectReferences[i])
                        {
                            break;
                        }
                    }

                    if (j == assetsSelection.refs.Count)
                    {
                        if (this.CheckMaxAssetsPerSelection(assetsSelection.refs.Count) == true)
                        {
                            Undo.RecordObject(settings, "Add to favorite");
                            assetsSelection.refs.Add(new SelectionItem(DragAndDrop.objectReferences[i]));
                            HQ.InvalidateSettings();
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                DragAndDrop.PrepareStartDrag();
                Event.current.Use();
            }

            // Just draw the button in front.
            if (rect.Contains(Event.current.mousePosition) == true)
            {
                rect.width   = 20F;
                rect.x       = x + width - rect.width;
                rect.height -= 4F;

                GUI.Button(rect, "X");
            }
        }
Exemple #27
0
        private static void     OnGUISettings()
        {
            if (HQ.Settings == null)
            {
                return;
            }

            HierarchyEnhancerSettings settings = HQ.Settings.Get <HierarchyEnhancerSettings>();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            using (BgColorContentRestorer.Get(settings.enable == true ? Color.green : Color.red))
            {
                EditorGUILayout.BeginVertical("ButtonLeft");
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        settings.enable = NGEditorGUILayout.Switch(LC.G("Enable"), settings.enable);
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_EnableDescription"), GeneralStyles.WrapLabel);
                }
                EditorGUILayout.EndVertical();
            }

            if (EditorGUI.EndChangeCheck() == true)
            {
                if (settings.enable == false)
                {
                    EditorApplication.hierarchyWindowItemOnGUI -= NGHierarchyEnhancer.DrawOverlay;
                }
                else
                {
                    EditorApplication.hierarchyWindowItemOnGUI += NGHierarchyEnhancer.DrawOverlay;
                }
                HQ.InvalidateSettings();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_MarginDescription"), GeneralStyles.WrapLabel);
            settings.margin = EditorGUILayout.FloatField(LC.G("NGHierarchyEnhancer_Margin"), settings.margin);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_HoldModifiersDescription"), GeneralStyles.WrapLabel);
            settings.holdModifiers = (EventModifiers)EditorGUILayout.MaskField(new GUIContent(LC.G("NGHierarchyEnhancer_HoldModifiers")), (int)settings.holdModifiers, NGHierarchyEnhancer.eventModifierNames);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_SelectionHoldModifiersDescription"), GeneralStyles.WrapLabel);
            settings.selectionHoldModifiers = (EventModifiers)EditorGUILayout.MaskField(new GUIContent(LC.G("NGHierarchyEnhancer_SelectionHoldModifiers")), (int)settings.selectionHoldModifiers, NGHierarchyEnhancer.eventModifierNames);
            if (EditorGUI.EndChangeCheck() == true)
            {
                HQ.InvalidateSettings();
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_LayersDescription"), GeneralStyles.WrapLabel);

            float maxLabelWidth = NGHierarchyEnhancer.width;

            for (int i = 0; i < HierarchyEnhancerSettings.TotalLayers; i++)
            {
                string layerName = LayerMask.LayerToName(i);

                if (layerName == string.Empty)
                {
                    layerName = "Layer " + i;
                }

                Utility.content.text = layerName;
                float width = GUI.skin.label.CalcSize(Utility.content).x;
                if (maxLabelWidth < width + 20F)                 // Add width for the icon.
                {
                    maxLabelWidth = width + 20F;
                }
            }

            using (LabelWidthRestorer.Get(maxLabelWidth))
            {
                for (int i = 0; i < HierarchyEnhancerSettings.TotalLayers; i++)
                {
                    string layerName = LayerMask.LayerToName(i);

                    if (layerName == string.Empty)
                    {
                        layerName = "Layer " + i;
                    }

                    EditorGUILayout.BeginHorizontal();

                    // (Label + icon) + color picker
                    Rect r = GUILayoutUtility.GetRect(maxLabelWidth + 40F, 16F, GUI.skin.label);

                    Utility.content.text = layerName;
                    float width = GUI.skin.label.CalcSize(Utility.content).x;

                    settings.layers[i] = EditorGUI.ColorField(r, layerName, settings.layers[i]);
                    r.width            = maxLabelWidth;
                    EditorGUI.DrawRect(r, settings.layers[i]);

                    if (settings.layersIcon[i] != null)
                    {
                        r.x    += width + 2F;                      // Little space before the icon.
                        r.width = 16F;
                        GUI.DrawTexture(r, settings.layersIcon[i], ScaleMode.ScaleToFit);
                    }

                    settings.layersIcon[i] = EditorGUILayout.ObjectField(settings.layersIcon[i], typeof(Texture2D), false) as Texture2D;
                    EditorGUILayout.EndHorizontal();
                }
            }

            if (EditorGUI.EndChangeCheck() == true)
            {
                HQ.InvalidateSettings();
                if (NGHierarchyEnhancer.instance != null)
                {
                    NGHierarchyEnhancer.instance.Repaint();
                }
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_WidthPerComponentDescription"), GeneralStyles.WrapLabel);
            settings.widthPerComponent = EditorGUILayout.FloatField(LC.G("NGHierarchyEnhancer_WidthPerComponent"), settings.widthPerComponent);
            if (EditorGUI.EndChangeCheck() == true)
            {
                if (settings.widthPerComponent < -1F)
                {
                    settings.widthPerComponent = -1F;
                }

                HQ.InvalidateSettings();
                if (NGHierarchyEnhancer.instance != null)
                {
                    NGHierarchyEnhancer.instance.Repaint();
                }
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_DrawUnityComponentsDescription"), GeneralStyles.WrapLabel);
            settings.drawUnityComponents = EditorGUILayout.Toggle(LC.G("NGHierarchyEnhancer_DrawUnityComponents"), settings.drawUnityComponents);
            if (EditorGUI.EndChangeCheck() == true)
            {
                HQ.InvalidateSettings();
                if (NGHierarchyEnhancer.instance != null)
                {
                    NGHierarchyEnhancer.instance.Repaint();
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_ComponentColorsDescription"), GeneralStyles.WrapLabel);

            if (reorder == null)
            {
                NGHierarchyEnhancer.colors  = new List <HierarchyEnhancerSettings.ComponentColor>(settings.componentData);
                NGHierarchyEnhancer.reorder = new ReorderableList(NGHierarchyEnhancer.colors, typeof(HierarchyEnhancerSettings.ComponentColor), true, false, true, true);
                NGHierarchyEnhancer.reorder.headerHeight         = 0F;
                NGHierarchyEnhancer.reorder.drawElementCallback += NGHierarchyEnhancer.DrawComponentType;
                NGHierarchyEnhancer.reorder.onReorderCallback   += (r) => NGHierarchyEnhancer.SerializeComponentColors();
                NGHierarchyEnhancer.reorder.onRemoveCallback    += (r) => {
                    r.list.RemoveAt(r.index);
                    NGHierarchyEnhancer.SerializeComponentColors();
                };
                NGHierarchyEnhancer.reorder.onAddCallback += (r) => {
                    colors.Add(new HierarchyEnhancerSettings.ComponentColor());
                    NGHierarchyEnhancer.SerializeComponentColors();
                };
            }

            reorder.DoLayoutList();
        }
Exemple #28
0
 private void    RefreshAllStreams()
 {
     Utility.RegisterIntervalCallback(this.DelayedRefreshStreams, 100, 1);
     HQ.InvalidateSettings();
     Utility.RepaintEditorWindow(typeof(NGConsoleWindow));
 }
        protected virtual void  OnGUI()
        {
            if (HQ.Settings == null)
            {
                GUILayout.Label(string.Format(LC.G("RequiringConfigurationFile"), NGSyncFoldersWindow.Title));
                if (GUILayout.Button(LC.G("ShowPreferencesWindow")) == true)
                {
                    Utility.ShowPreferencesWindowAt(Constants.PreferenceTitle);
                }
                return;
            }

            FreeLicenseOverlay.First(this, NGAssemblyInfo.Name + " Pro", NGSyncFoldersWindow.FreeAdContent);

            SyncFoldersSettings settings = HQ.Settings.Get <SyncFoldersSettings>();

            // Guarantee there is always one in the list.
            if (settings.syncProfiles.Count == 0)
            {
                settings.syncProfiles.Add(new Profile()
                {
                    name = "Profile 1"
                });
            }

            this.currentProfile = Mathf.Clamp(this.currentProfile, 0, settings.syncProfiles.Count - 1);
            this.profile        = settings.syncProfiles[this.currentProfile];

            Rect r = default(Rect);

            if (NGSyncFoldersWindow.cachePath == null)
            {
                NGSyncFoldersWindow.cachePath = Path.Combine(Application.persistentDataPath, Path.Combine(Constants.InternalPackageTitle, string.Format(NGSyncFoldersWindow.CachedHashedFile, this.currentProfile)));
            }

            this.slavesList.list  = this.profile.slaves;
            this.filtersList.list = this.profile.filters;

            r.width  = this.position.width;
            r.height = Constants.SingleLineHeight;
            GUI.Box(r, string.Empty, GeneralStyles.Toolbar);

            r.width = 20F;
            if (GUI.Button(r, "", GeneralStyles.ToolbarDropDown) == true)
            {
                GenericMenu menu = new GenericMenu();

                for (int i = 0; i < settings.syncProfiles.Count; i++)
                {
                    menu.AddItem(new GUIContent((i + 1) + " - " + settings.syncProfiles[i].name), i == this.currentProfile, this.SwitchProfile, i);
                }

                menu.AddSeparator("");
                menu.AddItem(new GUIContent(LC.G("Add")), false, this.AddProfile);
                menu.DropDown(r);

                GUI.FocusControl(null);
            }
            r.x += r.width + 4F;

            r.width = this.position.width - 20F - 100F - 4F;
            EditorGUI.BeginChangeCheck();
            r.y += 2F;
            string name = EditorGUI.TextField(r, this.profile.name, GeneralStyles.ToolbarTextField);

            if (EditorGUI.EndChangeCheck() == true)
            {
                Undo.RecordObject(settings, "Rename profile");
                this.profile.name = name;
                HQ.InvalidateSettings();
            }
            r.y -= 2F;
            r.x += r.width;

            r.width = 100F;
            EditorGUI.BeginDisabledGroup(settings.syncProfiles.Count <= 1);
            {
                if (GUI.Button(r, LC.G("Erase"), GeneralStyles.ToolbarButton) == true &&
                    ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 ||
                     EditorUtility.DisplayDialog(LC.G("NGSyncFolders_EraseSave"), string.Format(LC.G("NGSyncFolders_EraseSaveQuestion"), this.profile.name), LC.G("Yes"), LC.G("No")) == true))
                {
                    this.EraseProfile();
                    this.Focus();
                    return;
                }
            }
            EditorGUI.EndDisabledGroup();

            r.x     = 0F;
            r.y    += r.height + 5F;
            r.width = this.position.width;

            using (LabelWidthRestorer.Get(85F))
            {
                EditorGUI.BeginChangeCheck();
                string folderPath = NGEditorGUILayout.OpenFolderField(r, "Master Folder", this.profile.master.folderPath);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    Undo.RecordObject(settings, "Alter master path");
                    this.profile.master.folderPath = folderPath;
                    HQ.InvalidateSettings();
                }
                r.y += r.height + NGSyncFoldersWindow.Spacing;

                EditorGUI.BeginChangeCheck();
                string relativePath = NGEditorGUILayout.OpenFolderField(r, "Relative Path", this.profile.relativePath, this.profile.master.folderPath, NGEditorGUILayout.FieldButtons.Open);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    Undo.RecordObject(settings, "Alter relative path");
                    this.profile.relativePath = relativePath;
                    HQ.InvalidateSettings();
                }
                r.y += r.height + NGSyncFoldersWindow.Spacing;

                this.PreviewPath(r, this.profile.master.GetFullPath(this.profile.relativePath));
                r.y += r.height + NGSyncFoldersWindow.Spacing;

                r.height = this.slavesList.GetHeight();
                this.slavesList.DoList(r);

                if (this.showSlaves == false)
                {
                    r.y -= 16F;
                }

                r.y += r.height + NGSyncFoldersWindow.Spacing;
            }

            r.height = this.filtersList.GetHeight();
            this.filtersList.DoList(r);

            if (this.showFilters == false)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    Rect r2 = r;
                    r2.y     += r2.height - 14F;
                    r2.height = 16F;
                    r2.width  = 16F;
                    EditorGUI.DrawRect(r2, EditorGUIUtility.isProSkin == true ? new Color(55F / 255F, 55F / 255F, 55F / 255F, 1F) : new Color(162F / 255F, 162F / 255F, 162F / 255F, 1F));
                }

                r.y -= 16F;
            }

            r.y += r.height + NGSyncFoldersWindow.Spacing;

            if (string.IsNullOrEmpty(this.cacheFileSize) == true)
            {
                this.UpdateCacheFileSize();
            }

            EditorGUI.BeginChangeCheck();
            r.width -= 200F;
            r.height = 20F;
            bool useCache = EditorGUI.Toggle(r, this.cacheFileSize, this.profile.useCache);

            if (EditorGUI.EndChangeCheck() == true)
            {
                Undo.RecordObject(settings, "Toggle use cache");
                this.profile.useCache = useCache;
                HQ.InvalidateSettings();
            }

            if (this.cacheFileSize != "Use Cache")
            {
                r.x += r.width;

                r.width = 100F;
                if (GUI.Button(r, "Open", "ButtonLeft") == true)
                {
                    EditorUtility.RevealInFinder(NGSyncFoldersWindow.cachePath);
                }
                r.x += r.width;
                if (GUI.Button(r, "Clear", "ButtonRight") == true)
                {
                    System.IO.File.Delete(NGSyncFoldersWindow.cachePath);
                    this.UpdateCacheFileSize();
                }
            }
            r.y += r.height + NGSyncFoldersWindow.Spacing;

            bool hasActiveSlaves = false;

            for (int i = 0; i < this.profile.slaves.Count; i++)
            {
                if (this.profile.slaves[i].active == true)
                {
                    hasActiveSlaves = true;
                    break;
                }
            }

            EditorGUI.BeginDisabledGroup(hasActiveSlaves == false);
            {
                using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton))
                {
                    r.x      = 10F;
                    r.width  = 150F;
                    r.height = 32F;
                    if (GUI.Button(r, this.mode == ButtonMode.Scan ? "Scan" : "Scan & Watch", "Button" /*"ButtonLeft"*/) == true)
                    {
                        this.Scan();
                    }

                    //if (GUILayout.Button("☰", "ButtonRight", GUILayoutOptionPool.Height(32F), GUILayoutOptionPool.ExpandWidthFalse) == true)
                    //{
                    //	GenericMenu	menu = new GenericMenu();
                    //	menu.AddItem(new GUIContent("Scan"), this.mode == ButtonMode.Scan, () => this.mode = ButtonMode.Scan);
                    //	menu.AddItem(new GUIContent("Scan and Watch"), this.mode == ButtonMode.ScanAndWatch, () => this.mode = ButtonMode.ScanAndWatch);
                    //	menu.ShowAsContext();
                    //}
                }
            }
            EditorGUI.EndDisabledGroup();

            if (this.profile.master.IsScanned == true)
            {
                using (BgColorContentRestorer.Get(GeneralStyles.HighlightResultButton))
                {
                    r.x = this.position.width - r.width - 10F;
                    if (GUI.Button(r, "Sync All", "Button") == true)
                    {
                        this.SyncAll();
                    }
                    r.y += r.height + NGSyncFoldersWindow.Spacing;
                }
            }

            //if (this.mode == ButtonMode.ScanAndWatch)
            //	EditorGUILayout.HelpBox("Scan and Watch may induce huge freeze after a compilation when watching a lot of files. This mode is not recommended for programmers.", MessageType.Warning);

            if (this.profile.master.IsScanned == true)
            {
                r.x     = 0F;
                r.width = this.position.width;

                Rect bodyRect = r;
                bodyRect.height = this.position.height - r.y;

                Rect viewRect = new Rect {
                    height = this.profile.master.GetHeight()
                };

                for (int i = 0; i < this.profile.slaves.Count; i++)
                {
                    if (this.profile.slaves[i].active == true)
                    {
                        viewRect.height += this.profile.slaves[i].GetHeight(this.profile.master);
                    }
                }

                this.scrollPositionScan = GUI.BeginScrollView(bodyRect, this.scrollPositionScan, viewRect);
                {
                    r.y      = 0F;
                    r.height = this.profile.master.GetHeight();

                    if (viewRect.height > r.height)
                    {
                        r.width -= 15F;
                    }

                    if (r.yMax > this.scrollPositionScan.y)
                    {
                        this.profile.master.OnGUI(r, 0, this.scrollPositionScan.y, this.scrollPositionScan.y + bodyRect.height);
                    }

                    r.y += r.height;

                    for (int i = 0; i < this.profile.slaves.Count; i++)
                    {
                        if (this.profile.slaves[i].active == false)
                        {
                            continue;
                        }

                        r.height = this.profile.slaves[i].GetHeight(this.profile.master);

                        if (r.yMax > this.scrollPositionScan.y)
                        {
                            this.profile.slaves[i].OnGUI(r, i + 1, this.scrollPositionScan.y, this.scrollPositionScan.y + bodyRect.height, this.profile.master);
                        }

                        r.y += r.height;

                        if (r.y - this.scrollPositionScan.y > bodyRect.height)
                        {
                            break;
                        }
                    }
                }
                GUI.EndScrollView();
            }

            FreeLicenseOverlay.Last(NGAssemblyInfo.Name + " Pro");
        }