}   // end of ModularCheckboxList Update()

        /// <summary>
        /// Toggles the state of the current item.
        /// </summary>
        private void ToggleState()
        {
            // Toggle current item state.
            if (!allExclusive)
            {
                itemList[curIndex].Check = !itemList[curIndex].Check;
            }
            else
            {
                // Clear everything and set the current item.
                for (int i = 0; i < itemList.Count; i++)
                {
                    itemList[i].Check = i == curIndex;
                }
            }

            ApplyExclusiveFirstItemFiltering();

            if (onChange != null)
            {
                onChange(this);
            }

            Foley.PlayPressA();
        }   // end of ToggleState()
        public override void Update(ref Matrix parentMatrix)
        {
            // Check for input but only if selected.
            if (selected)
            {
                GamePadInput pad = GamePadInput.GetGamePad0();

                if (Actions.Select.WasPressed)
                {
                    Actions.Select.ClearAllWasPressedState();

                    if (onAButton != null)
                    {
                        onAButton();
                        Foley.PlayPressA();
                    }
                }

                if (Actions.X.WasPressed)
                {
                    Actions.X.ClearAllWasPressedState();

                    if (onXButton != null)
                    {
                        onXButton();
                        Foley.PlayCut();
                    }
                }
            }

            RefreshTexture();

            base.Update(ref parentMatrix);
        }   // end of UIGridModularButtonElement Update()
Exemple #3
0
        private void UpdateMouseInput()
        {
            Vector2 mouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y);

            // HitTest mouse vs elements.  Set selected state.
            curIndex = -1;
            for (int i = 0; i < itemList.Count; i++)
            {
                if (itemList[i].HitBox.Contains(mouseHit))
                {
                    itemList[i].Selected = true;
                    curIndex             = i;
                }
                else
                {
                    itemList[i].Selected = false;
                }
            }

            if (MouseInput.Left.WasReleased || MouseInput.Right.WasReleased)
            {
                // If released while over an item, then select that item.
                if (curIndex != -1)
                {
                    if (onSelect != null)
                    {
                        Foley.PlayPressA();
                        onSelect(this);
                        chosenIndex = curIndex;
                    }
                    itemList[CurIndex].Selected = false;
                    if (CurIndex != -1)
                    {
                        CurIndex = -1;
                    }
                    Deactivate();
                    return;
                }

                // If released near origin, then we assume that the user wants to click on items seperately so do nothing.
                // If released elsewhere, treat this as a cancel.
                float dist = (mouseHit - position).Length();
                if (dist > originRadius)
                {
                    // Cancel.
                    if (onCancel != null)
                    {
                        onCancel(this);
                    }
                    if (CurIndex != -1)
                    {
                        itemList[CurIndex].Selected = false;
                    }
                    CurIndex    = -1;
                    chosenIndex = -1;
                    Deactivate();
                    return;
                }
            }
        }
        }   // end of UIGridModularCheckboxElement Update()

        private void ToggleState()
        {
            check = !check;
            if (check && onCheck != null)
            {
                onCheck();
            }
            else if (!check && onClear != null)
            {
                onClear();
            }

            Foley.PlayPressA();
            dirty = true;
        }   // end of ToggleState()
        }   // end of UIGridModularRadioBoxElement RefreshTexture()

        public override void HandleMouseInput(Vector2 hitUV)
        {
            // See if we hit an element.
            int hit = -1;

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Box.Contains(hitUV))
                {
                    hit = i;
                    break;
                }
            }

            if (hit != -1)
            {
                if (MouseInput.Left.WasPressed)
                {
                    MouseInput.ClickedOnObject = list[hit];
                }
                if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == list[hit])
                {
                    //Play selection sound
                    Foley.PlayPressA();


                    bool indexChanged = hit != curIndex;
                    CurIndex = hit;

                    if (null != onSelection)
                    {
                        onSelection(list[curIndex]);
                    }

                    if (indexChanged)
                    {
                        if (null != onChange)
                        {
                            onChange(list[curIndex]);
                        }

                        dirty = true;
                    }
                }
            }
        }   // end of HandleMouseInput()
        }   // end of HandleMouseInput()

        public override void HandleTouchInput(TouchContact touch, Vector2 hitUV)
        {
            // See if we hit an element.
            int hit = -1;

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Box.Contains(hitUV))
                {
                    hit = i;
                    break;
                }
            }

            if (hit != -1)
            {
                if (TouchInput.WasTouched)
                {
                    touch.TouchedObject = list[hit];
                }
                if (TouchInput.WasReleased && touch.TouchedObject == list[hit])
                {
                    //Play sound.
                    Foley.PlayPressA();

                    bool indexChanged = hit != curIndex;
                    CurIndex = hit;

                    if (null != onSelection)
                    {
                        onSelection(list[curIndex]);
                    }

                    if (indexChanged)
                    {
                        if (null != onChange)
                        {
                            onChange(list[curIndex]);
                        }

                        dirty = true;
                    }
                }
            }
        }
        }   // end of UIGridModularRadioBoxElement AddText()

        public override void Update(ref Matrix parentMatrix)
        {
            // Check for input but only if selected.
            if (selected && list.Count > 1)
            {
                GamePadInput pad = GamePadInput.GetGamePad0();

                bool changed = false;

                // Handle input changes here.
                if (Actions.Select.WasPressedOrRepeat)
                {
                    Actions.Select.ClearAllWasPressedState();

                    ++curIndex;
                    if (curIndex >= list.Count)
                    {
                        curIndex = 0;
                    }

                    Foley.PlayPressA();
                    changed = true;
                }

                if (changed)
                {
                    if (null != onSelection)
                    {
                        onSelection(list[curIndex]);
                    }

                    if (null != onChange)
                    {
                        onChange(list[curIndex]);
                    }

                    dirty = true;
                    //RecalcPositions();
                }
            }

            RefreshTexture();

            base.Update(ref parentMatrix);
        }   // end of UIGridModularRadioBoxElement Update()
