Ejemplo n.º 1
0
        public override void Update()
        {
            m_touchInput = null;
            double frameStartTime = Time.FrameStartTime;
            int    frameIndex     = Time.FrameIndex;

            foreach (TouchLocation touchLocation in base.Input.TouchLocations)
            {
                if (touchLocation.State == TouchLocationState.Pressed)
                {
                    if (HitTestGlobal(touchLocation.Position) == this)
                    {
                        m_touchId            = touchLocation.Id;
                        m_touchLastPosition  = touchLocation.Position;
                        m_touchOrigin        = touchLocation.Position;
                        m_touchOriginLimited = touchLocation.Position;
                        m_touchTime          = frameStartTime;
                        m_touchFrameIndex    = frameIndex;
                        m_touchMoved         = false;
                    }
                }
                else if (touchLocation.State == TouchLocationState.Moved)
                {
                    if (m_touchId.HasValue && touchLocation.Id == m_touchId.Value)
                    {
                        m_touchMoved |= (Vector2.Distance(touchLocation.Position, m_touchOrigin) > SettingsManager.MinimumDragDistance * base.GlobalScale);
                        TouchInput value = default(TouchInput);
                        value.InputType        = ((!m_touchMoved) ? TouchInputType.Hold : TouchInputType.Move);
                        value.Duration         = (float)(frameStartTime - m_touchTime);
                        value.DurationFrames   = frameIndex - m_touchFrameIndex;
                        value.Position         = touchLocation.Position;
                        value.Move             = touchLocation.Position - m_touchLastPosition;
                        value.TotalMove        = touchLocation.Position - m_touchOrigin;
                        value.TotalMoveLimited = touchLocation.Position - m_touchOriginLimited;
                        if (MathUtils.Abs(value.TotalMoveLimited.X) > m_radius)
                        {
                            m_touchOriginLimited.X = touchLocation.Position.X - MathUtils.Sign(value.TotalMoveLimited.X) * m_radius;
                        }
                        if (MathUtils.Abs(value.TotalMoveLimited.Y) > m_radius)
                        {
                            m_touchOriginLimited.Y = touchLocation.Position.Y - MathUtils.Sign(value.TotalMoveLimited.Y) * m_radius;
                        }
                        m_touchInput        = value;
                        m_touchLastPosition = touchLocation.Position;
                    }
                }
                else if (touchLocation.State == TouchLocationState.Released && m_touchId.HasValue && touchLocation.Id == m_touchId.Value)
                {
                    if (frameStartTime - m_touchTime <= (double)SettingsManager.MinimumHoldDuration && Vector2.Distance(touchLocation.Position, m_touchOrigin) < SettingsManager.MinimumDragDistance * base.GlobalScale)
                    {
                        TouchInput value2 = default(TouchInput);
                        value2.InputType      = TouchInputType.Tap;
                        value2.Duration       = (float)(frameStartTime - m_touchTime);
                        value2.DurationFrames = frameIndex - m_touchFrameIndex;
                        value2.Position       = touchLocation.Position;
                        m_touchInput          = value2;
                    }
                    m_touchId = null;
                }
            }
        }
