public QuaternionPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { EditorContainer.AddNode(new Widget { Layout = new HBoxLayout { DefaultCell = new DefaultLayoutCell(Alignment.Center), Spacing = 4 }, Nodes = { (editorX = editorParams.NumericEditBoxFactory()), (editorY = editorParams.NumericEditBoxFactory()), (editorZ = editorParams.NumericEditBoxFactory()), Spacer.HStretch(), } }); var current = CoalescedPropertyValue(); editorX.Submitted += text => SetComponent(editorParams, 0, editorX, current.GetValue()); editorY.Submitted += text => SetComponent(editorParams, 1, editorY, current.GetValue()); editorZ.Submitted += text => SetComponent(editorParams, 2, editorZ, current.GetValue()); editorX.AddChangeWatcher(current, v => { var ea = v.ToEulerAngles() * Mathf.RadToDeg; editorX.Text = RoundAngle(ea.X).ToString("0.###"); editorY.Text = RoundAngle(ea.Y).ToString("0.###"); editorZ.Text = RoundAngle(ea.Z).ToString("0.###"); }); }
public Vector2PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { EditorContainer.AddNode(new Widget { Layout = new HBoxLayout { DefaultCell = new DefaultLayoutCell(Alignment.Center), Spacing = 4 }, Nodes = { //new SimpleText { Text = "X" }, (editorX = editorParams.NumericEditBoxFactory()), // new SimpleText { Text = "Y" }, (editorY = editorParams.NumericEditBoxFactory()), Spacer.HStretch(), } }); var currentX = CoalescedPropertyComponentValue(v => v.X); var currentY = CoalescedPropertyComponentValue(v => v.Y); editorX.Submitted += text => SetComponent(editorParams, 0, editorX, currentX.GetValue()); editorY.Submitted += text => SetComponent(editorParams, 1, editorY, currentY.GetValue()); editorX.AddChangeLateWatcher(currentX, v => editorX.Text = v.IsDefined ? v.Value.ToString("0.###") : ManyValuesText); editorY.AddChangeLateWatcher(currentY, v => editorY.Text = v.IsDefined ? v.Value.ToString("0.###") : ManyValuesText); ManageManyValuesOnFocusChange(editorX, currentX); ManageManyValuesOnFocusChange(editorY, currentY); }
public Vector3PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { EditorContainer.AddNode(new Widget { Layout = new HBoxLayout { DefaultCell = new DefaultLayoutCell(Alignment.Center), Spacing = 4 }, Nodes = { (editorX = editorParams.NumericEditBoxFactory()), (editorY = editorParams.NumericEditBoxFactory()), (editorZ = editorParams.NumericEditBoxFactory()), Spacer.HStretch(), } }); var currentX = CoalescedPropertyComponentValue(v => v.X); var currentY = CoalescedPropertyComponentValue(v => v.Y); var currentZ = CoalescedPropertyComponentValue(v => v.Z); editorX.Submitted += text => SetComponent(editorParams, 0, editorX, currentX.GetValue()); editorY.Submitted += text => SetComponent(editorParams, 1, editorY, currentY.GetValue()); editorZ.Submitted += text => SetComponent(editorParams, 2, editorZ, currentZ.GetValue()); editorX.AddChangeWatcher(currentX, v => editorX.Text = v.ToString("0.###")); editorY.AddChangeWatcher(currentY, v => editorY.Text = v.ToString("0.###")); editorZ.AddChangeWatcher(currentZ, v => editorZ.Text = v.ToString("0.###")); }
public TriggerPropertyEditor(IPropertyEditorParams editorParams, bool multiline = false) : base(editorParams) { comboBox = new ThemedComboBox { LayoutCell = new LayoutCell(Alignment.Center) }; EditorContainer.AddNode(comboBox); EditorContainer.AddNode(Spacer.HStretch()); comboBox.Changed += ComboBox_Changed; foreach (var obj in editorParams.Objects) { var node = (Node)obj; foreach (var a in node.Animations) { foreach (var m in a.Markers.Where(i => i.Action != MarkerAction.Jump && !string.IsNullOrEmpty(i.Id))) { var id = a.Id != null ? m.Id + '@' + a.Id : m.Id; if (!comboBox.Items.Any(i => i.Text == id)) { comboBox.Items.Add(new DropDownList.Item(id)); } } } } comboBox.AddChangeWatcher(CoalescedPropertyValue(), v => comboBox.Text = v); }
public ThicknessPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { EditorContainer.AddNode(new Widget { Layout = new HBoxLayout { DefaultCell = new DefaultLayoutCell(Alignment.Center), Spacing = 4 }, Nodes = { (editorLeft = editorParams.NumericEditBoxFactory()), (editorRight = editorParams.NumericEditBoxFactory()), (editorTop = editorParams.NumericEditBoxFactory()), (editorBottom = editorParams.NumericEditBoxFactory()), Spacer.HStretch(), } }); var currentLeft = CoalescedPropertyComponentValue(v => v.Left); var currentRight = CoalescedPropertyComponentValue(v => v.Right); var currentTop = CoalescedPropertyComponentValue(v => v.Top); var currentBottom = CoalescedPropertyComponentValue(v => v.Bottom); editorLeft.Submitted += text => SetComponent(editorParams, 0, editorLeft, currentLeft.GetValue()); editorRight.Submitted += text => SetComponent(editorParams, 1, editorRight, currentRight.GetValue()); editorTop.Submitted += text => SetComponent(editorParams, 2, editorTop, currentTop.GetValue()); editorBottom.Submitted += text => SetComponent(editorParams, 3, editorBottom, currentBottom.GetValue()); editorLeft.AddChangeLateWatcher(currentLeft, v => editorLeft.Text = v.IsDefined ? v.Value.ToString("0.###") : ManyValuesText); editorRight.AddChangeLateWatcher(currentRight, v => editorRight.Text = v.IsDefined ? v.Value.ToString("0.###") : ManyValuesText); editorTop.AddChangeLateWatcher(currentTop, v => editorTop.Text = v.IsDefined ? v.Value.ToString("0.###") : ManyValuesText); editorBottom.AddChangeLateWatcher(currentBottom, v => editorBottom.Text = v.IsDefined ? v.Value.ToString("0.###") : ManyValuesText); ManageManyValuesOnFocusChange(editorLeft, currentLeft); ManageManyValuesOnFocusChange(editorRight, currentRight); ManageManyValuesOnFocusChange(editorTop, currentTop); ManageManyValuesOnFocusChange(editorBottom, currentBottom); }
public FloatPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { editor = editorParams.NumericEditBoxFactory(); EditorContainer.AddNode(editor); EditorContainer.AddNode(Spacer.HStretch()); var current = CoalescedPropertyValue(); editor.Submitted += text => SetComponent(text, current); editor.AddChangeWatcher(current, v => editor.Text = v.ToString("0.###")); }
public FloatPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { editor = editorParams.NumericEditBoxFactory(); EditorContainer.AddNode(editor); EditorContainer.AddNode(Spacer.HStretch()); var current = CoalescedPropertyValue(); editor.Submitted += text => SetComponent(text, current.GetValue()); editor.AddChangeLateWatcher(current, v => editor.Text = v.IsDefined ? v.Value.ToString("0.###") : ManyValuesText); ManageManyValuesOnFocusChange(editor, current); }
public AnchorsPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { group = new Widget { Layout = new HBoxLayout { DefaultCell = new DefaultLayoutCell(Alignment.Center), Spacing = 4 } }; EditorContainer.AddNode(group); firstButton = AddButton(Anchors.Left, "Anchor to the left"); AddButton(Anchors.Right, "Anchor to the right"); AddButton(Anchors.Top, "Anchor to the top"); AddButton(Anchors.Bottom, "Anchor to the bottom"); AddButton(Anchors.CenterH, "Anchor to the center horizontally"); AddButton(Anchors.CenterV, "Anchor to the center vertically"); group.AddNode(Spacer.HStretch()); }
public SBytePropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { editor = editorParams.NumericEditBoxFactory(); // TODO: move IsReadOnly to IPropertyEditor editor.IsReadOnly = editorParams.PropertyInfo.GetCustomAttribute <TangerineReadOnlyAttribute>(true) != null; editor.LayoutCell = new LayoutCell(Alignment.Center); EditorContainer.AddNode(editor); EditorContainer.AddNode(Spacer.HStretch()); var current = CoalescedPropertyValue(); editor.Submitted += text => SetComponent(text, current.GetValue()); editor.AddChangeLateWatcher(current, v => editor.Text = v.IsDefined ? v.Value.ToString() : ManyValuesText); ManageManyValuesOnFocusChange(editor, current); }
public Color4PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { ColorBoxButton colorBox; var panel = new ColorPickerPanel(); var currentColor = CoalescedPropertyValue(Color4.White).DistinctUntilChanged(); EditorContainer.AddNode(new Widget { Layout = new HBoxLayout { DefaultCell = new DefaultLayoutCell(Alignment.Center) }, Nodes = { (editor = editorParams.EditBoxFactory()), Spacer.HSpacer(4), (colorBox = new ColorBoxButton(currentColor)), CreatePipetteButton(), Spacer.HStretch(), }, }); ExpandableContent.AddNode(panel.Widget); panel.Widget.Padding = panel.Widget.Padding + new Thickness(right: 12.0f); panel.Widget.Tasks.Add(currentColor.Consume(v => { if (panel.Color != v) { panel.Color = v; } Changed?.Invoke(); })); panel.Changed += () => { EditorParams.History?.RollbackTransaction(); SetProperty(panel.Color); }; panel.DragStarted += () => { EditorParams.History?.BeginTransaction(); lastColor = panel.Color; }; panel.DragEnded += () => { if (panel.Color != lastColor) { EditorParams.History?.CommitTransaction(); } EditorParams.History?.EndTransaction(); }; colorBox.Clicked += () => Expanded = !Expanded; var currentColorString = currentColor.Select(i => i.ToString(Color4.StringPresentation.Dec)); editor.Submitted += text => SetComponent(text, currentColorString); editor.Tasks.Add(currentColorString.Consume(v => editor.Text = v)); editor.AddChangeWatcher(() => editor.Text, value => CheckEditorText(value, editor)); }
public BooleanPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { checkBox = new ThemedCheckBox { LayoutCell = new LayoutCell(Alignment.LeftCenter) }; EditorContainer.AddNode(checkBox); EditorContainer.AddNode(Spacer.HStretch()); checkBox.Changed += args => { if (args.ChangedByUser) { SetProperty(args.Value); } }; checkBox.AddChangeWatcher(CoalescedPropertyValue(), v => checkBox.Checked = v); }
public BooleanPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { var checkBox = new ThemedCheckBox { LayoutCell = new LayoutCell(Alignment.LeftCenter) }; EditorContainer.AddNode(checkBox); EditorContainer.AddNode(Spacer.HStretch()); checkBox.Changed += args => { if (args.ChangedByUser) { SetProperty(args.Value); } }; checkBox.AddChangeLateWatcher(CoalescedPropertyValue(), v => checkBox.State = v.IsDefined ? v.Value ? CheckBoxState.Checked : CheckBoxState.Unchecked : CheckBoxState.Indeterminate); }
public NumericRangePropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { EditorContainer.AddNode(new Widget { Layout = new HBoxLayout { DefaultCell = new DefaultLayoutCell(Alignment.Center), Spacing = 4 }, Nodes = { (medEditor = editorParams.NumericEditBoxFactory()), (dispEditor = editorParams.NumericEditBoxFactory()), Spacer.HStretch(), } }); var currentMed = CoalescedPropertyComponentValue(v => v.Median); var currentDisp = CoalescedPropertyComponentValue(v => v.Dispersion); medEditor.Submitted += text => SetComponent(editorParams, 0, medEditor, currentMed.GetValue()); dispEditor.Submitted += text => SetComponent(editorParams, 1, dispEditor, currentDisp.GetValue()); medEditor.AddChangeWatcher(currentMed, v => medEditor.Text = v.ToString()); dispEditor.AddChangeWatcher(currentDisp, v => dispEditor.Text = v.ToString()); }
public DoublePropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { var editor = editorParams.NumericEditBoxFactory(); EditorContainer.AddNode(editor); EditorContainer.AddNode(Spacer.HStretch()); var current = CoalescedPropertyValue(); editor.Submitted += text => { if (Parser.TryParse(text, out double newValue)) { SetProperty(newValue); } else { var currentValue = current.GetValue(); editor.Text = currentValue.IsDefined ? currentValue.Value.ToString("0.###") : ManyValuesText; } }; editor.AddChangeLateWatcher(current, v => editor.Text = v.IsDefined ? v.Value.ToString("0.###") : ManyValuesText); ManageManyValuesOnFocusChange(editor, current); }
public TriggerPropertyEditor(IPropertyEditorParams editorParams, bool multiline = false) : base(editorParams) { if (EditorParams.Objects.Skip(1).Any()) { EditorContainer.AddNode(CreateWarning("Edit of triggers isn't supported for multiple selection.")); return; } node = (Node)editorParams.Objects.First(); var button = new ThemedButton { Text = "...", MinMaxWidth = 20, LayoutCell = new LayoutCell(Alignment.Center) }; var color = button.GlobalColor; EditorContainer.AddNode(editBox = editorParams.EditBoxFactory()); EditorContainer.AddNode(Spacer.HSpacer(4)); EditorContainer.AddNode(button); EditorContainer.AddNode(Spacer.HStretch()); editBox.Submitted += text => { var newValue = FilterTriggers(text); editBox.Text = newValue; SetProperty(newValue); }; button.Clicked += () => { var window = new TriggerSelectionDialog( GetAvailableTriggers(), new HashSet <string>(CurrentTriggers), s => { s = FilterTriggers(s); SetProperty(s); editBox.Text = s; } ); }; editBox.AddChangeLateWatcher(CoalescedPropertyValue(), v => editBox.Text = v.Value); Invalidate(); }
public Color4PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { ColorBoxButton colorBox; panel = new ColorPickerPanel(); var objects = EditorParams.Objects.ToList(); var first = PropertyValue(objects.First()).GetValue(); var @default = objects.All(o => PropertyValue(o).GetValue().A == first.A) ? new Color4(255, 255, 255, first.A) : Color4.White; var currentColor = CoalescedPropertyValue(@default).DistinctUntilChanged(); panel.Color = currentColor.GetValue().Value; EditorContainer.AddNode(new Widget { Layout = new HBoxLayout { DefaultCell = new DefaultLayoutCell(Alignment.Center) }, Nodes = { (editor = editorParams.EditBoxFactory()), Spacer.HSpacer(4), (colorBox = new ColorBoxButton(currentColor)), CreatePipetteButton(), Spacer.HStretch(), }, }); ExpandableContent.AddNode(panel.Widget); panel.Widget.Padding += new Thickness(right: 12.0f); panel.Widget.Components.GetOrAdd <LateConsumeBehaviour>().Add(currentColor.Consume(v => { if (panel.Color != v.Value) { panel.Color = v.Value; } Changed?.Invoke(); })); panel.Changed += () => { EditorParams.History?.RollbackTransaction(); if ((panel.Color.ABGR & 0xFFFFFF) == (previousColor.ABGR & 0xFFFFFF) && panel.Color.A != previousColor.A) { SetProperty <Color4>(c => { c.A = panel.Color.A; return(c); }); } else { SetProperty(panel.Color); } }; panel.DragStarted += () => { EditorParams.History?.BeginTransaction(); previousColor = panel.Color; }; panel.DragEnded += () => { if (panel.Color != previousColor || (editorParams.Objects.Skip(1).Any() && SameValues())) { EditorParams.History?.CommitTransaction(); } EditorParams.History?.EndTransaction(); }; colorBox.Clicked += () => Expanded = !Expanded; var currentColorString = currentColor.Select(i => i.Value.ToString(Color4.StringPresentation.Dec)); editor.Submitted += text => { SetComponent(text, currentColorString); }; editor.AddChangeLateWatcher(currentColorString, v => editor.Text = SameValues() ? v : ManyValuesText); editor.AddChangeLateWatcher(() => editor.Text, value => CheckEditorText(value, editor)); ManageManyValuesOnFocusChange(editor, currentColor); }
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); }); }