Inheritance: TileGridLayer
 public TileReplace2DCommand(MultiTileGridLayer source, Dictionary<TileCoord, TileStack> tileData)
     : this(source)
 {
     foreach (KeyValuePair<TileCoord, TileStack> kv in tileData) {
         _tiles[kv.Key] = new TileRecord(_tileSource[kv.Key], kv.Value);
     }
 }
Example #2
0
        public void CreateTileLayer()
        {
            TileLayer layer = new MultiTileGridLayer("layer", 16, 24, 30, 50);

            Assert.AreEqual(16, layer.TileWidth);
            Assert.AreEqual(24, layer.TileHeight);
        }
Example #3
0
        public void AddTileOutOfBounds()
        {
            TileGridLayer layer = new MultiTileGridLayer("tiles", 16, 16, 10, 10);
            try {
                layer.AddTile(-1, 2, _tile1);
                Assert.Fail();
            }
            catch { }

            try {
                layer.AddTile(2, -1, _tile1);
                Assert.Fail();
            }
            catch { }

            try {
                layer.AddTile(10, 8, _tile1);
                Assert.Fail();
            }
            catch { }

            try {
                layer.AddTile(8, 10, _tile1);
                Assert.Fail();
            }
            catch { }
        }
Example #4
0
        public void CloneTileLayer()
        {
            TileLayer layer = new MultiTileGridLayer("layer", 16, 24, 30, 50);
            TileLayer layer2 = layer.Clone() as TileLayer;

            Assert.AreEqual(16, layer2.TileWidth);
            Assert.AreEqual(24, layer2.TileHeight);
        }
Example #5
0
        public void AddProperty()
        {
            Layer layer = new MultiTileGridLayer("layer", 16, 16, 16, 16);
            AttachEvents(layer);

            Property prop = new StringProperty("author", "Justin");
            layer.CustomProperties.Add(prop);

            Assert.AreEqual(EventFlags.Modified, _eventsFired);
        }
Example #6
0
        public TileEraseTool(CommandHistory history, MultiTileGridLayer layer, ObservableCollection<Annotation> annots)
            : base(history, layer)
        {
            _annots = annots;

            _previewMarker = new SelectionAnnot(new Point(0, 0))
            {
                Fill = new SolidColorBrush(new Color(192, 0, 0, 128)),
            };

            _annots.Add(_previewMarker);
        }
Example #7
0
        public void ChangeLayerVisibiliityProperty()
        {
            Layer layer = new MultiTileGridLayer("layer", 16, 16, 16, 16);
            AttachEvents(layer);

            Assert.AreEqual(true, layer.IsVisible);

            layer.PredefinedProperties["Visible"].Parse("false");

            Assert.AreEqual(EventFlags.VisibilityChanged | EventFlags.Modified, _eventsFired);
            Assert.AreEqual(false, layer.IsVisible);
        }
Example #8
0
        public void ChangeLayerOpacityProperty()
        {
            Layer layer = new MultiTileGridLayer("layer", 16, 16, 16, 16);
            AttachEvents(layer);

            Assert.AreEqual(1f, layer.Opacity);

            layer.PredefinedProperties["Opacity"].Parse("0.5");

            Assert.AreEqual(EventFlags.OpacityChanged | EventFlags.Modified, _eventsFired);
            Assert.AreEqual(0.5f, layer.Opacity);
        }
Example #9
0
        public void ChangeLayerOpacity()
        {
            Layer layer = new MultiTileGridLayer("layer", 16, 16, 16, 16);
            AttachEvents(layer);

            Assert.AreEqual(1f, layer.Opacity);

            layer.Opacity = 0.5f;

            Assert.AreEqual(EventFlags.OpacityChanged | EventFlags.Modified, _eventsFired);
            Assert.AreEqual(0.5f, layer.Opacity);
        }
Example #10
0
        public MultiTileGridLayer(string name, MultiTileGridLayer layer)
            : base(name, layer)
        {
            _tiles = new TileStack[layer.TilesHigh, layer.TilesWide];

            for (int y = 0; y < layer.TilesHigh; y++) {
                for (int x = 0; x < layer.TilesWide; x++) {
                    if (layer._tiles[y, x] != null) {
                        _tiles[y, x] = layer._tiles[y, x].Clone() as TileStack;
                    }
                }
            }
        }
