Exemplo n.º 1
0
        static void NamedGeneratorButton(ChiselPlacementToolInstance generator, Rect togglePosition, GUIStyle style, bool isActive)
        {
            var temp = togglePosition;

            temp.xMin += 5;
            temp.width = 20;
            {
                EditorGUI.BeginChangeCheck();
                var value = GUI.Toggle(temp, generator.InToolBox, GUIContent.none);
                if (EditorGUI.EndChangeCheck())
                {
                    SetInToolBox(generator, value);
                }
            }
            temp       = togglePosition;
            temp.xMin += 25;
            {
                EditorGUI.BeginChangeCheck();
                var content    = ChiselEditorResources.GetIconContentWithName(generator.ToolName, generator.ToolName)[0];
                var isSelected = ChiselGeneratorManager.GeneratorMode == generator;
                var value      = ToggleButton(temp, content, isSelected, style, isActive);
                if (EditorGUI.EndChangeCheck() && value)
                {
                    // TODO: make undoable
                    generator.InToolBox = true;
                    ChiselPlacementTool.ActivateTool();
                    ChiselGeneratorManager.GeneratorMode = generator;
                    ChiselEditorSettings.Save();
                    SceneView.RepaintAll();
                }
            }
        }
        static void DisplayControls(SceneView sceneView)
        {
            InitStyles();
            EditorGUI.BeginChangeCheck();
            {
                var enabled = HaveNodesInSelection();

                var values = editModes.Values;
                if (values.Count > 0)
                {
                    using (new EditorGUI.DisabledScope(!enabled))
                    {
                        var style     = styles.toggleStyleMid;
                        var groupRect = EditorGUILayout.GetControlRect(false, style.fixedHeight + style.margin.vertical, ChiselOverlay.kMinWidthLayout);
                        groupRect.xMin -= 3;
                        groupRect.yMin += 3;

                        var startX     = style.margin.left + groupRect.x + 4;
                        var buttonStep = style.fixedWidth + style.margin.left;
                        var position   = new Rect(startX, groupRect.y, style.fixedWidth, style.fixedHeight);

                        int xPos  = 0;
                        var count = values.Count;
                        var index = 0;
                        for (int i = 0; i < count; i++)
                        {
                            var editMode    = values[i];
                            var toggleStyle = (index == 0)                ? styles.toggleStyleLeft :
                                              (index == count - 1) && (count < 7) ? styles.toggleStyleRight :
                                              styles.toggleStyleMid;
                            position.x = startX + (xPos * buttonStep);
                            EditModeButton(position, enabled, editMode, toggleStyle);
                            index++;
                            xPos++;
                        }

                        // TODO: assign hotkey to rebuild, and possibly move it elsewhere to avoid it seemingly like a necessary action.

                        xPos       = 7;
                        position.x = startX + (xPos * buttonStep);
                        var buttonStyle = (index == 7) ? styles.toggleStyleRight :
                                          styles.toggleStyle;
                        if (kRebuildButton == null)
                        {
                            kRebuildButton = ChiselEditorResources.GetIconContent(kRebuildIconName, kRebuildTooltip)[0];
                        }
                        if (GUI.Toggle(position, false, kRebuildButton, buttonStyle))
                        {
                            Rebuild();
                        }
                    }
                }

                ChiselPlacementToolsSelectionWindow.RenderCreationTools();
            }
            if (EditorGUI.EndChangeCheck())
            {
                ChiselEditorSettings.Save();
            }
        }
Exemplo n.º 3
0
        static bool Toggle(Rect togglePosition, ChiselEditModeManager.ChiselEditModeItem editMode)
        {
            var content  = ChiselEditorResources.GetIconContent(editMode.instance.ToolName, editMode.instance.ToolName);
            var selected = ChiselEditModeManager.EditMode == editMode.instance;

            return(GUI.Toggle(togglePosition, selected, content[0], GUI.skin.button));
        }
