Ejemplo n.º 1
0
        //public bool _IsObjectSelected( object obj )
        //{
        //	return _SelectedObjectsSet.Contains( obj );
        //}

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!IsHandleCreated || EditorUtility.IsDesignerHosted(this) || EditorAPI.ClosingApplication)
            {
                return;
            }

            UpdateEnabled();

            //check for DisplayHierarchyOfObjectsInSettingsWindow update
            if (settingsDisplayHierarchyOfObjectsInSettingsWindow != ProjectSettings.Get.DisplayHierarchyOfObjectsInSettingsWindow.Value)
            {
                settingsDisplayHierarchyOfObjectsInSettingsWindow = ProjectSettings.Get.DisplayHierarchyOfObjectsInSettingsWindow.Value;

                DocumentWindow documentWindow     = null;
                ESet <object>  selectedObjectsSet = null;
                if (SelectedPanel != null)
                {
                    documentWindow     = SelectedPanel.documentWindow;
                    selectedObjectsSet = SelectedPanel.selectedObjectsSet;
                }

                RemoveCachedPanels();

                if (selectedObjectsSet != null)
                {
                    SelectObjects(documentWindow, selectedObjectsSet);
                }
            }
        }
Ejemplo n.º 2
0
        public static SettingsProvider Create(DocumentWindow documentWindow, object[] selectedObjects, TableLayoutPanel layoutPanel, object anyData, bool update)
        {
            //create special
            SettingsProvider provider = null;

            CreateProvider?.Invoke(documentWindow, selectedObjects, layoutPanel, anyData, ref provider);

            //create default
            if (provider == null)
            {
                provider = new SettingsProvider(documentWindow, selectedObjects, layoutPanel, anyData);
            }

            if (update)
            {
                try
                {
                    //!!!!
                    layoutPanel.SuspendLayout();

                    provider.PerformUpdate(false);
                }
                finally
                {
                    layoutPanel.ResumeLayout();
                }
            }

            return(provider);
        }
Ejemplo n.º 3
0
        //

        public SettingsProvider(DocumentWindow documentWindow, object[] selectedObjects, TableLayoutPanel layoutPanel, object anyData)
        {
            this.selectedObjects = selectedObjects;
            this.documentWindow  = documentWindow;
            this.layoutPanel     = layoutPanel;
            this.anyData         = anyData;

            this.layoutPanel.Tag = this;
        }
Ejemplo n.º 4
0
        internal static void SelectedDocumentWindowChangedUpdate()
        {
            var selected = SelectedDocumentWindow;

            if (lastSelectedDocumentWindow != selected)
            {
                lastSelectedDocumentWindow = selected;
                SelectedDocumentWindowChanged?.Invoke();
            }
        }
            public static WindowConfig FromDocumentWindow(DocumentWindow window)
            {
                var obj = (Component)window.ObjectOfWindow;

                return(new WindowConfig()
                {
                    OpenAsSettings = window.OpenAsSettings,
                    ObjectPath = obj.GetPathFromRoot()
                });
            }
Ejemplo n.º 6
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!IsHandleCreated || WinFormsUtility.IsDesignerHosted(this) || EditorAPI.ClosingApplication)
            {
                return;
            }
            if (KryptonPage == null || KryptonPage.Parent == null)
            {
                return;
            }

            if (selectedPanel != null)
            {
                selectedPanel.layoutPanel.Enabled = GetEnabledForSelectedPanel();
            }

            //check for DisplayHierarchyOfObjectsInSettingsWindow update
            if (settingsDisplayHierarchyOfObjectsInSettingsWindow != ProjectSettings.Get.DisplayHierarchyOfObjectsInSettingsWindow.Value)
            {
                settingsDisplayHierarchyOfObjectsInSettingsWindow = ProjectSettings.Get.DisplayHierarchyOfObjectsInSettingsWindow.Value;

                DocumentWindow documentWindow     = null;
                ESet <object>  selectedObjectsSet = null;
                if (SelectedPanel != null)
                {
                    documentWindow     = SelectedPanel.documentWindow;
                    selectedObjectsSet = SelectedPanel.selectedObjectsSet;
                }

                RemoveCachedPanels();

                if (selectedObjectsSet != null)
                {
                    SelectObjects(documentWindow, selectedObjectsSet);
                }
            }

            //recreate panels
            if (needRecreatePanels)
            {
                var      documentWindow  = needRecreatePanelsDocumentWindow;
                object[] selectedObjects = needRecreatePanelsSelectObjects;

                needRecreatePanels = false;
                needRecreatePanelsDocumentWindow = null;
                needRecreatePanelsSelectObjects  = null;

                RemoveCachedPanels();

                if (selectedObjects != null)
                {
                    SelectObjects(documentWindow, selectedObjects);
                }
            }
        }
 public PanelData GetPanel(DocumentWindow documentWindow)
 {
     if (documentWindow != null)
     {
         PanelData panel;
         if (panelByDocumentWindow.TryGetValue(documentWindow, out panel))
         {
             return(panel);
         }
     }
     return(null);
 }