Example #11
0
        public static LevelX.MultiTileGridLayerX ToXmlProxyX(MultiTileGridLayer layer)
        {
            if (layer == null)
            {
                return(null);
            }

            const int blockSize = 4;

            int xLimit = (layer.TilesWide + blockSize - 1) / blockSize;
            int yLimit = (layer.TilesHigh + blockSize - 1) / blockSize;

            List <CommonX.TileBlockX> blocks = new List <CommonX.TileBlockX>();

            for (int y = 0; y < yLimit; y++)
            {
                for (int x = 0; x < xLimit; x++)
                {
                    string data = layer.BuildTileBlockString(x * blockSize, y * blockSize, blockSize, blockSize);
                    if (!string.IsNullOrEmpty(data))
                    {
                        blocks.Add(new CommonX.TileBlockX()
                        {
                            X    = x * blockSize,
                            Y    = y * blockSize,
                            Data = data,
                        });
                    }
                }
            }

            List <CommonX.PropertyX> props = new List <CommonX.PropertyX>();

            foreach (Property prop in layer.PropertyManager.CustomProperties)
            {
                props.Add(Property.ToXmlProxyX(prop));
            }

            return(new LevelX.MultiTileGridLayerX()
            {
                Name = layer.Name,
                Opacity = layer.Opacity,
                Visible = layer.IsVisible,
                RasterMode = layer.RasterMode,
                GridColor = layer.GridColor.ToArgbHex(),
                TileWidth = layer.TileWidth,
                TileHeight = layer.TileHeight,
                Blocks = blocks.Count > 0 ? blocks : null,
                Properties = props.Count > 0 ? props : null,
            });
        }
Example #12
0
        public MultiTileGridLayer(string name, MultiTileGridLayer layer)
            : base(name, layer)
        {
            _tiles = new TileStack[layer.TilesHigh, layer.TilesWide];

            for (int y = 0; y < layer.TilesHigh; y++)
            {
                for (int x = 0; x < layer.TilesWide; x++)
                {
                    if (layer._tiles[y, x] != null)
                    {
                        _tiles[y, x] = layer._tiles[y, x].Clone() as TileStack;
                    }
                }
            }
        }
Example #13
0
        public TileLayerForm(MultiTileGridLayer layer)
        {
            InitializeForm();

            Text = "Edit Tile Layer";

            _layer = layer;
            _nameField.Text = _layer.Name;
            _opacityField.Value = (decimal)_layer.Opacity;
            _tileWidthField.Value = _layer.TileWidth;
            _tileHeightField.Value = _layer.TileHeight;

            _tileHeightField.Enabled = false;
            _tileWidthField.Enabled = false;

            _validateController.Validate();
        }
Example #14
0
        public void AddTile()
        {
            TileGridLayer layer = new MultiTileGridLayer("tiles", 16, 16, 10, 10);
            AttachEvents(layer);

            layer.TileAdded += (s, e) =>
            {
                Assert.AreEqual(2, e.X);
                Assert.AreEqual(4, e.Y);
                Assert.AreSame(_tile1, e.Tile);
                Assert.AreEqual(1, layer.Tiles.Count());
                Assert.AreEqual(1, layer.TilesAt(new TileCoord(2, 4)).Count());
            };

            layer.AddTile(2, 4, _tile1);

            Assert.AreEqual(EventFlags.TileAdded | EventFlags.Modified, _eventsFired);
        }
Example #15
0
        public TileLayerForm(MultiTileGridLayer layer)
        {
            InitializeForm();

            Text = "Edit Tile Layer";

            _layer = layer;
            _nameField.Text = _layer.Name;
            _opacityField.Value = (decimal)_layer.Opacity;
            _tileWidthField.Value = _layer.TileWidth;
            _tileHeightField.Value = _layer.TileHeight;
            _gridColorButton.Color = Color.FromArgb(255, _layer.GridColor.R, _layer.GridColor.G, _layer.GridColor.B);

            _tileHeightField.Enabled = false;
            _tileWidthField.Enabled = false;

            _validateController.Validate();
        }
