/// <summary> Records any changes done on the object after this function </summary>
 /// <param name="undoMessage"> The title of the action to appear in the undo history (i.e. visible in the undo menu) </param>
 public void UndoRecord(string undoMessage)
 {
     DoozyUtils.UndoRecordObject(this, undoMessage);
 }
示例#2
0
        public static void DrawThemePopup(ThemesDatabase database, ThemeData themeData, string[] themeNames, int themeIndex,
                                          ColorName componentColorName, SerializedObject serializedObject, Object[] targets, ThemeTarget target, Color initialGUIColor,
                                          Action updateIds, Action updateLists)
        {
            GUILayout.BeginHorizontal();
            {
                DGUI.Line.Draw(false, componentColorName, true,
                               () =>
                {
                    GUILayout.Space(DGUI.Properties.Space(2));
                    DGUI.Label.Draw(UILabels.SelectedTheme, Size.S, componentColorName, DGUI.Properties.SingleLineHeight);
                    GUILayout.Space(DGUI.Properties.Space());
                    GUILayout.BeginVertical(GUILayout.Height(DGUI.Properties.SingleLineHeight));
                    {
                        GUILayout.Space(0);
                        GUI.color = DGUI.Colors.PropertyColor(componentColorName);
                        EditorGUI.BeginChangeCheck();
                        themeIndex = EditorGUILayout.Popup(GUIContent.none, themeIndex, themeNames);
                        GUI.color  = initialGUIColor;
                    }
                    GUILayout.EndVertical();
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (serializedObject.isEditingMultipleObjects)
                        {
                            DoozyUtils.UndoRecordObjects(targets, UILabels.UpdateValue);
                            themeData = database.Themes[themeIndex];
                            foreach (Object o in targets)
                            {
                                var themeTarget = (ThemeTarget)o;
                                if (themeTarget == null)
                                {
                                    continue;
                                }
                                themeTarget.ThemeId = themeData.Id;
                            }

                            updateIds.Invoke();
                            updateLists.Invoke();

                            foreach (Object o in targets)
                            {
                                var themeTarget = (ThemeTarget)o;
                                if (themeTarget == null)
                                {
                                    continue;
                                }

                                if (!themeData.ContainsColorProperty(themeTarget.PropertyId))
                                {
                                    themeTarget.PropertyId = themeData.ColorLabels.Count > 0
                                                                                ? themeData.ColorLabels[0].Id
                                                                                : Guid.Empty;
                                }

                                themeTarget.UpdateTarget(themeData);
                            }
                        }
                        else
                        {
                            DoozyUtils.UndoRecordObject(target, UILabels.UpdateValue);
                            themeData      = database.Themes[themeIndex];
                            target.ThemeId = themeData.Id;
                            updateIds.Invoke();
                            updateLists.Invoke();
                            target.UpdateTarget(themeData);
                        }
                    }
                });

                GUILayout.Space(DGUI.Properties.Space());

                ThemeTargetEditorUtils.DrawButtonTheme(themeData, componentColorName);
            }
            GUILayout.EndHorizontal();
        }
