예제 #1
0
        public void UpdateInputFromGamepad(WidgetInput input)
        {
            Vector3 viewPosition  = m_componentPlayer.GameWidget.ActiveCamera.ViewPosition;
            Vector3 viewDirection = m_componentPlayer.GameWidget.ActiveCamera.ViewDirection;

            if (m_componentGui.ModalPanelWidget != null || DialogsManager.HasDialogs(m_componentPlayer.GuiWidget))
            {
                if (!input.IsPadCursorVisible)
                {
                    ViewWidget viewWidget        = m_componentPlayer.ViewWidget;
                    Vector2    padCursorPosition = viewWidget.WidgetToScreen(viewWidget.ActualSize / 2f);
                    input.IsPadCursorVisible = true;
                    input.PadCursorPosition  = padCursorPosition;
                }
            }
            else
            {
                input.IsPadCursorVisible = false;
                Vector3 zero                = Vector3.Zero;
                Vector2 padStickPosition    = input.GetPadStickPosition(GamePadStick.Left, SettingsManager.GamepadDeadZone);
                Vector2 padStickPosition2   = input.GetPadStickPosition(GamePadStick.Right, SettingsManager.GamepadDeadZone);
                float   padTriggerPosition  = input.GetPadTriggerPosition(GamePadTrigger.Left);
                float   padTriggerPosition2 = input.GetPadTriggerPosition(GamePadTrigger.Right);
                zero += new Vector3(2f * padStickPosition.X, 0f, 2f * padStickPosition.Y);
                zero += Vector3.UnitY * (input.IsPadButtonDown(GamePadButton.A) ? 1 : 0);
                zero += -Vector3.UnitY * (input.IsPadButtonDown(GamePadButton.RightShoulder) ? 1 : 0);
                m_playerInput.Move             += zero;
                m_playerInput.SneakMove        += zero;
                m_playerInput.Look             += 0.75f * padStickPosition2 * MathUtils.Pow(padStickPosition2.LengthSquared(), 0.25f);
                m_playerInput.Jump             |= input.IsPadButtonDownOnce(GamePadButton.A);
                m_playerInput.Dig               = ((padTriggerPosition2 >= 0.5f) ? new Ray3?(new Ray3(viewPosition, viewDirection)) : m_playerInput.Dig);
                m_playerInput.Hit               = ((padTriggerPosition2 >= 0.5f && m_lastRightTrigger < 0.5f) ? new Ray3?(new Ray3(viewPosition, viewDirection)) : m_playerInput.Hit);
                m_playerInput.Aim               = ((padTriggerPosition >= 0.5f) ? new Ray3?(new Ray3(viewPosition, viewDirection)) : m_playerInput.Aim);
                m_playerInput.Interact          = ((padTriggerPosition >= 0.5f && m_lastLeftTrigger < 0.5f) ? new Ray3?(new Ray3(viewPosition, viewDirection)) : m_playerInput.Interact);
                m_playerInput.Drop             |= input.IsPadButtonDownOnce(GamePadButton.B);
                m_playerInput.ToggleMount      |= (input.IsPadButtonDownOnce(GamePadButton.LeftThumb) || input.IsPadButtonDownOnce(GamePadButton.DPadUp));
                m_playerInput.EditItem         |= input.IsPadButtonDownOnce(GamePadButton.LeftShoulder);
                m_playerInput.ToggleSneak      |= input.IsPadButtonDownOnce(GamePadButton.RightShoulder);
                m_playerInput.SwitchCameraMode |= (input.IsPadButtonDownOnce(GamePadButton.RightThumb) || input.IsPadButtonDownOnce(GamePadButton.DPadDown));
                if (input.IsPadButtonDownRepeat(GamePadButton.DPadLeft))
                {
                    m_playerInput.ScrollInventory--;
                }
                if (input.IsPadButtonDownRepeat(GamePadButton.DPadRight))
                {
                    m_playerInput.ScrollInventory++;
                }
                if (padStickPosition != Vector2.Zero || padStickPosition2 != Vector2.Zero)
                {
                    IsControlledByTouch = false;
                }
                m_lastLeftTrigger  = padTriggerPosition;
                m_lastRightTrigger = padTriggerPosition2;
            }
            if (!DialogsManager.HasDialogs(m_componentPlayer.GuiWidget))
            {
                m_playerInput.ToggleInventory |= input.IsPadButtonDownOnce(GamePadButton.X);
                m_playerInput.ToggleClothing  |= input.IsPadButtonDownOnce(GamePadButton.Y);
                m_playerInput.GamepadHelp     |= input.IsPadButtonDownOnce(GamePadButton.Start);
            }
        }
