Пример #1
0
 public void MouseDown(UpdateState state)
 {
     if (!Drawing)
     {
         HITVM.Get.PlaySoundEvent(UISounds.BuildDragToolDown);
         Drawing = true;
         var tilePos = World.EstTileAtPosWithScroll(Parent.GetScaledPoint(state.MouseState.Position).ToVector2() / FSOEnvironment.DPIScaleFactor);
         StartPosition = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y));
     }
 }
Пример #2
0
        public void MouseDown(UpdateState state)
        {
            if (!Drawing)
            {
                HITVM.Get().PlaySoundEvent(UISounds.BuildDragToolDown);

                var tilePos = World.EstTileAtPosWithScroll(Parent.GetScaledPoint(state.MouseState.Position).ToVector2());
                LastPosition = new Point(-2, -2);
                Drawing      = true;
            }
        }
Пример #3
0
        public void MouseDown(UpdateState state)
        {
            if (!Drawing)
            {
                HITVM.Get().PlaySoundEvent(UISounds.BuildDragToolDown);

                var tilePos = World.EstTileAtPosWithScroll(Parent.GetScaledPoint(state.MouseState.Position).ToVector2());
                StartPosition = new Point((int)Math.Round(tilePos.X), (int)Math.Round(tilePos.Y));
                var terrain = vm.Context.Architecture.Terrain;

                if (StartPosition.Y >= terrain.Height || StartPosition.X >= terrain.Width || StartPosition.X < 0 || StartPosition.Y < 0)
                {
                    return;
                }
                Drawing            = true;
                StartTerrainHeight = terrain.Heights[StartPosition.Y * terrain.Width + StartPosition.X];
                StartMousePosition = (int)(state.MouseState.Y - World.State.WorldSpace.GetScreenOffset().Y);
            }
        }
Пример #4
0
        public void Update(UpdateState state, bool scrolled)
        {
            ushort pattern = (state.CtrlDown) ? (ushort)0 : Pattern;

            var   tilePos = World.EstTileAtPosWithScroll(Parent.GetScaledPoint(state.MouseState.Position).ToVector2() / FSOEnvironment.DPIScaleFactor);
            Point cursor  = new Point((int)tilePos.X, (int)tilePos.Y);

            if (!Drawing && Commands.Count > 0)
            {
                vm.Context.Architecture.SignalRedraw();
                Commands.Clear();
            }
            if (state.ShiftDown)
            {
                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.CutRotation)
                {
                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);
            }

            if (cmds.Count > 0)
            {
                var cost = vm.Context.Architecture.LastTestCost;
                if (cost != 0)
                {
                    var disallowed = Parent.ActiveEntity != null && cost > Parent.ActiveEntity.TSOState.Budget.Value;
                    state.UIState.TooltipProperties.Show     = true;
                    state.UIState.TooltipProperties.Color    = disallowed ? Color.DarkRed : Color.Black;
                    state.UIState.TooltipProperties.Opacity  = 1;
                    state.UIState.TooltipProperties.Position = new Vector2(state.MouseState.X, state.MouseState.Y);
                    state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost);
                    state.UIState.TooltipProperties.UpdateDead = false;

                    if (disallowed)
                    {
                        HITVM.Get().PlaySoundEvent(UISounds.Error);
                    }
                }
                else
                {
                    state.UIState.TooltipProperties.Show    = false;
                    state.UIState.TooltipProperties.Opacity = 0;
                }
            }

            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);
        }
Пример #5
0
        public void Update(UpdateState state, bool scrolled)
        {
            ushort pattern = (state.CtrlDown) ? (ushort)0 : Pattern;

            var   tilePos = World.EstTileAtPosWithScroll(Parent.GetScaledPoint(state.MouseState.Position).ToVector2() / FSOEnvironment.DPIScaleFactor);
            Point cursor  = new Point((int)tilePos.X, (int)tilePos.Y);

            /*if (!Drawing && Commands.Count > 0)
             * {
             *  vm.Context.Architecture.SignalRedraw();
             *  Commands.Clear();
             * }*/
            if (state.ShiftDown && pattern < 65534)
            {
                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);
            }

            if (cmds.Count > 0)
            {
                var cost = vm.Context.Architecture.LastTestCost;
                if (cost != 0)
                {
                    var disallowed = Parent.ActiveEntity != null && cost > Parent.ActiveEntity.TSOState.Budget.Value;
                    state.UIState.TooltipProperties.Show     = true;
                    state.UIState.TooltipProperties.Color    = disallowed ? Color.DarkRed : Color.Black;
                    state.UIState.TooltipProperties.Opacity  = 1;
                    state.UIState.TooltipProperties.Position = new Vector2(state.MouseState.X, state.MouseState.Y);
                    state.UIState.Tooltip = (cost < 0) ? ("-$" + (-cost)) : ("$" + cost);
                    state.UIState.TooltipProperties.UpdateDead = false;

                    if (disallowed)
                    {
                        HITVM.Get().PlaySoundEvent(UISounds.Error);
                    }
                }
                else
                {
                    state.UIState.TooltipProperties.Show    = false;
                    state.UIState.TooltipProperties.Opacity = 0;
                }
            }
        }