Exemplo n.º 4
0
        public static GUIContent[] GetIconContent(CSGOperationType operation, string name)
        {
            int typeIndex = (int)operation;

            if (typeIndex < 0 || typeIndex > s_NamesWithOperations.Length)
            {
                typeIndex = 0;
            }
            return(ChiselEditorResources.GetIconContent(s_OperationIcons[typeIndex], GetOperationName(typeIndex, name)));
        }
Exemplo n.º 5
0
        public static Texture2D[] GetIcons(CSGOperationType operation, string name)
        {
            int typeIndex = (int)operation;

            if (typeIndex < 0 || typeIndex > s_NamesWithOperations.Length)
            {
                typeIndex = 0;
            }
            return(ChiselEditorResources.LoadIconImages(s_OperationIcons[typeIndex]));
        }
        public static void SetupToolbarElement(EditorToolbarButton element, string iconName, string tooltipName)
        {
            element.text = string.Empty;
            var icons = ChiselEditorResources.LoadIconImages(iconName);

            if (icons != null && icons[0] != null)
            {
                element.icon = icons[0];
            }
            element.tooltip = tooltipName;
        }
Exemplo n.º 7
0
        public static void SetupToolbarElement(EditorToolbarToggle element, string iconName, string tooltipName)
        {
            element.text = tooltipName;
            var icons = ChiselEditorResources.LoadIconImages(iconName);

            if (icons != null && icons[0] != null && icons[1] != null)
            {
                element.onIcon  = icons[0];
                element.offIcon = icons[1];
            }
            element.tooltip = tooltipName;
        }
Exemplo n.º 8
0
        public override GUIContent GetHierarchyIcon(T node)
        {
            switch (node.Operation)
            {
            default:
            case CSGOperationType.Additive:     return(ChiselEditorResources.GetIconContent(AdditiveIconName, $"Additive {node.NodeTypeName}")[0]);

            case CSGOperationType.Subtractive:  return(ChiselEditorResources.GetIconContent(SubtractiveIconName, $"Subtractive {node.NodeTypeName}")[0]);

            case CSGOperationType.Intersecting: return(ChiselEditorResources.GetIconContent(IntersectingIconName, $"Intersecting {node.NodeTypeName}")[0]);
            }
        }
Exemplo n.º 9
0
        public static GUIContent[] GetIconContent(CSGOperationType operation, string name)
        {
            switch (operation)
            {
            default:
            case CSGOperationType.Additive:     return(ChiselEditorResources.GetIconContent(kAdditiveIconName, $"{nameof(CSGOperationType.Additive)} {name}"));

            case CSGOperationType.Subtractive:  return(ChiselEditorResources.GetIconContent(kSubtractiveIconName, $"{nameof(CSGOperationType.Subtractive)} {name}"));

            case CSGOperationType.Intersecting: return(ChiselEditorResources.GetIconContent(kIntersectingIconName, $"{nameof(CSGOperationType.Intersecting)} {name}"));
            }
        }
