public GridEditor(Game1 game, Levels.MapType type, Rectangle bounds, TilesSet sprites, int[,] grid, Point position, OverlayGrid[] overlays, OverlayGrid[] underlays, int[,] selectionGrid, EditableGrid customInventory) { this.game = game; this.bounds = bounds; this.sprites = sprites; map = new EditableGrid(bounds, grid, position, 8); this.type = type; this.selectionGrid = selectionGrid; this.customInventory = customInventory; GridEnabled = true; // Load Inventory if (type != Levels.MapType.Minimap) { Point nbTiles = sprites.NumberTiles; int[,] inventoryGrid = new int[nbTiles.Y, nbTiles.X]; int i = 0; for (int y = 0; y < nbTiles.Y; y++) { for (int x = 0; x < nbTiles.X; x++) { inventoryGrid[y, x] = i; i++; } } inventory = new EditableGrid(bounds, inventoryGrid, new Point(-8, -8), 16); } else { inventory = null; } Overlays = overlays; Underlays = underlays; }
void DrawGrid(SpriteBatch sprite_batch, int[,] grid, TilesSet sprites, bool overridePalette, bool showSpecial, Rectangle?ignoreArea = null) { Rectangle notIn = ignoreArea.HasValue ? ignoreArea.Value : Rectangle.Empty; int h = grid.GetLength(0); int w = grid.GetLength(1); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { Rectangle dst = TileCoordToScreenRect(x, y); if (dst.Intersects(bounds) && !dst.Intersects(notIn)) { DrawTile(sprite_batch, sprites, dst, grid[y, x], overridePalette, showSpecial); } } } }
bool LoadGrid() { int[,] grid; List <GridEditor.OverlayGrid> underlays = new List <GridEditor.OverlayGrid>(); List <GridEditor.OverlayGrid> overlays = new List <GridEditor.OverlayGrid>(); string world = Levels.GetWorldOfLevel(map); Levels.MapType mapType = MapType(); string levelPath = Levels.GetLevelPath(map, mapType); if (!File.Exists(levelPath)) // Should only happen in Paradise { return(false); } if (mode == Mode.Minimap) { grid = Levels.GetGridFromLines(File.ReadAllLines(levelPath), 64, 64, Levels.TilesOffset(world, Levels.MapType.Minimap)); sset = new TilesSet(Load.MinimapColors, false, _ssetBounds, 64); } else { Load.LoadWorldTiles(GraphicsDevice, world); grid = Levels.GetGridFromLines(File.ReadAllLines(levelPath), Levels.TilesOffset(world, mapType)); sset = new TilesSet(Load.Tiles[new Load.WorldAndType(world, mapType)], true, _ssetBounds, 64); if (Settings.Paradise && mode == Mode.Physical) { string objectsPath = Levels.GetObjectsPath(map); string[] objects = File.Exists(objectsPath) ? File.ReadAllLines(objectsPath) : new string[0]; _paraPhysicalMapLogic = new ParadisePhysicalMapLogic(objects); } int[,] ogrid; TilesSet osset; if (mode != Mode.Background) { try { ogrid = Levels.GetGridFromLines(File.ReadAllLines(Levels.GetLevelPath(map, Levels.MapType.Background)), Levels.TilesOffset(world, Levels.MapType.Background)); osset = new TilesSet(Load.Tiles[new Load.WorldAndType(world, Levels.MapType.Background)], true, Rectangle.Empty, 0); underlays.Add(new GridEditor.OverlayGrid(osset, ogrid, false)); } catch { } } if (mode != Mode.Graphical2) { try { ogrid = Levels.GetGridFromLines(File.ReadAllLines(Levels.GetLevelPath(map, Levels.MapType.Graphical2)), Levels.TilesOffset(world, Levels.MapType.Graphical2)); osset = new TilesSet(Load.Tiles[new Load.WorldAndType(world, Levels.MapType.Graphical2)], true, Rectangle.Empty, 0); if (mode == Mode.Background) { overlays.Add(new GridEditor.OverlayGrid(osset, ogrid, false)); } else { underlays.Add(new GridEditor.OverlayGrid(osset, ogrid, false)); } } catch { } } if (mode != Mode.Graphical) { try { ogrid = Levels.GetGridFromLines(File.ReadAllLines(Levels.GetLevelPath(map, Levels.MapType.Graphical)), Levels.TilesOffset(world, Levels.MapType.Graphical)); osset = new TilesSet(Load.Tiles[new Load.WorldAndType(world, Levels.MapType.Graphical)], true, Rectangle.Empty, 0); if (mode == Mode.Physical) { underlays.Add(new GridEditor.OverlayGrid(osset, ogrid, false)); } else { overlays.Add(new GridEditor.OverlayGrid(osset, ogrid, false)); } } catch { } } if (mode != Mode.Physical) { try { ogrid = Levels.GetGridFromLines(File.ReadAllLines(Levels.GetLevelPath(map, Levels.MapType.Physical)), Levels.TilesOffset(world, Levels.MapType.Physical)); osset = new TilesSet(Load.Tiles[new Load.WorldAndType(world, Levels.MapType.Physical)], true, Rectangle.Empty, 0); overlays.Add(new GridEditor.OverlayGrid(osset, ogrid, true)); } catch { } } } int[,] selectionGrid = null; if (_lastMapType == mapType /*&& (_lastWorld == world || mapType == Levels.MapType.Physical || mapType == Levels.MapType.Minimap)*/) { // Sometimes, inter-world copy paste can be relevant even for grounds and backgrounds selectionGrid = _lastSelectionGrid; } editor = new GridEditor(this, MapType(), _gridEditorBounds, sset, grid, new Point(-8, -8), overlays.ToArray(), underlays.ToArray(), selectionGrid, _inventories.GetInventory(MapType())); return(true); }
void DrawTile(SpriteBatch sprite_batch, TilesSet sprites, Rectangle dst, int tile, bool overridePalette, bool showSpecial) { if (type == Levels.MapType.Minimap) { sprites.Draw(sprite_batch, overridePalette ? sprites.SelectedSet : tile, 0, dst); } else { tile = overridePalette ? ChangePalette(tile, sprites.SelectedSet) : tile; int tile_id = tile & 0x3FF; int palette = (tile & 0xF000) >> 12; SpriteEffects effects = ((tile & 0x400) != 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None) | ((tile & 0x800) != 0 ? SpriteEffects.FlipVertically : SpriteEffects.None); if (showSpecial) { if (Settings.Paradise) { if (tile_id >= PhysicalMapLogic.CONTROL_MIN_ID) { // Rendering of non-graphic special elements Color?c = null; if (ParadisePhysicalMapLogic.STARTING_ZONE_IDS.Contains(tile_id)) { c = ParadisePhysicalMapLogic.StartingZoneColor(tile_id); } else if (ParadisePhysicalMapLogic.HEALING_ZONE_IDS.Contains(tile_id)) { c = ParadisePhysicalMapLogic.HealingZoneColor(tile_id); } else if (ParadisePhysicalMapLogic.ENDING_ZONE_IDS.Contains(tile_id)) { c = ParadisePhysicalMapLogic.EndingZoneColor(tile_id); } else if (ParadisePhysicalMapLogic.FIXED_OBJECTS_IDS.Contains(tile_id)) { sprite_batch.Draw(ParadisePhysicalMapLogic.TextureOfFixedObjects(tile_id), dst, null, Color.White, 0, Vector2.Zero, effects, 0F); } else if (ParadisePhysicalMapLogic.MOVING_OBJECTS_IDS.Contains(tile_id)) // Flips have no effect on moving objects tiles { sprite_batch.Draw(ParadisePhysicalMapLogic.TextureOfMovingObject(tile_id), dst, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0F); } else if (ParadisePhysicalMapLogic.NUMBER_TILES.Contains(tile)) // Palette and flips matters for numbers { sprite_batch.Draw(ParadisePhysicalMapLogic.TextureOfNumber(tile), dst, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0F); } else { c = ParadisePhysicalMapLogic.UNSUPPORTED_COLOR; } if (c.HasValue) { sprite_batch.FillRectangle(dst, c.Value); } } if (tile_id <= PhysicalMapLogic.VISIBLE_MAX_ID) { sprites.Draw(sprite_batch, palette, tile_id, dst, effects); } } else { if (tile_id >= PhysicalMapLogic.CONTROL_MIN_ID) { // Rendering of non-graphic special elements Color?c = null; if (PhysicalMapLogic.STARTING_ZONE_IDS.Contains(tile_id)) { c = PhysicalMapLogic.StartingZoneColor(tile_id); } else if (PhysicalMapLogic.HEALING_ZONE_IDS.Contains(tile_id)) { c = PhysicalMapLogic.HealingZoneColor(tile_id); } else if (PhysicalMapLogic.ENDING_ZONE_IDS.Contains(tile_id)) { c = PhysicalMapLogic.EndingZoneColor(tile_id); } else if (PhysicalMapLogic.SPRING_IDS.Contains(tile_id)) { sprite_batch.Draw(PhysicalMapLogic.TextureOfSpring(tile_id), dst, null, Color.White, 0, Vector2.Zero, effects, 0F); } else if (PhysicalMapLogic.VISIBLE_CONTROL_TILES.Contains(tile_id)) { sprite_batch.Draw(PhysicalMapLogic.UnderlayOfVisibleControlTile(tile_id), dst, null, Color.White, 0, Vector2.Zero, effects, 0F); } else if (PhysicalMapLogic.MOVING_OBJECTS_IDS.Contains(tile_id)) // Flips have no effect on moving objects tiles { sprite_batch.Draw(PhysicalMapLogic.TextureOfMovingObject(tile_id), dst, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0F); } else if (PhysicalMapLogic.NUMBER_TILES.Contains(tile)) // Palette and flips matters for numbers { sprite_batch.Draw(PhysicalMapLogic.TextureOfNumber(tile), dst, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0F); } else { c = PhysicalMapLogic.UNSUPPORTED_COLOR; } if (c.HasValue) { sprite_batch.FillRectangle(dst, c.Value); } } if (tile_id <= PhysicalMapLogic.VISIBLE_MAX_ID || PhysicalMapLogic.VISIBLE_CONTROL_TILES.Contains(tile_id)) { sprites.Draw(sprite_batch, palette, tile_id, dst, effects); } } } else { sprites.Draw(sprite_batch, palette, tile_id, dst, effects); } } }
public OverlayGrid(TilesSet ts, int[,] grid, bool enabled) { this.ts = ts; this.grid = grid; this.enabled = enabled; }