Example #1
0
        /// <summary>
        /// Vector2 field with reset button.
        /// </summary>
        public static Vector2 Vector2WithReset(string label, string tooltip, Vector2 value, Vector2 defaultValue)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(new GUIContent(label, tooltip));

                float oldLabelWidth = EditorGUIUtility.labelWidth;

                EditorGUIUtility.labelWidth = 20.0f;

                value.x = EditorGUILayout.FloatField("X", value.x);

                value.y = EditorGUILayout.FloatField("Y", value.y);

                EditorGUIUtility.labelWidth = oldLabelWidth;

                if (SpriteColorFXEditorHelper.ButtonImage(string.Empty, string.Format("Reset to '{0}'", defaultValue), @"Icons/ic_cached") == true)
                {
                    value = defaultValue;
                }
            }
            EditorGUILayout.EndHorizontal();

            return(value);
        }
Example #2
0
        /// <summary>
        /// A slider with a reset button.
        /// </summary>
        public static int IntSliderWithReset(string label, string tooltip, int value, int minValue, int maxValue, int defaultValue)
        {
            EditorGUILayout.BeginHorizontal();
            {
                value = EditorGUILayout.IntSlider(new GUIContent(label, tooltip), value, minValue, maxValue);

                if (SpriteColorFXEditorHelper.ButtonImage(string.Empty, string.Format("Reset to '{0}'", defaultValue), @"Icons/ic_cached") == true)
                {
                    value = defaultValue;
                }
            }
            EditorGUILayout.EndHorizontal();

            return(value);
        }
Example #3
0
        /// <summary>
        /// Toogle with a reset button.
        /// </summary>
        public static bool ToogleWithReset(string label, string tooltip, bool value, bool defaultValue)
        {
            EditorGUILayout.BeginHorizontal();
            {
                value = EditorGUILayout.Toggle(new GUIContent(label, tooltip), value);

                if (SpriteColorFXEditorHelper.ButtonImage(string.Empty, string.Format("Reset to '{0}.'", defaultValue), @"Icons/ic_cached") == true)
                {
                    value = defaultValue;
                }
            }
            EditorGUILayout.EndHorizontal();

            return(value);
        }
Example #4
0
        /// <summary>
        /// A slider with a reset button.
        /// </summary>
        public static void MinMaxSliderWithReset(string label, string tooltip, ref float min, ref float max, float minLimit, float maxLimit, float defaultMinValue, float defaultMaxValue)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.MinMaxSlider(new GUIContent(label, tooltip), ref min, ref max, minLimit, maxLimit);

                EditorGUILayout.LabelField(string.Format("{0:0.00}-{1:0.00}", min, max), GUI.skin.textField, GUILayout.Width(60.0f));

                if (SpriteColorFXEditorHelper.ButtonImage(string.Empty, string.Format("Reset to ({0}..{1}).", defaultMinValue, defaultMaxValue), @"Icons/ic_cached") == true)
                {
                    min = defaultMinValue;
                    max = defaultMaxValue;
                }
            }
            EditorGUILayout.EndHorizontal();
        }
Example #5
0
        /// <summary>
        /// Vector2 field with reset button.
        /// </summary>
        public static Color ColorWithReset(string label, string tooltip, Color value, Color defaultValue)
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(new GUIContent(label, tooltip));

                value = EditorGUILayout.ColorField(value);

                if (SpriteColorFXEditorHelper.ButtonImage(string.Empty, string.Format("Reset to '{0}'", defaultValue), @"Icons/ic_cached") == true)
                {
                    value = defaultValue;
                }
            }
            EditorGUILayout.EndHorizontal();

            return(value);
        }