Ejemplo n.º 8
0
        void SelectItemsOfSelectedObjects(DocumentWindow documentWindow)
        {
            var panel = GetPanel(documentWindow);

            if (panel != null)
            {
                var browser = panel.control as ContentBrowser;
                if (browser != null)
                {
                    var items = new List <ContentBrowser.Item>();

                    if (documentWindow.SelectedObjects.Length != 0)
                    {
                        //precreate and expand all parents' items
                        {
                            var allParents = new ESet <Component>();
                            foreach (var obj in documentWindow.SelectedObjects)
                            {
                                var c = obj as Component;
                                if (c != null)
                                {
                                    allParents.AddRangeWithCheckAlreadyContained(c.GetAllParents(false));
                                }
                            }
                            foreach (var c in allParents)
                            {
                                var i = browser.FindItemByContainedObject(c);
                                if (i != null)
                                {
                                    browser.SelectItems(new ContentBrowser.Item[] { i }, true, false);
                                }
                            }
                        }

                        //get items to select
                        foreach (var item in browser.GetAllItems())
                        {
                            var componentItem = item as ContentBrowserItem_Component;
                            if (componentItem != null && documentWindow.SelectedObjectsSet.Contains(componentItem.Component))
                            {
                                items.Add(item);
                            }
                        }
                    }

                    browser.SelectItems(items.ToArray(), items.Count == 1);
                    //browser.SelectItems( items.ToArray() );
                }
            }
        }
Ejemplo n.º 9
0
        protected override void OnKryptonPageParentChanged()
        {
            base.OnKryptonPageParentChanged();

            //recreate panels when parent of KryptonPage was changed. need to restore _COMPOSITED flag, working tooltips
            if (KryptonPage != null && KryptonPage.Parent == null)
            {
                if (SelectedPanel != null)
                {
                    needRecreatePanels = true;
                    needRecreatePanelsDocumentWindow = SelectedPanel.documentWindow;
                    needRecreatePanelsSelectObjects  = SelectedPanel.selectedObjectsSet.ToArray();

                    RemoveCachedPanels();
                }
            }
        }
Ejemplo n.º 10
0
        public virtual void Finish(bool cancel)
        {
            if (!cancel)
            {
                //add to undo with deletion
                var document = DocumentWindow.Document;
                var action   = new UndoActionComponentCreateDelete(document, new Component[] { CreatingObject }, true);
                document.UndoSystem.CommitAction(action);
                document.Modified = true;
            }
            else
            {
                CreatingObject?.Dispose();
                documentWindow.SelectObjects(null);
            }

            DocumentWindow.ObjectCreationModeSet(null);
        }
        PanelData CreatePanel(DocumentWindow documentWindow, bool willSelected)
        {
            PanelData panel = new PanelData();

            panel.documentWindow = documentWindow;

            panels.Add(panel);
            panelByDocumentWindow.Add(panel.documentWindow, panel);

            //create control
            OnCreatePanelControl(panel);

            if (!willSelected && panel.control != null)
            {
                panel.control.Visible = false;
                panel.control.Enabled = false;
            }

            return(panel);
        }
Ejemplo n.º 12
0
        PanelData CreatePanel(DocumentWindow document, object[] key, bool willSelected)
        {
            PanelData panel = new PanelData();

            panels.Add(panel);
            panel.selectedObjects = key;

            panel.CreateAndAddPanel(this);

            //hide
            if (!willSelected && panel.layoutPanel != null)
            {
                panel.layoutPanel.Visible = false;
                panel.layoutPanel.Enabled = false;
            }

            SettingsProvider.Create(document, panel.selectedObjects, panel.layoutPanel, null, true);

            return(panel);
        }
Ejemplo n.º 13
0
        public static void OpenSetReferenceWindow(DocumentWindow documentWindow, Component[] selectedComponents, object[] propertyOwners, Metadata.Property property, object[] propertyIndexes)
        //, Metadata.TypeInfo demandedType, bool allowNull )
        {
            //!!!!

            var window = new SetReferenceWindow();

            window.documentWindow = documentWindow;

            var data = new ContentBrowser.SetReferenceModeDataClass();

            data.selectedComponents     = selectedComponents;
            data.propertyOwners         = propertyOwners;
            data.property               = property;
            data.propertyIndexes        = propertyIndexes;
            window.setReferenceModeData = data;

            //!!!!начальное положение, настройки. везде так

            EditorForm.Instance.WorkspaceController.AddDockWindow(window, true, true);
        }
