예제 #1
0
        private VisualElement GetNextFocusableRecursive(Focusable focused, IEnumerable <VisualElement> elements, bool reverse, ref bool found)
        {
            var collection = reverse ? elements.Reverse() : elements;

            foreach (var child in collection)
            {
                if (child == focused)
                {
                    found = true;
                    continue;
                }

                if (found && child != focused && child.enabledSelf && child.focusable)
                {
                    return(child);
                }

                var next = GetNextFocusableRecursive(focused, child.Children(), reverse, ref found);
                if (next != null)
                {
                    return(next);
                }
            }

            return(null);
        }
예제 #2
0
        public static T GetPooled(IEventHandler target, Focusable relatedTarget, FocusChangeDirection direction)
        {
            T e = GetPooled();

            e.target        = target;
            e.relatedTarget = relatedTarget;
            e.direction     = direction;
            return(e);
        }
예제 #3
0
        public static T GetPooled(IEventHandler target, Focusable relatedTarget, FocusChangeDirection direction, FocusController focusController, bool bIsFocusDelegated = false)
        {
            T e = GetPooled();

            e.target           = target;
            e.relatedTarget    = relatedTarget;
            e.direction        = direction;
            e.focusController  = focusController;
            e.IsFocusDelegated = bIsFocusDelegated;
            return(e);
        }
예제 #4
0
 void Start()
 {
     if (isLocalPlayer)
     {
         GameManager.instance.player = this;
         GameManager.instance.SetGameMode();
         focused = Station.stations[PlayerPrefs.GetString("homeStation", "Null Base")].GetComponent <Focusable>();
         Faction local = new Faction();
         local.InitLocal();
         CmdInit(local);
     }
 }
예제 #5
0
        //Next step:  Make animations vs. state interpolations visibly different in the tree view

        private void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Enter)
            {
                // your event handler here
                e.Handled = true;

                // Make it lose and regain focus to apply the databainding
                Focusable.Focus();

                //InterpolationTypeComboBox.Focus();
                TimeTextBox.Focus();
            }
        }
예제 #6
0
        internal void StartEditing()
        {
            if (m_IsEditing)
            {
                return;
            }

            m_IsEditing       = true;
            m_TextField.value = m_Label.text;
            Remove(m_Label);
            Add(m_TextField);
            m_TextField.focusIndex = 0;
            m_PreviouslyFocused    = focusController.focusedElement;
            m_TextField.Focus();
        }
        internal void StartEditing()
        {
            if (m_IsEditing)
            {
                return;
            }

            m_IsEditing       = true;
            m_TextField.value = m_Label.text;
            Remove(m_Label);
            Add(m_TextField);
            UIElementHelper.SetFocusable(m_TextField);
            m_TextField.delegatesFocus = true;
            m_PreviouslyFocused        = focusController.focusedElement;
            m_TextField.Focus();
        }
예제 #8
0
    private void SetStage(int stage)
    {
        _focused      = null;
        _focusedIndex = 0;
        this.stage    = stage;
        foreach (var item in stage1Items)
        {
            item.SetActive(stage == 1);
        }

        foreach (var item in stage2Items)
        {
            item.SetActive(stage != 1);
        }

        Focus(_focusedIndex);
    }
예제 #9
0
        void OnResizerMouseDown(MouseDownEvent evt)
        {
            if (evt.button != (int)MouseButton.LeftMouse)
            {
                return;
            }

            m_IsMouseDownOnResizer = true;

            m_NewWindowPos      = position;
            m_OriginalWindowPos = position;
            m_OriginalMousePos  = evt.mousePosition;

            m_FocusedBefore = rootVisualElement.panel.focusController.focusedElement;

            m_SearcherControl.Resizer.RegisterCallback <MouseMoveEvent>(OnResizerMouseMove);
            m_SearcherControl.Resizer.RegisterCallback <KeyDownEvent>(OnSearcherKeyDown);
            m_SearcherControl.Resizer.CaptureMouse();
        }