Example #16
0
 public void AddTiles(MultiTileGridLayer layer, Rectangle tileRegion)
 {
     for (int y = tileRegion.Top; y < tileRegion.Bottom; y++) {
         for (int x = tileRegion.Left; x < tileRegion.Right; x++) {
             AddTile(layer, new TileCoord(x, y));
         }
     }
 }
Example #17
0
 public void AddTiles(MultiTileGridLayer layer, IEnumerable<TileCoord> tileLocations)
 {
     foreach (TileCoord coord in tileLocations) {
         AddTile(layer, coord);
     }
 }
Example #18
0
        public FloatTileSelectionCommand(MultiTileGridLayer source, ITileSelectionLayer selectLayer)
        {
            _tileSource = source;
            _command = new TileReplace2DCommand(source);

            _selectLayer = selectLayer;
        }
Example #19
0
 public TileReplace2DCommand(MultiTileGridLayer source)
 {
     _tileSource = source;
     _tiles = new Dictionary<TileCoord, TileRecord>();
 }
Example #20
0
 public TileFillTool(CommandHistory history, MultiTileGridLayer layer)
     : base(history, layer)
 {
 }
Example #21
0
        private void ApplyNew()
        {
            _layer = new MultiTileGridLayer(
                _nameField.Text.Trim(),
                (int)_tileWidthField.Value,
                (int)_tileHeightField.Value,
                _level);

            _layer.Opacity = (float)_opacityField.Value;
            _layer.GridColor = new Treefrog.Framework.Imaging.Color(_gridColorButton.Color.R, _gridColorButton.Color.G, _gridColorButton.Color.B, 128);
        }
Example #22
0
        public static LevelX.MultiTileGridLayerX ToXmlProxyX(MultiTileGridLayer layer)
        {
            if (layer == null)
                return null;

            const int blockSize = 4;

            int xLimit = (layer.TilesWide + blockSize - 1) / blockSize;
            int yLimit = (layer.TilesHigh + blockSize - 1) / blockSize;

            List<CommonX.TileBlockX> blocks = new List<CommonX.TileBlockX>();
            for (int y = 0; y < yLimit; y++) {
                for (int x = 0; x < xLimit; x++) {
                    string data = layer.BuildTileBlockString(x * blockSize, y * blockSize, blockSize, blockSize);
                    if (!string.IsNullOrEmpty(data)) {
                        blocks.Add(new CommonX.TileBlockX() {
                            X = x * blockSize,
                            Y = y * blockSize,
                            Data = data,
                        });
                    }
                }
            }

            List<CommonX.PropertyX> props = new List<CommonX.PropertyX>();
            foreach (Property prop in layer.PropertyManager.CustomProperties)
                props.Add(Property.ToXmlProxyX(prop));

            return new LevelX.MultiTileGridLayerX() {
                Name = layer.Name,
                Opacity = layer.Opacity,
                Visible = layer.IsVisible,
                RasterMode = layer.RasterMode,
                GridColor = layer.GridColor.ToArgbHex(),
                TileWidth = layer.TileWidth,
                TileHeight = layer.TileHeight,
                Blocks = blocks.Count > 0 ? blocks : null,
                Properties = props.Count > 0 ? props : null,
            };
        }
Example #23
0
 public TileSelectTool(CommandHistory history, MultiTileGridLayer layer, ObservableCollection<Annotation> annots, ITileSelectionLayer selectLayer)
     : base(history, layer)
 {
     _annots = annots;
     _selectLayer = selectLayer;
 }
Example #24
0
        public void CreateLayer()
        {
            TileGridLayer layer = new MultiTileGridLayer("tiles", 16, 24, 10, 20);

            Assert.AreEqual(16, layer.TileWidth);
            Assert.AreEqual(24, layer.TileHeight);
            Assert.AreEqual(10, layer.TilesWide);
            Assert.AreEqual(20, layer.TilesHigh);
            Assert.AreEqual(16 * 10, layer.LayerWidth);
            Assert.AreEqual(24 * 20, layer.LayerHeight);
            Assert.IsTrue(layer.IsResizable);
        }