Ejemplo n.º 14
0
        public void SetData(DocumentWindow documentWindow, object[] objects, bool callPerformUpdate = true)
        {
            this.documentWindow  = documentWindow;
            this.selectedObjects = objects;

            if (callPerformUpdate)
            {
                PerformUpdate(true);
            }

            //start timer
            timer50ms?.Start();

            //if( callPerformUpdate )
            //	PerformUpdate();
            //else
            //{
            //	//start timer
            //	timer50ms?.Start();
            //}
        }
Ejemplo n.º 15
0
        //!!!!по сути не надо указывать documentWindow
        public static void SelectComponentsInMainObjectsWindow(DocumentWindow documentWindow, Component[] components)
        //public static void SelectComponentsInMainObjectsWindow( DocumentInstance document, Component[] components )
        {
            if (documentWindow == null || components.Length == 0)
            {
                return;
            }

            var window = FindWindow <ObjectsWindow>();

            if (window != null && window.Visible)
            {
                var panel = window.GetPanel(documentWindow);
                if (panel != null)
                {
                    var browser = panel.control as ContentBrowser;
                    if (browser != null)
                    {
                        ContentBrowserUtility.SelectComponentItems(browser, components);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        protected override bool OnKeyDown(Viewport viewport, KeyEvent e)
        {
            if (toolModify && e.Key == EKeys.Escape)
            {
                StopToolModify(true);
                return(true);
            }

            //disable workarea mode by Space or Escape
            if ((e.Key == EKeys.Space || e.Key == EKeys.Escape) && !toolModify)
            {
                DocumentWindow.ResetWorkareaMode();
                return(true);
            }

            //disable shortcuts
            if (toolModify)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 17
0
        public void SelectObjects(DocumentWindow document, IList <object> objects)
        {
            if (EditorAPI.ClosingApplication)
            {
                return;
            }

            object[] key = new object[objects.Count];
            objects.CopyTo(key, 0);

            PanelData panel = GetPanel(key);

            //find cached panel
            if (panel != null)
            {
                //move to last position (best priority)
                panels.Remove(panel);
                panels.Add(panel);
            }

            //create new panel
            if (panel == null)
            {
                //remove cached
                while (panels.Count >= maxCachedCount)
                {
                    RemovePanel(panels[0]);
                }

                panel = CreatePanel(document, key, true);
            }

            SelectedPanel = panel;

            //!!!!!
        }
Ejemplo n.º 18
0
        protected override bool OnMouseDown(Viewport viewport, EMouseButtons button)
        {
            if (button == EMouseButtons.Left)
            {
                if (GetToolPosition(viewport, out var terrain, out toolModifyStartPosition))
                {
                    var layer = DocumentWindow.TerrainPaintLayersGetSelected();

                    if (IsCurrentPaintTool() && layer != null)
                    {
                        if (layer.Mask.Value != null && layer.Mask.Value.Length != 0)
                        {
                            if (layer.Mask.Value.Length != terrain.GetPaintMaskSizeInteger() * terrain.GetPaintMaskSizeInteger())
                            {
                                EditorMessageBox.ShowWarning(EditorLocalization.Translate("Terrain", "Unable to paint to selected layer because Mask size of the layer and MaskSize of the terrain are not equal."));
                                return(true);
                            }
                        }
                    }

                    if (mode == ModeEnum.PaintFlatten)
                    {
                        if (layer != null)
                        {
                            Vector2I maskIndex = terrain.GetMaskIndexByPosition(toolModifyStartPosition.ToVector2());
                            toolModifyStartMaskValue = layer.GetMaskValue(maskIndex);
                        }
                    }

                    toolModify = true;
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 19
0
        public static void AddCollision(DocumentWindow documentWindow, string collisionName)
        {
            const string bodyName = "Collision Definition";

            var mesh = documentWindow.ObjectOfWindow as Component_Mesh;

            var body = mesh.CreateComponent <Component_RigidBody>(enabled: false);

            body.Name = bodyName;
            //collision.CanCreate = false;

            body.MotionType = Component_RigidBody.MotionTypeEnum.Static;

            string error = null;

            //!!!!plugin support to add new or override current implementations

            switch (collisionName)
            {
            case "Box":
            {
                var shape  = body.CreateComponent <Component_CollisionShape_Box>();
                var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                shape.TransformRelativeToParent = new Transform(bounds.GetCenter(), Quaternion.Identity);
                shape.Dimensions = bounds.GetSize();
            }
            break;

            case "Sphere":
            {
                var shape  = body.CreateComponent <Component_CollisionShape_Sphere>();
                var sphere = mesh.Result.SpaceBounds.CalculatedBoundingSphere;
                shape.TransformRelativeToParent = new Transform(sphere.Origin, Quaternion.Identity);
                shape.Radius = sphere.Radius;
            }
            break;

            case "Capsule":
            {
                var shape  = body.CreateComponent <Component_CollisionShape_Capsule>();
                var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                shape.TransformRelativeToParent = new Transform(bounds.GetCenter(), Quaternion.Identity);
                shape.Radius = Math.Max(bounds.GetSize().X, bounds.GetSize().Y) / 2;
                shape.Height = Math.Max(bounds.GetSize().Z - shape.Radius * 2, 0);
            }
            break;

            case "Cylinder":
            {
                var shape  = body.CreateComponent <Component_CollisionShape_Cylinder>();
                var bounds = mesh.Result.SpaceBounds.CalculatedBoundingBox;
                shape.TransformRelativeToParent = new Transform(bounds.GetCenter(), Quaternion.Identity);
                shape.Radius = Math.Max(bounds.GetSize().X, bounds.GetSize().Y) / 2;
                shape.Height = bounds.GetSize().Z;
            }
            break;

            case "Convex":
            {
                var shape = body.CreateComponent <Component_CollisionShape_Mesh>();
                shape.ShapeType = Component_CollisionShape_Mesh.ShapeTypeEnum.Convex;
                shape.Mesh      = ReferenceUtility.MakeThisReference(shape, mesh);
            }
            break;

            case "Convex Decomposition":
            {
                var settings = new ConvexDecomposition.Settings();

                var form = new SpecifyParametersForm("Convex Decomposition", settings);
                form.CheckHandler = delegate(ref string error2)
                {
                    //!!!!
                    return(true);
                };
                if (form.ShowDialog() != DialogResult.OK)
                {
                    mesh.RemoveComponent(body, false);
                    return;
                }

                var clusters = ConvexDecomposition.Decompose(mesh.Result.ExtractedVerticesPositions, mesh.Result.ExtractedIndices, settings);

                if (clusters == null)
                {
                    mesh.RemoveComponent(body, false);
                    Log.Warning("Unable to decompose.");
                    return;
                }

                foreach (var cluster in clusters)
                {
                    var shape = body.CreateComponent <Component_CollisionShape_Mesh>();
                    shape.Vertices  = cluster.Vertices;
                    shape.Indices   = cluster.Indices;
                    shape.ShapeType = Component_CollisionShape_Mesh.ShapeTypeEnum.Convex;
                }
            }
            break;

            case "Mesh":
            {
                var shape = body.CreateComponent <Component_CollisionShape_Mesh>();
                shape.Mesh = ReferenceUtility.MakeThisReference(shape, mesh);
            }
            break;

            default:
                error = "No implementation.";
                break;
            }

            if (!string.IsNullOrEmpty(error))
            {
                mesh.RemoveComponent(body, false);
                Log.Warning(error);
                return;
            }

            body.Enabled = true;

            var undoActions = new List <UndoSystem.Action>();

            undoActions.Add(new UndoActionComponentCreateDelete(documentWindow.Document, new Component[] { body }, true));

            //enable EditorDisplayCollision
            if (!mesh.EditorDisplayCollision)
            {
                mesh.EditorDisplayCollision = true;

                var property = (Metadata.Property)mesh.MetadataGetMemberBySignature("property:EditorDisplayCollision");
                var undoItem = new UndoActionPropertiesChange.Item(mesh, property, false, new object[0]);
                undoActions.Add(new UndoActionPropertiesChange(new UndoActionPropertiesChange.Item[] { undoItem }));
            }

            documentWindow.Document.UndoSystem.CommitAction(new UndoMultiAction(undoActions));
            documentWindow.Document.Modified = true;
        }
Ejemplo n.º 20
0
        PanelData CreatePanel(DocumentWindow documentWindow, object[] key, bool willSelected)
        {
            PanelData panel = new PanelData();

            panels.Add(panel);
            panel.selectedObjects = key;
            panel.CreateAndAddPanel(panelSettings);

            //hide
            if (!willSelected && panel.layoutPanel != null)
            {
                panel.layoutPanel.Visible = false;
                panel.layoutPanel.Enabled = false;
            }

            SettingsProvider.Create(documentWindow, panel.selectedObjects, panel.layoutPanel, null, true);

            //!!!!!было
            ////init panel
            //if( panel.selectedObjects != null && panel.selectedObjects.Length != 0 )//!!!!так?
            //{
            //try
            //{
            //	//!!!!
            //	//!!!!может раньше
            //	//!!!!где еще такое
            //	layoutPanel.SuspendLayout();

            //	//!!!!!

            //	//if( clear )
            //	//	Clear();

            //	//UpdateBegin?.Invoke( this );
            //	//AllProviders_UpdateBegin?.Invoke( this );

            //	//OnUpdate();

            //	xx xx;

            //	{
            //		var header = new SettingsHeader_ObjectInfo();
            //		header.Anchor = AnchorStyles.Left | AnchorStyles.Right;
            //		layoutPanel.Controls.Add( header );
            //	}

            //	{
            //		var header = new SettingsHeader_Components();
            //		header.Anchor = AnchorStyles.Left | AnchorStyles.Right;
            //		layoutPanel.Controls.Add( header );

            //		//!!!!!

            //		////!!!!не так видать. надо не создавать совсем контрол
            //		//bool showComponents = false;

            //		//if( panel.selectedObjects.Length == 1 )
            //		//{
            //		//	var obj = panel.selectedObjects[ 0 ] as Component;
            //		//	if( obj != null && obj.ShowComponentsInSettings )
            //		//		showComponents = true;
            //		//}

            //		////!!!!!
            //		//if( !showComponents )
            //		//	header.Visible = false;
            //	}

            //	//!!!!
            //	//separator
            //	{
            //		var header = new GroupBox();
            //		header.Size = new Size( 20, 20 );
            //		header.Anchor = AnchorStyles.Left | AnchorStyles.Right;
            //		layoutPanel.Controls.Add( header );
            //	}

            //	{
            //		var window = new SettingsLevel2Window();
            //		window.Dock = DockStyle.Fill;
            //		layoutPanel.Controls.Add( window );
            //	}

            //	//select root of level 2
            //	//!!!!всегда Component? если нет, то и окна этого нет
            //	xx xx;
            //	if( panel.GetControl<SettingsHeader_Components>() != null )
            //		panel.GetControl<SettingsHeader_Components>().SelectObjects( new Component[] { (Component)panel.selectedObjects[ 0 ] } );

            //	//UpdateEnd?.Invoke( this );
            //	//AllProviders_UpdateEnd?.Invoke( this );

            //	//provider.PerformUpdate( false );
            //}
            //finally
            //{
            //	layoutPanel.ResumeLayout();
            //}
            //}

            return(panel);
        }
Ejemplo n.º 21
0
        public override void OnDocumentWindowSelectedObjectsChangedByUser(DocumentWindow documentWindow)
        {
            base.OnDocumentWindowSelectedObjectsChangedByUser(documentWindow);

            SelectItemsOfSelectedObjects(documentWindow);
        }
 public virtual void OnDocumentWindowSelectedObjectsChangedByUser(DocumentWindow documentWindow)
 {
     //!!!!new
     UpdatePanels();
 }
Ejemplo n.º 23
0
        protected virtual void ToolPutTickPaint(Viewport viewport, double delta)
        {
            if (!GetToolPosition(viewport, out var selectedTerrain, out var position))
            {
                return;
            }

            var layer = DocumentWindow.TerrainPaintLayersGetSelected();

            if (layer == null)
            {
                return;
            }

            var toolRadius    = (float)Component_Scene_DocumentWindow.TerrainToolRadius;
            var toolHardness  = (float)Component_Scene_DocumentWindow.TerrainToolHardness;
            var toolShapeType = Component_Scene_DocumentWindow.TerrainToolShape;

            float strength = (float)(delta * Component_Scene_DocumentWindow.TerrainToolStrength * toolRadius * 0.5 * 2.0);

            Vector2 positionMin = position.ToVector2() - new Vector2(toolRadius, toolRadius);
            Vector2 positionMax = position.ToVector2() + new Vector2(toolRadius, toolRadius);

            List <Component_Terrain> terrains;

            //!!!!
            //if( selectedTerrain.HeightmapTerrainManager != null && HeightmapTerrainManager.Instance != null )
            //{
            //	terrains = HeightmapTerrainManager.Instance.GetTerrainsByArea( positionMin, positionMax, true );
            //}
            //else
            //{
            terrains = new List <Component_Terrain>();
            terrains.Add(selectedTerrain);
            //}

            foreach (var terrain in terrains)
            {
                UndoActionPropertiesChange undoSetPropertyAction = paintSetPropertyUndoActions.Find(a => a.Items[0].Obj == layer);
                var undoChangeAction = paintChangeUndoActions.Find(a => a.Terrain == terrain);

                Vector2I indexMin = terrain.GetMaskIndexByPosition(positionMin);
                Vector2I indexMax = terrain.GetMaskIndexByPosition(positionMax) + new Vector2I(1, 1);
                terrain.ClampMaskIndex(ref indexMin);
                terrain.ClampMaskIndex(ref indexMax);

                for (int y = indexMin.Y; y <= indexMax.Y; y++)
                {
                    for (int x = indexMin.X; x <= indexMax.X; x++)
                    {
                        Vector2 point = terrain.GetPositionXYByMaskIndex(new Vector2I(x, y));

                        float coef;
                        {
                            double length;
                            if (toolShapeType == ToolShape.Circle)
                            {
                                length = (point - position.ToVector2()).Length();
                            }
                            else
                            {
                                length = Math.Max(Math.Abs(point.X - position.X), Math.Abs(point.Y - position.Y));
                            }

                            if (length >= toolRadius)
                            {
                                coef = 0;
                            }
                            else if (length == 0)
                            {
                                coef = 1;
                            }
                            else if (length <= toolHardness * toolRadius)
                            {
                                coef = 1;
                            }
                            else
                            {
                                double c;
                                if (toolRadius - toolRadius * toolHardness != 0)
                                {
                                    c = (length - toolRadius * toolHardness) / (toolRadius - toolRadius * toolHardness);
                                }
                                else
                                {
                                    c = 0;
                                }
                                coef = (float)Math.Cos(Math.PI / 2 * c);
                            }
                        }

                        if (coef != 0)
                        {
                            float oldValue = layer.GetMaskValue(new Vector2I(x, y));

                            float value = oldValue;

                            //near corner (x == 0 or y == 0) take value from near terrain.
                            bool takeValueFromNearTerrain = false;
                            //!!!!
                            //if( selectedTerrain.HeightmapTerrainManager != null && HeightmapTerrainManager.Instance != null )
                            //{
                            //	if( x == 0 )
                            //	{
                            //		HeightmapTerrain terrain2 =
                            //			FindTerrainWithIndex( terrains, terrain.HeightmapTerrainManagerIndex - new Vector2I( 1, 0 ) );
                            //		if( terrain2 != null )
                            //		{
                            //			value = terrain2.GetHeight( terrain.GetPositionXY( new Vector2I( x, y ) ), false ) + terrain2.Position.Z;
                            //			value -= terrain.Position.Z;

                            //			takeValueFromNearTerrain = true;
                            //		}
                            //	}
                            //	else if( y == 0 )
                            //	{
                            //		HeightmapTerrain terrain2 =
                            //			FindTerrainWithIndex( terrains, terrain.HeightmapTerrainManagerIndex - new Vector2I( 0, 1 ) );
                            //		if( terrain2 != null )
                            //		{
                            //			value = terrain2.GetHeight( terrain.GetPositionXY( new Vector2I( x, y ) ), false ) + terrain2.Position.Z;
                            //			value -= terrain.Position.Z;

                            //			takeValueFromNearTerrain = true;
                            //		}
                            //	}
                            //}

                            if (!takeValueFromNearTerrain)
                            {
                                switch (mode)
                                {
                                case ModeEnum.PaintPaint:
                                case ModeEnum.PaintClear:
                                {
                                    bool paint = mode == ModeEnum.PaintPaint;
                                    if ((Form.ModifierKeys & Keys.Shift) != 0)
                                    {
                                        paint = !paint;
                                    }

                                    if (paint)
                                    {
                                        value = oldValue + strength * coef;
                                    }
                                    else
                                    {
                                        value = oldValue - strength * coef;
                                    }
                                }
                                break;

                                case ModeEnum.PaintSmooth:
                                {
                                    float needValue = 0;
                                    {
                                        needValue += layer.GetMaskValue(new Vector2I(x - 1, y));
                                        needValue += layer.GetMaskValue(new Vector2I(x + 1, y));
                                        needValue += layer.GetMaskValue(new Vector2I(x, y - 1));
                                        needValue += layer.GetMaskValue(new Vector2I(x, y + 1));
                                        //needValue += layer.GetMaskValue( GetClampedMaskIndex( terrain, new Vec2I( x - 1, y ) ) );
                                        //needValue += layer.GetMaskValue( GetClampedMaskIndex( terrain, new Vec2I( x + 1, y ) ) );
                                        //needValue += layer.GetMaskValue( GetClampedMaskIndex( terrain, new Vec2I( x, y - 1 ) ) );
                                        //needValue += layer.GetMaskValue( GetClampedMaskIndex( terrain, new Vec2I( x, y + 1 ) ) );
                                        needValue /= 4;
                                    }

                                    if (oldValue < needValue)
                                    {
                                        value = oldValue + strength * coef;
                                        if (value > needValue)
                                        {
                                            value = needValue;
                                        }
                                    }
                                    else if (oldValue > needValue)
                                    {
                                        value = oldValue - strength * coef;
                                        if (value < needValue)
                                        {
                                            value = needValue;
                                        }
                                    }
                                }
                                break;

                                case ModeEnum.PaintFlatten:
                                {
                                    float needValue = toolModifyStartMaskValue;

                                    if (oldValue < needValue)
                                    {
                                        value = oldValue + strength * coef;
                                        if (value > needValue)
                                        {
                                            value = needValue;
                                        }
                                    }
                                    else if (oldValue > needValue)
                                    {
                                        value = oldValue - strength * coef;
                                        if (value < needValue)
                                        {
                                            value = needValue;
                                        }
                                    }
                                }
                                break;
                                }
                            }

                            MathEx.Clamp(ref value, 0, 1);

                            if (oldValue != value)
                            {
                                //undo
                                if (layer.Mask.Value == null || layer.Mask.Value.Length == 0 || undoSetPropertyAction != null)
                                {
                                    if (undoSetPropertyAction == null)
                                    {
                                        var oldValue2 = layer.Mask;

                                        layer.Mask = new byte[terrain.GetPaintMaskSizeInteger() * terrain.GetPaintMaskSizeInteger()];

                                        var property = (Metadata.Property)layer.MetadataGetMemberBySignature("property:Mask");
                                        var undoItem = new UndoActionPropertiesChange.Item(layer, property, oldValue2);
                                        undoSetPropertyAction = new UndoActionPropertiesChange(undoItem);
                                        paintSetPropertyUndoActions.Add(undoSetPropertyAction);
                                    }
                                }
                                else
                                {
                                    if (undoChangeAction == null)
                                    {
                                        undoChangeAction = new Component_Terrain_PaintChangeUndoAction(terrain);
                                        paintChangeUndoActions.Add(undoChangeAction);
                                    }
                                    undoChangeAction.SaveValue(layer, new Vector2I(x, y), oldValue);
                                }

                                //update terrain
                                layer.SetMaskValue(new Vector2I(x, y), value);
                            }
                        }
                    }
                }

                //!!!!use mask indexes
                //var updateRectangle = new RectangleI( indexMin, indexMax );

                //terrain.UpdateRenderingData( updateRectangle, false );

                //bool foundItemForTerrain = false;
                //foreach( var updateItem in needUpdateRectangle )
                //{
                //	if( updateItem.Terrain == terrain )
                //	{
                //		updateItem.Rectangle.Add( updateRectangle );
                //		foundItemForTerrain = true;
                //		break;
                //	}
                //}
                //if( !foundItemForTerrain )
                //{
                //	NeedUpdateRectangleItem item = new NeedUpdateRectangleItem();
                //	item.Terrain = terrain;
                //	item.Rectangle = updateRectangle;
                //	needUpdateRectangle.Add( item );
                //}
            }
        }
Ejemplo n.º 24
0
 public ObjectCutCopyPasteData(DocumentWindow documentWindow, bool cut, object[] objects)
 {
     this.documentWindow = documentWindow;
     this.cut            = cut;
     this.objects        = objects;
 }
Ejemplo n.º 25
0
 public ObjectsInFocus(/*DockWindow dockWindow,*/ DocumentWindow documentWindow, object[] objects)
 {
     //this.dockWindow = dockWindow;
     this.DocumentWindow = documentWindow;
     this.Objects        = objects;
 }
Ejemplo n.º 26
0
 private void DocumentWindowWithViewport_CanvasBasedEditor_SelectedObjectsChanged(DocumentWindow sender, object[] oldSelectedObjects)
 {
     editor.PerformSelectedObjectsChanged(oldSelectedObjects);
 }
Ejemplo n.º 27
0
        public void SelectObjects(DocumentWindow documentWindow, ICollection <object> objects)
        {
            if (EditorAPI.ClosingApplication)
            {
                return;
            }
            //!!!!new
            var document = documentWindow?.Document;

            if (document != null && document.Destroyed)
            {
                return;
            }

            if (objects == null)
            {
                objects = new object[0];
            }

            object[] key = new object[objects.Count];
            objects.CopyTo(key, 0);

            PanelData panel = GetPanel(key);

            //find cached panel
            if (panel != null)
            {
                //move to last position (best priority)
                panels.Remove(panel);
                panels.Add(panel);
            }

            //create new panel
            if (panel == null)
            {
                //remove cached
                while (panels.Count >= maxCachedCount)
                {
                    RemovePanel(panels[0]);
                }

                panel = CreatePanel(documentWindow, key);                  //, true );
            }

            //select first object
            if (panel.selectedObjects != null && panel.selectedObjects.Length != 0)             //!!!!так?
            {
                bool allComponentsSelected = Array.TrueForAll(panel.selectedObjects, obj => obj is Component);
                if (allComponentsSelected)
                {
                    //select root of level 2
                    //!!!!всегда Component? если нет, то и окна этого нет

                    var list = new List <Component>();
                    foreach (var obj in panel.selectedObjects)
                    {
                        list.Add((Component)obj);
                    }
                    panel.GetControl <SettingsHeader_Components>()?.SelectObjects(list.ToArray());

                    //panel.GetControl<SettingsHeader_Components>()?.SelectObjects( new Component[] { (Component)panel.selectedObjects[ 0 ] } );
                }
            }

            SelectedPanel = panel;
        }
Ejemplo n.º 28
0
        PanelData CreatePanel(DocumentWindow documentWindow, object[] key)          //, bool willSelected )
        {
            PanelData panel = new PanelData();

            panels.Add(panel);
            panel.documentWindow     = documentWindow;
            panel.selectedObjects    = key;
            panel.selectedObjectsSet = new ESet <object>(panel.selectedObjects);

            panel.CreateAndAddPanel(this);

            ////hide
            //if( !willSelected && panel.layoutPanel != null )
            //{
            //	panel.layoutPanel.Visible = false;
            //	panel.layoutPanel.Enabled = false;
            //}

            //init panel
            if (panel.selectedObjects != null && panel.selectedObjects.Length != 0)             //!!!!так?
            {
                //no sense. same speed
                //bool canSuspendLayout = !ProjectSettings.Get.DisplayHierarchyOfObjectsInSettingsWindow.Value;

                try
                {
                    //!!!!
                    //!!!!может раньше

                    //if( canSuspendLayout )
                    //	panel.layoutPanel.SuspendLayout();

                    //!!!! отключено. для правильного расчёта splitContainer.SplitterDistance. см ниже.
                    //layoutPanel.SuspendLayout();

                    //!!!!!

                    //if( clear )
                    //	Clear();

                    //UpdateBegin?.Invoke( this );
                    //AllProviders_UpdateBegin?.Invoke( this );

                    //OnUpdate();


                    var objInfoHeader = new SettingsHeader_ObjectInfo();
                    objInfoHeader.Dock = DockStyle.Fill;
                    panel.layoutPanel.Controls.Add(objInfoHeader);

                    bool allComponentsSelected = Array.TrueForAll(panel.selectedObjects, obj => obj is Component);
                    if (allComponentsSelected)
                    {
                        if (ProjectSettings.Get.DisplayHierarchyOfObjectsInSettingsWindow.Value)
                        {
                            //with components hierarchy on second level

                            var splitContainer = new KryptonSplitContainer();
                            splitContainer.SplitterWidth = 8;
                            splitContainer.Orientation   = Orientation.Horizontal;
                            splitContainer.Dock          = DockStyle.Fill;
                            DarkThemeUtility.ApplyToSplitter(splitContainer);
                            panel.layoutPanel.Controls.Add(splitContainer);

                            {
                                var componentsHeader = new SettingsHeader_Components();
                                //header.Init( documentWindow );
                                componentsHeader.Dock = DockStyle.Fill;
                                splitContainer.Panel1.Controls.Add(componentsHeader);

                                // components panel autosize.
                                float splitterPercent = (float)componentsHeader.CalculateHeight() / splitContainer.Height;
                                float minCoef         = 0.33f;
                                if (splitterPercent < minCoef)
                                {
                                    splitContainer.SplitterDistance = componentsHeader.CalculateHeight() + 25;
                                }
                                else
                                {
                                    splitContainer.SplitterDistance = (int)(splitContainer.Height * minCoef);
                                }
                            }

                            {
                                var window = new SettingsLevel2Window();
                                window.Dock = DockStyle.Fill;
                                splitContainer.Panel2.Controls.Add(window);
                            }

                            //теперь ниже
                            ////select root of level 2
                            ////!!!!всегда Component? если нет, то и окна этого нет
                            //panel.GetControl<SettingsHeader_Components>()?.SelectObjects( new Component[] { (Component)panel.selectedObjects[ 0 ] } );

                            //UpdateEnd?.Invoke( this );
                            //AllProviders_UpdateEnd?.Invoke( this );

                            //provider.PerformUpdate( false );
                        }
                        else
                        {
                            //without components hierarchy on second level

                            var window = new SettingsLevel2Window();
                            window.Dock = DockStyle.Fill;
                            panel.layoutPanel.Controls.Add(window);

                            window.SelectObjects(panel.documentWindow, panel.selectedObjects);
                        }
                    }
                    else
                    {
                        //not components. can be flowchart Connector.

                        //!!!!можно показать свойства в гриде read only
                    }
                }
                finally
                {
                    //if( canSuspendLayout )
                    //	panel.layoutPanel.ResumeLayout();

                    //!!!! отключено. для правильного расчёта splitContainer.SplitterDistance
                    //layoutPanel.ResumeLayout();
                }
            }

            return(panel);
        }