コード例 #1
0
        public override void drawVoxel(QuarterViewDrawer view, DrawContextEx canvas, Location loc, Point pt)
        {
            if (base.currentPos != loc)
            {
                return;
            }
            if (!contribution.canBeBuilt(loc))
            {
                return;
            }

            int         x;
            RailPattern rp = TrafficVoxel.get(loc).railRoad.getPattern();

            if (rp.hasRail(Direction.NORTH))
            {
                x = 1;
            }
            else
            {
                x = 0;
            }

            contribution.sprites[x, 0].drawAlpha(canvas.surface, pt);
            contribution.sprites[x, 1].drawAlpha(canvas.surface, pt);
        }
コード例 #2
0
        public override void updatePreview()
        {
            RailPattern rp = RailPattern.get(currentDirection, currentDirection.opposite);

            using (PreviewDrawer drawer = new PreviewDrawer(preview.Size, new Size(1, 1), 0)) {
                // draw the rail
                for (int i = -5; i < 5; i++)
                {
                    if (currentDirection.isParallelToX)
                    {
                        drawer.draw(rp, i, 0);
                    }
                    else
                    {
                        drawer.draw(rp, 0, i);
                    }
                }

                // draw the signal
                drawer.draw(rp, 0, 0);
                drawer.draw(currentType.getSprite(currentDirection), 0, 0);

                // draw the arrow
                currentDirection.drawArrow(drawer.surface,
                                           drawer.getPoint(-currentDirection.offsetX, -currentDirection.offsetY));

                preview.Image = drawer.createBitmap();
            }
        }
コード例 #3
0
        public bool canBeBuilt(Location loc)
        {
            TrafficVoxel voxel = TrafficVoxel.get(loc);

            if (voxel == null)
            {
                return(false);
            }

            RailRoad rr = voxel.railRoad;

            if (rr == null)
            {
                return(false);
            }

            RailPattern rp = rr.getPattern();

            if (rp.numberOfRails != 2)
            {
                return(false);
            }

            if (!rp.hasRail(rr.dir1.opposite))
            {
                return(false);
            }

            return(rr.dir1.isSharp);
        }
コード例 #4
0
        public override void updatePreview()
        {
            PreviewDrawer drawer;

            // TODO: locations of the previews are uttely incorrect. fix them

            // direction N
            using (drawer = new PreviewDrawer(pictureN.ClientSize, new Size(2, 4), 0)) {
                drawer.draw(RailPattern.getSlope(Direction.NORTH, 3), 1, -1);
                drawer.draw(RailPattern.getSlope(Direction.NORTH, 2), 1, 0);
                drawer.draw(RailPattern.getSlope(Direction.NORTH, 1), 0, 2);
                drawer.draw(RailPattern.getSlope(Direction.NORTH, 0), 0, 3);
                if (pictureN.Image != null)
                {
                    pictureN.Image.Dispose();
                }
                pictureN.Image = drawer.createBitmap();
            }

            // direction S
            using (drawer = new PreviewDrawer(pictureS.ClientSize, new Size(2, 4), 0)) {
                drawer.draw(RailPattern.getSlope(Direction.SOUTH, 0), 0, 0);
                drawer.draw(RailPattern.getSlope(Direction.SOUTH, 1), 0, 1);
                drawer.draw(RailPattern.getSlope(Direction.SOUTH, 2), 1, 1);
                drawer.draw(RailPattern.getSlope(Direction.SOUTH, 3), 1, 2);
                if (pictureS.Image != null)
                {
                    pictureS.Image.Dispose();
                }
                pictureS.Image = drawer.createBitmap();
            }

            // direction E
            using (drawer = new PreviewDrawer(pictureE.ClientSize, new Size(4, 2), 0)) {
                drawer.draw(RailPattern.getSlope(Direction.EAST, 3), 3, 0);
                drawer.draw(RailPattern.getSlope(Direction.EAST, 2), 2, 0);
                drawer.draw(RailPattern.getSlope(Direction.EAST, 1), 0, 1);
                drawer.draw(RailPattern.getSlope(Direction.EAST, 0), -1, 1);
                if (pictureE.Image != null)
                {
                    pictureE.Image.Dispose();
                }
                pictureE.Image = drawer.createBitmap();
            }

            // direction W
            using (drawer = new PreviewDrawer(pictureW.ClientSize, new Size(4, 2), 0)) {
                drawer.draw(RailPattern.getSlope(Direction.WEST, 3), 1, 0);
                drawer.draw(RailPattern.getSlope(Direction.WEST, 2), 2, 0);
                drawer.draw(RailPattern.getSlope(Direction.WEST, 1), 2, 1);
                drawer.draw(RailPattern.getSlope(Direction.WEST, 0), 3, 1);
                if (pictureW.Image != null)
                {
                    pictureW.Image.Dispose();
                }
                pictureW.Image = drawer.createBitmap();
            }
        }
コード例 #5
0
 public SignalRailRoad(TrafficVoxel v, RailSignalContribution _type, Direction _dir)
     : base(v, _dir)
 {
     this.direction = _dir;
     this.type      = _type;
     pattern        = RailPattern.get(direction, direction.opposite);
     Debug.Assert(dir1.isSharp);
     Debug.Assert(dir2.isSharp);
 }