Exemplo n.º 10
0
        public static CSGOperationType?ShowOperationChoicesInternal(Rect rect, CSGOperationType?operation, bool showAuto = true)
        {
            if (styles == null)
            {
                styles = new Styles();
            }

            var additiveIcon     = ChiselDefaultGeneratorDetails.GetIconContent(CSGOperationType.Additive, "Boolean Operation");
            var subtractiveIcon  = ChiselDefaultGeneratorDetails.GetIconContent(CSGOperationType.Subtractive, "Boolean Operation");
            var intersectingIcon = ChiselDefaultGeneratorDetails.GetIconContent(CSGOperationType.Intersecting, "Boolean Operation");

            using (new EditorGUIUtility.IconSizeScope(new Vector2(16, 16)))     // This ensures that the icons will be the same size on regular displays and HDPI displays
                                                                                // Note that the loaded images are different sizes on different displays
            {
                Rect toggleRect = rect;
                toggleRect.xMin = toggleRect.xMax - GetOperationChoicesInternalWidth(showAuto);

                if (showAuto)
                {
                    toggleRect.width = kAutomaticToggleWidth;
                    var autoIcon = ChiselEditorResources.GetIconContent(kAutoIconName, $"Automatic boolean operation");
                    if (ToggleLabel(ref toggleRect, !operation.HasValue, autoIcon, styles.leftButton))
                    {
                        return(null);
                    }
                    toggleRect.width = kOperationToggleWidth;
                }
                else
                {
                    toggleRect.width = kOperationToggleWidth + kLeftStylePadding;
                }

                var operationType = !operation.HasValue ? ((CSGOperationType)255) : (operation.Value);
                if (Toggle(ref toggleRect, (operationType == CSGOperationType.Additive), additiveIcon, showAuto ? styles.midButton : styles.leftButton))
                {
                    return(CSGOperationType.Additive);
                }
                if (!showAuto)
                {
                    toggleRect.width -= kLeftStylePadding;
                }
                if (Toggle(ref toggleRect, (operationType == CSGOperationType.Subtractive), subtractiveIcon, styles.midButton))
                {
                    return(CSGOperationType.Subtractive);
                }
                if (Toggle(ref toggleRect, (operationType == CSGOperationType.Intersecting), intersectingIcon, styles.rightButton))
                {
                    return(CSGOperationType.Intersecting);
                }
                return(operationType);
            }
        }
Exemplo n.º 11
0
            public Styles()
            {
                smallToggleStyle = new GUIStyle("AppCommand")
                {
                    padding     = new RectOffset(kButtonPadding + kButtonMargin, kButtonPadding, 0, 0),
                    margin      = new RectOffset(0, 8, kButtonMargin + 1, 0),
                    fixedWidth  = kButtonSize + kButtonMargin,
                    fixedHeight = 20
                };

                boundsSnapIcons  = ChiselEditorResources.GetIconContent("BoundsSnap", "Snap bounds against grid");
                pivotSnapIcons   = ChiselEditorResources.GetIconContent("PivotSnap", "Snap pivots against grid");
                edgeSnapIcons    = ChiselEditorResources.GetIconContent("EdgeSnap", "Snap against edges");
                vertexSnapIcons  = ChiselEditorResources.GetIconContent("VertexSnap", "Snap against vertices");
                surfaceSnapIcons = ChiselEditorResources.GetIconContent("SurfaceSnap", "Snap against surfaces");

                uvGridSnapIcons   = ChiselEditorResources.GetIconContent("UVGridSnap", "Snap UV against grid");
                uvEdgeSnapIcons   = ChiselEditorResources.GetIconContent("UVEdgeSnap", "Snap UV against surface edges");
                uvVertexSnapIcons = ChiselEditorResources.GetIconContent("UVVertexSnap", "Snap UV against surface vertices");

                translateIcons = ChiselEditorResources.GetIconContent("moveTool", "Enable/Disable move snapping");
                rotateIcons    = ChiselEditorResources.GetIconContent("rotateTool", "Enable/Disable rotate snapping");
                scaleIcons     = ChiselEditorResources.GetIconContent("scaleTool", "Enable/Disable scale snapping");

                var plusIcons  = ChiselEditorResources.LoadIconImages("ol_plus");
                var minusIcons = ChiselEditorResources.LoadIconImages("ol_minus");


                plus                      = new GUIStyle();
                plus.margin               = new RectOffset(0, 0, 2, 0);
                plus.padding              = new RectOffset();
                plus.fixedWidth           = 16;
                plus.fixedHeight          = 16;
                plus.normal.background    = plusIcons[0] as Texture2D;
                plus.onNormal.background  = plusIcons[0] as Texture2D;
                plus.active.background    = plusIcons[1] as Texture2D;
                plus.onActive.background  = plusIcons[1] as Texture2D;
                plus.focused.background   = plusIcons[0] as Texture2D;
                plus.onFocused.background = plusIcons[1] as Texture2D;

                minus                      = new GUIStyle();
                minus.margin               = new RectOffset(0, 0, 2, 0);
                minus.padding              = new RectOffset();
                minus.fixedWidth           = 16;
                minus.fixedHeight          = 16;
                minus.normal.background    = minusIcons[0] as Texture2D;
                minus.onNormal.background  = minusIcons[0] as Texture2D;
                minus.active.background    = minusIcons[1] as Texture2D;
                minus.onActive.background  = minusIcons[1] as Texture2D;
                minus.focused.background   = minusIcons[0] as Texture2D;
                minus.onFocused.background = minusIcons[1] as Texture2D;
            }
