public override void OnNodeGUI()
 {
     PWGUI.ColorPicker("Base color", ref node.surfaceColor.baseColor);
 }
        void DrawElementCallback(Rect rect, int index, bool isActive, bool selected)
        {
            BiomeSwitchData elem = switchDatas[index];

            rect.y += 2;
            int   floatFieldSize = 70;
            int   colorFieldSize = 20;
            int   nameFieldSize  = (int)rect.width - colorFieldSize - 2;
            float lineHeight     = EditorGUIUtility.singleLineHeight;
            Rect  nameRect       = new Rect(rect.x, rect.y, nameFieldSize, EditorGUIUtility.singleLineHeight);
            Rect  colorFieldRect = new Rect(rect.x + nameFieldSize + 4, rect.y - 2, colorFieldSize, colorFieldSize);
            Rect  minRect        = new Rect(rect.x, rect.y + lineHeight + 2, floatFieldSize, EditorGUIUtility.singleLineHeight);
            Rect  maxRect        = new Rect(rect.x + floatFieldSize, rect.y + lineHeight + 2, floatFieldSize, EditorGUIUtility.singleLineHeight);

            EditorGUIUtility.labelWidth = 25;
            EditorGUI.BeginChangeCheck();
            {
                float oldMin = elem.min;
                float oldMax = elem.max;

                bool first = index == 0;
                bool last  = index == reorderableSwitchDataList.count - 1;

                PWGUI.ColorPicker(colorFieldRect, ref elem.color, false, true);
                elem.name = EditorGUI.TextField(nameRect, elem.name);
                EditorGUI.BeginDisabledGroup(first);
                elem.min = EditorGUI.FloatField(minRect, "min", elem.min);
                EditorGUI.EndDisabledGroup();
                EditorGUI.BeginDisabledGroup(last);
                elem.max = EditorGUI.FloatField(maxRect, "max", elem.max);
                EditorGUI.EndDisabledGroup();

                if (last)
                {
                    elem.max = bsl.relativeMax;
                }
                if (first)
                {
                    elem.min = bsl.relativeMin;
                }

                elem.min = Mathf.Max(elem.min, bsl.relativeMin);
                elem.max = Mathf.Min(elem.max, bsl.relativeMax);

                //affect up/down cell value
                if (elem.min != oldMin && index > 0)
                {
                    switchDatas[index - 1].max = elem.min;
                }
                if (elem.max != oldMax && index + 1 < switchDatas.Count)
                {
                    switchDatas[index + 1].min = elem.max;
                }
            }
            if (EditorGUI.EndChangeCheck() && bsl.OnBiomeDataModified != null)
            {
                bsl.OnBiomeDataModified(elem);
            }
            EditorGUIUtility.labelWidth = 0;

            switchDatas[index] = elem;
        }