Exemple #8
0
        }   // end of MoveDown()

        /// <summary>
        /// Put a reflex and its children into "moving" mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void MoveReflex(Object sender, EventArgs args)
        {
            Foley.PlayPressA();

            // Init the Moving block.
            ReflexPanel panel    = this.parent as ReflexPanel;
            int         curIndex = panel.LineNumber - 1;

            reflexBlock.Init(curIndex);
            reflexBlock.Moving = true;

            UiCursor.ActiveCursor.Parent = this;

            // switch modes
            this.updateObjPending = this.updateObjMoveReflex;
            this.renderObj.State  = ControlRenderObj.idStateSelected;
            AffixLineNumberToCurrentState();
            BokuGame.objectListDirty = true;
        }   // end of MoveReflex()
        }   // end of UIGridModularButtonElement Update()

        /// <summary>
        /// Test mouse input against buttons.  hitUV is in
        /// local UV coords for button.  Full range is 0..1
        /// in either coordinate.
        /// </summary>
        /// <param name="hitUV"></param>
        public override void HandleMouseInput(Vector2 hitUV)
        {
            if (onXButton != null)
            {
                if (xButtonBox.LeftPressed(hitUV))
                {
                    onXButton();
                    Foley.PlayCut();
                }
            }

            if (onAButton != null)
            {
                if (aButtonBox.LeftPressed(hitUV))
                {
                    onAButton();
                    Foley.PlayPressA();
                }
            }
        }   // end of HandleMouseInput()
        }   // end of HandleMouseInput()

        public override void HandleTouchInput(TouchContact touch, Vector2 hitUV)
        {
            if (onXButton != null)
            {
                if (xButtonBox.Touched(touch, hitUV))
                {
                    onXButton();
                    Foley.PlayCut();
                }
            }

            if (onAButton != null)
            {
                if (aButtonBox.Touched(touch, hitUV))
                {
                    onAButton();
                    Foley.PlayPressA();
                }
            }
        }   // end of HandleTouchInput()
        public override bool HandleMouseInput(Camera camera)
        {
            float  width;
            float  height;
            Matrix invMat;

            bool handled = false;

            // Test in-focus element for hit.
            UIGridElement e = grid.SelectionElement;

            if (e != null)
            {
                GetElementInfo(e, out invMat, out width, out height);
                Vector2 hitUV = MouseInput.GetHitUV(camera, ref invMat, width, height, useRtCoords: false);

                if (hitUV.X > 0 && hitUV.X < 1 && hitUV.Y > 0 && hitUV.Y < 1)
                {
                    if (MouseInput.Left.WasPressed)
                    {
                        MouseInput.ClickedOnObject = e;
                        handled = true;
                    }
                    if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e)
                    {
                        SelectCurrentChoice();
                        Foley.PlayPressA();
                        return(true);
                    }
                }

                // Test elements not in focus.  If one is hit, bring it to the fore.
                // Need to test inside out so that if any overlap we test the front
                // ones first and react to them.  If we find a UV hit with a tile
                // we break to skip testing the rest.
                // Left side first.
                for (int i = grid.SelectionIndex.X - 1; i >= 0; i--)
                {
                    e = grid.Get(i, 0);
                    GetElementInfo(e, out invMat, out width, out height);
                    hitUV = MouseInput.GetHitUV(camera, ref invMat, width, height, useRtCoords: false);

                    if (hitUV.X > 0 && hitUV.X < 1 && hitUV.Y > 0 && hitUV.Y < 1)
                    {
                        if (MouseInput.Left.WasPressed)
                        {
                            MouseInput.ClickedOnObject = e;
                            handled = true;
                        }
                        if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e)
                        {
                            int steps = grid.SelectionIndex.X - i;
                            while (steps > 0)
                            {
                                DecrementFocus();
                                --steps;
                            }
                            handled = true;
                        }
                        break;
                    }
                }
                // Now the right side.
                for (int i = grid.SelectionIndex.X + 1; i < grid.ActualDimensions.X; i++)
                {
                    e = grid.Get(i, 0);
                    GetElementInfo(e, out invMat, out width, out height);
                    hitUV = MouseInput.GetHitUV(camera, ref invMat, width, height, useRtCoords: false);

                    if (hitUV.X > 0 && hitUV.X < 1 && hitUV.Y > 0 && hitUV.Y < 1)
                    {
                        if (MouseInput.Left.WasPressed)
                        {
                            MouseInput.ClickedOnObject = e;
                            handled = true;
                        }
                        if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e)
                        {
                            int steps = i - grid.SelectionIndex.X;
                            while (steps > 0)
                            {
                                IncrementFocus();
                                --steps;
                            }
                            handled = true;
                        }
                        break;
                    }
                }
            }

            return(handled);
        }   // end of HandleMouseInput()
        public override bool HandleMouseInput(Camera camera)
        {
            Matrix mat;

            BoundingSphere sphere;      // Sphere we wrap around elements for hit testing.
            float?         dist = null; // Dist to sphere bounds hit.

            bool handled = false;

            // Test in-focus element for hit.
            UIGridMaterialElement e = grid.SelectionElement as UIGridMaterialElement;

            if (e != null)
            {
                Vector2 mouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y);
                Ray     ray      = new Ray(camera.From, camera.ScreenToWorldCoords(mouseHit));

                mat    = e.HitWorldMatrix;
                sphere = new BoundingSphere(mat.Translation, 2.5f * mat.M33);
                dist   = ray.Intersects(sphere);

                if (dist != null)
                {
                    if (MouseInput.Left.WasPressed)
                    {
                        MouseInput.ClickedOnObject = e;
                        handled = true;
                    }
                    if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e)
                    {
                        SelectCurrentChoice();
                        Foley.PlayPressA();
                        return(true);
                    }
                }

                // Test elements not in focus.  If one is hit, bring it to the fore.
                // Need to test inside out so that if any overlap we test the front
                // ones first and react to them.  If we find a UV hit with a tile
                // we break to skip testing the rest.
                // Left side first.
                for (int i = grid.SelectionIndex.X - 1; i >= 0; i--)
                {
                    e = grid.Get(i, 0) as UIGridMaterialElement;

                    mat    = e.HitWorldMatrix;
                    sphere = new BoundingSphere(mat.Translation, 2.5f * mat.M33);
                    dist   = ray.Intersects(sphere);

                    if (dist != null)
                    {
                        if (MouseInput.Left.WasPressed)
                        {
                            MouseInput.ClickedOnObject = e;
                            handled = true;
                        }
                        if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e)
                        {
                            int steps = grid.SelectionIndex.X - i;
                            while (steps > 0)
                            {
                                DecrementFocus();
                                --steps;
                            }
                            handled = true;
                        }
                        break;
                    }
                }
                // Now the right side.
                for (int i = grid.SelectionIndex.X + 1; i < grid.ActualDimensions.X; i++)
                {
                    e = grid.Get(i, 0) as UIGridMaterialElement;

                    mat    = e.HitWorldMatrix;
                    sphere = new BoundingSphere(mat.Translation, 2.5f * mat.M33);
                    dist   = ray.Intersects(sphere);

                    if (dist != null)
                    {
                        if (MouseInput.Left.WasPressed)
                        {
                            MouseInput.ClickedOnObject = e;
                            handled = true;
                        }
                        if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == e)
                        {
                            int steps = i - grid.SelectionIndex.X;
                            while (steps > 0)
                            {
                                IncrementFocus();
                                --steps;
                            }
                            handled = true;
                        }
                        break;
                    }
                }
            }

            return(handled);
        }   // end of HandleMouseInput()
        public override bool HandleTouchInput(Camera camera)
        {
            float scaleY = Math.Min((float)BokuGame.ScreenSize.Y / 576.0f, 1.0f);


            AABB2D box = new AABB2D(new Vector2(0, (BokuGame.ScreenSize.Y - (200.0f) * scaleY)), BokuGame.ScreenSize);



            TouchContact focusedTouch = null;

            //Finger ID is focused finger
            if (m_FingerID < 0)
            {
                TouchContact[] touches = TouchInput.Touches;

                for (int i = 0; i < touches.Length; ++i)
                {
                    if (TouchPhase.Began == touches[i].phase)
                    {
                        m_FingerID   = touches[i].fingerId;
                        m_bDraggable = box.Contains(touches[i].position);
                        break;
                    }
                }
            }
            else
            {
                focusedTouch = TouchInput.GetTouchContactByFingerId(m_FingerID);

                if (null != focusedTouch && TouchPhase.Ended != focusedTouch.phase)
                {
                    if (TouchPhase.Moved == focusedTouch.phase)
                    {
                        m_DragDelta += focusedTouch.deltaPosition;
                    }

                    if (!m_bDragging && m_bDraggable)
                    {
                        //Check to see if the dragging threshold has been exceeded to change material.
                        Vector2 distance = focusedTouch.position - focusedTouch.startPosition;

                        //Did we start a drag?
                        if (Math.Abs(distance.X) >= 20.0f)
                        {
                            m_bDragging = true;
                            m_DragDelta = distance;
                        }
                    }

                    if (m_bDragging)
                    {
                        while (Math.Abs(m_DragDelta.X) >= 200.0f)
                        {
                            if (m_DragDelta.X >= 200.0f)
                            {
                                DecrementFocus();
                                m_DragDelta.X -= 200.0f;
                            }
                            else if (m_DragDelta.X <= -200.0f)
                            {
                                IncrementFocus();
                                m_DragDelta.X += 200.0f;
                            }
                        }
                    }
                }
                else
                {
                    //When the focused touch is ended we check for selection
                    if (!m_bDragging && null != focusedTouch)
                    {
                        Ray    ray = new Ray(camera.From, camera.ScreenToWorldCoords(focusedTouch.position));
                        Matrix m   = (grid.SelectionElement as UIGridMaterialElement).HitWorldMatrix;

                        bool bSelectedMat = (null != ray.Intersects(new BoundingSphere(m.Translation, 2.5f * m.M33)));

                        if (bSelectedMat)
                        {
                            SelectCurrentChoice();
                            Foley.PlayPressA();
                        }
                        else
                        {
                            //Didn't select the center piece.  Check if we picked a material on the sides so we can go to it.
                            for (int i = 0; (!bSelectedMat && i < grid.SelectionIndex.X); i++)
                            {
                                m = (grid.Get(i, 0) as UIGridMaterialElement).HitWorldMatrix;
                                if (null != ray.Intersects(new BoundingSphere(m.Translation, 2.5f * m.M33)))
                                {
                                    int steps = grid.SelectionIndex.X - i;
                                    while (steps > 0)
                                    {
                                        DecrementFocus();
                                        --steps;
                                    }
                                    bSelectedMat = true;
                                    break;
                                }
                            }

                            for (int i = grid.SelectionIndex.X + 1; (!bSelectedMat && i < grid.ActualDimensions.X); i++)
                            {
                                m = (grid.Get(i, 0) as UIGridMaterialElement).HitWorldMatrix;
                                if (null != ray.Intersects(new BoundingSphere(m.Translation, 2.5f * m.M33)))
                                {
                                    int steps = i - grid.SelectionIndex.X;
                                    while (steps > 0)
                                    {
                                        IncrementFocus();
                                        --steps;
                                    }
                                    bSelectedMat = true;
                                    break;
                                }
                            }

                            //Cancel this menu.
                            if (!bSelectedMat &&
                                !box.Contains(focusedTouch.position) &&
                                (Time.WallClockTotalSeconds - focusedTouch.startTime <= 0.3))
                            {
                                //If we didn't select anything and we are outside the drag area + didn't move a lot then cancel.
                                RestorePreviousChoice();
                                Foley.PlayBack();
                                return(false);
                            }
                        }
                    }

                    m_bDraggable = false;
                    m_bDragging  = false;
                    m_FingerID   = -1;
                }
            }

            return(true);
        }   // end of HandleTouchInput()