예제 #10
0
        public FocusChangeDirection GetFocusChangeDirection(Focusable currentFocusable, EventBase e)
        {
            if (e.eventTypeId == PointerDownEvent.TypeId())
            {
                if (focusController.GetFocusableParentForPointerEvent(e.target as Focusable, out var target))
                {
                    return(VisualElementFocusChangeTarget.GetPooled(target));
                }
            }

            if (e.eventTypeId == NavigationMoveEvent.TypeId())
            {
                switch (((NavigationMoveEvent)e).direction)
                {
                case NavigationMoveEvent.Direction.Left: return(Left);

                case NavigationMoveEvent.Direction.Up: return(Up);

                case NavigationMoveEvent.Direction.Right: return(Right);

                case NavigationMoveEvent.Direction.Down: return(Down);
                }
            }
            //TODO: make NavigationTabEvent public and use it here
            else if (e.eventTypeId == KeyDownEvent.TypeId())
            {
                var kde = (KeyDownEvent)e;

                // Important: using KeyDownEvent.character for focus prevents a TextField bug.
                // IMGUI sends KeyDownEvent with keyCode != None, then it sends another one with character != '\0'.
                // If we use keyCode instead of character, TextField will receive focus on the first KeyDownEvent,
                // then text will become selected and, in the case of multiline, the KeyDownEvent with character = '\t'
                // will immediately overwrite the text with a single Tab string.
                if (kde.character == (char)25 || kde.character == '\t')
                {
                    return(kde.shiftKey ? Previous : Next);
                }
            }

            return(FocusChangeDirection.none);
        }
예제 #11
0
        public virtual Focusable GetNextFocusable(Focusable currentFocusable, FocusChangeDirection direction)
        {
            if (direction is VisualElementFocusChangeTarget changeTarget)
            {
                return(changeTarget.target);
            }

            if (direction == Next || direction == Previous)
            {
                return(m_Ring.GetNextFocusable(currentFocusable, direction == Next
                    ? VisualElementFocusChangeDirection.right
                    : VisualElementFocusChangeDirection.left));
            }

            if (direction == Up || direction == Down || direction == Right || direction == Left)
            {
                return(GetNextFocusable2D(currentFocusable, (ChangeDirection)direction));
            }

            return(currentFocusable);
        }
예제 #12
0
        Focusable GetNextFocusable2D(Focusable currentFocusable, ChangeDirection direction)
        {
            if (!(currentFocusable is VisualElement ve))
            {
                ve = m_Root;
            }

            ve = GetRootFocusable(ve);

            Rect panelBounds = m_Root.worldBoundingBox;
            Rect panelRect   = new Rect(panelBounds.position - Vector2.one, panelBounds.size + Vector2.one * 2);
            Rect rect        = ve.worldBound;
            Rect validRect   = new Rect(rect.position - Vector2.one, rect.size + Vector2.one * 2);

            if (direction == Up)
            {
                validRect.yMin = panelRect.yMin;
            }
            else if (direction == Down)
            {
                validRect.yMax = panelRect.yMax;
            }
            else if (direction == Left)
            {
                validRect.xMin = panelRect.xMin;
            }
            else if (direction == Right)
            {
                validRect.xMax = panelRect.xMax;
            }

            var best = new FocusableHierarchyTraversal
            {
                currentFocusable = ve,
                direction        = direction,
                validRect        = validRect,
                firstPass        = true
            }.GetBestOverall(m_Root);

            if (best != null)
            {
                return(GetLeafFocusable(best));
            }

            validRect = new Rect(rect.position - Vector2.one, rect.size + Vector2.one * 2);
            if (direction == Down)
            {
                validRect.yMin = panelRect.yMin;
            }
            else if (direction == Up)
            {
                validRect.yMax = panelRect.yMax;
            }
            else if (direction == Right)
            {
                validRect.xMin = panelRect.xMin;
            }
            else if (direction == Left)
            {
                validRect.xMax = panelRect.xMax;
            }

            best = new FocusableHierarchyTraversal
            {
                currentFocusable = ve,
                direction        = direction,
                validRect        = validRect,
                firstPass        = false
            }.GetBestOverall(m_Root);

            if (best != null)
            {
                return(GetLeafFocusable(best));
            }

            return(currentFocusable);
        }
