Exemple #1
0
        public void SetEntrance(int Index, Entrance Entrance)
        {
            entrances[Index] = Entrance;

            Saved = false;
            if (AttachedView != null)
            {
                AttachedView.UpdateTitle();
                AttachedView.UpdateObjects();
            }
        }
Exemple #2
0
        void DrawEntranceDesc(Graphics g)
        {
            for (int i = 0; i < doc.EntranceCount; i++)
            {
                Entrance  en = doc.GetEntrance(i);
                Rectangle rc = en.Rect;

                StringFormat fmt = new StringFormat();
                fmt.Alignment     = StringAlignment.Far;
                fmt.LineAlignment = StringAlignment.Far;
                g.DrawString((i + 1).ToString(), this.Font, new SolidBrush(Color.White), rc.Left, rc.Top, fmt);
            }
        }
Exemple #3
0
        public void AddEntrance(Rectangle Rect)
        {
            Entrance e = new Entrance();

            e.Rect = Rect;
            entrances.Add(e);

            Saved = false;
            if (AttachedView != null)
            {
                AttachedView.UpdateObjects();
                AttachedView.UpdateTitle();
            }
        }
Exemple #4
0
        void DrawEntrances(Graphics g)
        {
            for (int i = 0; i < doc.EntranceCount; i++)
            {
                Entrance  en  = doc.GetEntrance(i);
                Pen       pen = new Pen((i == entranceSelected && (Mode == EditMode.Entrance || Mode == EditMode.Way)) ? Color.Yellow : Color.Blue, 1);
                Rectangle rc  = en.Rect;
                //rc.Offset(-AutoScrollPosition.X, -AutoScrollPosition.Y);

                int alpha = 50;
                if (i == entranceMoveIndex)
                {
                    alpha = 150;
                }
                g.FillRectangle(new SolidBrush(Color.FromArgb(alpha, 0, 0, 255)), rc);
                g.DrawRectangle(pen, rc);
            }
        }
