public void New(Size Size, int TileSize) { this.Size = Size; this.TileSize = TileSize; Title = "unnamed"; Saved = true; tiles = new Tile[Size.Width, Size.Height]; AttachedView.UpdateMap(); AttachedView.UpdateTitle(); }
protected override void OnMouseDown(MouseEventArgs e) { if (doc == null) { return; } switch (mode) { case EditMode.Tile: if (e.Button == MouseButtons.Left) { if (doc != null && Mode == EditMode.Tile && Tile != null) { Point pt = e.Location; pt.X = (pt.X - AutoScrollPosition.X) / doc.TileSize; pt.Y = (pt.Y - AutoScrollPosition.Y) / doc.TileSize; if (pt.X >= 0 && pt.Y >= 0 && pt.X < doc.Size.Width && pt.Y < doc.Size.Height) { doc.SetTile(pt.X, pt.Y, Tile); } } tilePainting = true; } break; case EditMode.Entrance: if (e.Button == MouseButtons.Right) { entranceSelected = -1; } else if (e.Button == MouseButtons.Left) { if (entranceResizeIndex != -1) { entranceResizing = true; entranceSelected = entranceResizeIndex; ClickEntrance.Invoke(this, new EntranceEventArgs(entranceSelected)); UpdateObjects(); } if (entranceMoveIndex != -1) { Entrance en = doc.GetEntrance(entranceMoveIndex); entranceMoving = true; entranceMoveOffset.X = en.Rect.X - mouse.X; entranceMoveOffset.Y = en.Rect.Y - mouse.Y; entranceSelected = entranceMoveIndex; ClickEntrance.Invoke(this, new EntranceEventArgs(entranceSelected)); UpdateObjects(); } } break; case EditMode.Way: if (e.Button == MouseButtons.Right) { waySelectIndex = -1; } else if (e.Button == MouseButtons.Left) { if (entranceMoveIndex != -1) { waySelectIndex = -1; Entrance en = doc.GetEntrance(entranceMoveIndex); entranceMoving = true; entranceMoveOffset.X = en.Rect.X - mouse.X; entranceMoveOffset.Y = en.Rect.Y - mouse.Y; entranceSelected = entranceMoveIndex; ClickEntrance.Invoke(this, new EntranceEventArgs(entranceSelected)); UpdateObjects(); } if (wayHoverIndex != -1) { entranceSelected = -1; waySelectIndex = wayHoverIndex; UpdateObjects(); } if (wayPointHoverIndex != -1) { wayPointMoving = true; wayPointMoveOffset.X = doc.Ways[wayHoverIndex].Points[wayPointHoverIndex].X - mouse.X; wayPointMoveOffset.Y = doc.Ways[wayHoverIndex].Points[wayPointHoverIndex].Y - mouse.Y; wayPointMoveIndex = wayPointHoverIndex; wayMoveIndex = wayHoverIndex; } } break; case EditMode.Walkable: { Point pt = e.Location; pt.X = (pt.X - AutoScrollPosition.X) / doc.TileSize; pt.Y = (pt.Y - AutoScrollPosition.Y) / doc.TileSize; if (pt.X >= 0 && pt.Y >= 0 && pt.X < doc.Size.Width && pt.Y < doc.Size.Height) { Tile tile = doc.GetTile(pt.X, pt.Y); if (tile != null) { Point sub = e.Location; sub.X = (sub.X - AutoScrollPosition.X) / (doc.TileSize / 4); sub.Y = (sub.Y - AutoScrollPosition.Y) / (doc.TileSize / 4); sub.X -= pt.X * 4; sub.Y -= pt.Y * 4; tile.Mask[sub.X + sub.Y * 4] = (e.Button == MouseButtons.Left); TileManager.Change(tile); } } walkablePainting = true; } break; } if (e.Button == MouseButtons.Left && wayPointHoverIndex == -1) { Click.Invoke(this, new MapClickEventArgs(mouse)); } else if (e.Button == MouseButtons.Right) { RightClick.Invoke(this, new MapClickEventArgs(mouse)); } if (attachedView != null) { attachedView.UpdateTitle(); } base.OnMouseDown(e); }