Beispiel #1
0
        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().Value, q => q.ToEulerAngles().X);
            editorY.Submitted += text => SetComponent(editorParams, 1, editorY, current.GetValue().Value, q => q.ToEulerAngles().Y);
            editorZ.Submitted += text => SetComponent(editorParams, 2, editorZ, current.GetValue().Value, q => q.ToEulerAngles().Z);
            editorX.AddChangeLateWatcher(current, v => {
                var ea       = v.Value.ToEulerAngles() * Mathf.RadToDeg;
                editorX.Text = SameComponentValues(q => q.ToEulerAngles().X) ? RoundAngle(ea.X).ToString("0.###") : ManyValuesText;
                editorY.Text = SameComponentValues(q => q.ToEulerAngles().Y) ? RoundAngle(ea.Y).ToString("0.###") : ManyValuesText;
                editorZ.Text = SameComponentValues(q => q.ToEulerAngles().Z) ? RoundAngle(ea.Z).ToString("0.###") : ManyValuesText;
            });
        }
Beispiel #2
0
        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 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.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);
            editorZ.AddChangeLateWatcher(currentZ, v => editorZ.Text = v.IsDefined ? v.Value.ToString("0.###") : ManyValuesText);
            ManageManyValuesOnFocusChange(editorX, currentX);
            ManageManyValuesOnFocusChange(editorY, currentY);
            ManageManyValuesOnFocusChange(editorZ, currentZ);
        }
Beispiel #4
0
        public TextPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams)
        {
            EditorContainer.AddNode(new Widget {
                Layout = new HBoxLayout(),
                Nodes  =
                {
                    (editor         = editorParams.EditBoxFactory()),
                    Spacer.HSpacer(4),
                    (button         = new ThemedButton {
                        Text        = "...",
                        MinMaxWidth =                             20,
                        LayoutCell  = new LayoutCell(Alignment.Center)
                    })
                }
            });
            editor.LayoutCell = new LayoutCell(Alignment.Center);
            editor.Editor.EditorParams.MaxLines = maxLines;
            editor.MinHeight += editor.TextWidget.FontHeight * (maxLines - 1);
            var first     = true;
            var submitted = false;
            var current   = CoalescedPropertyValue();

            editor.AddChangeLateWatcher(current, v => editor.Text = v.IsDefined ? v.Value : ManyValuesText);
            button.Clicked += () => {
                var window = new TextEditorDialog(editorParams.DisplayName ?? editorParams.PropertyName, editor.Text, (s) => {
                    SetProperty(s);
                });
            };
            editor.Submitted += text => Submit();
            editor.AddChangeLateWatcher(() => editor.Text, text => {
                if (first)
                {
                    first = false;
                    return;
                }
                if (!editor.IsFocused())
                {
                    return;
                }
                if (submitted)
                {
                    Document.Current.History.Undo();
                }
                submitted = true;
                Submit();
            });
            editor.AddChangeLateWatcher(() => editor.IsFocused(), focused => {
                if (submitted)
                {
                    Document.Current.History.Undo();
                }
                if (!focused)
                {
                    submitted = false;
                }
            });
            ManageManyValuesOnFocusChange(editor, current);
        }
Beispiel #5
0
        protected FilePropertyEditor(IPropertyEditorParams editorParams, string[] allowedFileTypes) : base(editorParams)
        {
            EditorContainer.AddNode(new Widget {
                Layout = new HBoxLayout(),
                Nodes  =
                {
                    (editor         = editorParams.EditBoxFactory()),
                    Spacer.HSpacer(4),
                    (button         = new ThemedButton {
                        Text        = "...",
                        MinMaxWidth =                             20,
                        LayoutCell  = new LayoutCell(Alignment.Center)
                    })
                }
            });
            editor.LayoutCell = new LayoutCell(Alignment.Center);
            editor.Submitted += text => SetComponent(text);
            bool textValid = true;

            editor.AddChangeWatcher(() => editor.Text, text => textValid = IsValid(text));
            editor.CompoundPostPresenter.Add(new SyncDelegatePresenter <EditBox>(editBox => {
                if (!textValid)
                {
                    editBox.PrepareRendererState();
                    Renderer.DrawRect(Vector2.Zero, editBox.Size, Color4.Red.Transparentify(0.8f));
                }
            }));
            button.Clicked += () => {
                var dlg = new FileDialog {
                    AllowedFileTypes = allowedFileTypes,
                    Mode             = FileDialogMode.Open,
                    InitialDirectory = Directory.Exists(LastOpenedDirectory) ? LastOpenedDirectory : Project.Current.GetSystemDirectory(Document.Current.Path),
                };
                if (dlg.RunModal())
                {
                    SetFilePath(dlg.FileName);
                    LastOpenedDirectory = Project.Current.GetSystemDirectory(dlg.FileName);
                }
            };
            ExpandableContent.Padding = new Thickness(24, 10, 2, 2);
            var prefixEditor = new StringPropertyEditor(new PropertyEditorParams(ExpandableContent, prefix, nameof(PrefixData.Prefix))
            {
                LabelWidth = 180
            });

            prefix.Prefix = GetLongestCommonPrefix(GetPaths());
            ContainerWidget.AddChangeWatcher(() => prefix.Prefix, v => {
                string oldPrefix = GetLongestCommonPrefix(GetPaths());
                if (oldPrefix == v)
                {
                    return;
                }
                SetPathPrefix(oldPrefix, v);
                prefix.Prefix = v.Trim('/');
            });
        }