示例#3
0
        private void DrawColorProperties(ThemeData themeData, int propertyIndex, SelectionState selectionState)
        {
            GUIStyle colorButtonStyle         = Styles.GetStyle(Styles.StyleName.ColorButton);
            GUIStyle colorButtonSelectedStyle = Styles.GetStyle(Styles.StyleName.ColorButtonSelected);

            if (themeData.ColorLabels.Count != themeData.ActiveVariant.Colors.Count)
            {
                foreach (LabelId labelId in themeData.ColorLabels.Where(labelId => !themeData.ActiveVariant.ContainsColor(labelId.Id)))
                {
                    themeData.ActiveVariant.AddColorProperty(labelId.Id);
                }
            }

            for (int i = 0; i < themeData.ColorLabels.Count; i++)
            {
                LabelId colorProperty = themeData.ColorLabels[i];
                int     index         = i;
                bool    selected      = i == propertyIndex;
                GUILayout.BeginHorizontal();
                {
                    if (!selected)
                    {
                        GUILayout.Space((colorButtonSelectedStyle.fixedWidth - colorButtonStyle.fixedWidth) / 2);
                    }
                    GUI.color = themeData.ActiveVariant.Colors[i].Color;
                    {
                        if (GUILayout.Button(GUIContent.none, selected ? colorButtonSelectedStyle : colorButtonStyle))
                        {
                            if (serializedObject.isEditingMultipleObjects)
                            {
                                DoozyUtils.UndoRecordObjects(targets, UILabels.UpdateValue);
                                foreach (Object o in targets)
                                {
                                    var themeTarget = (ColorTargetSelectable)o;
                                    if (themeTarget == null)
                                    {
                                        continue;
                                    }
                                    switch (selectionState)
                                    {
                                    case SelectionState.Normal:
                                        themeTarget.NormalColorPropertyId = themeData.ColorLabels[index].Id;
                                        break;

                                    case SelectionState.Highlighted:
                                        themeTarget.HighlightedColorPropertyId = themeData.ColorLabels[index].Id;
                                        break;

                                    case SelectionState.Pressed:
                                        themeTarget.PressedColorPropertyId = themeData.ColorLabels[index].Id;
                                        break;

#if UNITY_2019_1_OR_NEWER
                                    case SelectionState.Selected:
                                        themeTarget.SelectedColorPropertyId = themeData.ColorLabels[index].Id;
                                        break;
#endif
                                    case SelectionState.Disabled:
                                        themeTarget.DisabledColorPropertyId = themeData.ColorLabels[index].Id;
                                        break;
                                    }

                                    themeTarget.UpdateTarget(themeData);
                                }
                            }
                            else
                            {
                                DoozyUtils.UndoRecordObject(target, UILabels.UpdateValue);
                                switch (selectionState)
                                {
                                case SelectionState.Normal:
                                    Target.NormalColorPropertyId = themeData.ColorLabels[index].Id;
                                    break;

                                case SelectionState.Highlighted:
                                    Target.HighlightedColorPropertyId = themeData.ColorLabels[index].Id;
                                    break;

                                case SelectionState.Pressed:
                                    Target.PressedColorPropertyId = themeData.ColorLabels[index].Id;
                                    break;

#if UNITY_2019_1_OR_NEWER
                                case SelectionState.Selected:
                                    Target.SelectedColorPropertyId = themeData.ColorLabels[index].Id;
                                    break;
#endif
                                case SelectionState.Disabled:
                                    Target.DisabledColorPropertyId = themeData.ColorLabels[index].Id;
                                    break;
                                }

                                Target.UpdateTarget(themeData);
                            }
                        }
                    }
                    GUI.color = InitialGUIColor;
                    GUILayout.Space(DGUI.Properties.Space(2));
                    GUI.enabled = selected;
                    DGUI.Label.Draw(colorProperty.Label, selected ? Size.L : Size.M,
                                    selected ? colorButtonSelectedStyle.fixedHeight : colorButtonStyle.fixedHeight);
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(DGUI.Properties.Space());
            }
        }
示例#4
0
        public static void DrawColorProperties(ThemeData themeData, int propertyIndex,
                                               SerializedObject serializedObject, Object[] targets, ThemeTarget target,
                                               Color initialGUIColor)
        {
            GUIStyle colorButtonStyle         = Styles.GetStyle(Styles.StyleName.ColorButton);
            GUIStyle colorButtonSelectedStyle = Styles.GetStyle(Styles.StyleName.ColorButtonSelected);

            if (themeData.ColorLabels.Count != themeData.ActiveVariant.Colors.Count)
            {
                foreach (LabelId labelId in themeData.ColorLabels.Where(labelId => !themeData.ActiveVariant.ContainsColor(labelId.Id)))
                {
                    themeData.ActiveVariant.AddColorProperty(labelId.Id);
                }
            }

            for (int i = 0; i < themeData.ColorLabels.Count; i++)
            {
                LabelId colorProperty = themeData.ColorLabels[i];
                int     index         = i;
                bool    selected      = i == propertyIndex;
                GUILayout.BeginHorizontal();
                {
                    if (!selected)
                    {
                        GUILayout.Space((colorButtonSelectedStyle.fixedWidth - colorButtonStyle.fixedWidth) / 2);
                    }
                    GUI.color = themeData.ActiveVariant.Colors[i].Color;
                    {
                        if (GUILayout.Button(GUIContent.none, selected ? colorButtonSelectedStyle : colorButtonStyle))
                        {
                            if (serializedObject.isEditingMultipleObjects)
                            {
                                DoozyUtils.UndoRecordObjects(targets, UILabels.UpdateValue);
                                foreach (Object o in targets)
                                {
                                    var themeTarget = (ThemeTarget)o;
                                    if (themeTarget == null)
                                    {
                                        continue;
                                    }
                                    themeTarget.PropertyId = themeData.ColorLabels[index].Id;
                                    themeTarget.UpdateTarget(themeData);
                                }
                            }
                            else
                            {
                                DoozyUtils.UndoRecordObject(target, UILabels.UpdateValue);
                                target.PropertyId = themeData.ColorLabels[index].Id;
                                target.UpdateTarget(themeData);
                            }
                        }
                    }
                    GUI.color = initialGUIColor;
                    GUILayout.Space(DGUI.Properties.Space(2));
                    GUI.enabled = selected;
                    DGUI.Label.Draw(colorProperty.Label, selected ? Size.L : Size.M, selected ? colorButtonSelectedStyle.fixedHeight : colorButtonStyle.fixedHeight);
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(DGUI.Properties.Space());
            }
        }
        private void DrawSpriteProperties(ThemeData themeData, int propertyIndex, ThemeTargetEditorUtils.SelectionState selectionState)
        {
            GUIStyle buttonStyleDisabled = Styles.GetStyle(Styles.StyleName.CheckBoxDisabled);
            GUIStyle buttonStyleEnabled  = Styles.GetStyle(Styles.StyleName.CheckBoxEnabled);

            for (var i = 0; i < themeData.SpriteLabels.Count; i++)
            {
                LabelId spriteProperty = themeData.SpriteLabels[i];
                int     index          = i;
                bool    selected       = i == propertyIndex;
                GUILayout.BeginHorizontal();
                {
                    GUI.color = DGUI.Colors.PropertyColor(ComponentColorName);
                    if (GUILayout.Button(GUIContent.none, selected ? buttonStyleEnabled : buttonStyleDisabled))
                    {
                        if (serializedObject.isEditingMultipleObjects)
                        {
                            DoozyUtils.UndoRecordObjects(targets, UILabels.UpdateValue);
                            foreach (Object o in targets)
                            {
                                var themeTarget = (SpriteTargetSelectable)o;
                                if (themeTarget == null)
                                {
                                    continue;
                                }
                                switch (selectionState)
                                {
                                case ThemeTargetEditorUtils.SelectionState.Highlighted:
                                    themeTarget.HighlightedSpritePropertyId = themeData.SpriteLabels[index].Id;
                                    break;

                                case ThemeTargetEditorUtils.SelectionState.Pressed:
                                    themeTarget.PressedSpritePropertyId = themeData.SpriteLabels[index].Id;
                                    break;

#if UNITY_2019_3_OR_NEWER
                                case ThemeTargetEditorUtils.SelectionState.Selected:
                                    themeTarget.SelectedSpritePropertyId = themeData.SpriteLabels[index].Id;
                                    break;
#endif
                                case ThemeTargetEditorUtils.SelectionState.Disabled:
                                    themeTarget.DisabledSpritePropertyId = themeData.SpriteLabels[index].Id;
                                    break;
                                }

                                themeTarget.UpdateTarget(themeData);
                            }
                        }
                        else
                        {
                            DoozyUtils.UndoRecordObject(target, UILabels.UpdateValue);
                            switch (selectionState)
                            {
                            case ThemeTargetEditorUtils.SelectionState.Highlighted:
                                Target.HighlightedSpritePropertyId = themeData.SpriteLabels[index].Id;
                                break;

                            case ThemeTargetEditorUtils.SelectionState.Pressed:
                                Target.PressedSpritePropertyId = themeData.SpriteLabels[index].Id;
                                break;

#if UNITY_2019_3_OR_NEWER
                            case ThemeTargetEditorUtils.SelectionState.Selected:
                                Target.SelectedSpritePropertyId = themeData.SpriteLabels[index].Id;
                                break;
#endif
                            case ThemeTargetEditorUtils.SelectionState.Disabled:
                                Target.DisabledSpritePropertyId = themeData.SpriteLabels[index].Id;
                                break;
                            }

                            Target.UpdateTarget(themeData);
                        }
                    }

                    GUI.color = InitialGUIColor;
                    GUILayout.Space(DGUI.Properties.Space(2));
                    GUI.enabled = selected;
                    DGUI.Label.Draw(spriteProperty.Label, selected ? Size.L : Size.M);
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(DGUI.Properties.Space());
            }
        }