예제 #1
0
        /** <summary> Reads the object data optional. </summary> */
        protected override void ReadOptional(BinaryReader reader)
        {
            // Read the 3D text
            if (Header.Flags.HasFlag(LargeSceneryFlags.Text3D))
            {
                for (int i = 0; i < 0x40E; i++)
                {
                    this.Text3D.Add(reader.ReadByte());
                }
            }
            // Read the tiles
            ushort flag = reader.ReadUInt16();

            while (flag != 0xFFFF)
            {
                reader.BaseStream.Position -= 2;
                LargeSceneryTileHeader tile = new LargeSceneryTileHeader();
                tile.Read(reader);
                this.Tiles.Add(tile);
                flag = reader.ReadUInt16();
            }
        }
예제 #2
0
        //=========== DRAWING ============
        #region Drawing

        /** <summary> Constructs the default object. </summary> */
        public override bool Draw(PaletteImage p, Point position, DrawSettings drawSettings)
        {
            try {
                LargeSceneryTileHeader[] tiles = new LargeSceneryTileHeader[Tiles.Count];
                Rectangle bounds = new Rectangle(100, 100, 0, 0);
                for (int i = 0; i < Tiles.Count; i++)
                {
                    tiles[i]         = Tiles[i];
                    tiles[i].Row    /= 32;
                    tiles[i].Column /= 32;
                    tiles[i].Index   = i;
                    switch (drawSettings.Rotation)
                    {
                    case 0: tiles[i].Depth = (float)tiles[i].Row * 1.001f - (float)tiles[i].Column; break;

                    case 1: tiles[i].Depth = (float)tiles[i].Row + (float)tiles[i].Column * 1.001f; break;

                    case 2: tiles[i].Depth = (float)-tiles[i].Row * 1.001f - (float)tiles[i].Column; break;

                    case 3: tiles[i].Depth = (float)-tiles[i].Row + (float)tiles[i].Column * 1.001f; break;
                    }
                    if (tiles[i].Row < bounds.X)
                    {
                        bounds.X = tiles[i].Row;
                    }
                    if (tiles[i].Column < bounds.Y)
                    {
                        bounds.Y = tiles[i].Column;
                    }
                    if (tiles[i].Row >= bounds.Width)
                    {
                        bounds.Width = tiles[i].Row + 1;
                    }
                    if (tiles[i].Column >= bounds.Height)
                    {
                        bounds.Height = tiles[i].Column + 1;
                    }
                }

                // Insertion sort the tile depths
                for (int i = 1; i < tiles.Length; i++)
                {
                    LargeSceneryTileHeader tile = tiles[i];
                    int j;

                    for (j = i - 1; j >= 0; j--)
                    {
                        if (tile.Depth >= tiles[j].Depth)
                        {
                            break;
                        }
                        tiles[j + 1] = tiles[j];
                    }
                    tiles[j + 1] = tile;
                }

                // Get tht tile corner
                Point cornerPos = Point.Empty;
                switch (drawSettings.Rotation)
                {
                case 0: cornerPos = new Point(bounds.Width - 1, bounds.Y); break;

                case 1: cornerPos = new Point(bounds.Width - 1, bounds.Height - 1); break;

                case 2: cornerPos = new Point(bounds.X, bounds.Height - 1); break;

                case 3: cornerPos = new Point(bounds.X, bounds.Y); break;
                }

                // Draw each tile
                for (int i = 0; i < tiles.Length; i++)
                {
                    int   rot   = (drawSettings.Rotation % 2 == 0 ? -1 :  1);
                    Point point = new Point(
                        (Math.Abs(tiles[i].Row - cornerPos.X) * rot + Math.Abs(tiles[i].Column - cornerPos.Y) * -rot),
                        (Math.Abs(tiles[i].Row - cornerPos.X) * -1 + Math.Abs(tiles[i].Column - cornerPos.Y) * -1)
                        );

                    DrawFrame(p, new Point(
                                  position.X + point.X * 32,
                                  position.Y + point.Y * 16
                                  ), drawSettings, 4 + tiles[i].Index * 4 + (drawSettings.Rotation + 3) % 4);
                }
                // Draw the tile overlay info

                /*if (DrawTileGrid) {
                 *      for (int i = 0; i < tiles.Length; i++) {
                 *              int rot = (drawSettings.Rotation % 2 == 0 ? -1 :  1);
                 *              Point point = new Point(
                 *                      (Math.Abs(tiles[i].Row - cornerPos.X) * rot + Math.Abs(tiles[i].Column - cornerPos.Y) * -rot),
                 *                      (Math.Abs(tiles[i].Row - cornerPos.X) * -1 + Math.Abs(tiles[i].Column - cornerPos.Y) * -1)
                 *              );
                 *
                 *              g.DrawImage(Resources.Selector, new Point(
                 *                      position.X + point.X * 32 - 32,
                 *                      position.Y + point.Y * 16
                 *              ));
                 *              Font font = new Font("Courier", 10f, FontStyle.Bold);
                 *              Brush brush = new SolidBrush(Color.Cyan);
                 *              g.DrawString(tiles[i].Row.ToString(), font, brush, new Point(
                 *                      position.X + point.X * 32 + 12 - 32,
                 *                      position.Y + point.Y * 16 + 8
                 *              ));
                 *              g.DrawString(tiles[i].Column.ToString(), font, brush, new Point(
                 *                      position.X + point.X * 32 + 36 - 32,
                 *                      position.Y + point.Y * 16 + 8
                 *              ));
                 *              font.Dispose();
                 *      }
                 * }*/
            }
            catch (IndexOutOfRangeException) { return(false); }
            catch (ArgumentOutOfRangeException) { return(false); }
            return(true);
        }