Exemplo n.º 1
0
        private static void SerializeMapCellState(BinaryWriter Writer, MapCellState CellState)
        {
            if (CellState == null)
            {
                return;
            }

            MapWallState northWall = CellState.GetWall(MapDirection.North);
            MapWallState southWall = CellState.GetWall(MapDirection.South);
            MapWallState westWall  = CellState.GetWall(MapDirection.West);
            MapWallState eastWall  = CellState.GetWall(MapDirection.East);

            SerializeMapPlaceState(Writer, CellState.Place);

            if (northWall != null)
            {
                SerializeMapWallState(Writer, northWall);
            }
            if (southWall != null)
            {
                SerializeMapWallState(Writer, southWall);
            }
            if (westWall != null)
            {
                SerializeMapWallState(Writer, westWall);
            }
            if (eastWall != null)
            {
                SerializeMapWallState(Writer, eastWall);
            }
        }
        private static MapWallState DeserializeMapWallState(BinaryReader Reader, MapWall wall, MapDirection direction)
        {
            MapWallState state = new MapWallState(wall, direction);

            state.Mode   = DeserializeMapWallMode(Reader);
            state.Health = Reader.ReadUInt16();
            return(state);
        }
        private FrameworkElement RenderWall(MapWallState wall, Rect area)
        {
            if (wall == null)
            {
                return(null);
            }
            if (wall.Wall == null)
            {
                return(null);
            }

            MapImageWPF imageSource = new MapImageWPF(wall.CurrentImage);
            Image       image       = new Image {
                Source = imageSource.Image
            };

            double wallWidth  = area.Width * WallPadding;
            double wallHeight = area.Height * WallPadding;

            double imageWidth  = area.Width;
            double imageHeight = wallHeight;

            image.Stretch = Stretch.Fill;


            if (wall.Direction == MapDirection.North)
            {
                Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top); image.Width = imageWidth; image.Height = imageHeight;
            }

            if (wall.Direction == MapDirection.South)
            {
                Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + area.Height); image.Width = imageWidth; image.Height = imageHeight;
                image.RenderTransformOrigin = new Point(0.5, 0);
                image.RenderTransform       = new RotateTransform(-180);
            }

            if (wall.Direction == MapDirection.West)
            {
                Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + imageWidth); image.Width = imageWidth; image.Height = imageHeight;
                image.RenderTransformOrigin = new Point(0, 0);
                image.RenderTransform       = new RotateTransform(-90);
            }

            if (wall.Direction == MapDirection.East)
            {
                Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + imageWidth); image.Width = imageWidth; image.Height = imageHeight;
                image.RenderTransformOrigin = new Point(1, 0);
                image.RenderTransform       = new RotateTransform(90);
            }

            return(image);
        }
        private FrameworkElement RenderWallCorner(MapWallState wall1, MapWallState wall2, Rect area)
        {
            if (wall1 == null)
            {
                return(null);
            }
            if (wall1.Wall == null)
            {
                return(null);
            }
            if (wall2 == null)
            {
                return(null);
            }
            if (wall2.Wall == null)
            {
                return(null);
            }

            if (wall1.Wall.Id != wall2.Wall.Id)
            {
                return(null);
            }

            MapImage cornerImage = wall1.Wall.ImageCorner;

            if (cornerImage == null)
            {
                return(null);
            }

            double wallWidth  = area.Width * WallPadding;
            double wallHeight = area.Height * WallPadding;

            MapImageWPF imageSource = new MapImageWPF(cornerImage);
            double      imageWidth  = wallWidth;
            double      imageHeight = wallHeight;

            Image image = new Image {
                Source = imageSource.Image, Width = imageWidth, Height = imageHeight, Stretch = Stretch.Uniform
            };

            image.RenderTransformOrigin = new Point(0.5, 0.5);

            if ((wall1.Direction == MapDirection.North) && (wall2.Direction == MapDirection.West))
            {
                Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top);
            }

            if ((wall1.Direction == MapDirection.North) && (wall2.Direction == MapDirection.East))
            {
                Canvas.SetLeft(image, area.Left + area.Width - imageWidth); Canvas.SetTop(image, area.Top);
                image.RenderTransform = new RotateTransform(90);
            }

            if ((wall1.Direction == MapDirection.South) && (wall2.Direction == MapDirection.West))
            {
                Canvas.SetLeft(image, area.Left); Canvas.SetTop(image, area.Top + area.Height - imageHeight);
                image.RenderTransform = new RotateTransform(-90);
            }

            if ((wall1.Direction == MapDirection.South) && (wall2.Direction == MapDirection.East))
            {
                Canvas.SetLeft(image, area.Left + area.Width - imageWidth); Canvas.SetTop(image, area.Top + area.Height - imageHeight);
                image.RenderTransform = new RotateTransform(180);
            }

            return(image);
        }
 private static MapWallState DeserializeMapWallState(BinaryReader Reader, MapWall wall, MapDirection direction)
 {
     MapWallState state = new MapWallState(wall, direction);
     state.Mode = DeserializeMapWallMode(Reader);
     state.Health = Reader.ReadUInt16();
     return state;
 }
 public static void SerializeMapWallState(BinaryWriter Writer, MapWallState WallState)
 {
     SerializeMapVisualObjectState(Writer, WallState);
     SerializeMapWallMode(Writer, WallState.Mode);
     Writer.Write(WallState.Health);
 }
Exemplo n.º 7
0
 public static void SerializeMapWallState(BinaryWriter Writer, MapWallState WallState)
 {
     SerializeMapVisualObjectState(Writer, WallState);
     SerializeMapWallMode(Writer, WallState.Mode);
     Writer.Write(WallState.Health);
 }