Ejemplo n.º 2
0
        public void UpdateInputFromWidgets(WidgetInput input)
        {
            float      num        = MathUtils.Pow(1.25f, 10f * (SettingsManager.MoveSensitivity - 0.5f));
            float      num2       = MathUtils.Pow(1.25f, 10f * (SettingsManager.LookSensitivity - 0.5f));
            float      num3       = MathUtils.Clamp(m_subsystemTime.GameTimeDelta, 0f, 0.1f);
            ViewWidget viewWidget = m_componentPlayer.ViewWidget;

            m_componentGui.MoveWidget.Radius = 30f / num * m_componentGui.MoveWidget.GlobalScale;
            if (m_componentGui.ModalPanelWidget != null || !(m_subsystemTime.GameTimeFactor > 0f) || !(num3 > 0f))
            {
                return;
            }
            Vector2 v = new Vector2(SettingsManager.LeftHandedLayout ? 96 : (-96), -96f);

            v = Vector2.TransformNormal(v, input.Widget.GlobalTransform);
            if (m_componentGui.ViewWidget != null && m_componentGui.ViewWidget.TouchInput.HasValue)
            {
                IsControlledByTouch = true;
                TouchInput value         = m_componentGui.ViewWidget.TouchInput.Value;
                Camera     activeCamera  = m_componentPlayer.GameWidget.ActiveCamera;
                Vector3    viewPosition  = activeCamera.ViewPosition;
                Vector3    viewDirection = activeCamera.ViewDirection;
                Vector3    direction     = Vector3.Normalize(activeCamera.ScreenToWorld(new Vector3(value.Position, 1f), Matrix.Identity) - viewPosition);
                Vector3    direction2    = Vector3.Normalize(activeCamera.ScreenToWorld(new Vector3(value.Position + v, 1f), Matrix.Identity) - viewPosition);
                if (value.InputType == TouchInputType.Tap)
                {
                    if (SettingsManager.LookControlMode == LookControlMode.SplitTouch)
                    {
                        m_playerInput.Interact = new Ray3(viewPosition, viewDirection);
                        m_playerInput.Hit      = new Ray3(viewPosition, viewDirection);
                    }
                    else
                    {
                        m_playerInput.Interact = new Ray3(viewPosition, direction);
                        m_playerInput.Hit      = new Ray3(viewPosition, direction);
                    }
                }
                else if (value.InputType == TouchInputType.Hold && value.DurationFrames > 1 && value.Duration > 0.2f)
                {
                    if (SettingsManager.LookControlMode == LookControlMode.SplitTouch)
                    {
                        m_playerInput.Dig = new Ray3(viewPosition, viewDirection);
                        m_playerInput.Aim = new Ray3(viewPosition, direction2);
                    }
                    else
                    {
                        m_playerInput.Dig = new Ray3(viewPosition, direction);
                        m_playerInput.Aim = new Ray3(viewPosition, direction2);
                    }
                    m_isViewHoldStarted = true;
                }
                else if (value.InputType == TouchInputType.Move)
                {
                    if (SettingsManager.LookControlMode == LookControlMode.EntireScreen || SettingsManager.LookControlMode == LookControlMode.SplitTouch)
                    {
                        Vector2 v2     = Vector2.TransformNormal(value.Move, m_componentGui.ViewWidget.InvertedGlobalTransform);
                        Vector2 vector = num2 / num3 * new Vector2(0.0006f, -0.0006f) * v2 * MathUtils.Pow(v2.LengthSquared(), 0.125f);
                        m_playerInput.Look += vector;
                    }
                    if (m_isViewHoldStarted)
                    {
                        if (SettingsManager.LookControlMode == LookControlMode.SplitTouch)
                        {
                            m_playerInput.Dig = new Ray3(viewPosition, viewDirection);
                            m_playerInput.Aim = new Ray3(viewPosition, direction2);
                        }
                        else
                        {
                            m_playerInput.Dig = new Ray3(viewPosition, direction);
                            m_playerInput.Aim = new Ray3(viewPosition, direction2);
                        }
                    }
                }
            }
            else
            {
                m_isViewHoldStarted = false;
            }
            if (m_componentGui.MoveWidget != null && m_componentGui.MoveWidget.TouchInput.HasValue)
            {
                IsControlledByTouch = true;
                float      radius = m_componentGui.MoveWidget.Radius;
                TouchInput value2 = m_componentGui.MoveWidget.TouchInput.Value;
                if (value2.InputType == TouchInputType.Tap)
                {
                    m_playerInput.Jump = true;
                }
                else if (value2.InputType == TouchInputType.Move || value2.InputType == TouchInputType.Hold)
                {
                    Vector2 v3      = Vector2.TransformNormal(value2.Move, m_componentGui.ViewWidget.InvertedGlobalTransform);
                    Vector2 vector2 = num / num3 * new Vector2(0.003f, -0.003f) * v3 * MathUtils.Pow(v3.LengthSquared(), 0.175f);
                    m_playerInput.SneakMove.X += vector2.X;
                    m_playerInput.SneakMove.Z += vector2.Y;
                    Vector2 vector3 = Vector2.TransformNormal(value2.TotalMoveLimited, m_componentGui.ViewWidget.InvertedGlobalTransform);
                    m_playerInput.Move.X += ProcessInputValue(vector3.X * viewWidget.GlobalScale, 0.2f * radius, radius);
                    m_playerInput.Move.Z += ProcessInputValue((0f - vector3.Y) * viewWidget.GlobalScale, 0.2f * radius, radius);
                }
            }
            if (m_componentGui.MoveRoseWidget != null)
            {
                if (m_componentGui.MoveRoseWidget.Direction != Vector3.Zero || m_componentGui.MoveRoseWidget.Jump)
                {
                    IsControlledByTouch = true;
                }
                m_playerInput.Move      += m_componentGui.MoveRoseWidget.Direction;
                m_playerInput.SneakMove += m_componentGui.MoveRoseWidget.Direction;
                m_playerInput.Jump      |= m_componentGui.MoveRoseWidget.Jump;
            }
            if (m_componentGui.LookWidget != null && m_componentGui.LookWidget.TouchInput.HasValue)
            {
                IsControlledByTouch = true;
                TouchInput value3 = m_componentGui.LookWidget.TouchInput.Value;
                if (value3.InputType == TouchInputType.Tap)
                {
                    m_playerInput.Jump = true;
                }
                else if (value3.InputType == TouchInputType.Move)
                {
                    Vector2 v4      = Vector2.TransformNormal(value3.Move, m_componentGui.ViewWidget.InvertedGlobalTransform);
                    Vector2 vector4 = num2 / num3 * new Vector2(0.0006f, -0.0006f) * v4 * MathUtils.Pow(v4.LengthSquared(), 0.125f);
                    m_playerInput.Look += vector4;
                }
            }
        }