Example #25
0
        public void GetTilesAtLocation()
        {
            TileGridLayer layer = new MultiTileGridLayer("tiles", 16, 16, 10, 10);
            layer.AddTile(2, 3, _tile1);
            layer.AddTile(6, 7, _tile2);

            Assert.AreEqual(1, layer.TilesAt(new TileCoord(2, 3)).Count());
            Assert.AreEqual(0, layer.TilesAt(new TileCoord(1, 3)).Count());
            Assert.AreEqual(0, layer.TilesAt(new TileCoord(3, 3)).Count());
            Assert.AreEqual(0, layer.TilesAt(new TileCoord(1, 2)).Count());
            Assert.AreEqual(0, layer.TilesAt(new TileCoord(1, 4)).Count());
        }
Example #26
0
 private void AddTile(MultiTileGridLayer layer, TileCoord location)
 {
     if (!_tiles.ContainsKey(location)) {
         TileStack stack = layer.TileStacksAt(location);
         if (!TileStack.NullOrEmpty(stack))
             _tiles.Add(location, stack);
         _tileAnnot.AddTileLocation(location);
     }
 }
Example #27
0
        public static LevelX ToXProxy(Level level)
        {
            if (level == null)
            {
                return(null);
            }

            foreach (Layer layer in level.Layers)
            {
                if (layer is TileGridLayer)
                {
                    TileGridLayer tileLayer = layer as TileGridLayer;
                    foreach (LocatedTile tile in tileLayer.Tiles)
                    {
                        if (!level._localTileIndex.ContainsValue(tile.Tile.Uid))
                        {
                            level._localTileIndex.Add(level._indexSequence++, tile.Tile.Uid);
                        }
                    }
                }
            }

            List <LevelX.TileIndexEntryX> tileIndexEntries = new List <LevelX.TileIndexEntryX>();

            foreach (var item in level._localTileIndex)
            {
                tileIndexEntries.Add(new LevelX.TileIndexEntryX()
                {
                    Id  = item.Key,
                    Uid = item.Value,
                });
            }

            LevelX.TileIndexX tileIndex = new LevelX.TileIndexX()
            {
                Entries  = tileIndexEntries,
                Sequence = level._indexSequence,
            };

            List <AbstractXmlSerializer <LevelX.LayerX> > layers = new List <AbstractXmlSerializer <LevelX.LayerX> >();

            foreach (Layer layer in level.Layers)
            {
                if (layer is MultiTileGridLayer)
                {
                    layers.Add(MultiTileGridLayer.ToXmlProxyX(layer as MultiTileGridLayer));
                }
                else if (layer is ObjectLayer)
                {
                    layers.Add(ObjectLayer.ToXmlProxyX(layer as ObjectLayer));
                }
            }

            LevelX.PropertyGroupX propGroup = new LevelX.PropertyGroupX()
            {
                LevelGuid = level.Uid,
                Extra     = (level.Extra != null && level.Extra.Count > 0) ? level.Extra.ToArray() : null,
            };

            if (level.Project != null)
            {
                propGroup.ProjectGuid = level.Project.Uid;
            }

            return(new LevelX()
            {
                PropertyGroup = propGroup,
                Name = level.Name,
                OriginX = level.OriginX,
                OriginY = level.OriginY,
                Width = level.Width,
                Height = level.Height,
                TileIndex = tileIndex,
                Layers = layers.Count > 0 ? layers : null,
            });
        }
Example #28
0
        private void StartFillSequence(PointerEventInfo info)
        {
            if (!SourceValid)
                return;

            TileCoord location = TileLocation(info);
            if (!TileInRange(location))
                return;

            if (SourceType == TileSourceType.Brush) {
                Layer.TileAdding += TileAddingHandler;
                Layer.TileRemoving += TileRemovingHandler;
            }

            _fillLayer = Layer;
            _sourceStack = new TileStack();
            _sourceStack.Add(ActiveTile);

            _fillCommand = new TileReplace2DCommand(Layer);
            FloodFill(location.X, location.Y);

            if (SourceType == TileSourceType.Brush) {
                Layer.TileAdding -= TileAddingHandler;
                Layer.TileRemoving -= TileRemovingHandler;
            }

            History.Execute(_fillCommand);
        }