Exemple #14
0
        }   // end of DeleteAll()

        public void Update(Camera camera, ref Matrix parentMatrix)
        {
            // Check for input.
            if (active && itemList.Count > 1 && !IgnoreInput && CommandStack.Peek() == commandMap)
            {
                bool selectionChanged = false;
                bool moveUp           = false;
                bool moveDown         = false;

                {
                    // Mouse input
                    if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                    {
                        // If the mouse is over the menu, move the selection index to the item under the mouse.
                        // On mouse down, make the item (if any) under the mouse the ClickedOnItem.
                        // On mouse up, if the mouse is still over the ClickedOnItem, activate it.  If not, just clear ClickedOnItem.

                        Vector2 hitUV = MouseInput.GetHitUV(camera, ref invWorldMatrix, width, height, useRtCoords);

                        // See if we're over anything.  If so, set that item to being selected but only if we've moved the mouse.
                        // This prevents the menu from feeling 'broken' if the mouse is over it and the user tries to use
                        // the gamepad or keyboard.
                        int mouseOverItem = -1;
                        for (int i = 0; i < itemList.Count; i++)
                        {
                            if (itemList[i].UVBoundingBox != null && itemList[i].UVBoundingBox.Contains(hitUV))
                            {
                                // Only update the current in-focus element when the mouse moves.
                                if (MouseInput.Position != MouseInput.PrevPosition)
                                {
                                    CurIndex = i;
                                }
                                mouseOverItem = i;
                            }
                        }

                        if (MouseInput.Left.WasPressed && mouseOverItem != -1)
                        {
                            MouseInput.ClickedOnObject = itemList[mouseOverItem];
                        }

                        if (MouseInput.Left.WasReleased && mouseOverItem != -1 && MouseInput.ClickedOnObject == itemList[mouseOverItem])
                        {
                            // Normally this is already set except in the case where the app didn't have focus and a menu item is clicked.
                            // In that case, the CurIndex value stays stuck at its previous position.  In particular this was causing Kodu's
                            // Main Menu to think RESUME was clicked even when it was one of the other menu items.
                            CurIndex = mouseOverItem;
                            if (onSelect != null)
                            {
                                onSelect(this);
                            }
                            Foley.PlayPressA();
                            return;
                        }

                        // Allow scroll wheel to cycle through elements.
                        int wheel = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel;

                        if (wheel > 0)
                        {
                            moveUp = true;
                        }
                        else if (wheel < 0)
                        {
                            moveDown = true;
                        }
                    }   // end if KeyboardMouse mode.

                    if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                    {
                        // Look for Tap gesture first.  No need to care about touch response if we've got a tap.
                        bool goodTapGesture = false;
                        if (TouchGestureManager.Get().TapGesture.WasTapped())
                        {
                            // Check if tap position hit any of the menu elements.
                            Vector2 tapPosition = TouchGestureManager.Get().TapGesture.Position;
                            Vector2 touchHitUV  = TouchInput.GetHitUV(tapPosition, camera, ref invWorldMatrix, width, height, useRtCoords);
                            for (int index = 0; index < itemList.Count; index++)
                            {
                                if (itemList[index].UVBoundingBox != null && itemList[index].UVBoundingBox.Contains(touchHitUV))
                                {
                                    CurIndex = index;
                                    if (onSelect != null)
                                    {
                                        onSelect(this);
                                        Foley.PlayPressA();
                                        selectionChanged = true;
                                        goodTapGesture   = true;
                                    }
                                }
                            }
                        }

                        // Look for touch events to change focus.  Ignore this if we had a good tap gesture.
                        if (!goodTapGesture)
                        {
                            for (int i = 0; i < TouchInput.TouchCount; i++)
                            {
                                TouchContact touch = TouchInput.GetTouchContactByIndex(i);

                                // Touch input
                                // If the user touched the menu, move the selection index to the item under the touch.
                                // On touch down, make the item (if any) under the contact the touchedItem.
                                // On touch up, if the touch is still over the touchedItem, activate it.  If not, just clear touchedItem.

                                Vector2 touchHitUV = TouchInput.GetHitUV(touch.position, camera, ref invWorldMatrix, width, height, useRtCoords);

                                // See what UI element we are over, if anything.  If it hits, set that item to being selected but only if the touch has moved.
                                // This emulates how the mouse is being handled by allowing the input to change only if the touch has moved. If a user moves
                                // the gamepad or keyboard but doesn't move their touch contact, then the selection won't flicker back and forth and feel 'broken'
                                int touchOverIndex = -1;
                                for (int index = 0; index < itemList.Count; index++)
                                {
                                    if (itemList[index].UVBoundingBox != null && itemList[index].UVBoundingBox.Contains(touchHitUV))
                                    {
                                        touchOverIndex = index;
                                    }
                                }

                                if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved)
                                {
                                    // Touch is down!
                                    if (touchOverIndex != -1)
                                    {
                                        touch.TouchedObject = itemList[touchOverIndex];
                                        if (CurIndex != touchOverIndex)
                                        {
                                            selectionChanged = true;
                                        }
                                        CurIndex = touchOverIndex;
                                    }
                                }
                                else if (touch.phase == TouchPhase.Moved)
                                {
                                    // Touch moved!!! Update Something!!
                                    if (CurIndex != touchOverIndex)
                                    {
                                        CurIndex = touchOverIndex;
                                    }
                                }
                            }
                        }   // end if not good tap gesture.

                        if (selectionChanged)
                        {
                            if (onChange != null)
                            {
                                onChange(this);
                            }
                            dirty = true;
                            //RecalcPositions();
                            // Ensure that the selected state of all items is correct.
                            for (int i = 0; i < itemList.Count; i++)
                            {
                                itemList[i].Selected = i == CurIndex;
                            }
                        }
                    }   // end of touch mode processing.
                }

                if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad ||
                    GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                {
                    // Gamepad / Keyboard input.
                    GamePadInput pad = GamePadInput.GetGamePad0();

                    if ((AcceptStartForCancel && Actions.Start.WasPressed) || Actions.Cancel.WasPressed)
                    {
                        Actions.Cancel.ClearAllWasPressedState();
                        if (onCancel != null)
                        {
                            onCancel(this);
                        }
                        Foley.PlayBack();
                        return;
                    }

                    if (Actions.Select.WasPressed)
                    {
                        Actions.Select.ClearAllWasPressedState();
                        if (onSelect != null)
                        {
                            onSelect(this);
                        }
                        Foley.PlayPressA();
                        return;
                    }

                    int prevIndex = CurIndex;

                    // Handle input changes here.
                    if (Actions.ComboDown.WasPressedOrRepeat || moveDown)
                    {
                        ++CurIndex;
                        if (CurIndex >= itemList.Count)
                        {
                            CurIndex = 0;
                        }

                        selectionChanged = true;
                    }

                    if (Actions.ComboUp.WasPressedOrRepeat || moveUp)
                    {
                        --CurIndex;
                        if (CurIndex < 0)
                        {
                            CurIndex = itemList.Count - 1;
                        }

                        selectionChanged = true;
                    }

                    if (selectionChanged)
                    {
                        if (onChange != null)
                        {
                            onChange(this);
                        }
                        dirty = true;
                        //RecalcPositions();
                    }

                    // Ensure that the selected state of all items is correct.
                    for (int i = 0; i < itemList.Count; i++)
                    {
                        itemList[i].Selected = i == CurIndex;
                    }
                }
            }

            RefreshTexture();
        }   // end of UIGridModularMenu Update()
        }   // end of BasePicker RestorePreviousChoice()

        public virtual void Update(PerspectiveUICamera camera)
        {
            if (active)
            {
                if (hidden)
                {
                    // Note, even though we're hidden we may still be rendering our fade out.
                    double elapsedTime = Time.WallClockTotalSeconds - startFadeTime;
                    if (elapsedTime >= fadeTime)
                    {
                        Alpha = 0.0f;
                    }
                    else
                    {
                        Alpha = 1.0f - (float)(elapsedTime / fadeTime);
                    }
                }
                else
                {
                    // Not hidden, so respond to user input.

                    int scroll = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel;

                    if (Actions.PickerRight.WasPressedOrRepeat || scroll > 0)
                    {
                        Actions.PickerRight.ClearAllWasPressedState();
                        DecrementFocus();
                    }
                    if (Actions.PickerLeft.WasPressedOrRepeat || scroll < 0)
                    {
                        Actions.PickerLeft.ClearAllWasPressedState();
                        IncrementFocus();
                    }

                    if (Actions.Select.WasPressed)
                    {
                        Actions.Select.ClearAllWasPressedState();

                        SelectCurrentChoice();
                        Foley.PlayPressA();
                    }

                    if (Actions.Cancel.WasPressedOrRepeat)
                    {
                        Actions.Cancel.ClearAllWasPressedState();

                        RestorePreviousChoice();
                        Foley.PlayBack();
                    }
                    bool handled = false;
                    if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                    {
                        handled = HandleTouchInput(camera);
                    }
                    else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                    {
                        handled = HandleMouseInput(camera);
                    }

                    if (!handled)
                    {
                        // If the user clicked but didn't hit any of the picker elements, close the picker.
                        // If alt is pressed, they must be in eyedropper mode.
                        if ((MouseInput.Left.WasPressed && !KeyboardInput.AltIsPressed) ||
                            (TouchGestureManager.Get().TapGesture.WasRecognized))
                        {
                            SelectCurrentChoice();
                            Foley.PlayPressA();
                        }
                        else if (Actions.Sample.WasPressed ||
                                 MouseEdit.TriggerSample() || TouchEdit.TriggerSample())
                        {
                            Actions.Sample.ClearAllWasPressedState();

                            int t = OnSampleType();
                            if (t >= 0)
                            {
                                OnSetType(t);
                                Point selection = grid.SelectionIndex;
                                selection.X         = t;
                                grid.SelectionIndex = selection;
                                Foley.PlayCut();
                            }
                            else
                            {
                                Foley.PlayNoBudget();
                            }
                        }
                    }

                    grid.Update(ref worldMatrix);
                }
            } // end if active
        }     // end of BasePicker Update()