Beispiel #6
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);
            editor.AddChangeWatcher(current, v => editor.Text = v.ToString("0.###"));
        }
Beispiel #7
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());
		}
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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));
        }
Beispiel #11
0
 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);
 }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        protected FilePropertyEditor(IPropertyEditorParams editorParams, string[] allowedFileTypes) : base(editorParams)
        {
            ThemedButton button;

            this.allowedFileTypes = allowedFileTypes;
            EditorContainer.AddNode(new Widget {
                Layout = new HBoxLayout(),
                Nodes  =
                {
                    (editor         = editorParams.EditBoxFactory()),
                    Spacer.HSpacer(4),
                    (button         = new ThemedButton {
                        Text        = "...",
                        MinMaxWidth =                             20,
                        LayoutCell  = new LayoutCell(Alignment.Center)
                    })
                }
            });
            editor.LayoutCell         = new LayoutCell(Alignment.Center);
            editor.Submitted         += text => SetComponent(text);
            button.Clicked           += OnSelectClicked;
            ExpandableContent.Padding = new Thickness(24, 10, 2, 2);
            var prefixEditor = new StringPropertyEditor(new PropertyEditorParams(ExpandableContent, prefix, nameof(PrefixData.Prefix))
            {
                LabelWidth = 180
            });

            prefix.Prefix = GetLongestCommonPrefix(GetPaths());
            ContainerWidget.AddChangeWatcher(() => prefix.Prefix, v => {
                string oldPrefix = GetLongestCommonPrefix(GetPaths());
                if (oldPrefix == v)
                {
                    return;
                }
                SetPathPrefix(oldPrefix, v);
                prefix.Prefix = v.Trim('/');
            });
            ContainerWidget.AddChangeWatcher(() => ShowPrefix, show => {
                Expanded             = show && Expanded;
                ExpandButton.Visible = show;
            });
            var current = CoalescedPropertyValue();

            editor.AddChangeLateWatcher(current, v => editor.Text = ValueToStringConverter(v.Value) ?? "");
            ManageManyValuesOnFocusChange(editor, current);
        }
        private Widget CreateTriggerSelectionWidget(string trigger, string key)
        {
            var isChecked = selected.Contains(trigger);
            var checkBox  = new ThemedCheckBox {
                Checked = isChecked
            };

            if (isChecked)
            {
                groupSelection[key].Enqueue(trigger);
            }
            checkBoxes[key].Add(trigger, checkBox);

            var widget = new Widget {
                Layout     = new HBoxLayout(),
                LayoutCell = new LayoutCell(Alignment.Center),
                Padding    = new Thickness(left: 8, right: 8, top: 4, bottom: 4),
                Nodes      =
                {
                    new ThemedSimpleText {
                        Text           = trigger,
                        LayoutCell     = new LayoutCell(Alignment.Center),
                        Anchors        = Anchors.LeftRight,
                        ForceUncutText = false
                    },
                    Spacer.HSpacer(5),
                    checkBox
                },
                HitTestTarget = true
            };

            widget.CompoundPresenter.Add(new SyncDelegatePresenter <Widget>(w => {
                if (w.IsMouseOverThisOrDescendant())
                {
                    w.PrepareRendererState();
                    Renderer.DrawRect(Vector2.Zero, w.Size, Theme.Colors.SelectedBackground);
                }
            }));
            widget.LateTasks.Add(Theme.MouseHoverInvalidationTask(widget));
            widget.Clicked   += checkBox.Toggle;
            checkBox.Changed += e => ToggleTriggerCheckbox(trigger, key);
            return(widget);
        }
        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());
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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 TriggerSelectionDialog(Dictionary <string, HashSet <string> > triggers, HashSet <string> selected, Action <string> onSave)
        {
            this.onSave    = onSave;
            this.triggers  = triggers;
            this.selected  = selected;
            groupSelection = new Dictionary <string, Queue <string> >();
            checkBoxes     = new Dictionary <string, Dictionary <string, ThemedCheckBox> >();
            window         = new Window(new WindowOptions {
                Title                = "Trigger Selection",
                ClientSize           = new Vector2(300, 400),
                MinimumDecoratedSize = new Vector2(300, 400),
                FixedSize            = false,
                Visible              = false,
#if WIN
                Icon = new System.Drawing.Icon(new EmbeddedResource(AppIconPath, "Tangerine").GetResourceStream()),
#endif // WIN
            });
            rootWidget = new ThemedInvalidableWindowWidget(window)
            {
                Padding = new Thickness(8),
                Layout  = new VBoxLayout(),
                Nodes   =
                {
                    CreateFilter(),
                    Spacer.VSpacer(5),
                    CreateScrollView(),
                    CreateButtonsPanel()
                }
            };
            rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
            rootWidget.LateTasks.AddLoop(() => {
                if (rootWidget.Input.ConsumeKeyPress(Key.Escape))
                {
                    window.Close();
                }
            });
            window.ShowModal();
        }
Beispiel #19
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.AddChangeWatcher(currentX, v => editorX.Text = v.ToString("0.###"));
            editorY.AddChangeWatcher(currentY, v => editorY.Text = v.ToString("0.###"));
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
        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);
            });
        }