コード例 #6
0
 public void drawVoxel(QuarterViewDrawer view, DrawContextEx dc, Location loc, Point pt)
 {
     if (loc == baseLoc)
     {
         RailPattern.get(currentDirection, currentDirection.opposite)
         .drawAlpha(dc.surface, pt);
         currentType.getSprite(currentDirection)
         .drawAlpha(dc.surface, pt);
     }
 }
コード例 #7
0
        /// <summary>
        /// Builds a nice preview of a train.
        /// </summary>
        public PreviewDrawer CreatePreview(Size pixelSize, int trainlength)
        {
            PreviewDrawer pd = new PreviewDrawer(pixelSize, new Size(1, 3), 0);

            // build up rail like
            //
            //     /~~~~~
            //    /
            for (int x = -10; x < 0; x++)
            {
                pd.Draw(RailPattern.get(Direction.WEST, Direction.EAST), x, 0);
            }
            pd.Draw(RailPattern.get(Direction.WEST, Direction.SOUTHEAST), 0, 0);
            for (int x = 1; x <= 10; x++)
            {
                pd.Draw(RailPattern.get(Direction.NORTHWEST, Direction.SOUTHEAST), x, x);
            }

            TrainCarContribution[] cars = Create(trainlength);

            /*if( cars==null ) {
             *  for( int i=6; cars==null && i<15; i++ )
             *      cars = create(i);
             *  for( int i=4; cars==null && i>0; i-- )
             *      cars = create(i);
             *  if( cars==null )
             *      return pd;	// no preview
             * }*/

            if (cars == null)
            {
                return(pd);                     // no preview
            }
            int[] pos    = new int[] { -2, 0, -1, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
            int[] angle  = new int[] { 12, 12, 13, 14, 14, 14, 14, 14 };
            int[] offset = new int[] { 0, 0, 0, 0, 4, +2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            using (DrawContext dc = new DrawContext(pd.Surface))
            {
                for (int i = 7; i >= 0; i--)
                {
                    if (cars.Length <= i)
                    {
                        continue;               // no car
                    }

                    Point pt = pd.GetPoint(pos[i * 2], pos[i * 2 + 1]);
                    cars[i].Draw(pd.Surface,
                                 new Point(pt.X + offset[i * 2], pt.Y + offset[i * 2 + 1] - 9), angle[i]);
                }
            }

            return(pd);
        }
コード例 #8
0
 public override void updatePreview()
 {
     using (PreviewDrawer drawer = new PreviewDrawer(picture.Size, new Size(1, 10), 0))
     {
         for (int i = 0; i < 10; i++)
         {
             drawer.draw(RailPattern.get(Direction.NORTH, Direction.SOUTH), 0, i);
         }
         if (picture.Image != null)
         {
             picture.Image.Dispose();
         }
         picture.Image = drawer.createBitmap();
     }
 }
コード例 #9
0
        /// <summary>
        /// Create a new electric pole at the specified location.
        /// </summary>
        /// <param name="loc"></param>
        public void create(Location loc)
        {
            Debug.Assert(canBeBuilt(loc));

            int         x;
            RailPattern rp = TrafficVoxel.get(loc).railRoad.getPattern();

            if (rp.hasRail(Direction.NORTH))
            {
                x = 1;
            }
            else
            {
                x = 0;
            }

            new ElectricPole(TrafficVoxel.get(loc), this, x);
        }
コード例 #10
0
        public override PreviewDrawer createPreview(Size pixelSize)
        {
            PreviewDrawer drawer = new PreviewDrawer(pixelSize, new Size(10, 1), 0);

            for (int x = 9; x >= 0; x--)
            {
                if (x == 5)
                {
                    drawer.draw(sprites[0, 0], x, 0);
                }
                drawer.draw(RailPattern.get(Direction.EAST, Direction.WEST), x, 0);
                if (x == 5)
                {
                    drawer.draw(sprites[0, 1], x, 0);
                }
            }
            return(drawer);
        }
コード例 #11
0
        public void drawVoxel(QuarterViewDrawer view, DrawContextEx canvas, Location loc, Point pt)
        {
            IDictionary dic = (IDictionary)canvas.tag;

            if (dic != null)
            {
                RailPattern rp = (RailPattern)dic[loc];
                if (rp != null)
                {
                    for (int j = World.world.getGroundLevel(loc); j < loc.z; j++)
                    {
                        // TODO: ground level handling
                        BridgePierVoxel.defaultSprite.drawAlpha(
                            canvas.surface,
                            view.fromXYZToClient(loc.x, loc.y, j));
                    }

                    rp.drawAlpha(canvas.surface, pt);
                }
            }
        }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="view"></param>
        /// <param name="canvas"></param>
        /// <param name="location"></param>
        /// <param name="point"></param>
        public void DrawVoxel(QuarterViewDrawer view, DrawContext canvas, Location location, Point point)
        {
            IDictionary dic = (IDictionary)canvas.Tag;

            if (dic != null)
            {
                RailPattern rp = (RailPattern)dic[location];
                if (rp != null)
                {
                    for (int j = WorldDefinition.World.GetGroundLevel(location); j < location.z; j++)
                    {
                        // TODO: ground level handling
                        BridgePierVoxel.defaultSprite.DrawAlpha(
                            canvas.Surface,
                            view.fromXYZToClient(location.x, location.y, j));
                    }

                    rp.DrawAlpha(canvas.Surface, point);
                }
            }
        }
コード例 #13
0
        public void drawAfter(QuarterViewDrawer view, DrawContextEx dc)
        {
            if (!isPlacing)
            {
                return;
            }
            Location loc = lastMouse;

            if (loc == world.Location.UNPLACED)
            {
                return;
            }
            if (!SlopeRailRoad.canCreateSlope(loc, direction))
            {
                return;
            }

            Surface canvas = dc.surface;

            int Z = loc.z;

            for (int i = 0; i < 4; i++)
            {
                if (i == 2)
                {
                    loc.z++;
                }

                for (int j = World.world.getGroundLevel(loc); j < Z; j++)
                {
                    // TODO: ground level handling
                    BridgePierVoxel.defaultSprite.drawAlpha(
                        canvas, view.fromXYZToClient(loc.x, loc.y, j));
                }

                RailPattern.getSlope(direction, i).drawAlpha(
                    canvas, view.fromXYZToClient(loc));
                loc += direction;
            }
        }
コード例 #14
0
ファイル: Traffic.cs プロジェクト: hayate891/freetrain
        /// <summary>
        /// Check if this voxel should have a rail road crossing.
        /// </summary>
        /// <returns></returns>
        private bool shouldHaveCrossing()
        {
            if (_railRoad == null || _road == null)
            {
                return(false);
            }

            RailPattern rp    = _railRoad.getPattern();
            Direction   rdir1 = _railRoad.dir1;

            if (rp.numberOfRails != 2 || !rp.hasRail(rdir1.opposite))
            {
                return(false);                  // the rail must be going straight.
            }
            if (!rdir1.isSharp)
            {
                return(false);                  // rail must be paralell to X-axis or Y-axis.
            }
            if (!_road.hasRoad(rdir1.left90) || !_road.hasRoad(rdir1.right90))
            {
                return(false);                  // road must be orthogonal to rail road
            }
            return(true);
        }
コード例 #15
0
ファイル: TrainGarage.cs プロジェクト: hayate891/freetrain
 /// <summary>
 /// Replace this garage by a normal rail road
 /// </summary>
 internal void remove()
 {
     new SingleRailRoad(voxel, RailPattern.get(dir1, dir2));
 }
コード例 #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="d"></param>
 /// <param name="canvas"></param>
 /// <param name="pt"></param>
 protected override void Draw(Direction d, DrawContext canvas, Point pt)
 {
     RailPattern.get(d, d.opposite).DrawAlpha(canvas.Surface, pt);
 }
コード例 #17
0
        /// <summary>
        /// Re-builds an alpha-blending preview.
        /// </summary>
        private void updateAlphaSprites()
        {
            if (direction == null)
            {
                return;                         // during the initialization, this method can be called in a wrong timing.
            }
            if (alphaSprites != null)
            {
                alphaSprites.Dispose();
            }


            ISprite[, ,] alphas = null;

            switch (this.currentMode)
            {
            case Mode.Station:
                // builds a new alpha blended preview
                alphas = selectedStation.Sprites;
                break;

            case Mode.ThinPlatform:
                ISprite spr = ThinPlatform.getSprite(direction, false);

                // build sprite set
                // TODO: use the correct sprite
                if (direction == Direction.NORTH || direction == Direction.SOUTH)
                {
                    alphas = new ISprite[1, length, 1];
                    for (int i = 0; i < length; i++)
                    {
                        alphas[0, i, 0] = spr;
                    }
                }
                else
                {
                    alphas = new ISprite[length, 1, 1];
                    for (int i = 0; i < length; i++)
                    {
                        alphas[i, 0, 0] = spr;
                    }
                }

                alphaSprites = new AlphaBlendSpriteSet(alphas);
                break;

            case Mode.FatPlatform:
                RailPattern rp = this.railPattern;


                // build sprite set
                if (direction == Direction.NORTH || direction == Direction.SOUTH)
                {
                    alphas = new ISprite[2, length, 1];
                    int j = direction == Direction.SOUTH ? 1 : 0;
                    for (int i = 0; i < length; i++)
                    {
                        alphas[j, i, 0]     = FatPlatform.getSprite(direction);
                        alphas[j ^ 1, i, 0] = railPattern;
                    }
                }
                else
                {
                    alphas = new ISprite[length, 2, 1];
                    int j = direction == Direction.WEST ? 1 : 0;
                    for (int i = 0; i < length; i++)
                    {
                        alphas[i, j, 0]     = FatPlatform.getSprite(direction);
                        alphas[i, j ^ 1, 0] = railPattern;
                    }
                }
                break;
            }

            alphaSprites = new AlphaBlendSpriteSet(alphas);
            WorldDefinition.World.OnAllVoxelUpdated();  // completely redraw the window
        }