public static Icon GetIcon(Type nodeType) { if (!map.TryGetValue(nodeType, out var icon)) { map[nodeType] = icon = IconPool.GetIcon("Nodes." + nodeType, "Nodes.Unknown"); } return(icon); }
private Node CreatePipetteButton() { var button = new ToolbarButton { Texture = IconPool.GetTexture("Tools.Pipette"), }; button.Tasks.Add(UIProcessors.PickColorProcessor(button, v => SetProperty(v))); return(button); }
private Node CreatePipetteButton() { var button = new ToolbarButton { Texture = IconPool.GetTexture("Tools.Pipette"), }; button.Tasks.Add(UIProcessors.PickColorProcessor( button, v => SetControlPointProperty(nameof(GradientControlPoint.Color), v))); return(button); }
public static ITexture GetTexture(Type nodeType) { ITexture texture; if (!map.TryGetValue(nodeType, out texture)) { texture = IconPool.GetTexture("Nodes." + nodeType, "Nodes.Unknown"); } return(texture); }
private void PanelAwake(Node node, int rowIndex, int panelIndex) { var drag = new Image { Texture = IconPool.GetTexture("Tools.ToolbarSeparator"), LayoutCell = new LayoutCell(Alignment.Center), MinMaxSize = new Vector2(16), HitTestTarget = true }; node.Tasks.Add(() => DragTask(node.AsWidget, drag.Input, rowIndex, panelIndex)); node.Nodes.Insert(0, drag); }
private Node CreatePipetteButton() { pipetteButton = new ToolbarButton { Texture = IconPool.GetTexture("Tools.Pipette"), }; var current = CoalescedPropertyValue(); pipetteButton.Tasks.Add(PickColorProcessor(pipetteButton, v => { var value = current.GetValue(); v.A = value.IsDefined ? value.Value.A : v.A; SetProperty(v); })); return(pipetteButton); }
public InstancePropertyEditor(IPropertyEditorParams editorParams, Action <Widget> onValueChanged) : base(editorParams) { Selector = editorParams.DropDownListFactory(); Selector.LayoutCell = new LayoutCell(Alignment.Center); var propertyType = typeof(T); var meta = Yuzu.Metadata.Meta.Get(editorParams.Type, InternalPersistence.Instance.YuzuCommonOptions); if (!propertyType.IsInterface && !propertyType.IsAbstract) { Selector.Items.Add(new CommonDropDownList.Item(propertyType.Name, propertyType)); } foreach (var t in DerivedTypesCache.GetDerivedTypesFor(propertyType)) { Selector.Items.Add(new CommonDropDownList.Item(t.Name, t)); } EditorContainer.AddChangeLateWatcher(CoalescedPropertyValue( comparator: (t1, t2) => t1 == null && t2 == null || t1 != null && t2 != null && t1.GetType() == t2.GetType()), v => { onValueChanged?.Invoke(ExpandableContent); if (v.IsDefined) { Selector.Value = v.Value?.GetType(); } else { Selector.Text = ManyValuesText; } } ); Selector.Changed += a => { if (a.ChangedByUser) { var type = (Type)Selector.Items[a.Index].Value; SetProperty <object>((_) => type != null ? Activator.CreateInstance(type) : null); } }; var propertyMetaItem = meta.Items.FirstOrDefault(i => i.Name == editorParams.PropertyName); var defaultValue = propertyMetaItem?.GetValue(meta.Default); var resetToDefaultButton = new ToolbarButton(IconPool.GetTexture("Tools.Revert")) { Clicked = () => SetProperty(Cloner.Clone(defaultValue)) }; if (Selector.Items.Count == 1) { var t = Selector.Items[0].Value as Type; var b = new ToolbarButton("Create") { TabTravesable = new TabTraversable(), LayoutCell = new LayoutCell(Alignment.LeftCenter), Padding = new Thickness(left: 5.0f), HitTestTarget = true, MinWidth = 0, MaxWidth = float.PositiveInfinity }; b.Clicked = () => { b.Visible = false; SetProperty <object>(_ => t != null ? Activator.CreateInstance(t) : null); onValueChanged?.Invoke(ExpandableContent); Expanded = true; }; var value = CoalescedPropertyValue().GetValue(); b.Visible = Equals(value.Value, defaultValue); resetToDefaultButton.Clicked = () => { b.Visible = true; SetProperty(defaultValue); onValueChanged?.Invoke(ExpandableContent); }; EditorContainer.AddNode(b); EditorContainer.AddNode(Spacer.HStretch()); onValueChanged?.Invoke(ExpandableContent); } else { EditorContainer.Nodes.Insert(0, Selector); } EditorContainer.AddNode(resetToDefaultButton); EditorContainer.AddChangeLateWatcher(CoalescedPropertyValue(), v => { resetToDefaultButton.Visible = !Equals(v.Value, defaultValue); }); }
public ThemedExpandButton() : base(IconPool.GetTexture("Tools.Folded")) { Highlightable = false; Clicked += () => { Expanded = !Expanded; }; }
public InstancePropertyEditor(IPropertyEditorParams editorParams, Action <Widget> OnValueChanged) : base(editorParams) { Selector = editorParams.DropDownListFactory(); Selector.LayoutCell = new LayoutCell(Alignment.Center); EditorContainer.AddNode(Selector); var propertyType = typeof(T); var meta = Yuzu.Metadata.Meta.Get(editorParams.Type, Serialization.YuzuCommonOptions); var propertyMetaItem = meta.Items.Where(i => i.Name == editorParams.PropertyName).FirstOrDefault(); if (propertyMetaItem != null) { var defaultValue = propertyMetaItem.GetValue(meta.Default); var resetToDefaultButton = new ToolbarButton(IconPool.GetTexture("Tools.Revert")) { Clicked = () => { SetProperty(defaultValue); } }; EditorContainer.AddNode(resetToDefaultButton); Selector.AddChangeWatcher(CoalescedPropertyValue(), v => { resetToDefaultButton.Visible = !Equals(v, defaultValue); }); } if (!propertyType.IsInterface) { Selector.Items.Add(new CommonDropDownList.Item(propertyType.Name, propertyType)); } // TODO: invalidate cache on loading new assemblies at runtime if (!derivedTypesCache.TryGetValue(propertyType, out List <Type> derivedTypes)) { derivedTypes = new List <Type>(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { var assignables = assembly .GetTypes() .Where(t => !t.IsInterface && t.GetCustomAttribute <TangerineIgnoreAttribute>(false) == null && t != propertyType && propertyType.IsAssignableFrom(t)); foreach (var type in assignables) { derivedTypes.Add(type); } } derivedTypesCache.Add(propertyType, derivedTypes); } foreach (var t in derivedTypes) { Selector.Items.Add(new CommonDropDownList.Item(t.Name, t)); } Selector.Changed += a => { if (a.ChangedByUser) { Type type = (Type)Selector.Items[a.Index].Value; SetProperty <object>((_) => type != null ? Activator.CreateInstance(type) : null); } }; Selector.AddChangeWatcher(CoalescedPropertyValue(), v => { OnValueChanged?.Invoke(ExpandableContent); Selector.Value = v?.GetType(); }); }