void SetFrom(ShapeCollectionSave shapeCollectionSave)
        {
            Clear();

            foreach(var saveObject in shapeCollectionSave.AxisAlignedRectangleSaves)
            {
                var runtime = saveObject.ToAxisAlignedRectangle();

                var vm = new AxisAlignedRectangleViewModel(runtime);

                Rectangles.Add(vm);
            }

            foreach (var saveObject in shapeCollectionSave.CircleSaves)
            {
                var runtime = saveObject.ToCircle();

                var vm = new CircleViewModel(runtime);

                Circles.Add(vm);
            }

            foreach(var saveObject in shapeCollectionSave.PolygonSaves)
            {
                var runtime = saveObject.ToPolygon();

                var vm = new PolygonViewModel(runtime);

                Polygons.Add(vm);
            }


        }
Example #2
0
        /// <summary>
        /// Deserializes a file into a new ShapeCollectionSave and returns it.
        /// </summary>
        /// <param name="fileName">The absolute or relative file name. If the file name is relative, then the FileManager's RelativeDirectory will be used.</param>
        /// <returns>The newly-created ShapeCollectionSave.</returns>
        public static ShapeCollectionSave FromFile(string fileName)
        {
            ShapeCollectionSave shapeSaveCollection =
                FileManager.XmlDeserialize <ShapeCollectionSave>(fileName);

            shapeSaveCollection.mFileName = fileName;

            return(shapeSaveCollection);
        }
Example #3
0
        public static ShapeCollectionSave FromShapeCollection(ShapeCollection shapeCollection)
        {
            ShapeCollectionSave toReturn = new ShapeCollectionSave();

            toReturn.AddAxisAlignedRectangleList(shapeCollection.AxisAlignedRectangles);
            toReturn.AddAxisAlignedCubeList(shapeCollection.AxisAlignedCubes);
            toReturn.AddCircleList(shapeCollection.Circles);
            toReturn.AddSphereList(shapeCollection.Spheres);
            toReturn.AddPolygonList(shapeCollection.Polygons);

            if (shapeCollection.Lines.Count != 0)
            {
                throw new NotImplementedException("Lines in ShapeCollectionSaves are not implemented yet.  Complain on the FRB forums");
            }

            if (shapeCollection.Capsule2Ds.Count != 0)
            {
                throw new NotImplementedException("Capsule2Ds in ShapeCollectionSaves are not implemented yet.  Complain on the FRB forums");
            }

            return(toReturn);
        }
