Beispiel #1
0
        public void Simulate()
        {
            if (UserInputDisabled)
            {
                return;
            }
            toolSelectionMenu.ProcessUserInput();

            /*if (TW.Graphics.Mouse.RelativeScrollWheel < 0 || TW.Graphics.Keyboard.IsKeyPressed(Key.UpArrow))
             *  inputHandler.OnPreviousTool();
             * if (TW.Graphics.Mouse.RelativeScrollWheel > 0 || TW.Graphics.Keyboard.IsKeyPressed(Key.DownArrow))
             *  inputHandler.OnNextTool();*/

            if (TW.Graphics.Keyboard.IsKeyPressed(Key.O))
            {
                inputHandler.OnSave();
            }

            if (trySimulateUIControls())
            {
                return;
            }

            var target = GetTargetedVoxel();

            if (target == null)
            {
                return;
            }
            if (target != previousTarget)
            {
                inputHandler.OnTargetChanged(target);
            }
            previousTarget = target;

            if (TW.Graphics.Mouse.LeftMouseJustPressed)
            {
                inputHandler.OnLeftClick(target);
            }
            if (TW.Graphics.Mouse.RightMouseJustPressed)
            {
                inputHandler.OnRightClick(target);
            }
            foreach (var k in TW.Graphics.Keyboard.PressedKeys.Where(k => TW.Graphics.Keyboard.IsKeyPressed(k)))
            {
                inputHandler.OnKeyPressed(target, k);
            }
        }
        public void ForwardReceivedInputs()
        {
            while (transporter.PacketAvailable)
            {
                var p = transporter.Receive();
                switch (p.Method)
                {
                case "OnSave":
                    handler.OnSave();
                    break;

                case "OnNextTool":
                    handler.OnNextTool();
                    break;

                case "OnPreviousTool":
                    handler.OnPreviousTool();
                    break;

                case "OnLeftClick":
                    handler.OnLeftClick(world.GetVoxel(new Point2(p.VoxelCoordX, p.VoxelCoordY)));
                    break;

                case "OnRightClick":
                    handler.OnRightClick(world.GetVoxel(new Point2(p.VoxelCoordX, p.VoxelCoordY)));
                    break;

                case "OnKeyPressed":
                    handler.OnKeyPressed(world.GetVoxel(new Point2(p.VoxelCoordX, p.VoxelCoordY)), (Key)p.Key);
                    break;

                default:
                    throw new InvalidOperationException("Unknown input method: " + p.Method);
                }
            }
        }