public ShortcutPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { editor = editorParams.EditBoxFactory(); editor.Updating += Updating; editor.Updated += Updated; editor.LayoutCell = new LayoutCell(Alignment.Center); editor.AddChangeLateWatcher(CoalescedPropertyValue(), v => { var text = v.Value.ToString(); editor.Text = v.IsDefined ? v.Value.Main != Key.Unknown ? text : text.Replace("Unknown", "") : ManyValuesText; }); editor.IsReadOnly = true; editor.TextWidget.Tasks.Clear(); editor.TextWidget.Position = new Vector2(0, editor.MinHeight / 2); editor.TextWidget.Padding = new Thickness(5, 0); editor.Gestures.Add(new ClickGesture(() => editor.SetFocus())); editor.Gestures.Add(new ClickGesture(1, () => { main = Key.Unknown; modifiers = Modifiers.None; SetValue(new Shortcut(modifiers, main)); })); editor.AddToNode(EditorContainer); PropertyLabel.Tasks.Clear(); PropertyLabel.Tasks.Add(ManageLabelFocus()); ContainerWidget.Tasks.Add(ManageFocusTask()); var value = CoalescedPropertyValue().GetValue(); main = value.Value.Main; modifiers = value.Value.Modifiers; flatFillPresenter = new WidgetFlatFillPresenter(Theme.Colors.GrayBackground); ContainerWidget.CompoundPresenter.Add(flatFillPresenter); }
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); editor.Submitted += text => SetProperty(text); editor.AddChangeWatcher(CoalescedPropertyValue(), v => editor.Text = v); button.Clicked += () => { var window = new TextEditorDialog(editorParams.DisplayName ?? editorParams.PropertyName, editor.Text, (s) => { SetProperty(s); }); }; }
protected FilePropertyEditor(IPropertyEditorParams editorParams, string[] allowedFileTypes) : base(editorParams) { ContainerWidget.AddNode(new Widget { Layout = new HBoxLayout(), Nodes = { (editor = editorParams.EditBoxFactory()), new HSpacer(4), (button = new ThemedButton { Text = "...", MinMaxWidth = 20, LayoutCell = new LayoutCell(Alignment.Center) }) } }); editor.LayoutCell = new LayoutCell(Alignment.Center); editor.Submitted += text => AssignAsset(AssetPath.CorrectSlashes(text)); 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); } }; }
public TextPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { ThemedButton button; 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); }
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('/'); }); }
public StringPropertyEditor(IPropertyEditorParams editorParams, bool multiline = false) : base(editorParams) { editor = editorParams.EditBoxFactory(); editor.LayoutCell = new LayoutCell(Alignment.Center); editor.Editor.EditorParams.MaxLines = multiline ? maxLines : 1; editor.MinHeight += multiline ? editor.TextWidget.FontHeight * (maxLines - 1) : 0; ContainerWidget.AddNode(editor); editor.Submitted += SetProperty; editor.AddChangeWatcher(CoalescedPropertyValue(), v => editor.Text = v); }
public NodeIdPropertyEditor(IPropertyEditorParams editorParams, bool multiline = false) : base(editorParams) { editor = editorParams.EditBoxFactory(); editor.LayoutCell = new LayoutCell(Alignment.Center); editor.Editor.EditorParams.MaxLines = 1; EditorContainer.AddNode(editor); editor.Submitted += SetValue; editor.AddChangeLateWatcher(CoalescedPropertyValue(), v => editor.Text = v.IsDefined ? v.Value : ManyValuesText); ManageManyValuesOnFocusChange(editor, CoalescedPropertyValue()); }
public RenderTexturePropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { editor = editorParams.EditBoxFactory(); editor.IsReadOnly = true; editor.LayoutCell = new LayoutCell(Alignment.Center); ContainerWidget.AddNode(editor); editor.AddChangeWatcher(CoalescedPropertyValue(), v => editor.Text = v == null ? "RenderTexture (null)" : $"RenderTexture ({v.ImageSize.Width}x{v.ImageSize.Height})" ); }
public StringPropertyEditor(IPropertyEditorParams editorParams, bool multiline = false) : base(editorParams) { editor = editorParams.EditBoxFactory(); editor.LayoutCell = new LayoutCell(Alignment.Center); editor.Editor.EditorParams.MaxLines = multiline ? maxLines : 1; editor.MinHeight += multiline ? editor.TextWidget.FontHeight * (maxLines - 1) : 0; EditorContainer.AddNode(editor); editor.Submitted += text => SetProperty(text); var current = CoalescedPropertyValue(); editor.AddChangeLateWatcher(current, v => editor.Text = v.IsDefined ? v.Value : ManyValuesText); ManageManyValuesOnFocusChange(editor, current); }
private static Widget CreateKeyEditor(IPropertyEditorParams editorParams, KeyValuePair keyValue, Action <string> submitted, Widget button) { var keyEditor = editorParams.EditBoxFactory(); keyEditor.AddChangeWatcher(() => keyValue.Key, s => keyEditor.Text = s); keyEditor.Submitted += submitted; var keyLabelContainer = new Widget { Layout = new HBoxLayout(), LayoutCell = new LayoutCell { StretchX = 1.0f }, Nodes = { new ThemedSimpleText { Text = "Key", VAlignment = VAlignment.Center, LayoutCell = new LayoutCell(Alignment.LeftCenter), ForceUncutText = false, Padding = new Thickness(left: 5f), HitTestTarget = true, TabTravesable = new TabTraversable(), }, }, }; var editorContainer = new Widget { Layout = new HBoxLayout(), LayoutCell = new LayoutCell { StretchX = 2.0f, }, Nodes = { new Widget { Layout = new HBoxLayout{ DefaultCell = new DefaultLayoutCell(Alignment.Center), Spacing = 4 }, Nodes ={ keyEditor, Spacer.HSpacer(4), button, Spacer.HStretch(), }, }, }, }; return(new Widget { Layout = new HBoxLayout { IgnoreHidden = false, }, LayoutCell = new LayoutCell { StretchY = 0f, }, Nodes = { keyLabelContainer, editorContainer, }, }); }
public NodeReferencePropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { var propName = editorParams.PropertyName; if (propName.EndsWith("Ref")) { PropertyLabel.Text = propName.Substring(0, propName.Length - 3); } editor = editorParams.EditBoxFactory(); editor.LayoutCell = new LayoutCell(Alignment.Center); EditorContainer.AddNode(editor); editor.Submitted += text => SetComponent(text); editor.AddChangeWatcher(CoalescedPropertyValue(), v => editor.Text = v?.Id); }
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 RenderTexturePropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { var editor = editorParams.EditBoxFactory(); editor.IsReadOnly = true; editor.LayoutCell = new LayoutCell(Alignment.Center); EditorContainer.AddNode(editor); var current = CoalescedPropertyValue(); editor.AddChangeLateWatcher(current, v => editor.Text = v.Value == null ? "RenderTexture (null)" : $"RenderTexture ({v.Value.ImageSize.Width}x{v.Value.ImageSize.Height})" ); ManageManyValuesOnFocusChange(editor, current); }
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); }
public NodeReferencePropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { var propName = editorParams.PropertyName; if (propName.EndsWith("Ref")) { PropertyLabel.Text = propName.Substring(0, propName.Length - 3); } editor = editorParams.EditBoxFactory(); editor.LayoutCell = new LayoutCell(Alignment.Center); EditorContainer.AddNode(editor); editor.Submitted += SetComponent; var current = CoalescedPropertyValue(); editor.AddChangeLateWatcher(current, v => { editor.Text = v.IsDefined ? v.Value?.Id: ManyValuesText; }); ManageManyValuesOnFocusChange(editor, current); }
public NodeIdPropertyEditor(IPropertyEditorParams editorParams, bool multiline = false) : base(editorParams) { editor = editorParams.EditBoxFactory(); editor.LayoutCell = new LayoutCell(Alignment.Center); editor.Editor.EditorParams.MaxLines = 1; EditorContainer.AddNode(editor); 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)); } })); editor.Submitted += text => SetValue(text); editor.AddChangeWatcher(CoalescedPropertyValue(), v => editor.Text = v); }
public IntPropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { editor = editorParams.EditBoxFactory(); editor.MinMaxWidth = 80; editor.LayoutCell = new LayoutCell(Alignment.Center); ContainerWidget.AddNode(editor); var current = CoalescedPropertyValue(); editor.Submitted += text => { int newValue; if (int.TryParse(text, out newValue)) { SetProperty(newValue); } else { editor.Text = current.GetValue().ToString(); } }; editor.AddChangeWatcher(current, v => editor.Text = v.ToString()); }
public Color4PropertyEditor(IPropertyEditorParams editorParams) : base(editorParams) { ColorBoxButton colorBox; var panel = new ColorPickerPanel(); var currentColor = CoalescedPropertyValue(Color4.White).DistinctUntilChanged(); ContainerWidget.AddNode(new Widget { Layout = new HBoxLayout { CellDefaults = new LayoutCell(Alignment.Center) }, Nodes = { (editor = editorParams.EditBoxFactory()), new HSpacer(4), (colorBox = new ColorBoxButton(currentColor)), CreatePipetteButton(), } }); ExpandableContent.AddNode(panel.Widget); panel.Widget.Padding.Right = 12; panel.Widget.Tasks.Add(currentColor.Consume(v => panel.Color = v)); panel.Changed += () => SetProperty(panel.Color); panel.DragStarted += Document.Current.History.BeginTransaction; panel.DragEnded += Document.Current.History.EndTransaction; colorBox.Clicked += () => Expanded = !Expanded; var currentColorString = currentColor.Select(i => i.ToString(Color4.StringPresentation.Dec)); editor.Submitted += text => { Color4 newColor; if (Color4.TryParse(text, out newColor)) { SetProperty(newColor); } else { editor.Text = currentColorString.GetValue(); } }; editor.Tasks.Add(currentColorString.Consume(v => editor.Text = v)); }
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); }