예제 #2
0
        public void UpdateInputFromMouseAndKeyboard(WidgetInput input)
        {
            Vector3 viewPosition  = m_componentPlayer.GameWidget.ActiveCamera.ViewPosition;
            Vector3 viewDirection = m_componentPlayer.GameWidget.ActiveCamera.ViewDirection;

            if (m_componentGui.ModalPanelWidget != null || DialogsManager.HasDialogs(m_componentPlayer.GuiWidget))
            {
                if (!input.IsMouseCursorVisible)
                {
                    ViewWidget viewWidget = m_componentPlayer.ViewWidget;
                    Vector2    value      = viewWidget.WidgetToScreen(viewWidget.ActualSize / 2f);
                    input.IsMouseCursorVisible = true;
                    input.MousePosition        = value;
                }
            }
            else
            {
                input.IsMouseCursorVisible = false;
                Vector2 zero = Vector2.Zero;
                int     num  = 0;
                if (Window.IsActive && Time.FrameDuration > 0f)
                {
                    Point2 mouseMovement      = input.MouseMovement;
                    int    mouseWheelMovement = input.MouseWheelMovement;
                    zero.X = 0.02f * (float)mouseMovement.X / Time.FrameDuration / 60f;
                    zero.Y = -0.02f * (float)mouseMovement.Y / Time.FrameDuration / 60f;
                    num    = mouseWheelMovement / 120;
                    if (mouseMovement != Point2.Zero)
                    {
                        IsControlledByTouch = false;
                    }
                }
                Vector3 vector = default(Vector3) + Vector3.UnitX * (input.IsKeyDown(Key.D) ? 1 : 0);
                vector                          += -Vector3.UnitZ * (input.IsKeyDown(Key.S) ? 1 : 0);
                vector                          += Vector3.UnitZ * (input.IsKeyDown(Key.W) ? 1 : 0);
                vector                          += -Vector3.UnitX * (input.IsKeyDown(Key.A) ? 1 : 0);
                vector                          += Vector3.UnitY * (input.IsKeyDown(Key.Space) ? 1 : 0);
                vector                          += -Vector3.UnitY * (input.IsKeyDown(Key.Shift) ? 1 : 0);
                m_playerInput.Look              += new Vector2(MathUtils.Clamp(zero.X, -15f, 15f), MathUtils.Clamp(zero.Y, -15f, 15f));
                m_playerInput.Move              += vector;
                m_playerInput.SneakMove         += vector;
                m_playerInput.Jump              |= input.IsKeyDownOnce(Key.Space);
                m_playerInput.ScrollInventory   -= num;
                m_playerInput.Dig                = (input.IsMouseButtonDown(MouseButton.Left) ? new Ray3?(new Ray3(viewPosition, viewDirection)) : m_playerInput.Dig);
                m_playerInput.Hit                = (input.IsMouseButtonDownOnce(MouseButton.Left) ? new Ray3?(new Ray3(viewPosition, viewDirection)) : m_playerInput.Hit);
                m_playerInput.Aim                = (input.IsMouseButtonDown(MouseButton.Right) ? new Ray3?(new Ray3(viewPosition, viewDirection)) : m_playerInput.Aim);
                m_playerInput.Interact           = (input.IsMouseButtonDownOnce(MouseButton.Right) ? new Ray3?(new Ray3(viewPosition, viewDirection)) : m_playerInput.Interact);
                m_playerInput.ToggleSneak       |= input.IsKeyDownOnce(Key.Shift);
                m_playerInput.ToggleMount       |= input.IsKeyDownOnce(Key.R);
                m_playerInput.ToggleCreativeFly |= input.IsKeyDownOnce(Key.F);
                m_playerInput.PickBlockType      = (input.IsMouseButtonDownOnce(MouseButton.Middle) ? new Ray3?(new Ray3(viewPosition, viewDirection)) : m_playerInput.PickBlockType);
            }
            if (!DialogsManager.HasDialogs(m_componentPlayer.GuiWidget))
            {
                m_playerInput.ToggleInventory  |= input.IsKeyDownOnce(Key.E);
                m_playerInput.ToggleClothing   |= input.IsKeyDownOnce(Key.C);
                m_playerInput.TakeScreenshot   |= input.IsKeyDownOnce(Key.P);
                m_playerInput.SwitchCameraMode |= input.IsKeyDownOnce(Key.V);
                m_playerInput.TimeOfDay        |= input.IsKeyDownOnce(Key.T);
                m_playerInput.Lighting         |= input.IsKeyDownOnce(Key.L);
                m_playerInput.Drop             |= input.IsKeyDownOnce(Key.Q);
                m_playerInput.EditItem         |= input.IsKeyDownOnce(Key.G);
                m_playerInput.KeyboardHelp     |= input.IsKeyDownOnce(Key.H);
                if (input.IsKeyDownOnce(Key.Number1))
                {
                    m_playerInput.SelectInventorySlot = 0;
                }
                if (input.IsKeyDownOnce(Key.Number2))
                {
                    m_playerInput.SelectInventorySlot = 1;
                }
                if (input.IsKeyDownOnce(Key.Number3))
                {
                    m_playerInput.SelectInventorySlot = 2;
                }
                if (input.IsKeyDownOnce(Key.Number4))
                {
                    m_playerInput.SelectInventorySlot = 3;
                }
                if (input.IsKeyDownOnce(Key.Number5))
                {
                    m_playerInput.SelectInventorySlot = 4;
                }
                if (input.IsKeyDownOnce(Key.Number6))
                {
                    m_playerInput.SelectInventorySlot = 5;
                }
                if (input.IsKeyDownOnce(Key.Number7))
                {
                    m_playerInput.SelectInventorySlot = 6;
                }
                if (input.IsKeyDownOnce(Key.Number8))
                {
                    m_playerInput.SelectInventorySlot = 7;
                }
                if (input.IsKeyDownOnce(Key.Number9))
                {
                    m_playerInput.SelectInventorySlot = 8;
                }
                if (input.IsKeyDownOnce(Key.Number0))
                {
                    m_playerInput.SelectInventorySlot = 9;
                }
            }
        }