Exemplo n.º 12
0
            public ChiselEditModeItem(IChiselToolMode value, Type type)
            {
                this.instance = value;
                this.type     = type;
                var icon = ChiselEditorResources.LoadIconImage(instance.ToolName, false);

                if (icon != null)
                {
                    this.content = new GUIContent(icon, instance.ToolName);
                }
                else
                {
                    this.content = new GUIContent(instance.ToolName);
                }
            }
        // TODO: put somewhere else
        public static void ShowOperationChoicesInternal(SerializedProperty operationProp)
        {
            if (operationProp == null)
            {
                return;
            }

            if (styles == null)
            {
                styles = new Styles();
            }

            const string AdditiveIconName     = "csg_addition";
            const string SubtractiveIconName  = "csg_subtraction";
            const string IntersectingIconName = "csg_intersection";

            const string AdditiveIconTooltip     = "Additive CSG Operation";
            const string SubtractiveIconTooltip  = "Subtractive CSG Operation";
            const string IntersectingIconTooltip = "Intersecting CSG Operation";

            var additiveIcon     = ChiselEditorResources.GetIconContent(AdditiveIconName, AdditiveIconTooltip);
            var subtractiveIcon  = ChiselEditorResources.GetIconContent(SubtractiveIconName, SubtractiveIconTooltip);
            var intersectingIcon = ChiselEditorResources.GetIconContent(IntersectingIconName, IntersectingIconTooltip);

            using (new EditorGUIUtility.IconSizeScope(new Vector2(16, 16)))     // This ensures that the icons will be the same size on regular displays and HDPI displays
                                                                                // Note that the loaded images are different sizes on different displays
            {
                var operation = operationProp.hasMultipleDifferentValues ? ((CSGOperationType)255) : ((CSGOperationType)operationProp.enumValueIndex);
                if (Toggle((operation == CSGOperationType.Additive), additiveIcon, styles.leftButton))
                {
                    operationProp.enumValueIndex = (int)CSGOperationType.Additive;
                }
                if (Toggle((operation == CSGOperationType.Subtractive), subtractiveIcon, styles.midButton))
                {
                    operationProp.enumValueIndex = (int)CSGOperationType.Subtractive;
                }
                if (Toggle((operation == CSGOperationType.Intersecting), intersectingIcon, styles.rightButton))
                {
                    operationProp.enumValueIndex = (int)CSGOperationType.Intersecting;
                }
            }
        }
Exemplo n.º 14
0
        public GUIContent GetHierarchyIconForGenericNode(ChiselNode node)
        {
            var generator = node as ChiselGeneratorComponent;

            if (generator == null)
            {
                return(GUIContent.none);
            }

            // TODO: when something is wrong with the node, we should show an indicator here

            switch (generator.Operation)
            {
            default:
            case CSGOperationType.Additive:     return(ChiselEditorResources.GetIconContent(kAdditiveIconName, $"Additive {node.NodeTypeName}")[0]);

            case CSGOperationType.Subtractive:  return(ChiselEditorResources.GetIconContent(kSubtractiveIconName, $"Subtractive {node.NodeTypeName}")[0]);

            case CSGOperationType.Intersecting: return(ChiselEditorResources.GetIconContent(kIntersectingIconName, $"Intersecting {node.NodeTypeName}")[0]);
            }
        }