예제 #13
0
 static bool IsLeaf(Focusable focusable)
 {
     return(!focusable.excludeFromFocusRing && !focusable.delegatesFocus);
 }
예제 #14
0
 static bool IsFocusable(Focusable focusable)
 {
     return(focusable.canGrabFocus && focusable.tabIndex >= 0);
 }
예제 #15
0
    // Update is called once per frame
    void Update()
    {
        RotateLookingObject();
        if (Physics.Raycast(_camera.transform.position, _camera.transform.forward, out var hit))
        {
            var ctrl = hit.transform.gameObject.GetComponent <Focusable>();
            if (ctrl)
            {
                if (ctrl.CanFocus)
                {
                    BlurAll();
                    ctrl.Focus();
                }

                _focused = ctrl;
            }
            else
            {
                BlurAll();
            }
        }

        var down = Input.GetAxis("Vertical") < -0.0001f;

        if (!_downPressedDown && down)
        {
            _downPressedDown = true;
            Focus(Math.Min(_focusedIndex + 1, CurrentStageItems().Length - 1));
        }

        if (!down && _downPressedDown)
        {
            _downPressedDown = false;
        }

        var up = Input.GetAxis("Vertical") > 0.0001f;

        if (!_upPressedDown && up)
        {
            _upPressedDown = true;
            Focus(Math.Max(_focusedIndex - 1, 0));
        }

        if (!up && _upPressedDown)
        {
            _upPressedDown = false;
        }

        var left = Input.GetAxis("Horizontal") < -0.0001f;

        if (!_leftPressedDown && left)
        {
            _leftPressedDown = true;
            if (_focused.TryGetComponent <SliderItemController>(out var slider))
            {
                slider.Decrement();
                if (slider.gameObject.name == "BoardSize")
                {
                    _size = slider.value;
                    _toWin.SetMax(slider.value);
                }
            }
        }

        if (!left && _leftPressedDown)
        {
            _leftPressedDown = false;
        }

        var right = Input.GetAxis("Horizontal") > 0.0001f;

        if (!_rightPressedDown && right)
        {
            _rightPressedDown = true;
            if (_focused.TryGetComponent <SliderItemController>(out var slider))
            {
                slider.Increment();

                if (slider.gameObject.name == "BoardSize")
                {
                    _size = slider.value;
                    _toWin.SetMax(slider.value);
                }
            }
        }

        if (!right && _rightPressedDown)
        {
            _rightPressedDown = false;
        }

        var click = Math.Abs(Input.GetAxis("Fire1")) > 0.0001f || Input.GetKey(KeyCode.Return);

        if (!_clickPressedDown && click && _focused && _focused.TryGetComponent <ButtonController>(out var btn))
        {
            _clickPressedDown = true;
            switch (btn.id)
            {
            case "exit":
                Application.Quit();
                break;

            case "new-game":
                SetStage(2);
                break;

            case "start-game-x":
            case "start-game-o":
                _gameCellType = btn.id == "start-game-x" ? CellType.X : CellType.O;
                SceneManager.LoadScene("MainScene");
                break;
            }
        }

        if (!click && _clickPressedDown)
        {
            _clickPressedDown = false;
        }
    }
예제 #16
0
        private VisualElement GetNextFocusable(Focusable focused, IEnumerable <VisualElement> elements, bool reverse)
        {
            var found = focused == null;

            return(GetNextFocusableRecursive(focused, elements, reverse, ref found));
        }