From b727feb70026da73339bc10ad06a2aef90e3ee87 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sat, 16 May 2020 07:17:02 -0400 Subject: [PATCH] rewrite New World Computing scene layout using Universal Editor's Component Designer editor; UWT preliminary implementation --- .../Editors/Designer/DesignerEditor.glade | 30 +++ .../NewWorldComputing/NWCResourceBIN.uexml | 2 +- ...lEditor.Content.PlatformIndependent.csproj | 1 + .../Designer/Controls/DesignerControl.cs | 135 ++++++++++++++ .../Editors/Designer/DesignerEditor.cs | 74 ++++++++ .../Properties/AssemblyInfo.cs | 46 +++++ ...itor.Plugins.Designer.UserInterface.csproj | 70 +++++++ .../ObjectModels/Designer/Component.cs | 33 ++++ .../Designer/ComponentInstance.cs | 17 ++ .../ObjectModels/Designer/Design.cs | 3 + .../Designer/DesignerObjectModel.cs | 5 +- .../ObjectModels/Designer/Property.cs | 25 +++ .../ObjectModels/Designer/PropertyValue.cs | 18 ++ .../UniversalEditor.Plugins.Designer.csproj | 8 + .../NewWorldComputing/BIN/BINComponentType.cs | 32 ++++ .../NewWorldComputing/BIN/BINDataFormat.cs | 173 ++++++++++++++++++ .../NWCSceneLayoutObjectModel.cs | 49 ----- .../NWCSceneLayout/SceneObjectGuids.cs | 30 +++ .../NWCSceneLayout/ScenePropertyGuids.cs | 42 +++++ ...salEditor.Plugins.NewWorldComputing.csproj | 13 +- UniversalEditor.sln | 7 + 21 files changed, 761 insertions(+), 52 deletions(-) create mode 100644 Content/UniversalEditor.Content.PlatformIndependent/Editors/Designer/DesignerEditor.glade create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Editors/Designer/Controls/DesignerControl.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Editors/Designer/DesignerEditor.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Properties/AssemblyInfo.cs create mode 100644 Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/UniversalEditor.Plugins.Designer.UserInterface.csproj create mode 100644 Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/NWCSceneLayout/NewWorldComputing/BIN/BINComponentType.cs create mode 100644 Plugins/UniversalEditor.Plugins.NewWorldComputing/DataFormats/NWCSceneLayout/NewWorldComputing/BIN/BINDataFormat.cs delete mode 100644 Plugins/UniversalEditor.Plugins.NewWorldComputing/ObjectModels/NWCSceneLayout/NWCSceneLayoutObjectModel.cs create mode 100644 Plugins/UniversalEditor.Plugins.NewWorldComputing/ObjectModels/NWCSceneLayout/SceneObjectGuids.cs create mode 100644 Plugins/UniversalEditor.Plugins.NewWorldComputing/ObjectModels/NWCSceneLayout/ScenePropertyGuids.cs diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Editors/Designer/DesignerEditor.glade b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Designer/DesignerEditor.glade new file mode 100644 index 00000000..a52af093 --- /dev/null +++ b/Content/UniversalEditor.Content.PlatformIndependent/Editors/Designer/DesignerEditor.glade @@ -0,0 +1,30 @@ + + + + + + False + + + + + + True + False + vertical + + + UniversalEditor.Plugins.Designer.UserInterface.Editors.Designer.Controls.DesignerControl + True + False + + + True + True + 0 + + + + + + diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/NewWorldComputing/NWCResourceBIN.uexml b/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/NewWorldComputing/NWCResourceBIN.uexml index 814d839c..daba2d24 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/NewWorldComputing/NWCResourceBIN.uexml +++ b/Content/UniversalEditor.Content.PlatformIndependent/Extensions/GameDeveloper/Associations/NewWorldComputing/NWCResourceBIN.uexml @@ -10,7 +10,7 @@ - + diff --git a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj index 9a40e296..c29376fa 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj +++ b/Content/UniversalEditor.Content.PlatformIndependent/UniversalEditor.Content.PlatformIndependent.csproj @@ -733,6 +733,7 @@ + diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Editors/Designer/Controls/DesignerControl.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Editors/Designer/Controls/DesignerControl.cs new file mode 100644 index 00000000..72050432 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Editors/Designer/Controls/DesignerControl.cs @@ -0,0 +1,135 @@ +// +// DesignerControl.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using MBS.Framework.Drawing; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Drawing; +using MBS.Framework.UserInterface.Input.Mouse; +using UniversalEditor.ObjectModels.Designer; + +namespace UniversalEditor.Plugins.Designer.UserInterface.Editors.Designer.Controls +{ + public class DesignerControl : CustomControl + { + private DesignerObjectModel m_ObjectModel = null; + public DesignerObjectModel ObjectModel { get { return m_ObjectModel; } set { m_ObjectModel = value; Refresh(); } } + + private Design _SelectedDesign = null; + public Design SelectedDesign { get { return _SelectedDesign; } set { _SelectedDesign = value; Refresh(); } } + + public ComponentInstance.ComponentInstanceCollection SelectedComponents { get; } = new ComponentInstance.ComponentInstanceCollection(); + + private int margin_x = 13, margin_y = 13, margin_r = 13, margin_b = 13; + + public ComponentInstance HitTest(Vector2D location) + { + for (int i = SelectedDesign.ComponentInstances.Count - 1; i >= 0; i--) + { + ComponentInstance inst = SelectedDesign.ComponentInstances[i]; + if (location.X >= inst.X.Value && location.X <= inst.X.Value + inst.Width.Value && location.Y >= inst.Y.Value && location.Y <= inst.Y.Value + inst.Height.Value) + return inst; + } + return null; + } + + private ComponentInstance dragging = null; + private double cx = 0, cy = 0; + private double dx = 0, dy = 0; + + protected override void OnMouseDown(MouseEventArgs e) + { + base.OnMouseDown(e); + + if (e.Buttons == MouseButtons.Primary || SelectedComponents.Count == 0) + { + ComponentInstance hit = HitTest(e.Location); + if (hit != null) + { + SelectedComponents.Clear(); + SelectedComponents.Add(hit); + Refresh(); + + if (e.Buttons == MouseButtons.Primary) + { + dragging = hit; + cx = e.X; + cy = e.Y; + dx = hit.X.Value; + dy = hit.Y.Value; + } + } + else + { + dragging = null; + } + } + } + protected override void OnMouseMove(MouseEventArgs e) + { + base.OnMouseMove(e); + + if (e.Buttons == MouseButtons.Primary && dragging != null) + { + dragging.X = new ObjectModels.Designer.Measurement(dx + (e.X - cx), ObjectModels.Designer.MeasurementUnit.Pixel); + dragging.Y = new ObjectModels.Designer.Measurement(dy + (e.Y - cy), ObjectModels.Designer.MeasurementUnit.Pixel); + Refresh(); + } + else + { + ComponentInstance hit = HitTest(e.Location); + if (hit != null) + { + Cursor = Cursors.Move; + } + else + { + Cursor = Cursors.Default; + } + } + } + + protected override void OnPaint(PaintEventArgs e) + { + if (m_ObjectModel == null) return; + if (_SelectedDesign == null && m_ObjectModel.Designs.Count > 0) _SelectedDesign = m_ObjectModel.Designs[0]; + if (_SelectedDesign == null) return; + + e.Graphics.DrawRectangle(new Pen(Colors.DarkGray), new Rectangle(margin_x, margin_y, _SelectedDesign.Size.Width - margin_x - margin_r, _SelectedDesign.Size.Height - margin_y - margin_b)); + + for (int i = 0; i < SelectedDesign.ComponentInstances.Count; i++) + { + ComponentInstance inst = SelectedDesign.ComponentInstances[i]; + Rectangle componentRect = new MBS.Framework.Drawing.Rectangle(margin_x + inst.X.Value, margin_y + inst.Y.Value, inst.Width.Value, inst.Height.Value); + inst.Component.Render(inst, e, componentRect); + + if (SelectedComponents.Contains(inst)) + { + e.Graphics.DrawRectangle(new Pen(SystemColors.HighlightBackground), componentRect); + } + else + { + e.Graphics.DrawRectangle(new Pen(Colors.DarkGray), componentRect); + } + } + base.OnPaint(e); + } + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Editors/Designer/DesignerEditor.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Editors/Designer/DesignerEditor.cs new file mode 100644 index 00000000..e8e08f05 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Editors/Designer/DesignerEditor.cs @@ -0,0 +1,74 @@ +// +// DesignerEditor.cs - provides a UWT-based Editor for manipulating component designer layouts +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using MBS.Framework.UserInterface; +using UniversalEditor.ObjectModels.Designer; +using UniversalEditor.UserInterface; + +namespace UniversalEditor.Plugins.Designer.UserInterface.Editors.Designer +{ + /// + /// Provides a UWT-based for manipulating component designer layouts. + /// + [ContainerLayout("~/Editors/Designer/DesignerEditor.glade")] + public class DesignerEditor : Editor + { + private static EditorReference _er = null; + public override EditorReference MakeReference() + { + if (_er == null) + { + _er = base.MakeReference(); + _er.SupportedObjectModels.Add(typeof(DesignerObjectModel)); + } + return _er; + } + + private Controls.DesignerControl designer; + + public override void UpdateSelections() + { + throw new System.NotImplementedException(); + } + + protected override EditorSelection CreateSelectionInternal(object content) + { + throw new System.NotImplementedException(); + } + + protected override void OnCreated(EventArgs e) + { + base.OnCreated(e); + OnObjectModelChanged(EventArgs.Empty); + } + + protected override void OnObjectModelChanged(EventArgs e) + { + base.OnObjectModelChanged(e); + + if (!IsCreated) return; + + DesignerObjectModel dsn = (ObjectModel as DesignerObjectModel); + designer.ObjectModel = dsn; + } + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Properties/AssemblyInfo.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..094ba714 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/Properties/AssemblyInfo.cs @@ -0,0 +1,46 @@ +// +// AssemblyInfo.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2020 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("UniversalEditor.Plugins.Designer.UserInterface")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Mike Becker's Software")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Mike Becker's Software")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/UniversalEditor.Plugins.Designer.UserInterface.csproj b/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/UniversalEditor.Plugins.Designer.UserInterface.csproj new file mode 100644 index 00000000..3c58043f --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Designer.UserInterface/UniversalEditor.Plugins.Designer.UserInterface.csproj @@ -0,0 +1,70 @@ + + + + Debug + AnyCPU + {08168BEA-E652-4493-8D89-5AB72B225841} + Library + UniversalEditor.Plugins.Designer.UserInterface + UniversalEditor.Plugins.Designer.UserInterface + v4.7 + 4.0.2019.12 + + + true + full + false + ..\..\Output\Debug\Plugins + DEBUG; + prompt + 4 + false + + + true + ..\..\Output\Release\Plugins + prompt + 4 + false + + + + + + + + + + + + + + + + + {8622EBC4-8E20-476E-B284-33D472081F5C} + UniversalEditor.UserInterface + + + {2D4737E6-6D95-408A-90DB-8DFF38147E85} + UniversalEditor.Core + + + {30467E5C-05BC-4856-AADC-13906EF4CADD} + UniversalEditor.Essential + + + {899E3DD6-EA65-4168-AAE3-867A4F9650A6} + UniversalEditor.Plugins.Designer + + + {29E1C1BB-3EA5-4062-B62F-85EEC703FE07} + MBS.Framework.UserInterface + + + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C} + MBS.Framework + + + + \ No newline at end of file diff --git a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Component.cs b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Component.cs index a8a35d63..2a9616a3 100644 --- a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Component.cs +++ b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Component.cs @@ -20,6 +20,7 @@ // along with this program. If not, see . using System; +using MBS.Framework.Drawing; namespace UniversalEditor.ObjectModels.Designer { @@ -31,7 +32,31 @@ namespace UniversalEditor.ObjectModels.Designer public class ComponentCollection : System.Collections.ObjectModel.Collection { + public Component this[Guid id] + { + get + { + for (int i = 0; i < Count; i++) + { + if (this[i].ID == id) + return this[i]; + } + return null; + } + } + } + public Component(Guid id, string title, Property[] properties = null, Action renderDelegate = null) + { + ID = id; + Title = title; + if (properties != null) + { + for (int i = 0; i < properties.Length; i++) + Properties.Add(properties[i]); + } + if (renderDelegate != null) + RenderDelegate += renderDelegate; } /// @@ -44,6 +69,14 @@ namespace UniversalEditor.ObjectModels.Designer /// /// The title of this . public string Title { get; set; } = String.Empty; + + public event Action RenderDelegate = null; + + public void Render(ComponentInstance instance, MBS.Framework.UserInterface.PaintEventArgs e, Rectangle bounds) + { + RenderDelegate?.Invoke(instance, e, bounds); + } + /// /// Gets a collection of instances representing properties associated with this . /// diff --git a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/ComponentInstance.cs b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/ComponentInstance.cs index aab6b304..a88f0b6b 100644 --- a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/ComponentInstance.cs +++ b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/ComponentInstance.cs @@ -20,6 +20,7 @@ // along with this program. If not, see . using System; +using MBS.Framework.Drawing; namespace UniversalEditor.ObjectModels.Designer { @@ -34,6 +35,22 @@ namespace UniversalEditor.ObjectModels.Designer } + public ComponentInstance(Component component, Rectangle rectangle, PropertyValue[] propertyValues = null) + { + Component = component; + X = new Measurement(rectangle.X, MeasurementUnit.Pixel); + Y = new Measurement(rectangle.Y, MeasurementUnit.Pixel); + Width = new Measurement(rectangle.Width, MeasurementUnit.Pixel); + Height = new Measurement(rectangle.Height, MeasurementUnit.Pixel); + if (propertyValues != null) + { + for (int i = 0; i < propertyValues.Length; i++) + { + PropertyValues.Add(propertyValues[i]); + } + } + } + /// /// Gets or sets the globally-unique identifier for this . /// diff --git a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Design.cs b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Design.cs index 35d18b89..4657044c 100644 --- a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Design.cs +++ b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Design.cs @@ -19,6 +19,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +using MBS.Framework.Drawing; + namespace UniversalEditor.ObjectModels.Designer { /// @@ -38,5 +40,6 @@ namespace UniversalEditor.ObjectModels.Designer /// The instances of components in this component designer layout. public ComponentInstance.ComponentInstanceCollection ComponentInstances { get; } = new ComponentInstance.ComponentInstanceCollection(); + public Dimension2D Size { get; set; } = new Dimension2D(600, 400); } } diff --git a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/DesignerObjectModel.cs b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/DesignerObjectModel.cs index cf9412c5..62c1ba66 100644 --- a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/DesignerObjectModel.cs +++ b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/DesignerObjectModel.cs @@ -21,6 +21,8 @@ using System; +using MBS.Framework.Drawing; + namespace UniversalEditor.ObjectModels.Designer { /// @@ -31,7 +33,8 @@ namespace UniversalEditor.ObjectModels.Designer public override void Clear() { - throw new NotImplementedException(); + Designs.Clear(); + Libraries.Clear(); } public override void CopyTo(ObjectModel where) diff --git a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Property.cs b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Property.cs index 3fe555d9..b8728be2 100644 --- a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Property.cs +++ b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/Property.cs @@ -19,6 +19,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +using System; + namespace UniversalEditor.ObjectModels.Designer { /// @@ -29,6 +31,29 @@ namespace UniversalEditor.ObjectModels.Designer public class PropertyCollection : System.Collections.ObjectModel.Collection { + public Property this[Guid id] + { + get + { + for (int i = 0; i < Count; i++) + { + if (this[i].ID == id) + return this[i]; + } + return null; + } + } + } + + public Guid ID { get; private set; } = Guid.Empty; + public string Title { get; set; } = String.Empty; + public object DefaultValue { get; set; } = null; + + public Property(Guid id, string title, object defaultValue = null) + { + ID = id; + Title = title; + DefaultValue = defaultValue; } } } diff --git a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/PropertyValue.cs b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/PropertyValue.cs index 9b0ad00d..bb4c4087 100644 --- a/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/PropertyValue.cs +++ b/Plugins/UniversalEditor.Plugins.Designer/ObjectModels/Designer/PropertyValue.cs @@ -29,9 +29,27 @@ namespace UniversalEditor.ObjectModels.Designer public class PropertyValueCollection : System.Collections.ObjectModel.Collection { + public PropertyValue this[Property property] + { + get + { + for (int i = 0; i < Count; i++) + { + if (this[i].Property == property) + return this[i]; + } + return null; + } + } } + public PropertyValue(Property property, object value = null) + { + Property = property; + Value = value; + } + /// /// Gets or sets the property associated with this . /// diff --git a/Plugins/UniversalEditor.Plugins.Designer/UniversalEditor.Plugins.Designer.csproj b/Plugins/UniversalEditor.Plugins.Designer/UniversalEditor.Plugins.Designer.csproj index 3663cc97..7f6ef9c6 100644 --- a/Plugins/UniversalEditor.Plugins.Designer/UniversalEditor.Plugins.Designer.csproj +++ b/Plugins/UniversalEditor.Plugins.Designer/UniversalEditor.Plugins.Designer.csproj @@ -58,6 +58,14 @@ {30467E5C-05BC-4856-AADC-13906EF4CADD} UniversalEditor.Essential + + {00266B21-35C9-4A7F-A6BA-D54D7FDCC25C} + MBS.Framework + + + {29E1C1BB-3EA5-4062-B62F-85EEC703FE07} + MBS.Framework.UserInterface +