Exemplo n.º 1
0
        private void MapInteractionOverlay_TextChanged(object sender, TextChangedEventArgs e)
        {
            MapTileInteraction selectedInteraction = (MapTileInteraction)MapInteractionList.SelectedItem;

            if (selectedInteraction != null)
            {
                try
                {
                    TileBlockOverlay overlay = JsonConvert.DeserializeObject <TileBlockOverlay>(MapInteractionOverlay.Text);

                    if (overlay != null && (overlay.PaletteIndex < 0 || overlay.PaletteIndex >= 8))
                    {
                        throw new Exception();
                    }

                    MapInteractionOverlay.Foreground = new SolidColorBrush(Colors.White);
                    selectedInteraction.Overlay      = overlay;

                    BlockSelector.Update(tileIndex: BlockSelector.SelectedBlockValue);
                    UpdateTileBlock();
                    SetUnsaved();
                }
                catch
                {
                    MapInteractionOverlay.Foreground = new SolidColorBrush(Colors.Red);
                }
            }
        }
Exemplo n.º 2
0
        public void RenderTiles(int blockX = 0, int blockY = 0, int blockWidth = World.BLOCK_WIDTH, int blockHeight = World.BLOCK_HEIGHT)
        {
            int maxRow = blockY + blockHeight;
            int maxCol = blockX + blockWidth;

            if (maxRow > World.BLOCK_HEIGHT)
            {
                maxRow = World.BLOCK_HEIGHT;
            }

            if (maxCol > World.BLOCK_WIDTH)
            {
                maxCol = World.BLOCK_WIDTH;
            }

            for (int row = blockY; row < maxRow; row++)
            {
                for (int col = blockX; col < maxCol; col++)
                {
                    int tileValue = _worldDataAccessor.GetData(col, row);

                    if (tileValue < 0)
                    {
                        continue;
                    }

                    int       paletteIndex = (tileValue & 0XC0) >> 6;
                    TileBlock tile = _tileSet.TileBlocks[tileValue];
                    int       x = col * 16, y = row * 16;

                    RenderTile(x, y, _graphicsAccessor.GetRelativeTile(tile.UpperLeft), _buffer, _palette.RgbColors[paletteIndex]);
                    RenderTile(x + 8, y, _graphicsAccessor.GetRelativeTile(tile.UpperRight), _buffer, _palette.RgbColors[paletteIndex]);
                    RenderTile(x, y + 8, _graphicsAccessor.GetRelativeTile(tile.LowerLeft), _buffer, _palette.RgbColors[paletteIndex]);
                    RenderTile(x + 8, y + 8, _graphicsAccessor.GetRelativeTile(tile.LowerRight), _buffer, _palette.RgbColors[paletteIndex]);

                    if (_withInteractionOverlay)
                    {
                        MapTileInteraction interaction = _terrain.Where(t => t.HasInteraction(tile.Property)).FirstOrDefault();

                        if (interaction != null)
                        {
                            TileBlockOverlay overlay = interaction.Overlay;
                            if (overlay != null)
                            {
                                RenderTile(x, y, _graphicsAccessor.GetOverlayTile(0, overlay.UpperLeft), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                                RenderTile(x + 8, y, _graphicsAccessor.GetOverlayTile(0, overlay.UpperRight), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                                RenderTile(x, y + 8, _graphicsAccessor.GetOverlayTile(0, overlay.LowerLeft), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                                RenderTile(x + 8, y + 8, _graphicsAccessor.GetOverlayTile(0, overlay.LowerRight), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Update()
        {
            if (_tileSet == null || _palette == null)
            {
                return;
            }

            int maxRow = 16;
            int maxCol = 16;

            for (int row = 0; row < maxRow; row++)
            {
                for (int col = 0; col < maxCol; col++)
                {
                    int tileValue    = row * 16 + col;
                    int PaletteIndex = tileValue / 0x40;

                    TileBlock tile = _tileSet.TileBlocks[tileValue];
                    int       paletteIndex = (tileValue & 0XC0) >> 6;
                    int       x = col * 16, y = row * 16;

                    RenderTile(x, y, _graphicsAccessor.GetRelativeTile(tile.UpperLeft), _buffer, _palette.RgbColors[paletteIndex]);
                    RenderTile(x + 8, y, _graphicsAccessor.GetRelativeTile(tile.UpperRight), _buffer, _palette.RgbColors[paletteIndex]);
                    RenderTile(x, y + 8, _graphicsAccessor.GetRelativeTile(tile.LowerLeft), _buffer, _palette.RgbColors[paletteIndex]);
                    RenderTile(x + 8, y + 8, _graphicsAccessor.GetRelativeTile(tile.LowerRight), _buffer, _palette.RgbColors[paletteIndex]);

                    if (_withTerrainOverlay)
                    {
                        TileTerrain terrain = _terrain.Where(t => t.HasTerrain(tile.Property)).FirstOrDefault();
                        if (terrain != null)
                        {
                            TileBlockOverlay overlay = terrain.Overlay;
                            if (overlay != null)
                            {
                                RenderTile(x, y, _graphicsAccessor.GetOverlayTile(0, overlay.UpperLeft), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .75);
                                RenderTile(x + 8, y, _graphicsAccessor.GetOverlayTile(0, overlay.UpperRight), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .75);
                                RenderTile(x, y + 8, _graphicsAccessor.GetOverlayTile(0, overlay.LowerLeft), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .75);
                                RenderTile(x + 8, y + 8, _graphicsAccessor.GetOverlayTile(0, overlay.LowerRight), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .75);
                            }
                        }
                    }

                    if (_withInteractionOverlay)
                    {
                        TileInteraction interaction = _terrain.Where(t => t.HasTerrain(tile.Property)).FirstOrDefault()?.Interactions.Where(i => i.HasInteraction(tile.Property)).FirstOrDefault();
                        if (interaction != null)
                        {
                            TileBlockOverlay overlay = interaction.Overlay;
                            if (overlay != null)
                            {
                                RenderTile(x, y, _graphicsAccessor.GetOverlayTile(0, overlay.UpperLeft), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                                RenderTile(x + 8, y, _graphicsAccessor.GetOverlayTile(0, overlay.UpperRight), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                                RenderTile(x, y + 8, _graphicsAccessor.GetOverlayTile(0, overlay.LowerLeft), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                                RenderTile(x + 8, y + 8, _graphicsAccessor.GetOverlayTile(0, overlay.LowerRight), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                            }
                        }
                    }

                    if (_withMapInteractionOverlay)
                    {
                        MapTileInteraction interaction = _mapTileInteractions.Where(i => i.HasInteraction(tile.Property)).FirstOrDefault();
                        if (interaction != null)
                        {
                            TileBlockOverlay overlay = interaction.Overlay;
                            if (overlay != null)
                            {
                                RenderTile(x, y, _graphicsAccessor.GetOverlayTile(0, overlay.UpperLeft), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                                RenderTile(x + 8, y, _graphicsAccessor.GetOverlayTile(0, overlay.UpperRight), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                                RenderTile(x, y + 8, _graphicsAccessor.GetOverlayTile(0, overlay.LowerLeft), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                                RenderTile(x + 8, y + 8, _graphicsAccessor.GetOverlayTile(0, overlay.LowerRight), _buffer, _palette.RgbColors[overlay.PaletteIndex], useTransparency: true, opacity: .85);
                            }
                        }
                    }

                    if (_withProjectileInteractions)
                    {
                        if (_tileSet.FireBallInteractions.Contains(tileValue))
                        {
                            RenderTile(x + 4, y + 4, _graphicsAccessor.GetOverlayTile(0, 0xEE), _buffer, _palette.RgbColors[5], useTransparency: true);
                        }

                        if (_tileSet.IceBallInteractions.Contains(tileValue))
                        {
                            RenderTile(x + 4, y + 4, _graphicsAccessor.GetOverlayTile(0, 0xEF), _buffer, _palette.RgbColors[5], useTransparency: true);
                        }

                        PSwitchAlteration alteration = _tileSet.PSwitchAlterations.Where(p => p.From == tileValue).FirstOrDefault();
                        if (alteration != null)
                        {
                            TileBlock alternativeTile = PSwitchAlteration.GetAlterationBlocks(alteration.To);

                            RenderTile(x, y, _graphicsAccessor.GetOverlayTile(4, alternativeTile.UpperLeft), _buffer, _palette.RgbColors[paletteIndex], useTransparency: true, opacity: .85);
                            RenderTile(x + 8, y, _graphicsAccessor.GetOverlayTile(4, alternativeTile.UpperRight), _buffer, _palette.RgbColors[paletteIndex], useTransparency: true, opacity: .85);
                            RenderTile(x, y + 8, _graphicsAccessor.GetOverlayTile(4, alternativeTile.LowerLeft), _buffer, _palette.RgbColors[paletteIndex], useTransparency: true, opacity: .85);
                            RenderTile(x + 8, y + 8, _graphicsAccessor.GetOverlayTile(4, alternativeTile.LowerRight), _buffer, _palette.RgbColors[paletteIndex], useTransparency: true, opacity: .85);
                        }
                    }
                }
            }
        }