Example #4
0
        void SaveShapeListOk(Window callingWindow)
        {
            string fileName = ((FileWindow)callingWindow).Results[0];

            ShapeCollectionSave shapeSaveList = new ShapeCollectionSave();

            shapeSaveList.AddPolygonList(EditorData.Polygons);
            shapeSaveList.AddAxisAlignedRectangleList(EditorData.AxisAlignedRectangles);
            shapeSaveList.AddCircleList(EditorData.Circles);
            shapeSaveList.AddAxisAlignedCubeList(EditorData.AxisAlignedCubes);
            shapeSaveList.AddSphereList(EditorData.Spheres);
            shapeSaveList.Save(fileName);

#if FRB_MDX
            GameForm.TitleText = "PolygonEditor - Editing " + fileName;
#else 
            FlatRedBallServices.Game.Window.Title = "PolygonEditor Editing - " + fileName;
#endif

            fileName = FileManager.RemoveExtension(fileName);
            fileName += ".pesix";
            PolygonEditorSettings savedInformation = new PolygonEditorSettings(EditorData.LineGrid);
			savedInformation.BoundsCameraSave = CameraSave.FromCamera(EditorData.BoundsCamera);
			savedInformation.UsePixelCoordinates = SpriteManager.Camera.Orthogonal;
            savedInformation.Save(fileName);


        }
        public static ShapeCollectionSave ToShapeCollectionSave(this TiledMapSave tiledMapSave, string layerName)
        {
            MapLayer mapLayer = null;
            if (!string.IsNullOrEmpty(layerName))
            {
                mapLayer = tiledMapSave.Layers.FirstOrDefault(l => l.Name.Equals(layerName));
            }
            var shapes = new ShapeCollectionSave();

            if ((mapLayer != null && !mapLayer.IsVisible && mapLayer.VisibleBehavior == TMXGlueLib.TiledMapSave.LayerVisibleBehavior.Skip) ||
                tiledMapSave.objectgroup == null || tiledMapSave.objectgroup.Count == 0)
            {
                return shapes;
            }

            foreach (mapObjectgroup group in tiledMapSave.objectgroup)
            {
                if (group.@object != null && !string.IsNullOrEmpty(group.Name) && (string.IsNullOrEmpty(layerName) || group.Name.Equals(layerName)))
                {
                    foreach (mapObjectgroupObject @object in group.@object)
                    {
                        ///November 8th, 2015
                        ///Jesse Crafts-Finch
                        ///If a polygon has a gid, and therefore an image associate with it, it will be turned into a spritesave, not a polygon. 
                        if (@object.gid != null)
                        {
                            continue; 
                        }

                        if (@object.polygon != null)
                        {
                            foreach (mapObjectgroupObjectPolygon polygon in @object.polygon)
                            {
                                // TODO: Make this a rectangle object
                                PolygonSave p = tiledMapSave.ConvertTmxObjectToFrbPolygonSave(@object.Name,
                                    @object.x, @object.y, @object.Rotation, polygon.points, true);
                                if (p != null)
                                {
                                    shapes.PolygonSaves.Add(p);                                   
                                }
                            }
                        }

                        if (@object.polyline != null)
                        {
                            foreach (mapObjectgroupObjectPolyline polyline in @object.polyline)
                            {
                                PolygonSave p = tiledMapSave.ConvertTmxObjectToFrbPolygonSave(@object.Name, 
                                    @object.x, @object.y, @object.Rotation, polyline.points, false);
                                if (p != null)
                                {
                                    shapes.PolygonSaves.Add(p);
                                }
                            }
                        }

                       

                        if (@object.polygon == null && @object.polyline == null)
                        {
                            PolygonSave p = tiledMapSave.ConvertTmxObjectToFrbPolygonSave(@object.Name, @object.x, @object.y, @object.width, @object.height, @object.Rotation, @object.ellipse);
                            if (p != null)
                            {
                                shapes.PolygonSaves.Add(p);
                            }
                        }

                        
                    }
                }
            }
            return shapes;
        }
        public override TImport Import(string filename, ContentImporterContext context)
        {
            ShapeCollectionSave shapeCollectionSave = ShapeCollectionSave.FromFile(filename);

            return(shapeCollectionSave);
        }
        public static ShapeCollectionSave ToShapeCollectionSave(this TiledMapSave tiledMapSave, string layerName)
        {
            MapLayer mapLayer = null;
            if (!string.IsNullOrEmpty(layerName))
            {
                mapLayer = tiledMapSave.Layers.FirstOrDefault(l => l.Name.Equals(layerName));
            }
            var shapes = new ShapeCollectionSave();

            if ((mapLayer != null && !mapLayer.IsVisible && mapLayer.VisibleBehavior == TMXGlueLib.TiledMapSave.LayerVisibleBehavior.Skip) ||
                tiledMapSave.objectgroup == null || tiledMapSave.objectgroup.Count == 0)
            {
                return shapes;
            }

            foreach (mapObjectgroup group in tiledMapSave.objectgroup)
            {
                if (group.@object != null && !string.IsNullOrEmpty(group.name) && (string.IsNullOrEmpty(layerName) || group.name.Equals(layerName)))
                {
                    foreach (mapObjectgroupObject @object in group.@object)
                    {
                        if (@object.polygon != null)
                        {
                            foreach (mapObjectgroupObjectPolygon polygon in @object.polygon)
                            {
                                // TODO: Make this a rectangle object
                                PolygonSave p = tiledMapSave.ConvertTmxObjectToFrbPolygonSave(@object.Name,
                                    @object.x, @object.y, @object.Rotation, polygon.points, true);
                                if (p != null)
                                {
                                    shapes.PolygonSaves.Add(p);
                                }
                            }
                        }

                        if (@object.polyline != null)
                        {
                            foreach (mapObjectgroupObjectPolyline polyline in @object.polyline)
                            {
                                PolygonSave p = tiledMapSave.ConvertTmxObjectToFrbPolygonSave(@object.Name,
                                    @object.x, @object.y, @object.Rotation, polyline.points, false);
                                if (p != null)
                                {
                                    shapes.PolygonSaves.Add(p);
                                }
                            }
                        }

                        if (@object.polygon == null && @object.polyline == null)
                        {
                            PolygonSave p = tiledMapSave.ConvertTmxObjectToFrbPolygonSave(@object.Name, @object.x, @object.y, @object.width, @object.height, @object.Rotation, @object.ellipse);
                            if (p != null)
                            {
                                shapes.PolygonSaves.Add(p);
                            }
                        }

                    }
                }
            }
            return shapes;
        }
        public static ShapeCollectionSave FromShapeCollection(ShapeCollection shapeCollection)
        {
            ShapeCollectionSave toReturn = new ShapeCollectionSave();
            toReturn.AddAxisAlignedRectangleList(shapeCollection.AxisAlignedRectangles);
            toReturn.AddAxisAlignedCubeList(shapeCollection.AxisAlignedCubes);
            toReturn.AddCircleList(shapeCollection.Circles);
            toReturn.AddSphereList(shapeCollection.Spheres);
            toReturn.AddPolygonList(shapeCollection.Polygons);

            if (shapeCollection.Lines.Count != 0)
            {
                throw new NotImplementedException("Lines in ShapeCollectionSaves are not implemented yet.  Complain on the FRB forums");
            }

            if (shapeCollection.Capsule2Ds.Count != 0)
            {
                throw new NotImplementedException("Capsule2Ds in ShapeCollectionSaves are not implemented yet.  Complain on the FRB forums");
            }

            return toReturn;
        }