示例#1
0
        public static void DrawFontAssetProperties(ThemeData themeData, int propertyIndex,
                                                   SerializedObject serializedObject, Object[] targets, ThemeTarget target,
                                                   ColorName componentColorName, Color initialGUIColor)
        {
            GUIStyle buttonStyleDisabled = Styles.GetStyle(Styles.StyleName.CheckBoxDisabled);
            GUIStyle buttonStyleEnabled  = Styles.GetStyle(Styles.StyleName.CheckBoxEnabled);

#if dUI_TextMeshPro
            if (themeData.FontAssetLabels.Count != themeData.ActiveVariant.FontAssets.Count)
            {
                foreach (LabelId labelId in themeData.FontAssetLabels.Where(labelId => !themeData.ActiveVariant.ContainsFontAsset(labelId.Id)))
                {
                    themeData.ActiveVariant.AddFontAssetProperty(labelId.Id);
                }
            }
#endif

            for (int i = 0; i < themeData.FontAssetLabels.Count; i++)
            {
                LabelId fontAssetProperty = themeData.FontAssetLabels[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 = (ThemeTarget)o;
                                if (themeTarget == null)
                                {
                                    continue;
                                }
                                themeTarget.PropertyId = themeData.FontAssetLabels[index].Id;
                                themeTarget.UpdateTarget(themeData);
                            }
                        }
                        else
                        {
                            DoozyUtils.UndoRecordObject(target, UILabels.UpdateValue);
                            target.PropertyId = themeData.FontAssetLabels[index].Id;
                            target.UpdateTarget(themeData);
                        }
                    }

                    GUI.color = initialGUIColor;
                    GUILayout.Space(DGUI.Properties.Space(2));
                    GUI.enabled = selected;
                    DGUI.Label.Draw(fontAssetProperty.Label, selected ? Size.L : Size.M);
                    GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(DGUI.Properties.Space());
            }
        }
示例#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
        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());
            }
        }