Exemple #16
0
        }     // end of MouseMenu Update()

        private void UpdateTouchInput()
        {
            for (int j = 0; j < TouchInput.TouchCount; j++)
            {
                TouchContact touch    = TouchInput.GetTouchContactByIndex(j);
                Vector2      touchHit = touch.position;

                // HitTest mouse vs elements.  Set selected state.
                curIndex = -1;
                for (int i = 0; i < itemList.Count; i++)
                {
                    if (itemList[i].HitBox.Contains(touchHit))
                    {
                        itemList[i].Selected = true;
                        curIndex             = i;
                    }
                    else
                    {
                        itemList[i].Selected = false;
                    }
                }

                if (TouchInput.WasReleased)
                {
                    // If released while over an item, then select that item.
                    if (curIndex != -1)
                    {
                        if (onSelect != null)
                        {
                            Foley.PlayPressA();
                            onSelect(this);
                            chosenIndex = curIndex;
                        }
                        itemList[CurIndex].Selected = false;
                        if (CurIndex != -1)
                        {
                            CurIndex = -1;
                        }
                        Deactivate();
                        return;
                    }

                    // If released near origin, then we assume that the user wants to click on items seperately so do nothing.
                    // If released elsewhere, treat this as a cancel, but only if its a tap release.
                    float dist = (touchHit - position).Length();
                    if (dist > originRadius)
                    {
                        if (TouchGestureManager.Get().TapGesture.WasTapped())
                        {
                            // Cancel.
                            if (onCancel != null)
                            {
                                onCancel(this);
                            }
                            if (CurIndex != -1)
                            {
                                itemList[CurIndex].Selected = false;
                            }
                            CurIndex    = -1;
                            chosenIndex = -1;
                            Deactivate();
                        }
                    }
                }
            }
        }
        }   // end of ClearAllItems()

        public void Update(Camera camera, ref Matrix parentMatrix)
        {
            CommandMap map = CommandStack.Peek();

            if (map != commandMap)
            {
                return;
            }

            // Check for input.
            if (active && itemList.Count > 0)
            {
                GamePadInput pad = GamePadInput.GetGamePad0();

                bool mouseDown   = false;
                bool mouseUp     = false;
                bool mouseSelect = false;
                bool touchSelect = false;
                if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                // MouseInput
                {
                    // Did user double click?  If so, treat as a shortcut to play.
                    if (MouseInput.Left.WasDoubleClicked)
                    {
                        // This works because we _know_ Play is the first one in the list.
                        // Not exactly a great solution.
                        curIndex    = 0;
                        mouseSelect = true;
                    }

                    Vector2 hit = MouseInput.GetMouseInRtCoords();
                    if (!mouseSelect)
                    {
                        if (itemList[CurIndex].hitBox.LeftPressed(hit))
                        {
                            mouseSelect = true;
                        }
                    }

                    // If mouse is over menu and moving, choose item under mouse as selection.
                    if (!mouseSelect && MouseInput.Position != MouseInput.PrevPosition)
                    {
                        for (int i = 0; i < itemList.Count; i++)
                        {
                            if (itemList[i].hitBox.Contains(hit))
                            {
                                CurIndex = i;
                                break;
                            }
                        }
                    }

                    int scroll = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel;
                    if (scroll > 0)
                    {
                        mouseUp = true;
                    }
                    else if (scroll < 0)
                    {
                        mouseDown = true;
                    }

                    // If user clicks off of the popup, treat as Back.
                    if (MouseInput.Left.WasPressed && MouseInput.ClickedOnObject == null)
                    {
                        Active = false;
                        return;
                    }
                }   // end of mouse input.
                else if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                // TouchInput
                {
                    TouchContact touch = TouchInput.GetOldestTouch();
                    if (touch != null)
                    {
                        Vector2 hit          = TouchInput.GetAspectRatioAdjustedPosition(touch.position, camera, true);
                        bool    hitSomething = false;

                        // Check for a hit on any of the items.
                        for (int i = 0; i < itemList.Count; i++)
                        {
                            if (itemList[i].hitBox.Contains(hit))
                            {
                                CurIndex     = i;
                                hitSomething = true;
                            }
                        }

                        if (touch.phase == TouchPhase.Ended)
                        {
                            if (hitSomething)
                            {
                                // We've touched off on an item so choose it.
                                touchSelect = true;
                            }
                            else
                            {
                                // We touched off and didn't hit anything.
                                if (touch.TouchedObject == this)
                                {
                                    touch.TouchedObject = null;
                                }
                                else
                                {
                                    Active = false;
                                }
                            }
                        }
                    }
                }   // end of Touch input.


                if (Actions.Select.WasPressed || mouseSelect || touchSelect)
                {
                    Actions.Select.ClearAllWasPressedState();

                    if (itemList[curIndex].OnSelect != null)
                    {
                        itemList[curIndex].OnSelect();
                    }
                    Foley.PlayPressA();

                    return;
                }

                if (Actions.Cancel.WasPressed)
                {
                    Actions.Cancel.ClearAllWasPressedState();

                    Active = false;
                    Foley.PlayBack();

                    return;
                }

                int prevIndex = curIndex;

                // Handle input changes here.
                if (Actions.ComboDown.WasPressedOrRepeat || mouseDown)
                {
                    ++curIndex;
                    if (curIndex >= itemList.Count)
                    {
                        curIndex = 0;
                    }

                    Foley.PlayShuffle();
                }

                if (Actions.ComboUp.WasPressedOrRepeat || mouseUp)
                {
                    --curIndex;
                    if (curIndex < 0)
                    {
                        curIndex = itemList.Count - 1;
                    }

                    Foley.PlayShuffle();
                }

                // Ensure that the selected state of all items is correct.
                for (int i = 0; i < itemList.Count; i++)
                {
                    itemList[i].Selected = i == CurIndex;
                }
            }
        }   // end of LoadLevelPopup Update()