Esempio n. 3
0
        public override void OnNodeGUI()
        {
            PWGUI.ColorPicker("Base color", ref surfaceColor.baseColor);

            // PWGUI.ColorPicker("Color over param", ref surfaceColor.colorOverParam);
        }
 public override void OnNodeGUI()
 {
     PWGUI.ColorPicker(ref outputColor, true, false);
 }
        public override void OnNodeCreate()
        {
            name             = "Biome switch";
            biomeSwitchModes = Enum.GetNames(typeof(BiomeSwitchMode));
            switchList       = new ReorderableList(switchDatas, typeof(BiomeFieldSwitchData), true, true, true, true);

            switchList.elementHeight = EditorGUIUtility.singleLineHeight * 2 + 4;             //padding

            delayedChanges.BindCallback(delayedUpdateKey, (elem) => { notifyBiomeDataChanged = true; });

            switchList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
                BiomeFieldSwitchData elem = switchDatas[index];

                rect.y += 2;
                int   floatFieldSize = 70;
                int   colorFieldSize = 20;
                int   nameFieldSize  = (int)rect.width - colorFieldSize - 2;
                float lineHeight     = EditorGUIUtility.singleLineHeight;
                Rect  nameRect       = new Rect(rect.x, rect.y, nameFieldSize, EditorGUIUtility.singleLineHeight);
                Rect  colorFieldRect = new Rect(rect.x + nameFieldSize + 4, rect.y - 2, colorFieldSize, colorFieldSize);
                Rect  minRect        = new Rect(rect.x, rect.y + lineHeight + 2, floatFieldSize, EditorGUIUtility.singleLineHeight);
                Rect  maxRect        = new Rect(rect.x + floatFieldSize, rect.y + lineHeight + 2, floatFieldSize, EditorGUIUtility.singleLineHeight);
                EditorGUI.BeginChangeCheck();
                {
                    EditorGUIUtility.labelWidth = 25;
                    EditorGUI.BeginChangeCheck();
                    {
                        float oldMin = elem.min;
                        float oldMax = elem.max;

                        PWGUI.ColorPicker(colorFieldRect, ref elem.color, false, true);
                        elem.name = EditorGUI.TextField(nameRect, elem.name);
                        elem.min  = EditorGUI.FloatField(minRect, "min", elem.min);
                        elem.max  = EditorGUI.FloatField(maxRect, "max", elem.max);

                        //affect up/down cell value
                        if (elem.min != oldMin && index > 0)
                        {
                            switchDatas[index - 1].max = elem.min;
                        }
                        if (elem.max != oldMax && index + 1 < switchDatas.Count)
                        {
                            switchDatas[index + 1].min = elem.max;
                        }
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        delayedChanges.UpdateValue(delayedUpdateKey, elem);
                    }
                    EditorGUIUtility.labelWidth = 0;
                }
                if (EditorGUI.EndChangeCheck())
                {
                    updatePreview = true;
                }

                switchDatas[index] = elem;
            };

            switchList.drawHeaderCallback = (rect) => {
                EditorGUI.LabelField(rect, "switches");
            };

            switchList.onReorderCallback += (ReorderableList l) => {
                notifyBiomeDataChanged = true;
            };

            switchList.onAddCallback += (ReorderableList l) => {
                switchDatas.Add(new BiomeFieldSwitchData(currentSampler));
                notifyBiomeDataChanged = true;
                UpdateSwitchMode();
            };

            switchList.onRemoveCallback += (ReorderableList l) => {
                if (switchDatas.Count > 1)
                {
                    switchDatas.RemoveAt(l.index);
                    notifyBiomeDataChanged = true;
                    UpdateSwitchMode();
                }
            };

            if (switchDatas.Count == 0)
            {
                switchDatas.Add(new BiomeFieldSwitchData(currentSampler));
            }

            UpdateSwitchMode();
        }
		public void RenderOrderingGroup(OrderingGroup orderingGroup, BaseGraph graph, Vector2 screenSize)
		{
			var e = Event.current;
			Rect screen = new Rect(-graph.panPosition, screenSize);
	
			//check if ordering group is not visible
			if (!orderingGroup.orderGroupRect.Overlaps(screen))
				return ;
			
			//Start GUI frame
			PWGUI.StartFrame(screen);
			
			if (orderingGroupStyle == null)
				LoadStyles();
	
			Rect		orderGroupWorldRect = Utils.DecalRect(orderingGroup.orderGroupRect, graph.panPosition);
	
			callbackId = 0;
	
			int			controlSize = 8;
			int			cornerSize = 14;
	
			//AH this is ugly
			CreateAnchorRectCallabck(orderingGroup, //left resize anchor
				new Rect(orderGroupWorldRect.x, orderGroupWorldRect.y + cornerSize, controlSize, orderGroupWorldRect.height - cornerSize * 2),
				MouseCursor.ResizeHorizontal,
				() => orderingGroup.orderGroupRect.xMin += e.delta.x
			);
			CreateAnchorRectCallabck(orderingGroup, //right resize anchor
				new Rect(orderGroupWorldRect.x + orderGroupWorldRect.width - controlSize, orderGroupWorldRect.y + cornerSize, controlSize, orderGroupWorldRect.height - cornerSize * 2),
				MouseCursor.ResizeHorizontal,
				() => orderingGroup.orderGroupRect.xMax += e.delta.x
			);
			CreateAnchorRectCallabck(orderingGroup, //top resize anchor
				new Rect(orderGroupWorldRect.x + cornerSize, orderGroupWorldRect.y, orderGroupWorldRect.width - cornerSize * 2, controlSize),
				MouseCursor.ResizeVertical,
				() => orderingGroup.orderGroupRect.yMin += e.delta.y
			);
			CreateAnchorRectCallabck(orderingGroup, //down resize anchor
				new Rect(orderGroupWorldRect.x + cornerSize, orderGroupWorldRect.y + orderGroupWorldRect.height - controlSize, orderGroupWorldRect.width - cornerSize * 2, controlSize),
				MouseCursor.ResizeVertical,
				() => orderingGroup.orderGroupRect.yMax += e.delta.y
			);
	
			CreateAnchorRectCallabck(orderingGroup, //top left anchor
				new Rect(orderGroupWorldRect.x, orderGroupWorldRect.y, cornerSize, cornerSize),
				MouseCursor.ResizeUpLeft,
				() => { orderingGroup.orderGroupRect.min += e.delta; }
			);
			CreateAnchorRectCallabck(orderingGroup, //top right anchor
				new Rect(orderGroupWorldRect.x + orderGroupWorldRect.width - cornerSize, orderGroupWorldRect.y, cornerSize, cornerSize),
				MouseCursor.ResizeUpRight,
				() => {
					orderingGroup.orderGroupRect.yMin += e.delta.y;
					orderingGroup.orderGroupRect.xMax += e.delta.x;
				}
			);
			CreateAnchorRectCallabck(orderingGroup, //down left anchor
				new Rect(orderGroupWorldRect.x, orderGroupWorldRect.y + orderGroupWorldRect.height - cornerSize, cornerSize, cornerSize),
				MouseCursor.ResizeUpRight,
				() => {
					orderingGroup.orderGroupRect.xMin += e.delta.x;
					orderingGroup.orderGroupRect.yMax += e.delta.y;
				}
			);
			CreateAnchorRectCallabck(orderingGroup, //down right anchor
				new Rect(orderGroupWorldRect.x + orderGroupWorldRect.width - cornerSize, orderGroupWorldRect.y + orderGroupWorldRect.height - cornerSize, cornerSize, cornerSize),
				MouseCursor.ResizeUpLeft,
				() => {
					orderingGroup.orderGroupRect.yMax += e.delta.y;
					orderingGroup.orderGroupRect.xMax += e.delta.x;
				}
			);
	
			if (e.rawType == EventType.MouseUp)
				orderingGroup.resizing = false;
	
			//draw renamable name field
			orderingGroupNameStyle.normal.textColor = orderingGroup.color;
			PWGUI.TextField(orderGroupWorldRect.position + new Vector2(10, -22), ref orderingGroup.name, true, orderingGroupNameStyle);
	
			//draw move pad
			Rect movePadRect = new Rect(orderGroupWorldRect.position + new Vector2(10, 10), new Vector2(50, 30));
			GUI.DrawTextureWithTexCoords(movePadRect, movepadTexture, new Rect(0, 0, 5, 4));
			EditorGUIUtility.AddCursorRect(movePadRect, MouseCursor.MoveArrow);
			if (e.type == EventType.MouseDown && e.button == 0)
				if (movePadRect.Contains(e.mousePosition))
				{
					orderingGroup.innerNodes = graph.allNodes.Where(n => n.rect.Overlaps(orderingGroup.orderGroupRect)).ToList();
					orderingGroup.moving = true;
					e.Use();
				}
			if (e.rawType == EventType.MouseUp)
				orderingGroup.moving = false;
	
			if (orderingGroup.moving && e.type == EventType.MouseDrag)
			{
				editorEvents.isDraggingOrderingGroup = true;
				orderingGroup.orderGroupRect.position += e.delta;
				orderingGroup.innerNodes.ForEach(n => n.rect.position += e.delta);
			}
	
			//draw ordering group
			GUI.color = orderingGroup.color;
			GUI.Label(orderGroupWorldRect, (string)null, orderingGroupStyle);
			GUI.color = Color.white;
	
			//draw color picker
			Rect colorPickerRect = new Rect(orderGroupWorldRect.x + orderGroupWorldRect.width - 30, orderGroupWorldRect.y + 10, 20, 20);
			PWGUI.ColorPicker(colorPickerRect, ref orderingGroup.color, false);
	
			if (orderGroupWorldRect.Contains(e.mousePosition))
			{
				graph.editorEvents.mouseOverOrderingGroup = orderingGroup;
				graph.editorEvents.isMouseOverOrderingGroupFrame = true;
			}
		}