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); } } }
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); } } } } } }
private void MapInteractionList_SelectionChanged(object sender, SelectionChangedEventArgs e) { MapTileInteraction selectedIteraction = (MapTileInteraction)MapInteractionList.SelectedItem; if (selectedIteraction != null) { BlockSelector.SelectedTileBlock.Property = ((MapTileInteraction)MapInteractionList.SelectedItem).Value; MapInteractionOverlay.Text = JsonConvert.SerializeObject(selectedIteraction.Overlay, Formatting.Indented); BlockSelector.Update(tileIndex: BlockSelector.SelectedBlockValue); UpdateTileBlock(); SetUnsaved(); } }
private void HandleTileMove(MouseEventArgs e) { Point tilePoint = Snap(e.GetPosition(WorldRenderSource)); if (_isDragging && ((_selectionMode == SelectionMode.SetTiles && _drawMode == DrawMode.Default) || _selectionMode == SelectionMode.SelectTiles)) { int x = (int)Math.Min(tilePoint.X, _dragStartPoint.X); int y = (int)Math.Min(tilePoint.Y, _dragStartPoint.Y); int width = (int)(Math.Max(tilePoint.X, _dragStartPoint.X)) - x; int height = (int)(Math.Max(tilePoint.Y, _dragStartPoint.Y)) - y; SetSelectionRectangle(new Rect(x, y, width + 16, height + 16)); } else if (_selectionMode != SelectionMode.SelectTiles) { SetSelectionRectangle(new Rect(tilePoint.X, tilePoint.Y, 16, 16)); } int blockX = (int)tilePoint.X / 16, blockY = (int)tilePoint.Y / 16; int tileValue = _worldDataAccessor.GetData(blockX, blockY); if (tileValue == -1) { InteractionDescription.Text = ""; TerrainDescription.Text = ""; PointerXY.Text = ""; TileValue.Text = ""; } else { TileBlock tileBlock = _tileSet.TileBlocks[tileValue]; MapTileInteraction tileInteraction = _interactions.Where(t => t.Value == tileBlock.Property).FirstOrDefault(); InteractionDescription.Text = tileInteraction.Name; PointerXY.Text = "X: " + blockX.ToString("X2") + " Y: " + blockY.ToString("X2"); TileValue.Text = tileValue.ToString("X"); } }
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); } } } } }