Пример #6
0
        public void SubmitCommand(string msg)
        {
            var state = LastState;

            if (state == null)
            {
                return;
            }
            var spaceIndex = msg.IndexOf(' ');

            if (spaceIndex == -1)
            {
                spaceIndex = msg.Length;
            }
            var    cmd      = msg.Substring(1, spaceIndex - 1);
            var    args     = msg.Substring(Math.Min(msg.Length, spaceIndex + 1), Math.Max(0, msg.Length - (spaceIndex + 1)));
            string response = "(" + msg + ") ";
            var    tilePos  = vm.Context.World.EstTileAtPosWithScroll(Control.GetScaledPoint(state.MouseState.Position).ToVector2());

            try {
                switch (cmd.ToLowerInvariant())
                {
                case "roomat":
                    //!roomat
                    LotTilePos targetrPos = new LotTilePos((short)(tilePos.X * 16), (short)(tilePos.Y * 16), vm.Context.World.State.Level);
                    var        room       = vm.Context.GetRoomAt(targetrPos);
                    response += "Room at (" + targetrPos.TileX + ", " + targetrPos.TileY + ", " + targetrPos.Level + ") is " + room + "\r\n";
                    var roomInfo = vm.Context.RoomInfo[room];
                    foreach (var obj in roomInfo.Room.AdjRooms)
                    {
                        var info = vm.Context.RoomInfo[obj];
                        response += "adjacent room: " + obj;
                        response += "\r\n";
                    }
                    break;

                case "objat":
                    //!objat (objects at mouse position)
                    LotTilePos targetPos = LotTilePos.FromBigTile((short)tilePos.X, (short)tilePos.Y, vm.Context.World.State.Level);
                    if (args == "oow")
                    {
                        targetPos = LotTilePos.OUT_OF_WORLD;
                    }
                    var objs = vm.Context.ObjectQueries.GetObjectsAt(targetPos);
                    response += "Objects at (" + targetPos.TileX + ", " + targetPos.TileY + ", " + targetPos.Level + ")\r\n";
                    foreach (var obj in objs)
                    {
                        response += ObjectSummary(obj);
                        response += "\r\n";
                    }
                    break;

                case "del":
                    //!del objectID
                    vm.SendCommand(new VMNetDeleteObjectCmd()
                    {
                        ObjectID   = short.Parse(args),
                        CleanupAll = true
                    });
                    response += "Sent deletion command.";
                    break;

                case "debugroutes":
                    var on = args.ToLowerInvariant() == "true" || args == "1";
                    SimAntics.Engine.VMRoutingFrame.DEBUG_DRAW = on;
                    response += "Debug Routes Set: " + on;
                    break;

                case "vc":
                case "validcollision":
                    if (CollisionTestInterval != null)
                    {
                        CollisionTestInterval.Clear();
                        CollisionTestInterval = null;
                        response += "Collision validator is now disabled.";
                    }
                    else
                    {
                        var collisionValidator = new CollisionTestUtils();
                        CollisionTestInterval = GameThread.SetInterval(() => { collisionValidator.VerifyAllCollision(vm); }, 1000);
                        response += "Collision validator is now running every second. An exception will be thrown if collision state is inconsistent.";
                    }
                    break;

                default:
                    response += "Unknown command.";
                    break;
                }
            } catch (Exception e)
            {
                response += "Bad command.";
            }
            vm.SignalChatEvent(new VMChatEvent(null, VMChatEventType.Generic, response));
        }
Пример #7
0
        public void SubmitCommand(string msg)
        {
            var state = LastState;

            if (state == null)
            {
                return;
            }
            var spaceIndex = msg.IndexOf(' ');

            if (spaceIndex == -1)
            {
                spaceIndex = msg.Length;
            }
            var    cmd      = msg.Substring(1, spaceIndex - 1);
            var    args     = msg.Substring(Math.Min(msg.Length, spaceIndex + 1), Math.Max(0, msg.Length - (spaceIndex + 1)));
            string response = "(" + msg + ") ";
            var    tilePos  = vm.Context.World.EstTileAtPosWithScroll(Control.GetScaledPoint(state.MouseState.Position).ToVector2() / FSOEnvironment.DPIScaleFactor);

            try {
                switch (cmd.ToLowerInvariant())
                {
                case "roomat":
                    //!roomat
                    LotTilePos targetrPos = new LotTilePos((short)(tilePos.X * 16), (short)(tilePos.Y * 16), vm.Context.World.State.Level);
                    var        room       = vm.Context.GetRoomAt(targetrPos);
                    response += "Room at (" + targetrPos.TileX + ", " + targetrPos.TileY + ", " + targetrPos.Level + ") is " + room + "\r\n";
                    var roomInfo = vm.Context.RoomInfo[room];
                    foreach (var obj in roomInfo.Room.AdjRooms)
                    {
                        var info = vm.Context.RoomInfo[obj];
                        response += "adjacent room: " + obj;
                        response += "\r\n";
                    }
                    break;

                case "objat":
                    //!objat (objects at mouse position)
                    LotTilePos targetPos = LotTilePos.FromBigTile((short)tilePos.X, (short)tilePos.Y, vm.Context.World.State.Level);
                    if (args == "oow")
                    {
                        targetPos = LotTilePos.OUT_OF_WORLD;
                    }
                    var objs = vm.Context.ObjectQueries.GetObjectsAt(targetPos);
                    response += "Objects at (" + targetPos.TileX + ", " + targetPos.TileY + ", " + targetPos.Level + ")\r\n";
                    foreach (var obj in objs)
                    {
                        response += ObjectSummary(obj);
                        response += "\r\n";
                    }
                    break;

                case "del":
                    //!del objectID
                    vm.SendCommand(new VMNetDeleteObjectCmd()
                    {
                        ObjectID   = short.Parse(args),
                        CleanupAll = true
                    });
                    response += "Sent deletion command.";
                    break;

                default:
                    response += "Unknown command.";
                    break;
                }
            } catch (Exception e)
            {
                response += "Bad command.";
            }
            vm.SignalChatEvent(new VMChatEvent(null, VMChatEventType.Generic, response));
        }