Example #6
0
        private void OnGUI()
        {
            EditorGUIUtility.LookLikeControls();

            EditorGUILayout.BeginVertical();
            {
                EditorGUIUtility.LookLikeControls(24.0f, 50.0f);

                // Colors
                EditorGUILayout.BeginVertical(GUI.skin.box);
                {
                    if (presets.Count > 0)
                    {
                        scroll = EditorGUILayout.BeginScrollView(scroll, GUI.skin.box);

                        int presetToDelete = -1;
                        int moveUp         = -1;
                        int moveDown       = -1;
                        int insertUp       = -1;

                        for (int i = 0; i < presets.Count; ++i)
                        {
                            GUI.backgroundColor = (i % 2 == 0) ? Color.white * 0.1f : Color.white * 0.2f;

                            EditorGUILayout.BeginHorizontal(SpriteColorFXEditorHelper.StyleScrollRow);
                            {
                                GUI.backgroundColor = Color.white;

                                EditorGUILayout.LabelField((i + 1).ToString("0000"), GUILayout.Width(32.0f));

                                EditorGUILayout.Space();

                                string newName = EditorGUILayout.TextField(presets[i].name, GUILayout.MinWidth(128.0f));
                                if (newName != presets[i].name)
                                {
                                    presets[i].name = newName;

                                    assetChanged = true;
                                }

                                EditorGUILayout.Space();

                                for (int j = 0; j < presets[i].colors.Length; ++j)
                                {
                                    Color newColor = EditorGUILayout.ColorField("#" + (j + 1), presets[i].colors[j]);
                                    if (newColor != presets[i].colors[j])
                                    {
                                        presets[i].colors[j] = newColor;

                                        assetChanged = true;
                                    }

                                    GUILayout.Space(5.0f);
                                }

                                EditorGUILayout.Space();

                                if (SpriteColorFXEditorHelper.ButtonImage(string.Empty, SpriteColorFXEditorHelper.TooltipInsertPallete, @"Icons/ic_playlist_add") == true)
                                {
                                    insertUp = i;
                                }

                                EditorGUILayout.Space();

                                if (SpriteColorFXEditorHelper.ButtonImage(string.Empty, SpriteColorFXEditorHelper.TooltipMoveUp, @"Icons/ic_keyboard_arrow_up") == true)
                                {
                                    moveUp = i;
                                }

                                if (SpriteColorFXEditorHelper.ButtonImage(string.Empty, SpriteColorFXEditorHelper.TooltipMoveDown, @"Icons/ic_keyboard_arrow_down") == true)
                                {
                                    moveDown = i;
                                }

                                EditorGUILayout.Space();

                                if (SpriteColorFXEditorHelper.ButtonImage(string.Empty, SpriteColorFXEditorHelper.TooltipRemove, @"Icons/ic_clear") == true)
                                {
                                    presetToDelete = i;
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }

                        if (presetToDelete != -1)
                        {
                            assetChanged = true;

                            presets.RemoveAt(presetToDelete);
                        }

                        if (insertUp != -1)
                        {
                            assetChanged = true;

                            presets.Insert(insertUp, new SpriteColorRampPreset.ColorPreset());
                        }

                        if (moveUp > 0)
                        {
                            assetChanged = true;

                            SpriteColorRampPreset.ColorPreset colorPreset = presets[moveUp];

                            presets.RemoveAt(moveUp);
                            presets.Insert(moveUp - 1, colorPreset);
                        }

                        if (moveDown != -1 && moveDown < (presets.Count - 1))
                        {
                            assetChanged = true;

                            SpriteColorRampPreset.ColorPreset colorPreset = presets[moveDown];

                            presets.RemoveAt(moveDown);
                            presets.Insert(moveDown + 1, colorPreset);
                        }

                        EditorGUILayout.EndScrollView();
                    }

                    GUILayout.FlexibleSpace();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (string.IsNullOrEmpty(assetFile) == true)
                        {
                            EditorGUILayout.Space();
                        }
                        else
                        {
                            if (assetChanged == true)
                            {
                                EditorGUILayout.LabelField(string.Format("*'{0}'*", assetFile));
                            }
                            else
                            {
                                GUI.enabled = false;

                                EditorGUILayout.LabelField(string.Format("'{0}'", assetFile));

                                GUI.enabled = true;
                            }
                        }

/* Planned for upcoming updates.
 *          if (GUILayout.Button("Adobe Color CC") == true)
 *            AddPaletteFromAdobeColorCC();
 */

/* Planned for upcoming updates.
 *          if (GUILayout.Button("COLOURlovers") == true)
 *            AddPaletteFromCOLOURlovers();
 */

/* Planned for upcoming updates.
 *          if (GUILayout.Button("Add pallete from image") == true)
 *            AddPaletteFromImage();
 */
                        if (GUILayout.Button(@"Add pallete", GUILayout.Width(75.0f)) == true)
                        {
                            presets.Add(new SpriteColorRampPreset.ColorPreset());

                            assetChanged = true;
                        }

                        if (GUILayout.Button(@"Clear all", GUILayout.Width(75.0f)) == true && presets.Count > 0)
                        {
                            if (EditorUtility.DisplayDialog(@"Clear all palletes.", @"Delete all palettes?", @"Ok", @"Cancel") == true)
                            {
                                presets.Clear();

                                assetChanged = true;
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();

                EditorGUIUtility.LookLikeControls(128.0f, 50.0f);

                // Buttons
                EditorGUILayout.BeginHorizontal(GUI.skin.box);
                {
                    EditorGUILayout.BeginVertical();
                    {
                        bool option = EditorGUILayout.Toggle(new GUIContent(@"Interpolate colors", SpriteColorFXEditorHelper.TooltipInterpolateColors), interpolateColors);
                        if (option != interpolateColors)
                        {
                            interpolateColors = option;

                            assetChanged = true;
                        }

                        option = EditorGUILayout.Toggle(new GUIContent(@"Sort by luminance", SpriteColorFXEditorHelper.TooltipSortByLuminance), sortColorsByLuminance);
                        if (option != sortColorsByLuminance)
                        {
                            sortColorsByLuminance = option;

                            assetChanged = true;
                        }
                    }
                    EditorGUILayout.EndVertical();

                    GUILayout.FlexibleSpace();

                    EditorGUILayout.BeginVertical();
                    {
                        if (GUILayout.Button("Load", GUILayout.Width(75.0f)) == true)
                        {
                            string filePath = EditorUtility.OpenFilePanel(@"Load asset", Application.dataPath + "/" + Path.GetDirectoryName(assetFile), "asset");
                            if (string.IsNullOrEmpty(filePath) == false)
                            {
                                LoadAsset(filePath);
                            }
                        }

                        if (GUILayout.Button("Save", GUILayout.Width(75.0f)) == true)
                        {
                            string filePath = EditorUtility.SaveFilePanel(@"Save asset", Application.dataPath + "/" + Path.GetDirectoryName(assetFile), Path.GetFileNameWithoutExtension(assetFile), "asset");
                            if (string.IsNullOrEmpty(filePath) == false)
                            {
                                SaveAsset(filePath);
                            }
                        }
                    }
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button(new GUIContent(@"Apply", SpriteColorFXEditorHelper.TooltipApply), GUILayout.ExpandHeight(true), GUILayout.Width(75.0f)) == true)
                        {
                            Process();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
        }