private void OpenDialog_FileOk(object sender, CancelEventArgs e) { currentFilePath = OpenDialog.FileName; BinaryReader input = new BinaryReader(File.OpenRead(currentFilePath)); MapView.CreateMap(input.ReadInt32(), input.ReadInt32()); for (int i = 0; i < MapView.MapWidth; i++) { for (int j = 0; j < MapView.MapHeight; j++) { // Quick fix to enable modifying maps made before code changes to fit the current format string name = input.ReadString(); if (name.Contains('.')) { name = name.Split('.')[0]; } MapView[i, j].Data = Tileset.Sources[name]; MapView[i, j].ImageIndex = input.ReadInt32(); input.ReadInt32(); // Depth, the program already knows this value for the given material } } MapView.MapEvents = new List <GameEvent>(); // Number of Events, not yet implemented int numEvents = input.ReadInt32(); for (int i = 0; i < numEvents; i++) { GameEvent g = new GameEvent(); g.EventType = (EventType)input.ReadInt32(); g.XIndex = input.ReadInt32(); g.YIndex = input.ReadInt32(); g.Location = new Point(1 + g.XIndex * 32, 1 + g.YIndex * 32); g.Image = Properties.Resources.Enemy; Map.SetupGameEvent(g); if (g.EventType == EventType.Warp) { WarpCreator c = new WarpCreator(); c.MapName = input.ReadString(); c.XOffset = input.ReadInt32(); c.YOffset = input.ReadInt32(); c.LoadMap(); g.Image = Properties.Resources.Warp; WarpData warpData = new WarpData(c); g.WarpData = warpData; } MapView.MapEvents.Add(g); MapView.Controls.Add(g); g.BringToFront(); } input.Close(); }
// Constructor public WarpData(WarpCreator creator) { this.creator = creator; }
private void SetEvent(int xIndex, int yIndex) { switch (mode) { case EditorMode.Remove: // Store all events that occur at the coordinates List <GameEvent> eventsAtLocation = new List <GameEvent>(); foreach (GameEvent g in events) { if (g.XIndex == xIndex && g.YIndex == yIndex) { eventsAtLocation.Add(g); } } // Remove all events at these coordinates foreach (GameEvent g in eventsAtLocation) { events.Remove(g); Controls.Remove(g); } break; case EditorMode.Enemy: // Only one enemy can exist at a location at a time, so first check for other enemies GameEvent enemyEvent = null; foreach (GameEvent g in events) { if (g.EventType == EventType.Enemy && g.XIndex == xIndex && g.YIndex == yIndex) { enemyEvent = g; break; } } // Only place an enemy if one doesn't exist if (enemyEvent == null) { enemyEvent = new GameEvent(); enemyEvent.EventType = EventType.Enemy; enemyEvent.Location = new Point(1 + xIndex * 32 + AutoScrollPosition.X, 1 + yIndex * 32 + AutoScrollPosition.Y); enemyEvent.Image = Properties.Resources.Enemy; enemyEvent.MouseClick += new MouseEventHandler(TileClick); enemyEvent.XIndex = xIndex; enemyEvent.YIndex = yIndex; events.Add(enemyEvent); Controls.Add(enemyEvent); enemyEvent.BringToFront(); } break; case EditorMode.Warp: // Only one warp can exist at a location at a time, so first check for other warps GameEvent warpEvent = null; foreach (GameEvent g in events) { if (g.EventType == EventType.Warp && g.XIndex == xIndex && g.YIndex == yIndex) { // Do stuff then break warpEvent = g; break; } } // Either edit the current warp if it exists or create a new one if (warpEvent == null) { WarpCreator creator = new WarpCreator(); creator.ShowDialog(); if (creator.Finished) { warpEvent = new GameEvent(); warpEvent.EventType = EventType.Warp; warpEvent.WarpData = new WarpData(creator); warpEvent.Location = new Point(1 + xIndex * 32 + AutoScrollPosition.X, 1 + yIndex * 32 + AutoScrollPosition.Y); warpEvent.MouseClick += new MouseEventHandler(TileClick); warpEvent.Image = Properties.Resources.Warp; warpEvent.XIndex = xIndex; warpEvent.YIndex = yIndex; events.Add(warpEvent); Controls.Add(warpEvent); warpEvent.BringToFront(); } } else { warpEvent.WarpData.WarpCreator.Show(); } break; } }