Example #29
0
        private void InitializeBrush(DynamicTileBrush brush)
        {
            _layerControl.ReferenceWidth = brush.BrushClass.TemplateWidth * brush.TileWidth + 1;
            _layerControl.ReferenceHeight = brush.BrushClass.TemplateHeight * brush.TileHeight + 1;

            _layer = new MultiTileGridLayer("Default", brush.TileWidth, brush.TileHeight, brush.BrushClass.TemplateWidth, brush.BrushClass.TemplateHeight);
            for (int i = 0; i < brush.BrushClass.SlotCount; i++) {
                LocatedTile tile = brush.GetLocatedTile(i);
                if (tile.Tile != null)
                    _layer.AddTile(tile.X, tile.Y, tile.Tile);
            }

            _rootLayer.Layers.Clear();
            _rootLayer.Layers.Add(new TileGridLayerPresenter(_layerContext, _layer));
            _rootLayer.Layers.Add(new LocalRenderLayerPresenter(new OverlayRenderCore(this)));
            _rootLayer.Layers.Add(new GridLayerPresenter() {
                GridSpacingX = brush.TileWidth,
                GridSpacingY = brush.TileHeight,
            });

            _nameField.Text = brush.Name;

            _brush = brush;

            SelectCurrentPrototype();
            SelectCurrentTileSize();
        }
Example #30
0
 public TileFillTool(CommandHistory history, MultiTileGridLayer layer, TileSourceType sourceType)
     : base(history, layer, sourceType)
 {
 }
Example #31
0
 public TileDrawTool(CommandHistory history, MultiTileGridLayer layer, ObservableCollection<Annotation> annots)
     : base(history, layer)
 {
     _annots = annots;
 }
Example #32
0
        private void InitializeBrush(StaticTileBrush brush)
        {
            int tilesW = brush.TilesWide + 12;
            int tilesH = brush.TilesHigh + 12;

            _layerControl.ReferenceWidth = tilesW * brush.TileWidth + 1;
            _layerControl.ReferenceHeight = tilesH * brush.TileHeight + 1;

            _layer = new MultiTileGridLayer("Default", brush.TileWidth, brush.TileHeight, tilesW, tilesH);
            foreach (LocatedTile tile in brush.Tiles) {
                if (tile.Tile != null)
                    _layer.AddTile(tile.X, tile.Y, tile.Tile);
            }

            _rootLayer.Layers.Clear();
            _rootLayer.Layers.Add(new TileGridLayerPresenter(_layerContext, _layer));
            _rootLayer.Layers.Add(new GridLayerPresenter() {
                GridSpacingX = brush.TileWidth,
                GridSpacingY = brush.TileHeight,
            });

            _nameField.Text = brush.Name;

            _brush = brush;

            SelectCurrentTileSize();
        }
Example #33
0
        public void GetTilesInRegion()
        {
            TileGridLayer layer = new MultiTileGridLayer("tiles", 16, 16, 10, 10);
            layer.AddTile(2, 3, _tile1);
            layer.AddTile(6, 7, _tile2);

            Assert.AreEqual(2, layer.TilesAt(new Rectangle(2, 2, 5, 6)).Count());
            Assert.AreEqual(1, layer.TilesAt(new Rectangle(3, 2, 5, 6)).Count());
            Assert.AreEqual(1, layer.TilesAt(new Rectangle(2, 4, 5, 6)).Count());
            Assert.AreEqual(1, layer.TilesAt(new Rectangle(2, 2, 4, 6)).Count());
            Assert.AreEqual(1, layer.TilesAt(new Rectangle(2, 2, 5, 5)).Count());
            Assert.AreEqual(0, layer.TilesAt(new Rectangle(3, 2, 5, 5)).Count());
        }