public override void Deserialize(BinaryReader reader)
 {
     Commands = new List<VMArchitectureCommand>();
     int length = reader.ReadInt32();
     for (int i=0; i<length; i++)
     {
         var cmd = new VMArchitectureCommand();
         cmd.Deserialize(reader);
         Commands.Add(cmd);
     }
 }
Пример #2
0
        public void Update(UpdateState state, bool scrolled)
        {
            var tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y));
            Point cursor = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y));

            var cmds = vm.Context.Architecture.Commands;
            cmds.Clear();
            if (Drawing)
            {
                var diff = cursor - StartPosition;
                DrawLength = (int)Math.Round(Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y));
                DrawDir = (int)DirectionUtils.PosMod(Math.Round(Math.Atan2(diff.Y, diff.X) / (Math.PI / 4)), 8);

                if (state.KeyboardState.IsKeyDown(Keys.LeftShift))
                {
                    EndPosition = cursor;
                    int smallX = Math.Min(StartPosition.X, EndPosition.X);
                    int smallY = Math.Min(StartPosition.Y, EndPosition.Y);
                    int bigX = Math.Max(StartPosition.X, EndPosition.X);
                    int bigY = Math.Max(StartPosition.Y, EndPosition.Y);
                    cmds.Add(new VMArchitectureCommand { Type = VMArchitectureCommandType.WALL_RECT, level = World.State.Level, pattern = DrawPattern, style = DrawStyle,
                        x = smallX, y = smallY,
                        x2 = bigX-smallX, y2 = bigY-smallY
                    });
                }
                else
                {
                    cursor = StartPosition + new Point(DirUnits[DrawDir].X * DrawLength, DirUnits[DrawDir].Y * DrawLength);
                    cmds.Add(new VMArchitectureCommand { Type = (state.KeyboardState.IsKeyDown(Keys.LeftControl)) ?
                            VMArchitectureCommandType.WALL_DELETE : VMArchitectureCommandType.WALL_LINE,
                        level = World.State.Level, pattern = DrawPattern, style = DrawStyle, x = StartPosition.X, y = StartPosition.Y, x2 = DrawLength, y2 = DrawDir });
                }
            }

            if (cmds.Count > 0)
            {
                if (!WasDown || !cmds[0].Equals(LastCmd))
                {
                    vm.Context.Architecture.SignalRedraw();
                    LastCmd = cmds[0];
                    WasDown = true;
                }
            }
            else
            {
                if (WasDown)
                {
                    vm.Context.Architecture.SignalRedraw();
                    WasDown = false;
                }
            }

            WallCursor.SetVisualPosition(new Vector3(cursor.X, cursor.Y, (World.State.Level-1)*2.95f), Direction.NORTH, vm.Context);

            if (state.KeyboardState.IsKeyDown(Keys.LeftShift)) SetCursorGraphic(3);
            else if (state.KeyboardState.IsKeyDown(Keys.LeftControl)) SetCursorGraphic(1);
            else SetCursorGraphic(0);
        }
        public void Update(UpdateState state, bool scrolled)
        {
            ushort pattern = (state.KeyboardState.IsKeyDown(Keys.LeftControl)) ? (ushort)0 : Pattern;

            var tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y));
            Point cursor = new Point((int)tilePos.X, (int)tilePos.Y);

            if (!Drawing && Commands.Count > 0)
            {
                vm.Context.Architecture.SignalRedraw();
                Commands.Clear();
            }
            if (state.KeyboardState.IsKeyDown(Keys.LeftShift))
            {
                if (Commands.Count == 0 || Commands[0].Type != VMArchitectureCommandType.FLOOR_FILL)
                {
                    Commands.Clear();
                    vm.Context.Architecture.SignalRedraw();
                }

                Commands.Add(new VMArchitectureCommand
                {
                    Type = VMArchitectureCommandType.FLOOR_FILL,
                    level = World.State.Level,
                    pattern = pattern,
                    style = 0,
                    x = cursor.X,
                    y = cursor.Y,
                });
            } else
            {
                if (Commands.Count > 0 && Commands[0].Type == VMArchitectureCommandType.FLOOR_FILL)
                {
                    Commands.Clear();
                    vm.Context.Architecture.SignalRedraw();
                }

                if (!Drawing || Commands.Count == 0)
                {
                    StartX = cursor.X;
                    StartY = cursor.Y;
                }

                int dir = 0;
                Vector2 fract = new Vector2(tilePos.X - cursor.X, tilePos.Y - cursor.Y);
                if (fract.X-fract.Y > 0)
                {
                    dir = (fract.X + fract.Y > 1) ? 2 : 1;
                } else
                {
                    dir = (fract.X + fract.Y > 1) ? 3 : 0;
                }

                int smallX = Math.Min(StartX, cursor.X);
                int smallY = Math.Min(StartY, cursor.Y);
                int bigX = Math.Max(StartX, cursor.X);
                int bigY = Math.Max(StartY, cursor.Y);

                var cmd = new VMArchitectureCommand
                {
                    Type = VMArchitectureCommandType.FLOOR_RECT,
                    level = World.State.Level,
                    pattern = pattern,
                    style = (ushort)dir,
                    x = smallX,
                    y = smallY,
                    x2 = bigX-smallX,
                    y2 = bigY-smallY
                };
                if (!Commands.Contains(cmd))
                {
                    Commands.Clear();
                    vm.Context.Architecture.SignalRedraw();
                    Commands.Add(cmd);
                }
            }

            var cmds = vm.Context.Architecture.Commands;
            cmds.Clear();
            foreach (var cmd in Commands)
            {
                cmds.Add(cmd);
            }
        }
        public void Update(UpdateState state, bool scrolled)
        {
            ushort pattern = (state.KeyboardState.IsKeyDown(Keys.LeftControl)) ? (ushort)0 : Pattern;

            var tilePos = World.State.WorldSpace.GetTileAtPosWithScroll(new Vector2(state.MouseState.X, state.MouseState.Y));
            Point cursor = new Point((int)tilePos.X, (int)tilePos.Y);

            if (!Drawing && Commands.Count > 0)
            {
                vm.Context.Architecture.SignalRedraw();
                Commands.Clear();
            }
            if (state.KeyboardState.IsKeyDown(Keys.LeftShift))
            {
                if (Commands.Count == 0 || Commands[0].Type != VMArchitectureCommandType.PATTERN_FILL)
                {
                    Commands.Clear();
                    vm.Context.Architecture.SignalRedraw();
                }
                Commands.Add(new VMArchitectureCommand
                {
                    Type = VMArchitectureCommandType.PATTERN_FILL,
                    level = World.State.Level,
                    pattern = pattern,
                    style = 0,
                    x = cursor.X,
                    y = cursor.Y
                });
            } else
            {
                if (Commands.Count > 0 && Commands[0].Type == VMArchitectureCommandType.PATTERN_FILL)
                {
                    Commands.Clear();
                    vm.Context.Architecture.SignalRedraw();
                }
                int dir = 0;
                int altdir = 0;
                Vector2 fract = new Vector2(tilePos.X - cursor.X, tilePos.Y - cursor.Y);
                switch (World.State.Rotation)
                {
                    case WorldRotation.BottomRight:
                        if (fract.X - fract.Y > 0) { dir = 2; altdir = 3; }
                        else { dir = 3; altdir = 2; }
                        break;
                    case WorldRotation.TopRight:
                        if (fract.X + fract.Y > 1) { dir = 3; altdir = 0; }
                        else { dir = 0; altdir = 3; }
                        break;
                    case WorldRotation.TopLeft:
                        //+x is right down. +y is left down
                        if (fract.X - fract.Y > 0) { dir = 1; altdir = 0; }
                        else { dir = 0; altdir = 1; }
                        break;
                    case WorldRotation.BottomLeft:
                        if (fract.X + fract.Y > 1) { dir = 2; altdir = 1; }
                        else { dir = 1; altdir = 2; }
                        break;
                }

                var finalDir = VMArchitectureTools.GetPatternDirection(vm.Context.Architecture, cursor, pattern, dir, altdir, World.State.Level);
                if (finalDir != -1)
                {
                    CursorDir = finalDir;
                    var cmd = new VMArchitectureCommand
                    {
                        Type = VMArchitectureCommandType.PATTERN_DOT,
                        level = World.State.Level,
                        pattern = pattern,
                        style = 0,
                        x = cursor.X,
                        y = cursor.Y,
                        x2 = dir,
                        y2 = altdir
                    };
                    if (!Commands.Contains(cmd))
                    {
                        vm.Context.Architecture.SignalRedraw();
                        Commands.Add(cmd);
                    }
                }
            }

            var cmds = vm.Context.Architecture.Commands;
            cmds.Clear();
            foreach (var cmd in Commands)
            {
                cmds.Add(cmd);
            }

            WallCursor.SetVisualPosition(new Vector3(cursor.X+0.5f, cursor.Y+0.5f, (World.State.Level-1)*2.95f), (Direction)(1<<((3-CursorDir)*2)), vm.Context);
        }