Exemplo n.º 15
0
        // TODO: put somewhere else
        public static CSGOperationType?ShowOperationChoicesInternal(CSGOperationType?operation, bool showAuto = true)
        {
            if (styles == null)
            {
                styles = new Styles();
            }

            var additiveIcon     = ChiselDefaultGeneratorDetails.GetIconContent(CSGOperationType.Additive, "Boolean Operation");
            var subtractiveIcon  = ChiselDefaultGeneratorDetails.GetIconContent(CSGOperationType.Subtractive, "Boolean Operation");
            var intersectingIcon = ChiselDefaultGeneratorDetails.GetIconContent(CSGOperationType.Intersecting, "Boolean Operation");

            using (new EditorGUIUtility.IconSizeScope(new Vector2(16, 16)))     // This ensures that the icons will be the same size on regular displays and HDPI displays
                                                                                // Note that the loaded images are different sizes on different displays
            {
                if (showAuto)
                {
                    const string kAutoIconName = "Automatic";
                    var          autoIcon      = ChiselEditorResources.GetIconContent(kAutoIconName, $"Automatic boolean operation");
                    if (Toggle(!operation.HasValue, autoIcon, styles.leftButton))
                    {
                        return(null);
                    }
                }
                var operationType = !operation.HasValue ? ((CSGOperationType)255) : (operation.Value);
                if (Toggle((operationType == CSGOperationType.Additive), additiveIcon, showAuto ? styles.midButton : styles.leftButton))
                {
                    return(CSGOperationType.Additive);
                }
                if (Toggle((operationType == CSGOperationType.Subtractive), subtractiveIcon, styles.midButton))
                {
                    return(CSGOperationType.Subtractive);
                }
                if (Toggle((operationType == CSGOperationType.Intersecting), intersectingIcon, styles.rightButton))
                {
                    return(CSGOperationType.Intersecting);
                }
                return(operationType);
            }
        }
Exemplo n.º 16
0
        static ToggleIcons[] GetIconsForProperty(Type type)
        {
            var members     = type.GetMembers(BindingFlags.Public | BindingFlags.Static);
            var toggleItems = new List <ToggleIcons>();

            foreach (var member in members)
            {
                var attribute = member.GetCustomAttribute <ToggleFlagAttribute>();
                if (attribute.Ignore)
                {
                    continue;
                }
                var value = (int)Enum.Parse(type, member.Name);

                GUIContent[] iconsOn, iconsOff;
                if (attribute == null)
                {
                    iconsOff    =
                        iconsOn = ChiselEditorResources.GetIconContent(member.Name, string.Empty);
                }
                else
                {
                    iconsOn  = ChiselEditorResources.GetIconContent(attribute.ActiveIcon, attribute.ActiveDescription);
                    iconsOff = ChiselEditorResources.GetIconContent(attribute.InactiveIcon, attribute.InactiveDescription);
                }

                toggleItems.Add(new ToggleIcons
                {
                    attribute  = attribute,
                    memberInfo = member,
                    iconsOn    = iconsOn,
                    iconsOff   = iconsOff,
                    value      = value,
                    name       = ObjectNames.NicifyVariableName(member.Name)
                });
            }
            return(toggleItems.ToArray());
        }
Exemplo n.º 17
0
 public override GUIContent GetHierarchyIcon(CSGModel node)
 {
     return(ChiselEditorResources.GetIconContent(ModelIconName, node.NodeTypeName)[0]);
 }
Exemplo n.º 18
0
 internal static void InitializeIcons()
 {
     kAddButton = ChiselEditorResources.GetIconContent(kAddIconName, kAddTooltip)[0];
 }
 static void Initialize()
 {
     sWarningContent = ChiselEditorResources.GetIconContent("warning")[0];
 }
Exemplo n.º 20
0
 internal static void Initialize()
 {
     kRebuildButton = ChiselEditorResources.GetIconContent(kRebuildIconName, kRebuildTooltip)[0];
 }