Exemple #5
0
        public bool Open(Stream File, List <TileSet> TileSets)
        {
            BinaryReader reader = new BinaryReader(File);

            if (reader.ReadString() != "Burntime Map")
            {
                return(false);
            }
            String ver = reader.ReadString();

            if (ver != "0.1" && ver != "0.2")
            {
                return(false);
            }

            // header
            Size.Width  = reader.ReadInt32();
            Size.Height = reader.ReadInt32();
            TileSize    = reader.ReadInt32();

            tiles = new Tile[Size.Width, Size.Height];

            // set indices
            List <String> indices = new List <string>();
            int           count   = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                indices.Add(reader.ReadString());
            }

            Dictionary <String, int> indices2 = new Dictionary <string, int>();

            for (int i = 0; i < TileSets.Count; i++)
            {
                indices2.Add(TileSets[i].Name, i);
            }

            // tiles
            for (int y = 0; y < Size.Height; y++)
            {
                for (int x = 0; x < Size.Width; x++)
                {
                    byte id     = reader.ReadByte();
                    byte subset = reader.ReadByte();
                    byte set    = reader.ReadByte();

                    if (subset == 0)
                    {
                    }
                    else
                    {
#warning // crashes if tile set was removed
                        tiles[x, y] = TileSets[indices2[indices[set]]].Find(subset, id);
                    }
                }
            }

            // entrances

            count = reader.ReadByte();
            for (int i = 0; i < count; i++)
            {
                Entrance e = new Entrance();

                e.Rect.X      = reader.ReadInt32();
                e.Rect.Y      = reader.ReadInt32();
                e.Rect.Width  = reader.ReadInt32();
                e.Rect.Height = reader.ReadInt32();

                entrances.Add(e);
            }

            if (ver == "0.2")
            {
                count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    Way way = new Way();
                    way.Days        = reader.ReadByte();
                    way.Entrance[0] = reader.ReadByte();
                    way.Entrance[1] = reader.ReadByte();

                    int wpc = reader.ReadByte();
                    for (int j = 0; j < wpc; j++)
                    {
                        Point pt = new Point();
                        pt.X = reader.ReadInt32();
                        pt.Y = reader.ReadInt32();
                        way.Points.Add(pt);
                    }
                }
            }

            Saved = true;
            if (AttachedView != null)
            {
                AttachedView.UpdateTitle();
                AttachedView.UpdateMap();
            }

            return(true);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            mouse.X = (e.Location.X - AutoScrollPosition.X);
            mouse.Y = (e.Location.Y - AutoScrollPosition.Y);
            base.OnMouseMove(e);

            if (doc == null)
            {
                return;
            }

            if (Mode != EditMode.Entrance)
            {
                entranceResizeIndex = -1;
                entranceMoveIndex   = -1;
            }

            if (Mode != EditMode.Way)
            {
                waySelectIndex     = -1;
                wayPointMoveIndex  = -1;
                wayPointHoverIndex = -1;
            }

            switch (mode)
            {
            case EditMode.Tile:
                if (e.Button == MouseButtons.Left && Tile != null && tilePainting)
                {
                    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)
                    {
                        if (doc.GetTile(pt.X, pt.Y) != Tile)
                        {
                            doc.SetTile(pt.X, pt.Y, Tile);
                        }
                    }
                }
                break;

            case EditMode.Entrance:
                if (!entranceMoving && !entranceResizing)
                {
                    Cursor cursor = Cursors.Arrow;

                    entranceResizeCorner = ResizeCorner.None;
                    entranceResizeIndex  = -1;
                    entranceMoveIndex    = -1;

                    for (int i = 0; i < doc.EntranceCount && entranceResizeIndex == -1; i++)
                    {
                        Entrance en = doc.GetEntrance(i);

                        Rectangle rc = en.Rect;
                        rc.Inflate(2, 2);

                        if (rc.Contains(mouse))
                        {
                            rc.Inflate(-4, -4);
                            if (!rc.Contains(mouse))
                            {
                                entranceResizeCorner |= (mouse.X <= rc.Left) ? ResizeCorner.Left : ResizeCorner.None;
                                entranceResizeCorner |= (mouse.X >= rc.Right) ? ResizeCorner.Right : ResizeCorner.None;
                                entranceResizeCorner |= (mouse.Y <= rc.Top) ? ResizeCorner.Top : ResizeCorner.None;
                                entranceResizeCorner |= (mouse.Y >= rc.Bottom) ? ResizeCorner.Bottom : ResizeCorner.None;

                                entranceResizeIndex = i;

                                switch (entranceResizeCorner)
                                {
                                case ResizeCorner.Left:
                                case ResizeCorner.Right:
                                    cursor = Cursors.SizeWE;
                                    break;

                                case ResizeCorner.Top:
                                case ResizeCorner.Bottom:
                                    cursor = Cursors.SizeNS;
                                    break;

                                case ResizeCorner.TopRight:
                                case ResizeCorner.BottomLeft:
                                    cursor = Cursors.SizeNESW;
                                    break;

                                case ResizeCorner.TopLeft:
                                case ResizeCorner.BottomRight:
                                    cursor = Cursors.SizeNWSE;
                                    break;

                                default:
                                    entranceResizeIndex  = -1;
                                    entranceResizeCorner = ResizeCorner.None;
                                    break;
                                }
                            }
                            else
                            {
                                cursor            = Cursors.SizeAll;
                                entranceMoveIndex = i;
                            }
                        }
                    }

                    Cursor = cursor;
                }
                if (entranceResizing)
                {
                    Entrance en = doc.GetEntrance(entranceResizeIndex);

                    if ((entranceResizeCorner & ResizeCorner.Left) != ResizeCorner.None)
                    {
                        int change = (en.Rect.X - mouse.X) + en.Rect.Width;
                        if (change < 6)
                        {
                            change = 6;
                        }
                        en.Rect.X     = en.Rect.Right - change;
                        en.Rect.Width = change;
                    }
                    if ((entranceResizeCorner & ResizeCorner.Right) != ResizeCorner.None)
                    {
                        en.Rect.Width = (mouse.X - en.Rect.X);
                        if (en.Rect.Width < 6)
                        {
                            en.Rect.Width = 6;
                        }
                    }
                    if ((entranceResizeCorner & ResizeCorner.Top) != ResizeCorner.None)
                    {
                        int change = (en.Rect.Y - mouse.Y) + en.Rect.Height;
                        if (change < 6)
                        {
                            change = 6;
                        }
                        en.Rect.Y      = en.Rect.Bottom - change;
                        en.Rect.Height = change;
                    }
                    if ((entranceResizeCorner & ResizeCorner.Bottom) != ResizeCorner.None)
                    {
                        en.Rect.Height = (mouse.Y - en.Rect.Y);
                        if (en.Rect.Height < 6)
                        {
                            en.Rect.Height = 6;
                        }
                    }

                    doc.SetEntrance(entranceResizeIndex, en);
                }

                if (entranceMoving)
                {
                    Entrance en = doc.GetEntrance(entranceMoveIndex);

                    if (en.Rect.X != mouse.X + entranceMoveOffset.X &&
                        en.Rect.Y != mouse.Y + entranceMoveOffset.Y)
                    {
                        en.Rect.X = mouse.X + entranceMoveOffset.X;
                        en.Rect.Y = mouse.Y + entranceMoveOffset.Y;

                        doc.SetEntrance(entranceMoveIndex, en);
                    }
                }
                break;

            case EditMode.Way:
                entranceMoveIndex = -1;

                for (int i = 0; i < doc.EntranceCount; i++)
                {
                    Entrance en = doc.GetEntrance(i);

                    Rectangle rc = en.Rect;
                    rc.Inflate(2, 2);

                    if (rc.Contains(mouse))
                    {
                        entranceMoveIndex = i;
                    }
                }

                wayHoverIndex = -1;
                if (entranceMoveIndex == -1 && entranceResizeIndex == -1)
                {
                    for (int j = 0; j < doc.WayCount; j++)
                    {
                        Way way = doc.GetWay(j);

                        Rectangle rc0 = doc.GetEntrance(way.Entrance[0]).Rect;
                        Rectangle rc1 = doc.GetEntrance(way.Entrance[1]).Rect;

                        Rectangle area = Rectangle.Union(rc0, rc1);
                        if (area.Contains(mouse))
                        {
                            PointF start = new PointF(rc0.Left + rc0.Width / 2, rc0.Top + rc0.Height / 2);
                            PointF end   = new PointF(rc1.Left + rc1.Width / 2, rc1.Top + rc1.Height / 2);
                            PointF dir   = new PointF(end.X - start.X, end.Y - start.Y);
                            float  len   = (float)Math.Sqrt(dir.X * dir.X + dir.Y * dir.Y);
                            dir.X /= len;
                            dir.Y /= len;

                            float  lambda = (mouse.X - start.X) * dir.X + (mouse.Y - start.Y) * dir.Y;
                            PointF d      = new PointF();
                            d.X = start.X + lambda * dir.X;
                            d.Y = start.Y + lambda * dir.Y;

                            float dist = (float)Math.Sqrt((d.X - mouse.X) * (d.X - mouse.X) + (d.Y - mouse.Y) * (d.Y - mouse.Y));
                            if (dist < 8)
                            {
                                wayHoverIndex = j;
                            }
                        }
                    }
                }

                wayPointHoverIndex = -1;
                if (entranceMoveIndex == -1 && entranceResizeIndex == -1)
                {
                    for (int j = 0; j < doc.WayCount; j++)
                    {
                        Way way = doc.GetWay(j);

                        for (int k = 0; k < doc.Ways[j].Points.Count; k++)
                        {
                            Rectangle rect = new Rectangle(way.Points[k].X - 2, way.Points[k].Y - 2, 5, 5);
                            rect.Inflate(3, 3);
                            if (rect.Contains(mouse))
                            {
                                wayPointHoverIndex = k;
                                wayHoverIndex      = j;
                            }
                        }
                    }
                }

                if (wayPointMoving)
                {
                    Point pt = doc.Ways[wayMoveIndex].Points[wayPointMoveIndex];
                    if (pt.X != mouse.X + wayPointMoveOffset.X &&
                        pt.Y != mouse.Y + wayPointMoveOffset.Y)
                    {
                        pt.X = mouse.X + wayPointMoveOffset.X;
                        pt.Y = mouse.Y + wayPointMoveOffset.Y;
                        doc.Ways[wayMoveIndex].Points[wayPointMoveIndex] = pt;
                        doc.Saved = false;
                    }
                }
                break;

            case EditMode.Walkable:
                if (walkablePainting)
                {
                    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);
                        }
                    }
                }
                break;
            }

            Invalidate();
        }